diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml index f083793083..5db8392b28 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml @@ -3,13 +3,18 @@ + + + parent="baseJsonConversionComponent" init-method="init"> + + + @@ -861,7 +866,7 @@ - + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java index 239af0c1ff..186409450f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java @@ -28,6 +28,10 @@ import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.JavaBehaviour; +import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.service.cmr.dictionary.DictionaryService; @@ -35,6 +39,9 @@ import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.PathUtil; import org.apache.commons.lang.ArrayUtils; @@ -46,7 +53,8 @@ import org.json.simple.JSONObject; * * @author Roy Wetherall */ -public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONConversionComponent +public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONConversionComponent implements NodeServicePolicies.OnDeleteNodePolicy, + NodeServicePolicies.OnCreateNodePolicy { /** Record service */ private RecordService recordService; @@ -60,12 +68,24 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC /** dictionary service */ private DictionaryService dictionaryService; + /** site service */ + private SiteService siteService; + /** Indicators */ private List indicators = new ArrayList(); /** Actions */ private List actions = new ArrayList(); + /** The policy component */ + private PolicyComponent policyComponent; + + /** JSON conversion component cache */ + private SimpleCache jsonConversionComponentCache; + + /** Constant for checking the cache */ + private static final String RM_SITE_EXISTS = "rmSiteExists"; + /** * @param recordService record service */ @@ -98,6 +118,14 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC this.dictionaryService = dictionaryService; } + /** + * @param siteService site service + */ + public void setSiteService(SiteService siteService) + { + this.siteService = siteService; + } + /** * @param indicator registered indicator */ @@ -114,6 +142,50 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC actions.add(action); } + /** + * @param policyComponent policy component + */ + public void setPolicyComponent(PolicyComponent policyComponent) + { + this.policyComponent = policyComponent; + } + + /** + * Gets the json conversion component cache + * + * @return The json conversion component cache + */ + protected SimpleCache getJsonConversionComponentCache() + { + return this.jsonConversionComponentCache; + } + + /** + * Sets the json conversion component cache + * + * @param jsonConversionComponentCache The json conversion component cache + */ + public void setJsonConversionComponentCache(SimpleCache jsonConversionComponentCache) + { + this.jsonConversionComponentCache = jsonConversionComponentCache; + } + + /** + * The initialise method + */ + public void init() + { + policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"), + RecordsManagementModel.TYPE_RM_SITE, + new JavaBehaviour(this, "onDeleteNode")); + + policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), + RecordsManagementModel.TYPE_RM_SITE, + new JavaBehaviour(this, "onCreateNode")); + } + /** * @see org.alfresco.repo.jscript.app.JSONConversionComponent#setRootValues(org.alfresco.service.cmr.model.FileInfo, * org.json.simple.JSONObject, boolean) @@ -127,6 +199,8 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC // Set the base root values super.setRootValues(nodeInfo, rootJSONObject, useShortQNames); + checkRmSiteExistence(rootJSONObject); + // Get the node reference for convenience NodeRef nodeRef = nodeInfo.getNodeRef(); @@ -148,6 +222,29 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC } } + @SuppressWarnings("unchecked") + private void checkRmSiteExistence(JSONObject rootJSONObject) + { + if (!getJsonConversionComponentCache().contains(RM_SITE_EXISTS)) + { + SiteInfo site = siteService.getSite(FilePlanService.DEFAULT_RM_SITE_ID); + if (site != null) + { + getJsonConversionComponentCache().put(RM_SITE_EXISTS, true); + rootJSONObject.put("isRmSiteCreated", true); + } + else + { + getJsonConversionComponentCache().put(RM_SITE_EXISTS, false); + rootJSONObject.put("isRmSiteCreated", false); + } + } + else + { + rootJSONObject.put("isRmSiteCreated", getJsonConversionComponentCache().get(RM_SITE_EXISTS)); + } + } + /** * Helper method to add information about node * @@ -286,20 +383,20 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC rmNodeValues.put("actions", jsonActions); } } - + /** * @see org.alfresco.repo.jscript.app.JSONConversionComponent#permissionsToJSON(org.alfresco.service.cmr.repository.NodeRef) */ protected JSONObject permissionsToJSON(final NodeRef nodeRef) { - JSONObject permissionsJSON = null; + JSONObject permissionsJSON = null; if (!filePlanService.isFilePlanComponent(nodeRef)) { permissionsJSON = super.permissionsToJSON(nodeRef); } else { - permissionsJSON = new JSONObject(); + permissionsJSON = new JSONObject(); } return permissionsJSON; } @@ -381,4 +478,22 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC return result; } + + /** + * @see org.alfresco.repo.node.NodeServicePolicies.OnDeleteNodePolicy#onDeleteNode(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) + */ + @Override + public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived) + { + getJsonConversionComponentCache().put(RM_SITE_EXISTS, false); + } + + /** + * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy#onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef) + */ + @Override + public void onCreateNode(ChildAssociationRef childAssocRef) + { + getJsonConversionComponentCache().put(RM_SITE_EXISTS, true); + } }