Page tree
Skip to end of metadata
Go to start of metadata

The SugarCRM module is connector for Customer Relationships Management System SugarCRM.

Installing

Maven is the easiest way to install the module. Add the following dependency to your bundle:

<dependency>
  <groupId>info.magnolia.sugarcrm</groupId>
  <artifactId>magnolia-module-sugarcrm</artifactId>
  <version>1.1.2</version>
</dependency>

Pre-built jars are also available for download. See Installing a module for help.

Configuration

  • Provide URL of your SugarCRM instance (config:/module/sugarcrm/rest-client/sugarCrmHttpClient/baseUrl).
  • Rest calls to SugarCRM need to be done as administrator. Please provide admin username and password (config:/module/sugarcrm/rest-client/config). More information about user authentication.

 sugarcrm

 

     config

 

         clientSecret

*

         clientId

*

         adminUserPassword

*

         adminUserName

*

     rest-client

 

         sugarCrmHttpsClient

 

             class

info.magnolia.resteasy.client.RestEasyClientDefinition

             baseUrl

https://YOUR_SUGAR_CRM_INSTANCE//rest/v10/

             clientFactoryClass

info.magnolia.resteasy.client.factory.RestEasyClientFactory

     commands

 

     dialogs

 

     templates

 

     traits

 

  • We need to authenticate Accounts to be able provide personalized content for them. Accounts are not logged into SugarCRM as Users but only into Magnolia context. You need to provide a custom text field to Accounts module via SugarCRM studio where the passwords will be stored. Define the name of this field under config:server/filters

 filters

 

    ...

 

     SugarCrmAccountAuthenticationFilter

 

         class

info.magnolia.sugarcrm.filter.SugarCrmAccountAuthenticationFilter

         passwordFieldName

password_c

     SugarCrmDetectorFilter

 

 

Sample pages

Commands

The first thing which we need is a command which performs rest calls to SugarCRM. You can use info.magnolia.sugarcrm.command.SugarCrmCommand class for the basic calls and set property module to the name of SugarCRM module. You need to pass method as a context attribute when executing such command. Other parameter such path and body are optional. You can see PUT rest call to YOUR_SUGAR_CRM_INSTANCE/rest/v10/Accounts/CURRENT_SUGARCRM_USER_ID  in the java code below:

 sugarcrm

 

     commands

 

         sugarCRM

 

             SugarCrmAccountCommand

 

                 class

info.magnolia.sugarcrm.command.SugarCrmCommand

                 module

Accounts

 

SugarCrmCommand parameters
DescriptionConstant in info.magnolia.sugarcrm.command.SugarCrmCommandDefault valueAvailable values
PathPARAMETER_PATH = "sugarCrmPath"Empty stringA string representing path after module name
MethodPARAMETER_METHOD = "sugarCrmMethod"Not defined

info.magnolia.sugarcrm.command.SugarCrmCommand#

METHOD_GET / METHOD_PUT / METHOD_POST

Request bodyPARAMETER_BODY = "sugarCrmBody"Empty bodyan instance of org.codehaus.jackson.JsonNode
public class MyTestClass {
    private final RestEasyCommandsManager commandsManager;
 
    @Inject
    public MyTestClass(RestEasyCommandsManager commandsManager) {
            this.commandsManager = commandsManager;
    }
    public JsonNode execute(final String command, final String path, final Map<String, Object> parameters) throws Exception {

            Map<String, Object> parameters = new HashMap<String, Object>();
            parameters.put(SugarCrmCommand.PARAMETER_METHOD, SugarCrmCommand.METHOD_PUT);
            parameters.put(SugarCrmCommand.PARAMETER_PATH, path);
            return this.getCommandsManager().executeCommand(SugarCrmCommand.DEFAULT_SUGAR_CRM_CATALOG, commandName, SugarCrmCommand.PARAMETER_RESULT, parameters);
    }}
}

Personalization

The samples contain traits for Personalization module. Those are able to retrieve information from SugarCRM to provide personalized content. In this chapter is described on the provided samples how you can create a custom trait . If you've never created personalized content in Magnolia, please follow Creating custom traits.

Trait detector

Is the filter which retrieves external information, for example the logged in Account information. You need to specify for each trait which you want to retrieve (e.g. Account, Opportunity...):

  • commandName which operates under related module (e.g Account module)
  • filter which is a map containing properties to filters records (e.g for Account it's only id of the logged in account, we can use variable {sugarCrmExternalName} which we'll be replaced with the name of logged in account before sending the request to the SugarCrm instance)
  • Specifying of fields is optional.  You can define a collection of properties which you want to retrieve. Otherwise all the properties will be retrieved which could result in requesting of unnecessary big amount of data.

 SugarCrmDetectorFilter

 

     class

info.magnolia.sugarcrm.personalization.SugarCrmDetectorFilter

     traitDetectorConfigs

 

         Account

 

             commandName

SugarCrmAccountCommand

             filter

 

                 id

{sugarCrmExternalName}

             fields

 

                 name

name

                 billing_address_country

billing_address_country

                 billing_address_city

billing_address_city

                 twitter

twitter

                 billing_address_state

billing_address_state

                 facebook

facebook

                 billing_address_street

billing_address_street

                 googleplus

googleplus

                 billing_address_postalcode

billing_address_postalcode

Trait voter

A trait voter decides if a certain page variant has to be served to the current user or not. There's no much difference between a SugarCRM trait voter and any other voter. You can see voter which checks if the detected user has a facebook account registered in his SugarCRM account with the following code:

public class SugarCrmAccountVoter extends SugarCrmVoter {
    private boolean facebook = false;

    @Override
    protected boolean boolVote(final TraitCollector traitCollector) {
        if (traitCollector != null) {
            final SugarCrmAccount records = traitCollector.getTrait(SugarCrmAccount.class);
            if (records == null) {
                return false;
            }
            JsonNode account = records.getNode();
            if (facebook &amp;&amp; !this.isSocialSiteRegistered(account, SugarCrmAccount.FIELD_FACEBOOK)) {
                return false;
            }
            ... other social sites ...
            return true;
        }
        return false;
    }
    private boolean isSocialSiteRegistered(JsonNode account, String socialSite) {
        return StringUtils.isNotBlank(account.path(socialSite).getTextValue());
    }
    public boolean isFacebook() {
        return facebook;
    }
    public void setFacebook(boolean facebook) {
        this.facebook = facebook;
    }
}

Preview parameter converter

Parameter converter is needed for Personalization#Personalization-Preview. It converts String to a corresponding trait class holding a json and vice versa.

public class SugarCrmAccountParameterConverter extends SugarCrmParameterConverter {
    @Override
    public SugarCrmTraits fromString(String string) {
        ArrayNode records = JsonNodeFactory.instance.arrayNode();
        String[] splitValue = StringUtils.split(string, "-");
        for (String entry: splitValue) {
            records.add(this.createRecord(entry, "Content doesn't matter, it can't be just empty"));
        }
        SugarCrmTraits traits = (SugarCrmTraits) this.getTraitClass();
        traits.put("Account", records);
        return traits;
    }
}

Sample traits

Read more