From 223a354b04b66af7706b8c2571b8bba9adb97e11 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Tue, 18 Dec 2012 07:19:37 +0000 Subject: [PATCH] RM-572 - Refactor: Filling action logic moved to Record Service * file and setup folder action removed in favour of services * disposition action methods consolidated in disposition service * vital record action methods consolidated in vital record service * unit test updates * other code fallout git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../model/recordsModel.xml | 3 +- .../rm-action-context.xml | 54 -- .../rm-service-context.xml | 32 +- .../RecordsManagementServiceImpl.java | 35 +- .../action/impl/FileAction.java | 168 ---- .../action/impl/SetupRecordFolderAction.java | 70 -- .../RecordsManagementAuditServiceImpl.java | 10 +- .../dataset/DataSetServiceImpl.java | 841 +++++++++--------- .../disposableitem/RecordFolderService.java | 30 + .../RecordFolderServiceImpl.java | 124 +++ .../disposableitem/RecordService.java | 19 +- .../disposableitem/RecordServiceImpl.java | 212 +++-- .../disposition/DispositionService.java | 20 +- .../disposition/DispositionServiceImpl.java | 174 +++- .../model/behaviour/RecordContainerType.java | 8 +- .../model/behaviour/RecordCopyBehaviours.java | 25 +- .../RecordsManagementSearchBehaviour.java | 23 +- .../script/BootstrapTestDataGet.java | 23 +- .../script/TransferReportPost.java | 6 +- .../vital/VitalRecordService.java | 6 +- .../vital/VitalRecordServiceImpl.java | 178 ++-- .../test/WebScriptTestSuite.java | 2 - .../test/action/CreateRecordActionTest.java | 86 ++ .../service/CapabilityServiceImplTest.java | 33 +- .../test/service/CreateRecordActionTest.java | 155 ---- .../test/service/RecordServiceImplTest.java | 182 ++-- .../service/VitalRecordServiceImplTest.java | 80 ++ .../test/util/BaseRMTestCase.java | 91 +- .../test/util/TestUtilities.java | 219 ----- .../BootstraptestDataRestApiTest.java | 79 -- 30 files changed, 1465 insertions(+), 1523 deletions(-) delete mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileAction.java delete mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/SetupRecordFolderAction.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderService.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderServiceImpl.java create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/CreateRecordActionTest.java delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CreateRecordActionTest.java delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml index 8fa9c83db3..30237164ee 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml @@ -254,7 +254,8 @@ cm:titled rma:recordComponentIdentifier rma:commonRecordDetails - rma:filePlanComponent + rma:filePlanComponent + diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml index b9957f7141..78e9836a8f 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml @@ -64,34 +64,6 @@ - - - - - - - - - - - - - - - - - - - org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction.execute=RM_ALLOW - org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction.*=RM_ALLOW - org.alfresco.repo.action.executer.ActionExecuter.*=RM_ALLOW - - - - - - - @@ -278,32 +250,6 @@ - - - - - - - - - - - - - - - - - - org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction.execute=RM_ALLOW - org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction.*=RM_ALLOW - org.alfresco.repo.action.executer.ActionExecuter.*=RM_ALLOW - - - - - - diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 7a9777937f..c19cdd615b 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -156,11 +156,12 @@ - + + @@ -966,21 +967,31 @@ + + + + + + + + - + + + - org.alfresco.module.org_alfresco_module_rm.record.RecordService + org.alfresco.module.org_alfresco_module_rm.disposableitem.RecordService @@ -1018,14 +1029,13 @@ diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java index 0869148a72..4081812ce8 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java @@ -175,13 +175,7 @@ public class RecordsManagementServiceImpl implements RecordsManagementService, */ public void init() { - // Register the association behaviours - policyComponent.bindAssociationBehaviour( - QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"), - TYPE_RECORD_FOLDER, - ContentModel.ASSOC_CONTAINS, - new JavaBehaviour(this, "onFileContent", NotificationFrequency.TRANSACTION_COMMIT)); - + // Register the association behaviours policyComponent.bindAssociationBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"), TYPE_FILE_PLAN, @@ -193,6 +187,7 @@ public class RecordsManagementServiceImpl implements RecordsManagementService, ContentModel.ASSOC_CONTAINS, new JavaBehaviour(this, "onAddContentToContainer", NotificationFrequency.EVERY_EVENT)); + // TODO move this into the record service policyComponent.bindAssociationBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"), ASPECT_RECORD, @@ -226,32 +221,6 @@ public class RecordsManagementServiceImpl implements RecordsManagementService, new JavaBehaviour(this, "onIdentifierUpdate", NotificationFrequency.TRANSACTION_COMMIT)); } - /** - * Try to file any record created in a record folder - * - * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) - */ - public void onFileContent(ChildAssociationRef childAssocRef, boolean bNew) - { - NodeRef nodeRef = childAssocRef.getChildRef(); - if (nodeService.exists(nodeRef) == true) - { - // Ensure that the filed item is cm:content - QName type = nodeService.getType(nodeRef); - if (ContentModel.TYPE_CONTENT.equals(type) == true || - dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) == true) - { - // File the document - rmActionService.executeRecordsManagementAction(childAssocRef.getChildRef(), "file"); - } - else - { - // Raise an exception since we should only be filling content into a record folder - throw new AlfrescoRuntimeException("Unable to complete operation, because only content can be filed within a record folder."); - } - } - } - /** * On add content to container * diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileAction.java deleted file mode 100644 index bcb0607e24..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileAction.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.action.impl; - -import java.io.Serializable; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; -import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordDefinition; -import org.alfresco.repo.action.ParameterDefinitionImpl; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ParameterDefinition; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.apache.commons.lang.StringUtils; - -/** - * Files a record into a particular record folder - * - * @author Roy Wetherall - */ -public class FileAction extends RMActionExecuterAbstractBase -{ - /** Parameter names */ - public static final String PARAM_RECORD_METADATA_ASPECTS = "recordMetadataAspects"; - - /** - * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) - */ - @SuppressWarnings("unchecked") - @Override - protected void executeImpl(Action action, NodeRef actionedUponNodeRef) - { - // Permissions perform the following checks so this action doesn't need to. - // - // check the record is within a folder - // check that the folder we are filing into is not closed - - // Get the optional list of record meta-data aspects - List recordMetadataAspects = (List)action.getParameterValue(PARAM_RECORD_METADATA_ASPECTS); - - // Add the record aspect (doesn't matter if it is already present) - if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD) == false) - { - nodeService.addAspect(actionedUponNodeRef, RecordsManagementModel.ASPECT_RECORD, null); - } - - // Get the records properties - Map recordProperties = this.nodeService.getProperties(actionedUponNodeRef); - - Calendar fileCalendar = Calendar.getInstance(); - if (recordProperties.get(RecordsManagementModel.PROP_IDENTIFIER) == null) - { - // Calculate the filed date and record identifier - String year = Integer.toString(fileCalendar.get(Calendar.YEAR)); - QName nodeDbid = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "node-dbid"); - String recordId = year + "-" + StringUtils.leftPad(recordProperties.get(nodeDbid).toString(), 10, "0"); - recordProperties.put(RecordsManagementModel.PROP_IDENTIFIER, recordId); - } - - // Update/set the date this record was refiled/filed - recordProperties.put(RecordsManagementModel.PROP_DATE_FILED, fileCalendar.getTime()); - - // Set the record properties - this.nodeService.setProperties(actionedUponNodeRef, recordProperties); - - // Apply any record meta-data aspects - if (recordMetadataAspects != null && recordMetadataAspects.size() != 0) - { - for (QName aspect : recordMetadataAspects) - { - nodeService.addAspect(actionedUponNodeRef, aspect, null); - } - } - - // Calculate the review schedule - VitalRecordDefinition viDef = vitalRecordService.getVitalRecordDefinition(actionedUponNodeRef); - if (viDef != null && viDef.isEnabled() == true) - { - Date reviewAsOf = viDef.getNextReviewDate(); - if (reviewAsOf != null) - { - Map reviewProps = new HashMap(1); - reviewProps.put(RecordsManagementModel.PROP_REVIEW_AS_OF, reviewAsOf); - - if (!nodeService.hasAspect(actionedUponNodeRef, ASPECT_VITAL_RECORD)) - { - this.nodeService.addAspect(actionedUponNodeRef, RecordsManagementModel.ASPECT_VITAL_RECORD, reviewProps); - } - else - { - Map props = nodeService.getProperties(actionedUponNodeRef); - props.putAll(reviewProps); - nodeService.setProperties(actionedUponNodeRef, props); - } - } - } - - // Get the disposition instructions for the actioned upon record - DispositionSchedule di = this.dispositionService.getDispositionSchedule(actionedUponNodeRef); - - // Set up the disposition schedule if the dispositions are being managed at the record level - if (di != null && di.isRecordLevelDisposition() == true) - { - // Setup the next disposition action - updateNextDispositionAction(actionedUponNodeRef); - } - } - - /** - * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) - */ - @Override - protected void addParameterDefinitions(List paramList) - { - // No parameters - paramList.add(new ParameterDefinitionImpl(PARAM_RECORD_METADATA_ASPECTS, DataTypeDefinition.QNAME, false, "Record Metadata Aspects", true)); - } - -// @Override -// public Set getProtectedAspects() -// { -// HashSet qnames = new HashSet(); -// qnames.add(ASPECT_RECORD); -// qnames.add(ASPECT_VITAL_RECORD); -// return qnames; -// } -// -// @Override -// public Set getProtectedProperties() -// { -// HashSet qnames = new HashSet(); -// qnames.add(PROP_DATE_FILED); -// qnames.add(PROP_REVIEW_AS_OF); -// return qnames; -// } - - @Override - protected boolean isExecutableImpl(NodeRef filePlanComponent, Map parameters, boolean throwException) - { - return true; - } - -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/SetupRecordFolderAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/SetupRecordFolderAction.java deleted file mode 100644 index ac1793448e..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/SetupRecordFolderAction.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.action.impl; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ParameterDefinition; -import org.alfresco.service.cmr.repository.NodeRef; - -/** - * Action to close the records folder - * - * @author Roy Wetherall - */ -public class SetupRecordFolderAction extends RMActionExecuterAbstractBase -{ - /** - * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) - */ - @Override - protected void executeImpl(Action action, NodeRef actionedUponNodeRef) - { - if (this.recordsManagementService.isRecordFolder(actionedUponNodeRef) == true) - { - // Set up the disposition schedule if the dispositions are being managed at the folder level - DispositionSchedule di = this.dispositionService.getDispositionSchedule(actionedUponNodeRef); - if (di != null && di.isRecordLevelDisposition() == false) - { - // Setup the next disposition action - updateNextDispositionAction(actionedUponNodeRef); - } - } - } - - /** - * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) - */ - @Override - protected void addParameterDefinitions(List paramList) - { - } - - @Override - protected boolean isExecutableImpl(NodeRef filePlanComponent, Map parameters, boolean throwException) - { - return true; - } - -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java index ed279bd596..f483d59f5e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java @@ -140,7 +140,6 @@ public class RecordsManagementAuditServiceImpl protected static final String AUDIT_TRAIL_FILE_PREFIX = "audit_"; protected static final String AUDIT_TRAIL_JSON_FILE_SUFFIX = ".json"; protected static final String AUDIT_TRAIL_HTML_FILE_SUFFIX = ".html"; - protected static final String FILE_ACTION = "file"; private PolicyComponent policyComponent; private DictionaryService dictionaryService; @@ -268,8 +267,6 @@ public class RecordsManagementAuditServiceImpl this.auditEvents.put(RM_AUDIT_EVENT_LOGIN_FAILURE, new AuditEvent(RM_AUDIT_EVENT_LOGIN_FAILURE, MSG_LOGIN_FAILED)); - this.auditEvents.put("file", - new AuditEvent("file", MSG_FILED_RECORD)); this.auditEvents.put("reviewed", new AuditEvent("reviewed", MSG_REVIEWED)); this.auditEvents.put("cutoff", @@ -282,8 +279,6 @@ public class RecordsManagementAuditServiceImpl new AuditEvent("openRecordFolder", MSG_OPENED_RECORD_FOLDER)); this.auditEvents.put("closeRecordFolder", new AuditEvent("closeRecordFolder", MSG_CLOSED_RECORD_FOLDER)); - this.auditEvents.put("setupRecordFolder", - new AuditEvent("setupRecordFolder", MSG_SETUP_RECORD_FOLDER)); this.auditEvents.put("declareRecord", new AuditEvent("declareRecord", MSG_DECLARED_RECORD)); this.auditEvents.put("undeclareRecord", @@ -994,10 +989,7 @@ public class RecordsManagementAuditServiceImpl ContentWriter writer = this.contentService.getWriter(record, ContentModel.PROP_CONTENT, true); writer.setMimetype(format == ReportFormat.HTML ? MimetypeMap.MIMETYPE_HTML : MimetypeMap.MIMETYPE_JSON); writer.setEncoding("UTF-8"); - writer.putContent(auditTrail); - - // file the node as a record - this.rmActionService.executeRecordsManagementAction(record, FILE_ACTION); + writer.putContent(auditTrail); } finally { diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/dataset/DataSetServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/dataset/DataSetServiceImpl.java index d7ba5dbf28..3377921ded 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/dataset/DataSetServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/dataset/DataSetServiceImpl.java @@ -17,6 +17,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.disposableitem.RecordFolderServiceImpl; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; @@ -38,475 +39,479 @@ import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; -public class DataSetServiceImpl implements DataSetService, RecordsManagementModel +public class DataSetServiceImpl implements DataSetService, RecordsManagementModel, ApplicationContextAware { - /** Logger */ - private static Log logger = LogFactory.getLog(DataSetServiceImpl.class); + /** Logger */ + private static Log logger = LogFactory.getLog(DataSetServiceImpl.class); - /** Registered data set implementations */ - private Map dataSets = new HashMap(); + /** Registered data set implementations */ + private Map dataSets = new HashMap(); - /** Spaces store */ - private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, - "SpacesStore"); + /** Spaces store */ + private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); - /** Importer service */ - private ImporterService importerService; + /** Importer service */ + private ImporterService importerService; - /** Search service */ - private SearchService searchService; + /** Search service */ + private SearchService searchService; - /** Node service */ - private NodeService nodeService; + /** Node service */ + private NodeService nodeService; - /** Records management service */ - private RecordsManagementService recordsManagementService; + /** Records management service */ + private RecordsManagementService recordsManagementService; - /** Records management action service */ - private RecordsManagementActionService recordsManagementActionService; + /** Records management action service */ + private RecordsManagementActionService recordsManagementActionService; - /** Permission service */ - private PermissionService permissionService; + /** Permission service */ + private PermissionService permissionService; - /** Authority service */ - private AuthorityService authorityService; + /** Authority service */ + private AuthorityService authorityService; - /** Records management security service */ - private RecordsManagementSecurityService recordsManagementSecurityService; + /** Records management security service */ + private RecordsManagementSecurityService recordsManagementSecurityService; - /** Records management search behaviour */ - private RecordsManagementSearchBehaviour recordsManagementSearchBehaviour; + /** Records management search behaviour */ + private RecordsManagementSearchBehaviour recordsManagementSearchBehaviour; - /** Disposition service */ - private DispositionService dispositionService; + /** Disposition service */ + private DispositionService dispositionService; - /** - * Set importer service - * - * @param importerService the importer service - */ - public void setImporterService(ImporterService importerService) - { - this.importerService = importerService; - } + /** Application context */ + private ApplicationContext applicationContext; - /** - * Set search service - * - * @param searchService the search service - */ - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } + /** + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.applicationContext = applicationContext; + } - /** - * Set node service - * - * @param nodeService the node service - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } + /** + * Set importer service + * + * @param importerService the importer service + */ + public void setImporterService(ImporterService importerService) + { + this.importerService = importerService; + } - /** - * Set records management service - * - * @param recordsManagementService the records management service - */ - public void setRecordsManagementService(RecordsManagementService recordsManagementService) - { - this.recordsManagementService = recordsManagementService; - } + /** + * Set search service + * + * @param searchService the search service + */ + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } - /** - * Set records management action service - * - * @param recordsManagementActionService the records management action - * service - */ - public void setRecordsManagementActionService( - RecordsManagementActionService recordsManagementActionService) - { - this.recordsManagementActionService = recordsManagementActionService; - } + /** + * Set node service + * + * @param nodeService the node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } - /** - * Set permission service - * - * @param permissionService the permission service - */ - public void setPermissionService(PermissionService permissionService) - { - this.permissionService = permissionService; - } + /** + * Set records management service + * + * @param recordsManagementService the records management service + */ + public void setRecordsManagementService(RecordsManagementService recordsManagementService) + { + this.recordsManagementService = recordsManagementService; + } - /** - * Set authority service - * - * @param authorityService the authority service - */ - public void setAuthorityService(AuthorityService authorityService) - { - this.authorityService = authorityService; - } + /** + * Set records management action service + * + * @param recordsManagementActionService the records management action + * service + */ + public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService) + { + this.recordsManagementActionService = recordsManagementActionService; + } - /** - * Set records management security service - * - * @param recordsManagementSecurityService the records management security - * service - */ - public void setRecordsManagementSecurityService( - RecordsManagementSecurityService recordsManagementSecurityService) - { - this.recordsManagementSecurityService = recordsManagementSecurityService; - } + /** + * Set permission service + * + * @param permissionService the permission service + */ + public void setPermissionService(PermissionService permissionService) + { + this.permissionService = permissionService; + } - /** - * Set records management search behaviour - * - * @param recordsManagementSearchBehaviour the records management search - * behaviour - */ - public void setRecordsManagementSearchBehaviour( - RecordsManagementSearchBehaviour recordsManagementSearchBehaviour) - { - this.recordsManagementSearchBehaviour = recordsManagementSearchBehaviour; - } + /** + * Set authority service + * + * @param authorityService the authority service + */ + public void setAuthorityService(AuthorityService authorityService) + { + this.authorityService = authorityService; + } - /** - * Set disposition service - * - * @param dispositionService the disposition service - */ - public void setDispositionService(DispositionService dispositionService) - { - this.dispositionService = dispositionService; - } + /** + * Set records management security service + * + * @param recordsManagementSecurityService the records management security + * service + */ + public void setRecordsManagementSecurityService(RecordsManagementSecurityService recordsManagementSecurityService) + { + this.recordsManagementSecurityService = recordsManagementSecurityService; + } - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#register(org.alfresco.module.org_alfresco_module_rm.dataset.DataSet) - */ - @Override - public void register(DataSet dataSet) - { - ParameterCheck.mandatory("dataSet", dataSet); + /** + * Set records management search behaviour + * + * @param recordsManagementSearchBehaviour the records management search + * behaviour + */ + public void setRecordsManagementSearchBehaviour(RecordsManagementSearchBehaviour recordsManagementSearchBehaviour) + { + this.recordsManagementSearchBehaviour = recordsManagementSearchBehaviour; + } - this.dataSets.put(dataSet.getId(), dataSet); - } + /** + * Set disposition service + * + * @param dispositionService the disposition service + */ + public void setDispositionService(DispositionService dispositionService) + { + this.dispositionService = dispositionService; + } - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getDataSets() - */ - @Override - public Map getDataSets() - { - return this.dataSets; - } + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#register(org.alfresco.module.org_alfresco_module_rm.dataset.DataSet) + */ + @Override + public void register(DataSet dataSet) + { + ParameterCheck.mandatory("dataSet", dataSet); - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getDataSets(NodeRef, - * boolean) - */ - @Override - public Map getDataSets(NodeRef filePlan, boolean excludeLoaded) - { - ParameterCheck.mandatory("filePlan", filePlan); - ParameterCheck.mandatory("excludeLoaded", excludeLoaded); + this.dataSets.put(dataSet.getId(), dataSet); + } - // Get the list of all available data sets - Map dataSets = new HashMap(getDataSets()); + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getDataSets() + */ + @Override + public Map getDataSets() + { + return this.dataSets; + } - // Should the list of unloaded data sets be retrieved - if (excludeLoaded) - { - dataSets.keySet().removeAll(getLoadedDataSets(filePlan).keySet()); - } + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getDataSets(NodeRef, + * boolean) + */ + @Override + public Map getDataSets(NodeRef filePlan, boolean excludeLoaded) + { + ParameterCheck.mandatory("filePlan", filePlan); + ParameterCheck.mandatory("excludeLoaded", excludeLoaded); - // Return the (filtered) list of data sets - return dataSets; - } + // Get the list of all available data sets + Map dataSets = new HashMap(getDataSets()); - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#loadDataSet(java.lang.String, - * org.alfresco.service.cmr.repository.NodeRef) - */ - @Override - public void loadDataSet(NodeRef filePlan, String dataSetId) - { - ParameterCheck.mandatory("filePlan", filePlan); - ParameterCheck.mandatoryString("dataSetId", dataSetId); + // Should the list of unloaded data sets be retrieved + if (excludeLoaded) + { + dataSets.keySet().removeAll(getLoadedDataSets(filePlan).keySet()); + } - // Get the data set - DataSet dataSet = getDataSets().get(dataSetId); + // Return the (filtered) list of data sets + return dataSets; + } - // Import the RM test data ACP into the the provided file plan node reference - InputStream is = null; - try - { - is = getClass().getClassLoader().getResourceAsStream(dataSet.getPath()); - if (is == null) - { - throw new AlfrescoRuntimeException("The '" + dataSet.getLabel() - + "' import file could not be found!"); - } - - // Import view - Reader viewReader = new InputStreamReader(is); - Location location = new Location(filePlan); - importerService.importView(viewReader, location, null, null); + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#loadDataSet(java.lang.String, + * org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public void loadDataSet(NodeRef filePlan, String dataSetId) + { + ParameterCheck.mandatory("filePlan", filePlan); + ParameterCheck.mandatoryString("dataSetId", dataSetId); - // Patch data - patchLoadedData(); + // Get the data set + DataSet dataSet = getDataSets().get(dataSetId); - // Set the data set id into the file plan's custom aspect - setDataSetIdIntoFilePlan(dataSetId, filePlan); - } - catch (Exception ex) - { - throw new RuntimeException("Unexpected exception thrown. Please refer to the log files for details.", ex); - } - finally - { - if (is != null) - { - try + // Import the RM test data ACP into the the provided file plan node + // reference + InputStream is = null; + try + { + is = getClass().getClassLoader().getResourceAsStream(dataSet.getPath()); + if (is == null) { throw new AlfrescoRuntimeException("The '" + dataSet.getLabel() + + "' import file could not be found!"); } + + // Import view + Reader viewReader = new InputStreamReader(is); + Location location = new Location(filePlan); + importerService.importView(viewReader, location, null, null); + + // Patch data + patchLoadedData(); + + // Set the data set id into the file plan's custom aspect + setDataSetIdIntoFilePlan(dataSetId, filePlan); + } + catch (Exception ex) + { + throw new RuntimeException("Unexpected exception thrown. Please refer to the log files for details.", ex); + } + finally + { + if (is != null) { - is.close(); - is = null; + try + { + is.close(); + is = null; + } + catch (IOException ex) + { + throw new RuntimeException("Failed to close the input stream!", ex); + } } - catch (IOException ex) + } + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#existsDataSet(java.lang.String) + */ + @Override + public boolean existsDataSet(String dataSetId) + { + ParameterCheck.mandatoryString("dataSetId", dataSetId); + + return getDataSets().containsKey(dataSetId); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getLoadedDataSets(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public Map getLoadedDataSets(NodeRef filePlan) + { + ParameterCheck.mandatory("filePlan", filePlan); + + // Get the list of available data sets + Map availableDataSets = new HashMap(getDataSets()); + + // Get the property value of the aspect + Serializable dataSetIds = nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS); + // Check if any data has been loaded before + if (dataSetIds != null) + { + // Filter the data sets which have already been loaded + @SuppressWarnings("unchecked") + ArrayList loadedDataSetIds = (ArrayList) dataSetIds; + Iterator> iterator = availableDataSets.entrySet().iterator(); + while (iterator.hasNext()) { - throw new RuntimeException("Failed to close the input stream!", ex); + Entry entry = iterator.next(); + String key = entry.getKey(); + if (!loadedDataSetIds.contains(key)) + { + iterator.remove(); + } } - } - } - } + return availableDataSets; + } - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#existsDataSet(java.lang.String) - */ - @Override - public boolean existsDataSet(String dataSetId) - { - ParameterCheck.mandatoryString("dataSetId", dataSetId); + return new HashMap(); + } - return getDataSets().containsKey(dataSetId); - } + /** + * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#isLoadedDataSet(org.alfresco.service.cmr.repository.NodeRef, + * java.lang.String) + */ + @Override + public boolean isLoadedDataSet(NodeRef filePlan, String dataSetId) + { + ParameterCheck.mandatory("filePlan", filePlan); + ParameterCheck.mandatory("dataSetId", dataSetId); - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getLoadedDataSets(org.alfresco.service.cmr.repository.NodeRef) - */ - @Override - public Map getLoadedDataSets(NodeRef filePlan) - { - ParameterCheck.mandatory("filePlan", filePlan); + return getLoadedDataSets(filePlan).containsKey(dataSetId); + } - // Get the list of available data sets - Map availableDataSets = new HashMap(getDataSets()); - - // Get the property value of the aspect - Serializable dataSetIds = nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS); - // Check if any data has been loaded before - if (dataSetIds != null) - { - // Filter the data sets which have already been loaded - @SuppressWarnings("unchecked") - ArrayList loadedDataSetIds = (ArrayList) dataSetIds; - Iterator> iterator = availableDataSets.entrySet().iterator(); - while (iterator.hasNext()) - { - Entry entry = iterator.next(); - String key = entry.getKey(); - if (!loadedDataSetIds.contains(key)) + /** + * Temp method to patch AMP'ed data + * + * @param searchService + * @param nodeService + * @param recordsManagementService + * @param recordsManagementActionService + */ + private void patchLoadedData() + { + AuthenticationUtil.RunAsWork runAsWork = new AuthenticationUtil.RunAsWork() + { + public Object doWork() throws Exception { - iterator.remove(); + java.util.List rmRoots = recordsManagementService.getFilePlans(); + logger.info("Bootstraping " + rmRoots.size() + " rm roots ..."); + for (NodeRef rmRoot : rmRoots) + { + if (permissionService.getInheritParentPermissions(rmRoot) == true) + { + logger.info("Updating permissions for rm root: " + rmRoot); + permissionService.setInheritParentPermissions(rmRoot, false); + } + + String allRoleShortName = "AllRoles" + rmRoot.getId(); + String allRoleGroupName = authorityService.getName(AuthorityType.GROUP, allRoleShortName); + + if (authorityService.authorityExists(allRoleGroupName) == false) + { + logger.info("Creating all roles group for root node: " + rmRoot.toString()); + + // Create "all" role group for root node + String allRoles = authorityService.createAuthority(AuthorityType.GROUP, allRoleShortName, + "All Roles", null); + + // Put all the role groups in it + Set roles = recordsManagementSecurityService.getRoles(rmRoot); + for (Role role : roles) + { + logger.info(" - adding role group " + role.getRoleGroupName() + " to all roles group"); + authorityService.addAuthority(allRoles, role.getRoleGroupName()); + } + + // Set the permissions + permissionService.setPermission(rmRoot, allRoles, RMPermissionModel.READ_RECORDS, true); + } + } + + // Make sure all the containers do not inherit permissions + ResultSet rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, + "TYPE:\"rma:recordsManagementContainer\""); + try + { + logger.info("Bootstraping " + rs.length() + " record containers ..."); + + for (NodeRef container : rs.getNodeRefs()) + { + String containerName = (String) nodeService.getProperty(container, ContentModel.PROP_NAME); + + // Set permissions + if (permissionService.getInheritParentPermissions(container) == true) + { + logger.info("Updating permissions for record container: " + containerName); + permissionService.setInheritParentPermissions(container, false); + } + } + } + finally + { + rs.close(); + } + + // fix up the test dataset to fire initial events for + // disposition + // schedules + rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"rma:recordFolder\""); + try + { + logger.info("Bootstraping " + rs.length() + " record folders ..."); + + for (NodeRef recordFolder : rs.getNodeRefs()) + { + String folderName = (String) nodeService.getProperty(recordFolder, ContentModel.PROP_NAME); + + // Set permissions + if (permissionService.getInheritParentPermissions(recordFolder) == true) + { + logger.info("Updating permissions for record folder: " + folderName); + permissionService.setInheritParentPermissions(recordFolder, false); + } + + if (nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE) == false) + { + // See if the folder has a disposition schedule that + // needs + // to be applied + DispositionSchedule ds = dispositionService.getDispositionSchedule(recordFolder); + if (ds != null) + { + // Fire action to "set-up" the folder correctly + logger.info("Setting up bootstraped record folder: " + folderName); + RecordFolderServiceImpl recordService = (RecordFolderServiceImpl)applicationContext.getBean("recordFolderService"); + recordService.initialiseRecordFolder(recordFolder); + } + } + + // fixup the search behaviour aspect for the record + // folder + logger.info("Setting up search aspect for record folder: " + folderName); + recordsManagementSearchBehaviour.fixupSearchAspect(recordFolder); + } + } + finally + { + rs.close(); + } + + return null; } - } - return availableDataSets; - } + }; - return new HashMap(); - } + AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName()); - /** - * @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#isLoadedDataSet(org.alfresco.service.cmr.repository.NodeRef, - * java.lang.String) - */ - @Override - public boolean isLoadedDataSet(NodeRef filePlan, String dataSetId) - { - ParameterCheck.mandatory("filePlan", filePlan); - ParameterCheck.mandatory("dataSetId", dataSetId); + } - return getLoadedDataSets(filePlan).containsKey(dataSetId); - } + /** + * Helper method for setting the id of the imported data set into the file + * plan's aspect + * + * @param dataSetId The id of the imported data set + * @param filePlan The file plan into which the data set has been imported + */ + @SuppressWarnings("unchecked") + private void setDataSetIdIntoFilePlan(String dataSetId, NodeRef filePlan) + { + ArrayList loadedDataSetIds; + Serializable dataSetIds = nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS); - /** - * Temp method to patch AMP'ed data - * - * @param searchService - * @param nodeService - * @param recordsManagementService - * @param recordsManagementActionService - */ - private void patchLoadedData() - { - AuthenticationUtil.RunAsWork runAsWork = new AuthenticationUtil.RunAsWork() - { - public Object doWork() throws Exception - { - java.util.List rmRoots = recordsManagementService.getFilePlans(); - logger.info("Bootstraping " + rmRoots.size() + " rm roots ..."); - for (NodeRef rmRoot : rmRoots) - { - if (permissionService.getInheritParentPermissions(rmRoot) == true) - { - logger.info("Updating permissions for rm root: " + rmRoot); - permissionService.setInheritParentPermissions(rmRoot, false); - } + // Check if any data set has been imported + if (dataSetIds == null) + { + Map aspectProperties = new HashMap(1); + aspectProperties.put(PROP_LOADED_DATA_SET_IDS, (Serializable) new ArrayList()); + nodeService.addAspect(filePlan, ASPECT_LOADED_DATA_SET_ID, aspectProperties); + loadedDataSetIds = (ArrayList) nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS); + } + else + { + loadedDataSetIds = (ArrayList) dataSetIds; + } - String allRoleShortName = "AllRoles" + rmRoot.getId(); - String allRoleGroupName = authorityService.getName(AuthorityType.GROUP, - allRoleShortName); - - if (authorityService.authorityExists(allRoleGroupName) == false) - { - logger.info("Creating all roles group for root node: " + rmRoot.toString()); - - // Create "all" role group for root node - String allRoles = authorityService.createAuthority(AuthorityType.GROUP, - allRoleShortName, "All Roles", null); - - // Put all the role groups in it - Set roles = recordsManagementSecurityService.getRoles(rmRoot); - for (Role role : roles) - { - logger.info(" - adding role group " + role.getRoleGroupName() - + " to all roles group"); - authorityService.addAuthority(allRoles, role.getRoleGroupName()); - } - - // Set the permissions - permissionService.setPermission(rmRoot, allRoles, RMPermissionModel.READ_RECORDS, - true); - } - } - - // Make sure all the containers do not inherit permissions - ResultSet rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, - "TYPE:\"rma:recordsManagementContainer\""); - try - { - logger.info("Bootstraping " + rs.length() + " record containers ..."); - - for (NodeRef container : rs.getNodeRefs()) - { - String containerName = (String) nodeService.getProperty(container, - ContentModel.PROP_NAME); - - // Set permissions - if (permissionService.getInheritParentPermissions(container) == true) - { - logger.info("Updating permissions for record container: " + containerName); - permissionService.setInheritParentPermissions(container, false); - } - } - } - finally - { - rs.close(); - } - - // fix up the test dataset to fire initial events for disposition - // schedules - rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, - "TYPE:\"rma:recordFolder\""); - try - { - logger.info("Bootstraping " + rs.length() + " record folders ..."); - - for (NodeRef recordFolder : rs.getNodeRefs()) - { - String folderName = (String) nodeService.getProperty(recordFolder, - ContentModel.PROP_NAME); - - // Set permissions - if (permissionService.getInheritParentPermissions(recordFolder) == true) - { - logger.info("Updating permissions for record folder: " + folderName); - permissionService.setInheritParentPermissions(recordFolder, false); - } - - if (nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE) == false) - { - // See if the folder has a disposition schedule that needs - // to be applied - DispositionSchedule ds = dispositionService - .getDispositionSchedule(recordFolder); - if (ds != null) - { - // Fire action to "set-up" the folder correctly - logger.info("Setting up bootstraped record folder: " + folderName); - recordsManagementActionService.executeRecordsManagementAction(recordFolder, - "setupRecordFolder"); - } - } - - // fixup the search behaviour aspect for the record folder - logger.info("Setting up search aspect for record folder: " + folderName); - recordsManagementSearchBehaviour.fixupSearchAspect(recordFolder); - } - } - finally - { - rs.close(); - } - - return null; - } - }; - - AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName()); - - } - - /** - * Helper method for setting the id of the imported data set into the file - * plan's aspect - * - * @param dataSetId The id of the imported data set - * @param filePlan The file plan into which the data set has been imported - */ - @SuppressWarnings("unchecked") - private void setDataSetIdIntoFilePlan(String dataSetId, NodeRef filePlan) - { - ArrayList loadedDataSetIds; - Serializable dataSetIds = nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS); - - // Check if any data set has been imported - if (dataSetIds == null) - { - Map aspectProperties = new HashMap(1); - aspectProperties.put(PROP_LOADED_DATA_SET_IDS, (Serializable) new ArrayList()); - nodeService.addAspect(filePlan, ASPECT_LOADED_DATA_SET_ID, aspectProperties); - loadedDataSetIds = (ArrayList) nodeService.getProperty(filePlan, - PROP_LOADED_DATA_SET_IDS); - } - else - { - loadedDataSetIds = (ArrayList) dataSetIds; - } - - // Add the new loaded data set id - loadedDataSetIds.add(dataSetId); - Map aspectProperties = new HashMap(1); - aspectProperties.put(PROP_LOADED_DATA_SET_IDS, (Serializable) loadedDataSetIds); - nodeService.addAspect(filePlan, ASPECT_LOADED_DATA_SET_ID, aspectProperties); - } + // Add the new loaded data set id + loadedDataSetIds.add(dataSetId); + Map aspectProperties = new HashMap(1); + aspectProperties.put(PROP_LOADED_DATA_SET_IDS, (Serializable) loadedDataSetIds); + nodeService.addAspect(filePlan, ASPECT_LOADED_DATA_SET_ID, aspectProperties); + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderService.java new file mode 100644 index 0000000000..fa119df470 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderService.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm.disposableitem; + +/** + * Record folder service interface + * + * @author Roy Wetherall + * @since 2.1 + */ +public interface RecordFolderService +{ + +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderServiceImpl.java new file mode 100644 index 0000000000..2a06648e16 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordFolderServiceImpl.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm.disposableitem; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.JavaBehaviour; +import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; + +/** + * Record Folder Service Implementation + * + * @author Roy Wetherall + * @since 2.1 + */ +public class RecordFolderServiceImpl implements RecordFolderService, + RecordsManagementModel, + NodeServicePolicies.OnCreateChildAssociationPolicy +{ + /** Policy component */ + private PolicyComponent policyComponent; + + /** Node service */ + private NodeService nodeService; + + /** Disposition service */ + private DispositionService dispositionService; + + /** Behaviours */ + private JavaBehaviour onCreateChildAssociation = new JavaBehaviour( + this, + "onCreateChildAssociation", + NotificationFrequency.FIRST_EVENT); + + /** + * @param policyComponent policy component + */ + public void setPolicyComponent(PolicyComponent policyComponent) + { + this.policyComponent = policyComponent; + } + + /** + * @param nodeService node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * @param dispositionService disposition service + */ + public void setDispositionService(DispositionService dispositionService) + { + this.dispositionService = dispositionService; + } + + /** + * Init method + */ + public void init() + { + policyComponent.bindAssociationBehaviour( + NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME, + TYPE_RECORD_CATEGORY, + ContentModel.ASSOC_CONTAINS, + onCreateChildAssociation); + } + + /** + * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) + */ + @Override + public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) + { + NodeRef nodeRef = childAssocRef.getChildRef(); + if (nodeService.exists(nodeRef) == true) + { + initialiseRecordFolder(nodeRef); + } + } + + /** + * + * @param nodeRef + */ + public void initialiseRecordFolder(NodeRef nodeRef) + { + // initialise disposition details + if (nodeService.hasAspect(nodeRef, ASPECT_DISPOSITION_LIFECYCLE) == false) + { + DispositionSchedule di = dispositionService.getDispositionSchedule(nodeRef); + if (di != null && di.isRecordLevelDisposition() == false) + { + nodeService.addAspect(nodeRef, ASPECT_DISPOSITION_LIFECYCLE, null); + } + } + } + +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordService.java index 869bf59268..6a4001b5fd 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordService.java @@ -32,7 +32,7 @@ import org.alfresco.service.namespace.QName; */ public interface RecordService { - /** + /** * Gets a list of all the record meta-data aspects * * @return {@link Set}<{@link QName}> list of record meta-data aspects @@ -55,14 +55,7 @@ public interface RecordService */ boolean isDeclared(NodeRef nodeRef); - /** - * Indicates whether the record is filed or not - * - * @param nodeRef record - * @return boolean true if filed, false otherwise - */ - boolean isFiled(NodeRef nodeRef); - + // TODO move to filePlan service /** * Gets the unfiled root container for the given file plan * @@ -80,10 +73,10 @@ public interface RecordService void createRecord(NodeRef filePlan, NodeRef nodeRef); /** - * Files an unfiled record. + * Indicates whether the record is filed or not * - * @param record record - * @param recordFolder record folder + * @param nodeRef record + * @return boolean true if filed, false otherwise */ - void fileRecord(NodeRef record, NodeRef recordFolder); + boolean isFiled(NodeRef record); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordServiceImpl.java index 22fbd7cde6..31f0304c01 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposableitem/RecordServiceImpl.java @@ -18,6 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.disposableitem; +import java.util.Calendar; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -26,9 +27,16 @@ import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; +import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordServiceImpl; +import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.JavaBehaviour; +import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.permissions.AccessDeniedException; @@ -42,6 +50,9 @@ import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.ParameterCheck; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; /** * Record service implementation @@ -49,12 +60,18 @@ import org.alfresco.util.ParameterCheck; * @author Roy Wetherall * @since 2.1 */ -public class RecordServiceImpl implements RecordService, RecordsManagementModel +public class RecordServiceImpl implements RecordService, + RecordsManagementModel, + NodeServicePolicies.OnCreateChildAssociationPolicy, + ApplicationContextAware { + /** Application context */ + private ApplicationContext applicationContext; + /** Node service **/ private NodeService nodeService; - /** Indentiy service */ + /** Indentity service */ private IdentifierService identifierService; /** Dictionary service */ @@ -68,10 +85,28 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel /** Records management service */ private RecordsManagementService recordsManagementService; + + /** Disposition service */ + private DispositionService dispositionService; + + /** Policy component */ + private PolicyComponent policyComponent; /** List of available record meta-data aspects */ private Set recordMetaDataAspects; + + /** Behaviours */ + private JavaBehaviour onCreateChildAssociation = new JavaBehaviour( + this, + "onCreateChildAssociation", + NotificationFrequency.FIRST_EVENT); + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.applicationContext = applicationContext; + } + /** * @param nodeService node service */ @@ -120,14 +155,50 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel this.recordsManagementService = recordsManagementService; } + /** + * @param dispositionService disposition service + */ + public void setDispositionService(DispositionService dispositionService) + { + this.dispositionService = dispositionService; + } + + /** + * @param policyComponent policy component + */ + public void setPolicyComponent(PolicyComponent policyComponent) + { + this.policyComponent = policyComponent; + } + /** * Init method */ public void init() { - // TODO + policyComponent.bindAssociationBehaviour( + NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME, + TYPE_RECORD_FOLDER, + ContentModel.ASSOC_CONTAINS, + onCreateChildAssociation); } + /** + * Behaviour executed when a new item is added to a record folder. + * + * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) + */ + @Override + public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) + { + NodeRef nodeRef = childAssocRef.getChildRef(); + if (nodeService.exists(nodeRef) == true) + { + // create and file the content as a record + file(nodeRef); + } + } + /** * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#getRecordMetaDataAspects() */ @@ -176,33 +247,7 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel return nodeService.hasAspect(record, ASPECT_DECLARED_RECORD); } - /** - * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#isFiled(org.alfresco.service.cmr.repository.NodeRef) - */ - @Override - public boolean isFiled(NodeRef nodeRef) - { - ParameterCheck.mandatory("nodeRef", nodeRef); - - boolean result = false; - - if (isRecord(nodeRef) == true) - { - ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(nodeRef); - if (childAssocRef != null) - { - NodeRef parent = childAssocRef.getParentRef(); - if (parent != null && - recordsManagementService.isRecordFolder(parent) == true) - { - result = true; - } - } - } - - return result; - } - + /** * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#getUnfiledRootContainer(org.alfresco.service.cmr.repository.NodeRef) */ @@ -292,38 +337,7 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel }); } } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#fileRecord(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef) - */ - @Override - public void fileRecord(NodeRef record, NodeRef recordFolder) - { - // check if this is a record - if (isRecord(record) == false) - { - // TODO .. should we make this a record? - throw new UnsupportedOperationException("Currently unable to file something that isn't already a record"); - } - - if (isFiled(record) == false) - { - // TODO .. refactor the existing code to file a record here ... this will include moving the code that - // currently manages the properties of the disposition lifecycle aspect into the disposition service - throw new UnsupportedOperationException("Currently unsuported."); - } - else - { - // TODO .. figure out how we 'refile' a currently filed record - throw new UnsupportedOperationException("Currently unable to file an already filed record."); - } - - } - /** - * Helper Methods - */ - /** * Creates a record from the given document * @@ -337,4 +351,80 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel .getParentRef()); nodeService.setProperty(document, PROP_IDENTIFIER, recordId); } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.disposableitem.RecordService#isFiled(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public boolean isFiled(NodeRef nodeRef) + { + ParameterCheck.mandatory("nodeRef", nodeRef); + + boolean result = false; + + if (isRecord(nodeRef) == true) + { + ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(nodeRef); + if (childAssocRef != null) + { + NodeRef parent = childAssocRef.getParentRef(); + if (parent != null && + recordsManagementService.isRecordFolder(parent) == true) + { + result = true; + } + } + } + + return result; + } + + /** + * Helper method to 'file' a new document that arrived in the file plan structure. + * + * TODO atm we only 'file' content as a record .. may need to consider other types if we + * are to support the notion of composite records. + * + * @param record node reference to record (or soon to be record!) + */ + private void file(NodeRef record) + { + ParameterCheck.mandatory("item", record); + + // we only support filling of content items + // TODO composite record support needs to file containers too + QName type = nodeService.getType(record); + if (ContentModel.TYPE_CONTENT.equals(type) == true || + dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) == true) + { + // check whether this item is already an item or not + if (isRecord(record) == false) + { + // make the item a record + makeRecord(record); + } + + // set filed date + if (nodeService.getProperty(record, PROP_DATE_FILED) == null) + { + Calendar fileCalendar = Calendar.getInstance(); + nodeService.setProperty(record, PROP_DATE_FILED, fileCalendar.getTime()); + } + + // initialise vital record details + // TODO .. change this to add the aspect which will trigger the init behaviour + VitalRecordServiceImpl vitalRecordService = (VitalRecordServiceImpl)applicationContext.getBean("vitalRecordService"); + vitalRecordService.initialiseVitalRecord(record); + + // initialise disposition details + if (nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE) == false) + { + DispositionSchedule di = dispositionService.getDispositionSchedule(record); + if (di != null && di.isRecordLevelDisposition() == true) + { + nodeService.addAspect(record, ASPECT_DISPOSITION_LIFECYCLE, null); + } + } + } + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionService.java index 3a13336a95..2885e00fa2 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionService.java @@ -28,7 +28,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; /** - * Disposition service + * Disposition service interface. * * @author Roy Wetherall * @since 2.0 @@ -157,24 +157,28 @@ public interface DispositionService DispositionActionDefinition actionDefinition, Map actionDefinitionParams); + + /** ========= Disposition Action Methods ========= */ /** - * TODO MOVE THIS FROM THIS API + * Indicates whether the next disposition action is eligible or not. * - * @param nodeRef - * @return + * @param nodeRef node reference to disposable item + * @return boolean true if next disposition action is eligible, false otherwise */ boolean isNextDispositionActionEligible(NodeRef nodeRef); - - /** ========= Disposition Action Methods ========= */ /** * Gets the next disposition action for a given node * - * @param nodeRef - * @return + * @param nodeRef node reference to disposable item + * @return DispositionAction next disposition action, null if none */ DispositionAction getNextDispositionAction(NodeRef nodeRef); + + // TODO void startNextDispositionAction(NodeRef nodeRef); + + // TODO void completeNextDispositionAction(NodeRef nodeRef); /** ========= Disposition Action History Methods ========= */ diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java index 35e59a7429..071e8d4d8c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java @@ -30,12 +30,19 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistry; import org.alfresco.module.org_alfresco_module_rm.disposition.property.DispositionProperty; +import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent; +import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventType; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.policy.BehaviourFilter; +import org.alfresco.repo.policy.JavaBehaviour; +import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.Period; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; @@ -51,7 +58,11 @@ import org.springframework.context.ApplicationContextAware; * * @author Roy Wetherall */ -public class DispositionServiceImpl implements DispositionService, RecordsManagementModel, ApplicationContextAware +public class DispositionServiceImpl implements + DispositionService, + RecordsManagementModel, + ApplicationContextAware, + NodeServicePolicies.OnAddAspectPolicy { /** Logger */ private static Log logger = LogFactory.getLog(DispositionServiceImpl.class); @@ -77,9 +88,15 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage /** Application context */ private ApplicationContext applicationContext; + /** Policy component */ + private PolicyComponent policyComponent; + /** Disposition properties */ private Map dispositionProperties = new HashMap(4); + /** Behaviours */ + private JavaBehaviour onAddAspect; + /** * Set node service * @@ -120,6 +137,14 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage this.serviceRegistry = serviceRegistry; } + /** + * @param policyComponent policy component + */ + public void setPolicyComponent(PolicyComponent policyComponent) + { + this.policyComponent = policyComponent; + } + /** * Get the records management service * NOTE: have to pull it out of the app context manually to prevent Spring circular dependancy issue @@ -154,6 +179,40 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage this.dispositionSelectionStrategy = dispositionSelectionStrategy; } + /** + * Bean initialisation + */ + public void init() + { + onAddAspect = new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT); + policyComponent.bindClassBehaviour(NodeServicePolicies.OnAddAspectPolicy.QNAME, ASPECT_DISPOSITION_LIFECYCLE, onAddAspect); + } + + /** + * Initialises the details of the disposition life cycle + */ + @Override + public void onAddAspect(NodeRef nodeRef, QName aspect) + { + if (nodeService.exists(nodeRef) == true) + { + // get this disposition instructions for the node + DispositionSchedule di = getDispositionSchedule(nodeRef); + if (di != null) + { + List dispositionActionDefinitions = di.getDispositionActionDefinitions(); + if (dispositionActionDefinitions.isEmpty() == false) + { + // get the first disposition action definition + DispositionActionDefinition nextDispositionActionDefinition = dispositionActionDefinitions.get(0); + + // initialise the details of the next disposition action + initialiseDispositionAction(nodeRef, nextDispositionActionDefinition); + } + } + } + } + /** ========= Disposition Property Methods ========= */ /** @@ -184,6 +243,9 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage return result; } + /** + * @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#getDispositionProperties() + */ @Override public Collection getDispositionProperties() { @@ -199,7 +261,7 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage { DispositionSchedule di = null; NodeRef diNodeRef = null; - if (getRmService().isRecord(nodeRef) == true) + if (serviceRegistry.getRecordService().isRecord(nodeRef) == true) { // Get the record folders for the record List recordFolders = getRmService().getRecordFolders(nodeRef); @@ -536,10 +598,106 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage NodeRef ds = this.nodeService.getPrimaryParent(actionDefinition.getNodeRef()).getParentRef(); DispositionSchedule updatedSchedule = new DispositionScheduleImpl(serviceRegistry, nodeService, ds); return updatedSchedule.getDispositionActionDefinition(actionDefinition.getId()); + } + + /** ========= Disposition Action Methods ========= */ + + /** + * Initialises the details of the next disposition action based on the details of a disposition + * action definition. + * + * @param nodeRef node reference + * @param dispositionActionDefinition disposition action definition + */ + private void initialiseDispositionAction(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition) + { + // Create the properties + Map props = new HashMap(10); + + // Calculate the asOf date + Date asOfDate = null; + Period period = dispositionActionDefinition.getPeriod(); + if (period != null) + { + Date contextDate = null; + + // Get the period properties value + QName periodProperty = dispositionActionDefinition.getPeriodProperty(); + if (periodProperty != null) + { + // doesn't matter if the period property isn't set ... the asOfDate will get updated later + // when the value of the period property is set + contextDate = (Date)this.nodeService.getProperty(nodeRef, periodProperty); + } + else + { + // for now use 'NOW' as the default context date + // TODO set the default period property ... cut off date or last disposition date depending on context + contextDate = new Date(); + } + + // Calculate the as of date + if (contextDate != null) + { + asOfDate = period.getNextDate(contextDate); + } + } + + // Set the property values + props.put(PROP_DISPOSITION_ACTION_ID, dispositionActionDefinition.getId()); + props.put(PROP_DISPOSITION_ACTION, dispositionActionDefinition.getName()); + if (asOfDate != null) + { + props.put(PROP_DISPOSITION_AS_OF, asOfDate); + } + + // Create a new disposition action object + NodeRef dispositionActionNodeRef = this.nodeService.createNode( + nodeRef, + ASSOC_NEXT_DISPOSITION_ACTION, + ASSOC_NEXT_DISPOSITION_ACTION, + TYPE_DISPOSITION_ACTION, + props).getChildRef(); + + // Create the events + List events = dispositionActionDefinition.getEvents(); + for (RecordsManagementEvent event : events) + { + // For every event create an entry on the action + createEvent(event, dispositionActionNodeRef); + } } /** + * Creates the given records management event for the given 'next action'. * + * @param event The event to create + * @param nextActionNodeRef The next action node + * @return The created event NodeRef + */ + private NodeRef createEvent(RecordsManagementEvent event, NodeRef nextActionNodeRef) + { + NodeRef eventNodeRef = null; + + Map eventProps = new HashMap(7); + eventProps.put(PROP_EVENT_EXECUTION_NAME, event.getName()); + // TODO display label + RecordsManagementEventType eventType = serviceRegistry.getRecordsManagementEventService().getEventType(event.getType()); + eventProps.put(PROP_EVENT_EXECUTION_AUTOMATIC, eventType.isAutomaticEvent()); + eventProps.put(PROP_EVENT_EXECUTION_COMPLETE, false); + + // Create the event execution object + this.nodeService.createNode(nextActionNodeRef, + ASSOC_EVENT_EXECUTIONS, + ASSOC_EVENT_EXECUTIONS, + TYPE_EVENT_EXECUTION, + eventProps); + + return eventNodeRef; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#isNextDispositionActionEligible(org.alfresco.service.cmr.repository.NodeRef) */ public boolean isNextDispositionActionEligible(NodeRef nodeRef) { @@ -609,7 +767,7 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage private NodeRef getNextDispositionActionNodeRef(NodeRef nodeRef) { NodeRef result = null; - List assocs = this.nodeService.getChildAssocs(nodeRef, ASSOC_NEXT_DISPOSITION_ACTION, RegexQNamePattern.MATCH_ALL); + List assocs = nodeService.getChildAssocs(nodeRef, ASSOC_NEXT_DISPOSITION_ACTION, RegexQNamePattern.MATCH_ALL); if (assocs.size() != 0) { result = assocs.get(0).getChildRef(); @@ -617,10 +775,8 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage return result; } - /** ========= Disposition Action Methods ========= */ - /** - * + * @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#getNextDispositionAction(org.alfresco.service.cmr.repository.NodeRef) */ public DispositionAction getNextDispositionAction(NodeRef nodeRef) { @@ -629,7 +785,7 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage if (dispositionActionNodeRef != null) { - result = new DispositionActionImpl(this.serviceRegistry, dispositionActionNodeRef); + result = new DispositionActionImpl(serviceRegistry, dispositionActionNodeRef); } return result; } @@ -637,9 +793,10 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage /** ========= Disposition Action History Methods ========= */ + public List getCompletedDispositionActions(NodeRef nodeRef) { - List assocs = this.nodeService.getChildAssocs(nodeRef, ASSOC_DISPOSITION_ACTION_HISTORY, RegexQNamePattern.MATCH_ALL); + List assocs = nodeService.getChildAssocs(nodeRef, ASSOC_DISPOSITION_ACTION_HISTORY, RegexQNamePattern.MATCH_ALL); List result = new ArrayList(assocs.size()); for (ChildAssociationRef assoc : assocs) { @@ -660,5 +817,4 @@ public class DispositionServiceImpl implements DispositionService, RecordsManage } return result; } - } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordContainerType.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordContainerType.java index d4117ea00b..f72d409d27 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordContainerType.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordContainerType.java @@ -145,13 +145,7 @@ public class RecordContainerType implements RecordsManagementModel, // Assume any created folder is a rma:recordFolder nodeService.setType(child, TYPE_RECORD_FOLDER); - } - - if (TYPE_RECORD_FOLDER.equals(nodeService.getType(child)) == true) - { - // Setup record folder - recordsManagementActionService.executeRecordsManagementAction(child, "setupRecordFolder"); - } + } // Catch all to generate the rm id (assuming it doesn't already have one!) setIdenifierProperty(child); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java index c58cca1a05..2d262ae272 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java @@ -143,11 +143,12 @@ public class RecordCopyBehaviours implements RecordsManagementModel * @param oldChildAssocRef * @param newChildAssocRef */ + @SuppressWarnings("unused") public void onMoveRecordFolderNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef) { final NodeRef newNodeRef = newChildAssocRef.getChildRef(); final NodeService nodeService = rmServiceRegistry.getNodeService(); - final RecordsManagementService rmService = rmServiceRegistry.getRecordsManagementService(); + final RecordsManagementService rmService = rmServiceRegistry.getRecordsManagementService(); final RecordsManagementActionService rmActionService = rmServiceRegistry.getRecordsManagementActionService(); AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() @@ -159,15 +160,21 @@ public class RecordCopyBehaviours implements RecordsManagementModel // Remove unwanted aspects removeUnwantedAspects(nodeService, newNodeRef); - // Trigger folder setup - rmActionService.executeRecordsManagementAction(newNodeRef, "setupRecordFolder"); + // TODO .. this isn't right!! + // .. what if the folder is in motion .. do we really want to lose all the disposition information? + // .. how do we merge from one disposition schedule to another + // .. for now throw unsupportedOperationException and refactor when considered + throw new UnsupportedOperationException("Moving a record folder is currently not supported."); - // Sort out the child records - for (NodeRef record : rmService.getRecords(newNodeRef)) - { - removeUnwantedAspects(nodeService, record); - rmActionService.executeRecordsManagementAction(record, "file"); - } +// // Trigger folder setup +// rmActionService.executeRecordsManagementAction(newNodeRef, "setupRecordFolder"); +// +// // Sort out the child records +// for (NodeRef record : rmService.getRecords(newNodeRef)) +// { +// removeUnwantedAspects(nodeService, record); +// rmActionService.executeRecordsManagementAction(record, "file"); +// } } return null; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java index 84adf52828..2905f8eb86 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java @@ -399,17 +399,20 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel props.put(PROP_RS_DISPOSITION_ACTION_AS_OF, da.getAsOfDate()); props.put(PROP_RS_DISPOSITION_EVENTS_ELIGIBLE, this.nodeService.getProperty(dispositionAction, PROP_DISPOSITION_EVENTS_ELIGIBLE)); - DispositionActionDefinition daDefinition = da.getDispositionActionDefinition(); - Period period = daDefinition.getPeriod(); - if (period != null) + DispositionActionDefinition daDefinition = da.getDispositionActionDefinition(); + if (daDefinition != null) { - props.put(PROP_RS_DISPOSITION_PERIOD, period.getPeriodType()); - props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, period.getExpression()); - } - else - { - props.put(PROP_RS_DISPOSITION_PERIOD, null); - props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, null); + Period period = daDefinition.getPeriod(); + if (period != null) + { + props.put(PROP_RS_DISPOSITION_PERIOD, period.getPeriodType()); + props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, period.getExpression()); + } + else + { + props.put(PROP_RS_DISPOSITION_PERIOD, null); + props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, null); + } } nodeService.setProperties(record, props); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BootstrapTestDataGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BootstrapTestDataGet.java index 3b27ca58ee..e67c5e894c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BootstrapTestDataGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BootstrapTestDataGet.java @@ -30,6 +30,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.disposableitem.RecordFolderServiceImpl; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; @@ -52,6 +53,9 @@ import org.alfresco.service.cmr.view.ImporterService; import org.alfresco.service.cmr.view.Location; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; @@ -62,7 +66,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest; */ @Deprecated public class BootstrapTestDataGet extends DeclarativeWebScript - implements RecordsManagementModel + implements RecordsManagementModel, ApplicationContextAware { private static Log logger = LogFactory.getLog(BootstrapTestDataGet.class); @@ -83,7 +87,14 @@ public class BootstrapTestDataGet extends DeclarativeWebScript private RecordsManagementSecurityService recordsManagementSecurityService; private AuthorityService authorityService; private RecordsManagementSearchBehaviour recordsManagementSearchBehaviour; - private DispositionService dispositionService; + private DispositionService dispositionService; + private ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.applicationContext = applicationContext; + } public void setNodeService(NodeService nodeService) { @@ -184,7 +195,7 @@ public class BootstrapTestDataGet extends DeclarativeWebScript } // Patch data - BootstrapTestDataGet.patchLoadedData(searchService, nodeService, recordsManagementService, + BootstrapTestDataGet.patchLoadedData(applicationContext, searchService, nodeService, recordsManagementService, recordsManagementActionService, permissionService, authorityService, recordsManagementSecurityService, recordsManagementSearchBehaviour, @@ -204,7 +215,8 @@ public class BootstrapTestDataGet extends DeclarativeWebScript * @param recordsManagementService * @param recordsManagementActionService */ - public static void patchLoadedData( final SearchService searchService, + public static void patchLoadedData( final ApplicationContext applicationContext, + final SearchService searchService, final NodeService nodeService, final RecordsManagementService recordsManagementService, final RecordsManagementActionService recordsManagementActionService, @@ -302,7 +314,8 @@ public class BootstrapTestDataGet extends DeclarativeWebScript { // Fire action to "set-up" the folder correctly logger.info("Setting up bootstraped record folder: " + folderName); - recordsManagementActionService.executeRecordsManagementAction(recordFolder, "setupRecordFolder"); + RecordFolderServiceImpl recordService = (RecordFolderServiceImpl)applicationContext.getBean("recordFolderService"); + recordService.initialiseRecordFolder(recordFolder); } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java index f95dbfa4e9..b28761370e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java @@ -73,7 +73,6 @@ public class TransferReportPost extends BaseTransferWebScript protected static final String RESPONSE_SUCCESS = "success"; protected static final String RESPONSE_RECORD = "record"; protected static final String RESPONSE_RECORD_NAME = "recordName"; - protected static final String FILE_ACTION = "file"; protected DictionaryService ddService; protected RecordsManagementActionService rmActionService; @@ -418,10 +417,7 @@ public class TransferReportPost extends BaseTransferWebScript ContentWriter writer = this.contentService.getWriter(record, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_HTML); writer.setEncoding("UTF-8"); - writer.putContent(report); - - // file the node as a record - this.rmActionService.executeRecordsManagementAction(record, FILE_ACTION); + writer.putContent(report); return record; } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java index 248fd32c77..a572c1b1a7 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java @@ -29,6 +29,9 @@ import org.alfresco.service.cmr.repository.Period; */ public interface VitalRecordService { + /** Period 'none' */ + static final Period PERIOD_NONE = new Period("none|0"); + /** * Gets the vital record definition details for the node. * @@ -53,6 +56,5 @@ public interface VitalRecordService * @param nodeRef node reference * @return boolean true if this is a vital record, false otherwise */ - boolean isVitalRecord(NodeRef nodeRef); - + boolean isVitalRecord(NodeRef nodeRef); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java index 464a1cfe36..3160834377 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java @@ -19,8 +19,11 @@ package org.alfresco.module.org_alfresco_module_rm.vital; import java.io.Serializable; +import java.util.Date; +import java.util.HashMap; import java.util.Map; +import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.FilePlanComponentKind; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; @@ -31,6 +34,7 @@ import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.Period; @@ -46,10 +50,8 @@ import org.alfresco.util.ParameterCheck; public class VitalRecordServiceImpl implements VitalRecordService, RecordsManagementModel, NodeServicePolicies.OnUpdatePropertiesPolicy, - NodeServicePolicies.OnAddAspectPolicy + NodeServicePolicies.OnCreateChildAssociationPolicy { - private static final Period PERIOD_NONE = new Period("none|0"); - /** Services */ private NodeService nodeService; private PolicyComponent policyComponent; @@ -58,7 +60,7 @@ public class VitalRecordServiceImpl implements VitalRecordService, /** Behaviours */ private JavaBehaviour onUpdateProperties; - private JavaBehaviour onAddAspect; + private JavaBehaviour onCreateChildAssociation; /** * @param nodeService node service @@ -103,11 +105,17 @@ public class VitalRecordServiceImpl implements VitalRecordService, ASPECT_VITAL_RECORD_DEFINITION, onUpdateProperties); - onAddAspect = new JavaBehaviour(this, "onAddAspect", NotificationFrequency.TRANSACTION_COMMIT); - policyComponent.bindClassBehaviour( - NodeServicePolicies.OnAddAspectPolicy.QNAME, - ASPECT_VITAL_RECORD_DEFINITION, - onAddAspect); + onCreateChildAssociation = new JavaBehaviour(this, "onCreateChildAssociation", NotificationFrequency.TRANSACTION_COMMIT); + policyComponent.bindAssociationBehaviour( + NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME, + TYPE_RECORD_FOLDER, + ContentModel.ASSOC_CONTAINS, + onCreateChildAssociation); + policyComponent.bindAssociationBehaviour( + NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME, + TYPE_RECORD_CATEGORY, + ContentModel.ASSOC_CONTAINS, + onCreateChildAssociation); } /** @@ -121,64 +129,114 @@ public class VitalRecordServiceImpl implements VitalRecordService, rmActionService.executeRecordsManagementAction(nodeRef, "broadcastVitalRecordDefinition"); } } - + /** - * @see org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy#onAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) + * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) */ - @Override - public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName) + public void onCreateChildAssociation(ChildAssociationRef childAssociationRef, boolean bNew) { - ParameterCheck.mandatory("nodeRef", nodeRef); - ParameterCheck.mandatory("aspectTypeQName", aspectTypeQName); - - if (nodeService.exists(nodeRef) == true) + if (childAssociationRef != null) { - onUpdateProperties.disable(); - try - { - AuthenticationUtil.runAs(new RunAsWork() - { - public Void doWork() throws Exception - { - // get the current review period value - Period currentReviewPeriod = (Period)nodeService.getProperty(nodeRef, PROP_REVIEW_PERIOD); - if (currentReviewPeriod == null || - PERIOD_NONE.equals(currentReviewPeriod) == true) - { - // get the immediate parent - NodeRef parentRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); - - // is the parent a record category - if (parentRef != null && - FilePlanComponentKind.RECORD_CATEGORY.equals(rmService.getFilePlanComponentKind(parentRef)) == true) - { - // is the child a record category or folder - FilePlanComponentKind kind = rmService.getFilePlanComponentKind(nodeRef); - if (kind.equals(FilePlanComponentKind.RECORD_CATEGORY) == true || - kind.equals(FilePlanComponentKind.RECORD_FOLDER) == true) - { - // set the vital record definition values to match that of the parent - nodeService.setProperty(nodeRef, - PROP_VITAL_RECORD_INDICATOR, - nodeService.getProperty(parentRef, PROP_VITAL_RECORD_INDICATOR)); - nodeService.setProperty(nodeRef, - PROP_REVIEW_PERIOD, - nodeService.getProperty(parentRef, PROP_REVIEW_PERIOD)); - } - } - } - - return null; - } - }, AuthenticationUtil.getSystemUserName()); - } - finally - { - onUpdateProperties.enable(); - } + final NodeRef nodeRef = childAssociationRef.getChildRef(); + if (nodeService.exists(nodeRef) == true) + { + onCreateChildAssociation.disable(); + onUpdateProperties.disable(); + try + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() throws Exception + { + if (rmService.isRecordCategory(nodeRef) == true || + rmService.isRecordFolder(nodeRef) == true) + { + inheritVitalRecordDefinition(nodeRef); + } + + return null; + } + }); + } + finally + { + onCreateChildAssociation.enable(); + onUpdateProperties.enable(); + } + } } } + /** + * Helper method to set the inherited vital record definition details. + * + * @param nodeRef node reference + */ + private void inheritVitalRecordDefinition(NodeRef nodeRef) + { + // get the current review period value + Period currentReviewPeriod = (Period)nodeService.getProperty(nodeRef, PROP_REVIEW_PERIOD); + if (currentReviewPeriod == null || + PERIOD_NONE.equals(currentReviewPeriod) == true) + { + // get the immediate parent + NodeRef parentRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); + + // is the parent a record category + if (parentRef != null && + FilePlanComponentKind.RECORD_CATEGORY.equals(rmService.getFilePlanComponentKind(parentRef)) == true) + { + // is the child a record category or folder + FilePlanComponentKind kind = rmService.getFilePlanComponentKind(nodeRef); + if (kind.equals(FilePlanComponentKind.RECORD_CATEGORY) == true || + kind.equals(FilePlanComponentKind.RECORD_FOLDER) == true) + { + // set the vital record definition values to match that of the parent + nodeService.setProperty(nodeRef, + PROP_VITAL_RECORD_INDICATOR, + nodeService.getProperty(parentRef, PROP_VITAL_RECORD_INDICATOR)); + nodeService.setProperty(nodeRef, + PROP_REVIEW_PERIOD, + nodeService.getProperty(parentRef, PROP_REVIEW_PERIOD)); + } + } + } + } + + /** + * Helper method used by services with access to the private bean to initialise vital record details. + * + * TODO consider what (if any of this) should be on the public interface + * + * @param nodeRef node reference to initialise with vital record details + */ + public void initialiseVitalRecord(NodeRef nodeRef) + { + // Calculate the review schedule + VitalRecordDefinition viDef = getVitalRecordDefinition(nodeRef); + if (viDef != null && viDef.isEnabled() == true) + { + Date reviewAsOf = viDef.getNextReviewDate(); + if (reviewAsOf != null) + { + Map reviewProps = new HashMap(1); + reviewProps.put(RecordsManagementModel.PROP_REVIEW_AS_OF, reviewAsOf); + + if (nodeService.hasAspect(nodeRef, ASPECT_VITAL_RECORD) == false) + { + nodeService.addAspect(nodeRef, RecordsManagementModel.ASPECT_VITAL_RECORD, reviewProps); + } + else + { + Map props = nodeService.getProperties(nodeRef); + props.putAll(reviewProps); + nodeService.setProperties(nodeRef, props); + } + } + } + } + /** * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementService#getVitalRecordDefinition(org.alfresco.service.cmr.repository.NodeRef) */ diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/WebScriptTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/WebScriptTestSuite.java index 50453987db..a5b5c103d6 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/WebScriptTestSuite.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/WebScriptTestSuite.java @@ -21,7 +21,6 @@ package org.alfresco.module.org_alfresco_module_rm.test; import junit.framework.Test; import junit.framework.TestSuite; -import org.alfresco.module.org_alfresco_module_rm.test.webscript.BootstraptestDataRestApiTest; import org.alfresco.module.org_alfresco_module_rm.test.webscript.DataSetRestApiTest; import org.alfresco.module.org_alfresco_module_rm.test.webscript.DispositionRestApiTest; import org.alfresco.module.org_alfresco_module_rm.test.webscript.EventRestApiTest; @@ -46,7 +45,6 @@ public class WebScriptTestSuite extends TestSuite public static Test suite() { TestSuite suite = new TestSuite(); - suite.addTestSuite(BootstraptestDataRestApiTest.class); suite.addTestSuite(DispositionRestApiTest.class); suite.addTestSuite(EventRestApiTest.class); suite.addTestSuite(RMCaveatConfigScriptTest.class); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/CreateRecordActionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/CreateRecordActionTest.java new file mode 100644 index 0000000000..b1fa2a2681 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/CreateRecordActionTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm.test.action; + +import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; +import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; + +/** + * Record service implementation unit test. + * + * @author Roy Wetherall + */ +public class CreateRecordActionTest extends BaseRMTestCase +{ + /** Services */ + protected ActionService dmActionService; + protected PermissionService dmPermissionService; + + @Override + protected void initServices() + { + super.initServices(); + + dmActionService = (ActionService)applicationContext.getBean("ActionService"); + dmPermissionService = (PermissionService)applicationContext.getBean("PermissionService"); + } + + @Override + protected boolean isUserTest() + { + return true; + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + public void testCreateRecordAction() + { + doTestInTransaction(new Test() + { + public Void run() + { + assertEquals(AccessStatus.DENIED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); + assertEquals(AccessStatus.DENIED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); + + Action action = dmActionService.createAction(CreateRecordAction.NAME); + dmActionService.executeAction(action, dmDocument); + + return null; + } + + public void test(Void result) throws Exception + { + assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); + assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); + + assertTrue(recordService.isRecord(dmDocument)); + }; + }, + dmCollaborator); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java index 6a65821f94..48c23a0e6a 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java @@ -95,9 +95,9 @@ public class CapabilityServiceImplTest extends BaseRMTestCase { Group auditGroup = capabilityService.getGroup("audit"); assertNotNull(auditGroup); - assertTrue(auditGroup.getIndex() == 1); - assertTrue(auditGroup.getTitle().equalsIgnoreCase("Audit")); - assertTrue(auditGroup.getId().equalsIgnoreCase("audit")); + assertEquals(10, auditGroup.getIndex()); + assertEquals("Audit", auditGroup.getTitle()); + assertEquals("audit", auditGroup.getId()); return null; } @@ -110,7 +110,7 @@ public class CapabilityServiceImplTest extends BaseRMTestCase { GroupImpl testGroup = new GroupImpl(); testGroup.setId("testGroup"); - testGroup.setIndex(14); + testGroup.setIndex(140); testGroup.setTitle("Test group"); capabilityService.addGroup(testGroup); @@ -120,7 +120,7 @@ public class CapabilityServiceImplTest extends BaseRMTestCase assertNotNull(group); assertTrue(group.getId().equalsIgnoreCase("testGroup")); assertTrue(group.getTitle().equalsIgnoreCase("Test group")); - assertTrue(group.getIndex() == 14); + assertTrue(group.getIndex() == 140); return null; } @@ -152,21 +152,15 @@ public class CapabilityServiceImplTest extends BaseRMTestCase int size = groups.size(); assertTrue(size == 13); - for (int i = 0; i < size; i++) - { - assertNotNull(groups.get(i)); - assertTrue(groups.get(i).getIndex() == (i + 1)); - } - Group auditGroup = groups.get(0); assertNotNull(auditGroup); - assertTrue(auditGroup.getIndex() == 1); + assertTrue(auditGroup.getIndex() == 10); assertTrue(auditGroup.getId().equalsIgnoreCase("audit")); assertTrue(auditGroup.getTitle().equalsIgnoreCase("Audit")); Group vitalRecords = groups.get(size - 1); assertNotNull(vitalRecords); - assertTrue(vitalRecords.getIndex() == 13); + assertTrue(vitalRecords.getIndex() == 130); assertTrue(vitalRecords.getId().equalsIgnoreCase("vitalRecords")); assertTrue(vitalRecords.getTitle().equalsIgnoreCase("Vital Records")); @@ -194,11 +188,11 @@ public class CapabilityServiceImplTest extends BaseRMTestCase int vitalRecordCapabilitiesSize = auditCapabilities.size(); assertTrue(vitalRecordCapabilitiesSize == 6); - for (int i = 0; i < vitalRecordCapabilitiesSize; i++) + for (int i = 1; i == vitalRecordCapabilitiesSize; i++) { Capability capability = auditCapabilities.get(i); assertNotNull(capability); - assertTrue(capability.getIndex() == (i + 1)); + assertEquals(i * 10, capability.getIndex()); } Group vitalRecordsGroup = groups.get(groups.size() - 1); @@ -208,14 +202,7 @@ public class CapabilityServiceImplTest extends BaseRMTestCase assertNotNull(vitalRecordCapabilities); vitalRecordCapabilitiesSize = vitalRecordCapabilities.size(); - assertTrue(vitalRecordCapabilitiesSize == 3); - - for (int i = 0; i < vitalRecordCapabilitiesSize; i++) - { - Capability capability = vitalRecordCapabilities.get(i); - assertNotNull(capability); - assertTrue(capability.getIndex() == (i + 1)); - } + assertEquals(3, vitalRecordCapabilitiesSize); return null; } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CreateRecordActionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CreateRecordActionTest.java deleted file mode 100644 index 47ee86d8e4..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CreateRecordActionTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2005-2012 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.test.service; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; -import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.site.SiteModel; -import org.alfresco.repo.site.SiteServiceImpl; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.site.SiteInfo; -import org.alfresco.service.cmr.site.SiteService; -import org.alfresco.service.cmr.site.SiteVisibility; -import org.alfresco.service.cmr.tagging.TaggingService; -import org.alfresco.util.GUID; - -/** - * Record service implementation unit test. - * - * @author Roy Wetherall - */ -public class CreateRecordActionTest extends BaseRMTestCase -{ - protected static final String COLLABORATION_SITE_ID = "collab-site-id"; - - protected ActionService dmActionService; - protected TaggingService taggingService; - protected PermissionService dmPermissionService; - - protected SiteInfo collaborationSite; - protected NodeRef documentLibrary; - protected NodeRef dmFolder; - protected NodeRef dmDocument; - - protected String dmUserName; - protected NodeRef dmUserPerson; - - @Override - protected void initServices() - { - super.initServices(); - - dmActionService = (ActionService)applicationContext.getBean("ActionService"); - taggingService = (TaggingService)applicationContext.getBean("TaggingService"); - dmPermissionService = (PermissionService)applicationContext.getBean("PermissionService"); - } - - @Override - protected boolean isUserTest() - { - return true; - } - - @Override - protected void setupTestData() - { - super.setupTestData(); - - doTestInTransaction(new Test() - { - public Void run() - { - setupCollaborationSiteTestDataImpl(); - return null; - } - }, - AuthenticationUtil.getSystemUserName()); - } - - protected void setupCollaborationSiteTestDataImpl() - { - // create collaboration site - collaborationSite = siteService.createSite("preset", COLLABORATION_SITE_ID, "title", "description", SiteVisibility.PRIVATE); - documentLibrary = SiteServiceImpl.getSiteContainer( - COLLABORATION_SITE_ID, - SiteService.DOCUMENT_LIBRARY, - true, - siteService, - transactionService, - taggingService); - - assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary); - - // create a folder and documents - dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef(); - dmDocument = fileFolderService.create(dmFolder, "collabDocument.txt", ContentModel.TYPE_CONTENT).getNodeRef(); - - - } - - @Override - protected void setupTestUsersImpl(NodeRef filePlan) - { - super.setupTestUsersImpl(filePlan); - - dmUserName = GUID.generate(); - dmUserPerson = createPerson(dmUserName); - siteService.setMembership(COLLABORATION_SITE_ID, dmUserName, SiteModel.SITE_COLLABORATOR); - } - - @Override - protected void tearDownImpl() - { - super.tearDownImpl(); - siteService.deleteSite(COLLABORATION_SITE_ID); - } - - public void testCreateRecordAction() - { - doTestInTransaction(new Test() - { - public Void run() - { - assertEquals(AccessStatus.DENIED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); - assertEquals(AccessStatus.DENIED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); - - Action action = dmActionService.createAction(CreateRecordAction.NAME); - dmActionService.executeAction(action, dmDocument); - - return null; - } - - public void test(Void result) throws Exception - { - assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); - assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); - - assertTrue(recordService.isRecord(dmDocument)); - }; - }, - dmUserName); - } -} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceImplTest.java index bbea845ca4..83c3a6cfe4 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceImplTest.java @@ -22,26 +22,19 @@ import java.util.Arrays; import java.util.List; import java.util.Set; -import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.disposableitem.RecordService; import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model; -import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.permissions.AccessDeniedException; -import org.alfresco.repo.site.SiteModel; -import org.alfresco.repo.site.SiteServiceImpl; import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.site.SiteInfo; -import org.alfresco.service.cmr.site.SiteService; -import org.alfresco.service.cmr.site.SiteVisibility; -import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.namespace.QName; -import org.alfresco.util.GUID; /** * Records Service Implementation Test @@ -52,35 +45,20 @@ import org.alfresco.util.GUID; */ public class RecordServiceImplTest extends BaseRMTestCase { - protected static final String COLLABORATION_SITE_ID = "collab-site-id"; - + /** Services */ protected ActionService dmActionService; - - protected TaggingService taggingService; - - protected PermissionService dmPermissionService; - + protected PermissionService dmPermissionService; protected ExtendedSecurityService extendedSecurityService; - // collaboration site artifacts - protected SiteInfo collaborationSite; - protected NodeRef documentLibrary; - protected NodeRef dmFolder; - protected NodeRef dmDocument; - - // dm users - protected String dmConsumer; - protected NodeRef dmConsumerNodeRef; - protected String dmCollaborator; - protected NodeRef dmCollaboratorNodeRef; - + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices() + */ @Override protected void initServices() { super.initServices(); dmActionService = (ActionService) applicationContext.getBean("ActionService"); - taggingService = (TaggingService) applicationContext.getBean("TaggingService"); dmPermissionService = (PermissionService) applicationContext.getBean("PermissionService"); extendedSecurityService = (ExtendedSecurityService) applicationContext.getBean("ExtendedSecurityService"); } @@ -106,64 +84,14 @@ public class RecordServiceImplTest extends BaseRMTestCase { return true; } - + /** - * Setup the collaboration site test data + * This is a collaboration site test */ @Override - protected void setupTestData() + protected boolean isCollaborationSiteTest() { - super.setupTestData(); - - doTestInTransaction(new Test() - { - public Void run() - { - setupCollaborationSiteTestDataImpl(); - return null; - } - }, AuthenticationUtil.getSystemUserName()); - } - - protected void setupCollaborationSiteTestDataImpl() - { - // create collaboration site - collaborationSite = siteService.createSite("preset", COLLABORATION_SITE_ID, "title", "description", SiteVisibility.PRIVATE); - documentLibrary = SiteServiceImpl.getSiteContainer( - COLLABORATION_SITE_ID, - SiteService.DOCUMENT_LIBRARY, - true, - siteService, - transactionService, - taggingService); - - assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary); - - // create a folder and documents - dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef(); - dmDocument = fileFolderService.create(dmFolder, "collabDocument.txt", ContentModel.TYPE_CONTENT).getNodeRef(); - - } - - @Override - protected void setupTestUsersImpl(NodeRef filePlan) - { - super.setupTestUsersImpl(filePlan); - - dmConsumer = GUID.generate(); - dmConsumerNodeRef = createPerson(dmConsumer); - siteService.setMembership(COLLABORATION_SITE_ID, dmConsumer, SiteModel.SITE_CONSUMER); - - dmCollaborator = GUID.generate(); - dmCollaboratorNodeRef = createPerson(dmCollaborator); - siteService.setMembership(COLLABORATION_SITE_ID, dmCollaborator, SiteModel.SITE_COLLABORATOR); - } - - @Override - protected void tearDownImpl() - { - super.tearDownImpl(); - siteService.deleteSite(COLLABORATION_SITE_ID); + return true; } /** @@ -329,9 +257,89 @@ public class RecordServiceImplTest extends BaseRMTestCase return null; } }, dmCollaborator); - - - + } + + public void testFileNewContent() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + NodeRef record = fileFolderService.create(rmFolder, "test101.txt" , TYPE_CONTENT).getNodeRef(); + + ContentWriter writer = contentService.getWriter(record, PROP_CONTENT, true); + writer.setEncoding("UTF-8"); + writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); + writer.putContent("hello world this is some test content"); + + return record; + } + + @Override + public void test(NodeRef record) throws Exception + { + assertTrue(recordService.isRecord(record)); + assertTrue(recordService.isFiled(record)); + + assertNotNull(nodeService.getProperty(record, PROP_DATE_FILED)); + } + }); + } + + public void testFileUnfiledrecord() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + recordService.createRecord(filePlan, dmDocument); + + assertTrue(recordService.isRecord(dmDocument)); + assertFalse(recordService.isFiled(dmDocument)); + + assertNull(nodeService.getProperty(dmDocument, PROP_DATE_FILED)); + + fileFolderService.move(dmDocument, rmFolder, "record.txt"); + + return dmDocument; + } + + @Override + public void test(NodeRef record) throws Exception + { + assertTrue(recordService.isRecord(record)); + assertTrue(recordService.isFiled(record)); + + assertNotNull(nodeService.getProperty(record, PROP_DATE_FILED)); + } + }); + } + + public void testFileDirectlyFromCollab() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + assertNull(nodeService.getProperty(dmDocument, PROP_DATE_FILED)); + + fileFolderService.move(dmDocument, rmFolder, "record.txt"); + + return dmDocument; + } + + @Override + public void test(NodeRef record) throws Exception + { + assertTrue(recordService.isRecord(record)); + assertTrue(recordService.isFiled(record)); + + assertNotNull(nodeService.getProperty(record, PROP_DATE_FILED)); + } + }); } private void checkPermissions(String permission, AccessStatus filePlanExpected, diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java index a714452d41..38f82203fd 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/VitalRecordServiceImplTest.java @@ -23,8 +23,10 @@ import java.util.Date; import org.alfresco.module.org_alfresco_module_rm.model.behaviour.RecordsManagementSearchBehaviour; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordDefinition; +import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.Period; import org.alfresco.util.GUID; @@ -48,6 +50,15 @@ public class VitalRecordServiceImplTest extends BaseRMTestCase private NodeRef mhRecord54; private NodeRef mhRecord55; + /** + * Indicate this test uses the collaboration site test data + */ + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + /** Indicate this is a multi hierarchy test */ @Override protected boolean isMultiHierarchyTest() @@ -212,6 +223,75 @@ public class VitalRecordServiceImplTest extends BaseRMTestCase }); } + /** Filling tests */ + + public void testFileNewContent() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public NodeRef run() + { + NodeRef record = fileFolderService.create(mhRecordFolder41, "test101.txt" , TYPE_CONTENT).getNodeRef(); + + ContentWriter writer = contentService.getWriter(record, PROP_CONTENT, true); + writer.setEncoding("UTF-8"); + writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); + writer.putContent("hello world this is some test content"); + + return record; + } + + @Override + public void test(NodeRef record) throws Exception + { + assertVitalRecord(record, true, PERIOD_WEEK); + } + }); + } + +// public void testFileUnfiledrecord() throws Exception +// { +// doTestInTransaction(new Test() +// { +// @Override +// public NodeRef run() throws Exception +// { +// recordService.createRecord(filePlan, dmDocument); +// fileFolderService.move(dmDocument, mhRecordFolder41, "record.txt"); +// +// return dmDocument; +// } +// +// @Override +// public void test(NodeRef record) throws Exception +// { +// assertVitalRecord(record, true, PERIOD_WEEK); +// } +// }); +// } +// +// public void testFileDirectlyFromCollab() throws Exception +// { +// doTestInTransaction(new Test() +// { +// @Override +// public NodeRef run() throws Exception +// { +// fileFolderService.move(dmDocument, mhRecordFolder41, "record.txt"); +// return dmDocument; +// } +// +// @Override +// public void test(NodeRef record) throws Exception +// { +// assertVitalRecord(record, true, PERIOD_WEEK); +// } +// }); +// } + + /** Helper Methods */ + /** * Test to ensure that changes made to vital record definitions are reflected down the hierarchy. */ diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 851175cd5d..1c8d73b9cc 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -29,18 +29,20 @@ import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; import org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService; +import org.alfresco.module.org_alfresco_module_rm.disposableitem.RecordService; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService; import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.model.behaviour.RmSiteType; -import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService; import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService; import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.site.SiteModel; +import org.alfresco.repo.site.SiteServiceImpl; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.dictionary.DictionaryService; @@ -57,6 +59,7 @@ import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; @@ -81,15 +84,16 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase }; protected ApplicationContext applicationContext; - /** Test model contants */ + /** test model constants */ protected String URI = "http://www.alfresco.org/model/rmtest/1.0"; protected String PREFIX = "rmt"; protected QName TYPE_CUSTOM_TYPE = QName.createQName(URI, "customType"); protected QName ASPECT_CUSTOM_ASPECT = QName.createQName(URI, "customAspect"); protected QName ASPECT_RECORD_META_DATA = QName.createQName(URI, "recordMetaData"); - /** Site id */ + /** site id's */ protected static final String SITE_ID = "mySite"; + protected static final String COLLABORATION_SITE_ID = "collab-site-id"; /** Common test utils */ protected CommonRMTestUtils utils; @@ -109,6 +113,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected TransactionService transactionService; protected FileFolderService fileFolderService; protected PermissionService permissionService; + protected TaggingService taggingService; /** RM Services */ protected RecordsManagementService rmService; @@ -214,6 +219,18 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected NodeRef recordDeclaredOne; protected NodeRef recordDeclaredTwo; + /** collaboration site artifacts */ + protected SiteInfo collaborationSite; + protected NodeRef documentLibrary; + protected NodeRef dmFolder; + protected NodeRef dmDocument; + + /** collaboration site users */ + protected String dmConsumer; + protected NodeRef dmConsumerNodeRef; + protected String dmCollaborator; + protected NodeRef dmCollaboratorNodeRef; + /** * Indicates whether this is a multi-hierarchy test or not. If it is then the multi-hierarchy record * taxonomy test data is loaded. @@ -248,6 +265,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase return false; } + /** + * Indicates whether the test collaboration site should be created + * or not. + */ + protected boolean isCollaborationSiteTest() + { + return false; + } + /** * @see junit.framework.TestCase#setUp() */ @@ -263,17 +289,26 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase // Setup test data setupTestData(); + + // Create multi hierarchy data if (isMultiHierarchyTest() == true) { setupMultiHierarchyTestData(); - } + } + + // Create collaboration data + if (isCollaborationSiteTest() == true) + { + setupCollaborationSiteTestData(); + } + // Create the users here if (isUserTest() == true) { setupTestUsers(filePlan); } } - + /** * Initialise the service beans. */ @@ -294,6 +329,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase transactionService = (TransactionService)applicationContext.getBean("TransactionService"); fileFolderService = (FileFolderService)applicationContext.getBean("FileFolderService"); permissionService = (PermissionService)applicationContext.getBean("PermissionService"); + taggingService = (TaggingService)applicationContext.getBean("TaggingService"); // Get RM services rmService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService"); @@ -342,6 +378,12 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase // Delete the site siteService.deleteSite(SITE_ID); + + // delete the collaboration site (if required) + if (isCollaborationSiteTest() == true) + { + siteService.deleteSite(COLLABORATION_SITE_ID); + } } /** @@ -573,6 +615,45 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase mhRecordFolder45 = rmService.createRecordFolder(mhContainer35, "mhFolder45"); } + protected void setupCollaborationSiteTestData() + { + doTestInTransaction(new Test() + { + public Void run() + { + setupCollaborationSiteTestDataImpl(); + return null; + } + }, AuthenticationUtil.getSystemUserName()); + } + + protected void setupCollaborationSiteTestDataImpl() + { + // create collaboration site + collaborationSite = siteService.createSite("preset", COLLABORATION_SITE_ID, "title", "description", SiteVisibility.PRIVATE); + documentLibrary = SiteServiceImpl.getSiteContainer( + COLLABORATION_SITE_ID, + SiteService.DOCUMENT_LIBRARY, + true, + siteService, + transactionService, + taggingService); + + assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary); + + // create a folder and documents + dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef(); + dmDocument = fileFolderService.create(dmFolder, "collabDocument.txt", ContentModel.TYPE_CONTENT).getNodeRef(); + + dmConsumer = GUID.generate(); + dmConsumerNodeRef = createPerson(dmConsumer); + siteService.setMembership(COLLABORATION_SITE_ID, dmConsumer, SiteModel.SITE_CONSUMER); + + dmCollaborator = GUID.generate(); + dmCollaboratorNodeRef = createPerson(dmCollaborator); + siteService.setMembership(COLLABORATION_SITE_ID, dmCollaborator, SiteModel.SITE_COLLABORATOR); + } + /** * Helper class to try and simplify {@link Void} tests. * diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java deleted file mode 100644 index b14ddb239e..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/TestUtilities.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.test.util; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.Assert; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; -import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.model.behaviour.RecordsManagementSearchBehaviour; -import org.alfresco.module.org_alfresco_module_rm.script.BootstrapTestDataGet; -import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.AuthorityService; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.view.ImporterBinding; -import org.alfresco.service.cmr.view.ImporterService; -import org.alfresco.service.cmr.view.Location; -import org.alfresco.service.namespace.QName; -import org.springframework.context.ApplicationContext; - -/** - * This class is an initial placeholder for miscellaneous helper methods used in - * the testing or test initialisation of the DOD5015 module. - * - * @author neilm - */ -public class TestUtilities implements RecordsManagementModel -{ - public static NodeRef loadFilePlanData(ApplicationContext applicationContext) - { - return TestUtilities.loadFilePlanData(applicationContext, true, false); - } - - public static final String TEST_FILE_PLAN_NAME = "testUtilities.filePlan"; - - private static NodeRef getFilePlan(NodeService nodeService, NodeRef rootNode) - { - NodeRef filePlan = null; - - // Try and find a file plan hanging from the root node - List assocs = nodeService.getChildAssocs(rootNode, ContentModel.ASSOC_CHILDREN, TYPE_FILE_PLAN); - if (assocs.size() != 0) - { - filePlan = assocs.get(0).getChildRef(); - } - - return filePlan; - } - - public static NodeRef loadFilePlanData(ApplicationContext applicationContext, boolean patchData, boolean alwaysLoad) - { - NodeService nodeService = (NodeService)applicationContext.getBean("NodeService"); - AuthorityService authorityService = (AuthorityService)applicationContext.getBean("AuthorityService"); - PermissionService permissionService = (PermissionService)applicationContext.getBean("PermissionService"); - SearchService searchService = (SearchService)applicationContext.getBean("SearchService"); - ImporterService importerService = (ImporterService)applicationContext.getBean("importerComponent"); - RecordsManagementService recordsManagementService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService"); - RecordsManagementActionService recordsManagementActionService = (RecordsManagementActionService)applicationContext.getBean("RecordsManagementActionService"); - RecordsManagementSecurityService recordsManagementSecurityService = (RecordsManagementSecurityService)applicationContext.getBean("RecordsManagementSecurityService"); - RecordsManagementSearchBehaviour recordsManagementSearchBehaviour = (RecordsManagementSearchBehaviour)applicationContext.getBean("recordsManagementSearchBehaviour"); - DispositionService dispositionService = (DispositionService)applicationContext.getBean("DispositionService"); - - NodeRef filePlan = null; - NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - - if (alwaysLoad == false && getFilePlan(nodeService, rootNode) != null) - { - return filePlan; - } - - // For now creating the filePlan beneath the - Map props = new HashMap(1); - props.put(ContentModel.PROP_NAME, TEST_FILE_PLAN_NAME); - filePlan = nodeService.createNode(rootNode, ContentModel.ASSOC_CHILDREN, - TYPE_FILE_PLAN, - TYPE_FILE_PLAN, - props).getChildRef(); - - // Do the data load into the the provided filePlan node reference - // TODO ... - InputStream is = TestUtilities.class.getClassLoader().getResourceAsStream( - "alfresco/module/org_alfresco_module_rm/dod5015/DODExampleFilePlan.xml"); - //"alfresco/module/org_alfresco_module_rm/bootstrap/temp.xml"); - Assert.assertNotNull("The DODExampleFilePlan.xml import file could not be found", is); - Reader viewReader = new InputStreamReader(is); - Location location = new Location(filePlan); - importerService.importView(viewReader, location, REPLACE_BINDING, null); - - if (patchData == true) - { - // Tempory call out to patch data after AMP - BootstrapTestDataGet.patchLoadedData(searchService, nodeService, recordsManagementService, - recordsManagementActionService, permissionService, - authorityService, recordsManagementSecurityService, - recordsManagementSearchBehaviour, - dispositionService); - } - - return filePlan; - } - - public static NodeRef getRecordSeries(RecordsManagementService rmService, NodeService nodeService, String seriesName) - { - NodeRef result = null; - NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - NodeRef filePlan = getFilePlan(nodeService, rootNode); - - if (filePlan != null) - { - result = nodeService.getChildByName(filePlan, ContentModel.ASSOC_CONTAINS, seriesName); - } - return result; - } - - public static NodeRef getRecordCategory(RecordsManagementService rmService, NodeService nodeService, String seriesName, String categoryName) - { - NodeRef seriesNodeRef = getRecordSeries(rmService, nodeService, seriesName); - - NodeRef result = null; - if (seriesNodeRef != null) - { - result = nodeService.getChildByName(seriesNodeRef, ContentModel.ASSOC_CONTAINS, categoryName); - } - return result; - } - - public static NodeRef getRecordFolder(RecordsManagementService rmService, NodeService nodeService, String seriesName, String categoryName, String folderName) - { - NodeRef categoryNodeRef = getRecordCategory(rmService, nodeService, seriesName, categoryName); - - NodeRef result = null; - if (categoryNodeRef != null) - { - result = nodeService.getChildByName(categoryNodeRef, ContentModel.ASSOC_CONTAINS, folderName); - } - return result; - - } - - - // TODO .. do we need to redeclare this here ?? - private static ImporterBinding REPLACE_BINDING = new ImporterBinding() - { - - public UUID_BINDING getUUIDBinding() - { - return UUID_BINDING.REPLACE_EXISTING; - } - - public String getValue(String key) - { - return null; - } - - public boolean allowReferenceWithinTransaction() - { - return false; - } - - public QName[] getExcludedClasses() - { - return null; - } - - }; - - public static void declareRecord(NodeRef recordToDeclare, NodeService nodeService, - RecordsManagementActionService rmActionService) - { - // Declare record - Map propValues = nodeService.getProperties(recordToDeclare); - propValues.put(RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); - List smList = new ArrayList(2); -// smList.add(DOD5015Test.FOUO); -// smList.add(DOD5015Test.NOFORN); - propValues.put(RecordsManagementModel.PROP_SUPPLEMENTAL_MARKING_LIST, (Serializable)smList); - propValues.put(RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); - propValues.put(RecordsManagementModel.PROP_FORMAT, "formatValue"); - propValues.put(RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); - propValues.put(RecordsManagementModel.PROP_ORIGINATOR, "origValue"); - propValues.put(RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); - propValues.put(ContentModel.PROP_TITLE, "titleValue"); - nodeService.setProperties(recordToDeclare, propValues); - rmActionService.executeRecordsManagementAction(recordToDeclare, "declareRecord"); - } -} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java deleted file mode 100644 index e137b85263..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/BootstraptestDataRestApiTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.test.webscript; - -import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; -import org.alfresco.module.org_alfresco_module_rm.test.util.TestUtilities; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; - -/** - * This class tests the Rest API for disposition related operations - * - * @author Roy Wetherall - */ -public class BootstraptestDataRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel -{ - protected static StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); - protected static final String URL = "/api/rma/bootstraptestdata"; - protected static final String SERVICE_URL_PREFIX = "/alfresco/service"; - protected static final String APPLICATION_JSON = "application/json"; - - protected NodeService nodeService; - protected RetryingTransactionHelper transactionHelper; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); - transactionHelper = (RetryingTransactionHelper)getServer().getApplicationContext().getBean("retryingTransactionHelper"); - } - - public void testBoostrapTestData() throws Exception - { - final NodeRef filePlan = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() - { - public NodeRef execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - return TestUtilities.loadFilePlanData(getServer().getApplicationContext(), false, true); - } - }); - - sendRequest(new GetRequest(URL), 200); - - transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() - { - public NodeRef execute() throws Throwable - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - nodeService.deleteNode(filePlan); - return null; - } - }); - } - -}