RM-784: Possible to create categories/folders with the same identifier

* started out adding a RM query DOA so canned queries could be added .. turned out this wasn't required, but it's a handy
   bit of framework to have in place for the future so I've left it in with an example query and unit test.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@54102 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2013-08-15 06:25:18 +00:00
parent d8f66a6994
commit 53e3f9d36b
10 changed files with 290 additions and 13 deletions

View File

@@ -42,6 +42,9 @@
</bean>
<import resource="classpath:alfresco/module/org_alfresco_module_rm/rm-model-context.xml"/>
<!-- Import RM query context -->
<import resource="classpath:alfresco/module/org_alfresco_module_rm/query/rm-query-context.xml" />
<!-- Load audit config -->

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="alfresco.query.rm">
<parameterMap id="parameter_CountRMIndentifier" type="map">
<parameter property="qnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
</parameterMap>
<select id="select_CountRMIndentifier" parameterMap="parameter_CountRMIndentifier" resultType="java.lang.Integer">
select
count(*)
from
alf_node node
join alf_node_properties prop on (prop.node_id = node.id)
where
prop.qname_id = ? and
prop.string_value = ?
</select>
</mapper>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeHandlers>
<typeHandler javaType="java.io.Serializable" handler="org.alfresco.ibatis.SerializableTypeHandler"/>
</typeHandlers>
<mappers>
<mapper resource="alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml"/>
</mappers>
</configuration>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="rmSqlSessionFactory" class="org.alfresco.ibatis.HierarchicalSqlSessionFactoryBean">
<property name="useLocalCaches" value="${mybatis.useLocalCaches}"/>
<property name="resourceLoader" ref="dialectResourceLoader"/>
<property name="dataSource" ref="dataSource"/>
<property name="configLocation">
<value>classpath:alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMapConfig.xml</value>
</property>
</bean>
<bean id="rmSqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="rmSqlSessionFactory"/>
</bean>
<bean id="recordsManagementQueryDAO" class="org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAOImpl">
<property name="sqlSessionTemplate" ref="rmSqlSessionTemplate"/>
<property name="qnameDAO" ref="qnameDAO"/>
</bean>
</beans>

View File

@@ -70,6 +70,7 @@
class="org.alfresco.module.org_alfresco_module_rm.model.behaviour.RecordComponentIdentifierAspect"
parent="org_alfresco_module_rm_BaseBehaviour">
<property name="attributeService" ref="attributeService"/>
<property name="filePlanService" ref="FilePlanService" />
</bean>
<!-- Copy policy management for records -->

View File

@@ -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);

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<Long, QName> pair = qnameDAO.getQName(PROP_IDENTIFIER);
if (pair != null)
{
// create query params
Map<String, Object> params = new HashMap<String, Object>(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;
}
}

View File

@@ -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
{

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<Void>()
{
@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;
}
});
}
}