Magnolia 5.3 reached end of life on June 30, 2017. This branch is no longer supported, see End-of-life policy.
The SugarCRM module is connector for Customer Relationships Management System SugarCRM.
The SugarCRM connector module is not bundled with Magnolia. You can download it from our Nexus repository as magnolia-module-sugarcrm-1.0.1.jar, or include it in your custom webapp by adding following Maven dependency to your pom.
<dependency>
<groupId>info.magnolia.sugarcrm</groupId>
<artifactId>magnolia-module-sugarcrm</artifactId>
<version>1.0.1</version>
</dependency>
Make sure you're using the version 1.0.1 or higher. The passwords for Accounts created in version 1.0 are not compatible with newer versions.
SugarCRM is a Enterprise Edition module.
sugarcrm config clientSecret * clientId * adminUserPassword * adminUserName * rest-client sugarCrmHttpsClient class info.magnolia.resteasy.client.RestEasyClientDefinition baseUrl clientFactoryClass info.magnolia.resteasy.client.factory.RestEasyClientFactory commands dialogs templates traits https://YOUR_SUGAR_CRM_INSTANCE//rest/v10/
filters ... SugarCrmAccountAuthenticationFilter class info.magnolia.sugarcrm.filter.SugarCrmAccountAuthenticationFilter passwordFieldName password_c SugarCrmAccountDetectorFilter SugarCrmOpportunityDetectorFilter
The first think 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 | |||
Description | Constant in info.magnolia.sugarcrm.command.SugarCrmCommand | Default value | Available values |
---|---|---|---|
Path | PARAMETER_PATH = "sugarCrmPath" | Empty string | A string representing path after module name |
Method | PARAMETER_METHOD = "sugarCrmMethod" | Not defined | info.magnolia.sugarcrm.command.SugarCrmCommand# METHOD_GET / METHOD_PUT / METHOD_POST |
Request body | PARAMETER_BODY = "sugarCrmBody" | Empty body | an instance of org.codehaus.jackson.JsonNode |
public class MyClass { private final CommandsManager commandsManager; @Inject public MyClass(CommandsManager commandsManager) { this.commandsManager = commandsManager; } public JsonNode execute(final String command, final Map<String, Object> parameters) throws Exception { Map<String, Object> ctxParams = new HashMap<String, Object>(); ctxParams.put(SugarCrmCommand.PARAMETER_METHOD, SugarCrmCommand.METHOD_PUT); ctxParams.put(SugarCrmCommand.PARAMETER_PATH, MgnlContext.getAttribute(SugarCrmCommand.PARAMETER_USER_NAME, Context.SESSION_SCOPE)); ctxParams.put(SugarCrmCommand.PARAMETER_BODY, parameters); commandsManager.executeCommand(SugarCrmCommand.DEFAULT_SUGAR_CRM_CATALOG, command, new SimpleContext(ctxParams)); return ctxParams.get(SugarCrmCommand.PARAMETER_RESULT); }}
The samples contain traits for Personalisation module. Those are able to retrieve informations from SugarCRM to provide a personalised content. In this chapter is described on the provided samples how you can create a custom trait . If you've never created a personalised content in Magnolia, please follow Creating+custom+traits.
A SugarCRM trait is a wrapper for json response. Extend info.magnolia.sugarcrm.personalization.trait.AbstractSugarCrmTrait for every trait you want to create since traits are identified by their java classes.
public class SugarCrmAccount extends AbstractSugarCrmTrait { public SugarCrmAccount(JsonNode result) { super(result); } }
Extend info.magnolia.sugarcrm.personalization.detector.AbstractSugarCrmDetectorFilter to retrieve a trait. Set command in the constructor or via config tree. Don't forgot to order your custom trait detector filter after SugarCrmLoginLogoutFilter on installation. The provided sample for detection of the SugarCRM user account sends POST request to YOUR_SUGAR_CRM_INSTANCE/rest/v10/Accounts/filter with following body:
{ "filter":[ { "id":"YOUR_SUGARCRM_USER_ID" } ] }
public class SugarCrmAccountDetectorFilter extends AbstractSugarCrmDetectorFilter<SugarCrmAccount> { @Inject public SugarCrmAccountDetectorFilter(Provider<TraitCollector> traitCollectorProvider, CommandsManager commandsManager) { super(traitCollectorProvider, commandsManager); this.setCommand("SugarCrmAccountCommand"); } @Override protected SugarCrmAccount createTrait(JsonNode records) { return new SugarCrmAccount(records.path(0)); } @Override protected Map<String, Object> getFilter() { Map<String, Object> filter = new HashMap<String, Object>(); filter.put("id", MgnlContext.getAttribute(SugarCrmCommand.PARAMETER_USER_NAME, Context.SESSION_SCOPE)); return filter; } @Override protected Class<SugarCrmAccount> getTraitClass() { return SugarCrmAccount.class; } }
A trait voter decides if a certain page variant has to be served to the current user or not. There 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 in the following code:
public class SugarCrmSocialSitesVoter extends AbstractBoolVoter<TraitCollector> { 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 && !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; } }
Parameter converter is needed for Personalization#Personalization-Preview. It Converts String to a corresponding trait class holding a json and vice versa.
public class SugarCrmSocialSitesParameterConverter implements PreviewParameterConverter<Object> { @Override public SugarCrmAccount fromString(String string) { ObjectNode node = JsonNodeFactory.instance.objectNode(); if (string.contains(SugarCrmAccount.FIELD_FACEBOOK)) { node.put(SugarCrmAccount.FIELD_FACEBOOK, SugarCrmAccount.FIELD_FACEBOOK); } ... other social sites ... return new SugarCrmAccount(node); } @Override public String toString(Object object) { if (object instanceof LinkedHashSet) { LinkedHashSet set = (LinkedHashSet) object; if (set != null && !set.isEmpty()) { String[] parameters = (String[]) set.toArray(new String[set.size()]); return StringUtils.join(parameters, "-"); } } return null; } }