diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml
index b9197962d2..6d382917ad 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml
@@ -42,6 +42,9 @@
+
+
+
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml
new file mode 100644
index 0000000000..3b050f6164
--- /dev/null
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMapConfig.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMapConfig.xml
new file mode 100644
index 0000000000..bc08a1ec1b
--- /dev/null
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMapConfig.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-query-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-query-context.xml
new file mode 100644
index 0000000000..9310260baf
--- /dev/null
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/query/rm-query-context.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+ classpath:alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMapConfig.xml
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml
index fbaa11b0a6..29f3291417 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml
@@ -70,6 +70,7 @@
class="org.alfresco.module.org_alfresco_module_rm.model.behaviour.RecordComponentIdentifierAspect"
parent="org_alfresco_module_rm_BaseBehaviour">
+
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordComponentIdentifierAspect.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordComponentIdentifierAspect.java
index 97e3b434a4..342e9b71c1 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordComponentIdentifierAspect.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordComponentIdentifierAspect.java
@@ -21,17 +21,17 @@ package org.alfresco.module.org_alfresco_module_rm.model.behaviour;
import java.io.Serializable;
import java.util.Map;
+import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy;
+import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
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.service.cmr.attributes.AttributeService;
-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.namespace.QName;
@@ -52,6 +52,7 @@ public class RecordComponentIdentifierAspect
private PolicyComponent policyComponent;
private NodeService nodeService;
private AttributeService attributeService;
+ private FilePlanService filePlanService;
/**
* @param policyComponent the policyComponent to set
@@ -76,6 +77,11 @@ public class RecordComponentIdentifierAspect
{
this.attributeService = attributeService;
}
+
+ public void setFilePlanService(FilePlanService filePlanService)
+ {
+ this.filePlanService = filePlanService;
+ }
/**
* Initialise method
@@ -137,27 +143,21 @@ public class RecordComponentIdentifierAspect
*/
private void updateUniqueness(NodeRef nodeRef, String beforeId, String afterId)
{
+ NodeRef contextNodeRef = filePlanService.getFilePlan(nodeRef);
+
if (beforeId == null)
{
if (afterId != null)
{
// Just create it
- ChildAssociationRef childAssoc = nodeService.getPrimaryParent(nodeRef);
- NodeRef contextNodeRef = childAssoc.getParentRef();
attributeService.createAttribute(null, CONTEXT_VALUE, contextNodeRef, afterId);
}
- else
- {
- // This happens if the unique property is not present
- }
}
else if (afterId == null)
{
if (beforeId != null)
{
// The before value was not null, so remove it
- ChildAssociationRef childAssoc = nodeService.getPrimaryParent(nodeRef);
- NodeRef contextNodeRef = childAssoc.getParentRef();
attributeService.removeAttribute(CONTEXT_VALUE, contextNodeRef, beforeId);
}
// Do a blanket removal in case this is a contextual nodes
@@ -166,8 +166,6 @@ public class RecordComponentIdentifierAspect
else
{
// This is a full update
- ChildAssociationRef childAssoc = nodeService.getPrimaryParent(nodeRef);
- NodeRef contextNodeRef = childAssoc.getParentRef();
attributeService.updateOrCreateAttribute(
CONTEXT_VALUE, contextNodeRef, beforeId,
CONTEXT_VALUE, contextNodeRef, afterId);
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java
new file mode 100644
index 0000000000..5c1cb12480
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2005-2013 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.query;
+
+/**
+ * Records management query DAO
+ *
+ * NOTE: a place holder that can be extended later when we want to enhance performance with canned queries.
+ *
+ * @author Roy Wetherall
+ * @since 2.1
+ */
+public interface RecordsManagementQueryDAO
+{
+ /**
+ * Get the number of objects with the given identifier value.
+ *
+ * Note: this is provided as an example and is not currently used
+ *
+ * @param identifierValue id value
+ * @return int count
+ */
+ int getCountRmaIdentifier(String identifierValue);
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java
new file mode 100644
index 0000000000..23c4039910
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2005-2013 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.query;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
+import org.alfresco.repo.domain.qname.QNameDAO;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.util.Pair;
+import org.mybatis.spring.SqlSessionTemplate;
+
+/**
+ * Records management query DAO implementation
+ *
+ * @author Roy Wetherall
+ * @since 2.1
+ */
+public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO, RecordsManagementModel
+{
+ private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
+
+ /** SQL session template */
+ protected SqlSessionTemplate template;
+
+ /** QName DAO */
+ protected QNameDAO qnameDAO;
+
+ /**
+ * @param sqlSessionTemplate SQL session template
+ */
+ public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
+ {
+ this.template = sqlSessionTemplate;
+ }
+
+ /**
+ * @param qnameDAO qname DAO
+ */
+ public final void setQnameDAO(QNameDAO qnameDAO)
+ {
+ this.qnameDAO = qnameDAO;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getCountRmaIdentifier(java.lang.String)
+ */
+ @Override
+ public int getCountRmaIdentifier(String identifierValue)
+ {
+ int result = 0;
+
+ // lookup the id of the identifier property qname
+ Pair pair = qnameDAO.getQName(PROP_IDENTIFIER);
+ if (pair != null)
+ {
+ // create query params
+ Map params = new HashMap(2);
+ params.put("qnameId", pair.getFirst());
+ params.put("idValue", identifierValue);
+
+ // return the number of rma identifiers found that match the passed value
+ Integer count = (Integer)template.selectOne(COUNT_IDENTIFIER, params);
+
+ if (count != null)
+ {
+ result = count;
+ }
+ }
+
+ return result;
+ }
+
+}
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java
index 12225298ba..509e59cbde 100644
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java
@@ -32,6 +32,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.service.RecordServiceImpl
import org.alfresco.module.org_alfresco_module_rm.test.service.RecordsManagementActionServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.RecordsManagementAdminServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.RecordsManagementAuditServiceImplTest;
+import org.alfresco.module.org_alfresco_module_rm.test.service.RecordsManagementQueryDAOImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.RecordsManagementSearchServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.ReportServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.VitalRecordServiceImplTest;
@@ -66,7 +67,8 @@ import org.junit.runners.Suite.SuiteClasses;
FilePlanRoleServiceImplTest.class,
FilePlanServiceImplTest.class,
FilePlanPermissionServiceImplTest.class,
- ReportServiceImplTest.class
+ ReportServiceImplTest.class,
+ RecordsManagementQueryDAOImplTest.class
})
public class ServicesTestSuite
{
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementQueryDAOImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementQueryDAOImplTest.java
new file mode 100644
index 0000000000..766f6dffae
--- /dev/null
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementQueryDAOImplTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.module.org_alfresco_module_rm.model.RecordsManagementModel;
+import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
+import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
+import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
+
+/**
+ * Records Management Query DAO
+ *
+ * @author Roy Wetherall
+ * @since 2.1
+ */
+public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements RecordsManagementModel
+{
+ protected RecordsManagementQueryDAO queryDAO;
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices()
+ */
+ @Override
+ protected void initServices()
+ {
+ super.initServices();
+
+ queryDAO = (RecordsManagementQueryDAO)applicationContext.getBean("recordsManagementQueryDAO");
+ }
+
+ /**
+ * This is a record test
+ *
+ * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isRecordTest()
+ */
+ @Override
+ protected boolean isRecordTest()
+ {
+ return true;
+ }
+
+ /**
+ * @see RecordService#getRecordMetaDataAspects()
+ */
+ public void testGetRecordMetaDataAspects() throws Exception
+ {
+ doTestInTransaction(new Test()
+ {
+ @Override
+ public Void run()
+ {
+ int count = queryDAO.getCountRmaIdentifier("abc-123");
+ assertEquals(0, count);
+
+ String existingID = (String)nodeService.getProperty(recordOne, PROP_IDENTIFIER);
+ count = queryDAO.getCountRmaIdentifier(existingID);
+ assertEquals(1, count);
+
+ return null;
+ }
+ });
+ }
+
+
+}