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

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