mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
MNT-20740 New db query
This commit is contained in:
@@ -8,6 +8,10 @@
|
|||||||
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
|
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
|
||||||
</parameterMap>
|
</parameterMap>
|
||||||
|
|
||||||
|
<resultMap id="result_NodeIds" type="java.lang.Long">
|
||||||
|
<result property="node.id" column="node_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
<select id="select_CountRMIndentifier" parameterMap="parameter_CountRMIndentifier" resultType="java.lang.Integer">
|
<select id="select_CountRMIndentifier" parameterMap="parameter_CountRMIndentifier" resultType="java.lang.Integer">
|
||||||
select
|
select
|
||||||
count(*)
|
count(*)
|
||||||
@@ -35,6 +39,21 @@
|
|||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- Get list of node ids which reference given content url -->
|
||||||
|
<select id="select_NodeIdsWhichReferenceContentUrl"
|
||||||
|
parameterType="ContentUrl"
|
||||||
|
resultMap="result_NodeIds">
|
||||||
|
select
|
||||||
|
p.node_id
|
||||||
|
from
|
||||||
|
alf_content_url cu
|
||||||
|
LEFT OUTER JOIN alf_content_data cd ON (cd.content_url_id = cu.id)
|
||||||
|
LEFT OUTER JOIN alf_node_properties p ON (p.long_value = cd.id)
|
||||||
|
WHERE
|
||||||
|
content_url_short = #{contentUrlShort} and
|
||||||
|
content_url_crc = #{contentUrlCrc}
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
@@ -3,18 +3,8 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<typeAliases>
|
<typeAliases>
|
||||||
<!-- General -->
|
|
||||||
<typeAlias alias="Ids" type="org.alfresco.ibatis.IdsEntity"/>
|
|
||||||
|
|
||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<typeAlias alias="Mimetype" type="org.alfresco.repo.domain.mimetype.MimetypeEntity"/>
|
|
||||||
<typeAlias alias="Encoding" type="org.alfresco.repo.domain.encoding.EncodingEntity"/>
|
|
||||||
<typeAlias alias="ContentUrl" type="org.alfresco.repo.domain.contentdata.ContentUrlEntity"/>
|
<typeAlias alias="ContentUrl" type="org.alfresco.repo.domain.contentdata.ContentUrlEntity"/>
|
||||||
<typeAlias alias="ContentUrlUpdate" type="org.alfresco.repo.domain.contentdata.ContentUrlUpdateEntity"/>
|
|
||||||
<typeAlias alias="ContentData" type="org.alfresco.repo.domain.contentdata.ContentDataEntity"/>
|
|
||||||
<typeAlias alias="ContentUrlKey" type="org.alfresco.repo.domain.contentdata.ContentUrlKeyEntity"/>
|
|
||||||
<typeAlias alias="ContentUrlOrphanQuery" type="org.alfresco.repo.domain.contentdata.ContentUrlOrphanQuery"/>
|
|
||||||
<typeAlias alias="SymmetricKeyCount" type="org.alfresco.repo.domain.contentdata.SymmetricKeyCount"/>
|
|
||||||
</typeAliases>
|
</typeAliases>
|
||||||
|
|
||||||
<typeHandlers>
|
<typeHandlers>
|
||||||
@@ -23,7 +13,6 @@
|
|||||||
|
|
||||||
<mappers>
|
<mappers>
|
||||||
<mapper resource="alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml"/>
|
<mapper resource="alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml"/>
|
||||||
<mapper resource="alfresco/ibatis/#resource.dialect#/content-common-SqlMap.xml"/>
|
|
||||||
</mappers>
|
</mappers>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
@@ -29,7 +29,6 @@ package org.alfresco.module.org_alfresco_module_rm.query;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
@@ -64,9 +63,8 @@ public interface RecordsManagementQueryDAO
|
|||||||
public Set<String> getChildrenStringPropertyValues(NodeRef parent, QName property);
|
public Set<String> getChildrenStringPropertyValues(NodeRef parent, QName property);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param contentUrl the URL of the content url entity
|
* @param contentUrl the URL of the content url entity
|
||||||
* @return Return the entity or null if it doesn't exist or is still
|
* @return Return a set of UUIDs which reference the given node
|
||||||
* referenced by a content_data entity
|
|
||||||
*/
|
*/
|
||||||
public ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl);
|
Set<String> getNodeRefsWhichReferenceContentUrl(String contentUrl);
|
||||||
}
|
}
|
||||||
|
@@ -30,18 +30,24 @@ package org.alfresco.module.org_alfresco_module_rm.query;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
||||||
import org.alfresco.repo.domain.node.NodeDAO;
|
import org.alfresco.repo.domain.node.NodeDAO;
|
||||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||||
import org.alfresco.repo.tenant.TenantService;
|
import org.alfresco.repo.tenant.TenantService;
|
||||||
|
import org.alfresco.repo.version.Version2Model;
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.mybatis.spring.SqlSessionTemplate;
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +60,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
{
|
{
|
||||||
private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
|
private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
|
||||||
private static final String GET_CHILDREN_PROPERTY_VALUES = "select_GetStringPropertyValuesOfChildren";
|
private static final String GET_CHILDREN_PROPERTY_VALUES = "select_GetStringPropertyValuesOfChildren";
|
||||||
private static final String SELECT_CONTENT_URL_BY_KEY_UNREFERENCED = "alfresco.content.select_ContentUrlByKeyUnreferenced";
|
private static final String SELECT_NODE_IDS_WHICH_REFERENCE_CONTENT_URL = "select_NodeIdsWhichReferenceContentUrl";
|
||||||
|
|
||||||
/** SQL session template */
|
/** SQL session template */
|
||||||
protected SqlSessionTemplate template;
|
protected SqlSessionTemplate template;
|
||||||
@@ -103,7 +109,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
if (pair != null)
|
if (pair != null)
|
||||||
{
|
{
|
||||||
// create query params
|
// create query params
|
||||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
Map<String, Object> params = new HashMap<>(2);
|
||||||
params.put("qnameId", pair.getFirst());
|
params.put("qnameId", pair.getFirst());
|
||||||
params.put("idValue", identifierValue);
|
params.put("idValue", identifierValue);
|
||||||
|
|
||||||
@@ -147,7 +153,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl)
|
public Set<String> getNodeRefsWhichReferenceContentUrl(String contentUrl)
|
||||||
{
|
{
|
||||||
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
||||||
contentUrlEntity.setContentUrl(contentUrl);
|
contentUrlEntity.setContentUrl(contentUrl);
|
||||||
@@ -155,8 +161,31 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
{
|
{
|
||||||
contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
|
contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
|
||||||
}
|
}
|
||||||
contentUrlEntity = (ContentUrlEntity) template.selectOne(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity);
|
|
||||||
|
|
||||||
return contentUrlEntity;
|
// Get all the node ids which reference the given content url
|
||||||
|
List<Long> nodeIds = template.selectList(SELECT_NODE_IDS_WHICH_REFERENCE_CONTENT_URL, contentUrlEntity);
|
||||||
|
|
||||||
|
// create a set of uuids which reference the content url
|
||||||
|
Set<String> nodesReferencingContentUrl = new HashSet<>();
|
||||||
|
for(Long nodeId : nodeIds)
|
||||||
|
{
|
||||||
|
String uuidToAdd;
|
||||||
|
|
||||||
|
// if the referencing node is a version2Store reference to the content url, add the uuid for the version 2 frozen node ref
|
||||||
|
NodeRef version2FrozenNodeRef = (NodeRef) nodeDAO.getNodeProperty(nodeId, Version2Model.PROP_QNAME_FROZEN_NODE_REF);
|
||||||
|
if (version2FrozenNodeRef != null)
|
||||||
|
{
|
||||||
|
uuidToAdd = version2FrozenNodeRef.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the uuid for the node ref of the referencing node
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uuidToAdd = (String) nodeDAO.getNodeProperty(nodeId, ContentModel.PROP_NODE_UUID);
|
||||||
|
}
|
||||||
|
nodesReferencingContentUrl.add(uuidToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodesReferencingContentUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,13 +28,14 @@ package org.alfresco.module.org_alfresco_module_rm.util;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class to duplicate the content of a node without triggering the audit or versioning behaviours
|
* Utility class to duplicate the content of a node without triggering the audit or versioning behaviours
|
||||||
* @author Ross Gale
|
* @author Ross Gale
|
||||||
@@ -94,8 +95,9 @@ public class ContentBinDuplicationUtility
|
|||||||
{
|
{
|
||||||
boolean hasAtLeastOneOtherReference = false;
|
boolean hasAtLeastOneOtherReference = false;
|
||||||
String contentUrl = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl();
|
String contentUrl = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl();
|
||||||
ContentUrlEntity contentUrlEntity = recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl);
|
|
||||||
if (contentUrlEntity == null)
|
Set<String> referencesToContentNode = recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(contentUrl);
|
||||||
|
if (referencesToContentNode.size() > 1)
|
||||||
{
|
{
|
||||||
hasAtLeastOneOtherReference = true;
|
hasAtLeastOneOtherReference = true;
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,6 @@ package org.alfresco.module.org_alfresco_module_rm.util;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
@@ -41,6 +40,10 @@ import org.mockito.InjectMocks;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -54,6 +57,9 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
public class ContentBinDuplicationUtilityUnitTest
|
public class ContentBinDuplicationUtilityUnitTest
|
||||||
{
|
{
|
||||||
|
private final static NodeRef NODE_REF = new NodeRef("some://test/noderef");
|
||||||
|
private final static NodeRef NODE_REF2 = new NodeRef("some://test/anothernoderef");
|
||||||
|
private final static String CONTENT_URL = "someContentUrl";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
@@ -85,10 +91,9 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testContentUrlIsUpdated()
|
public void testContentUrlIsUpdated()
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
when(contentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(contentWriter);
|
||||||
when(contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true)).thenReturn(contentWriter);
|
contentBinDuplicationUtility.duplicate(NODE_REF);
|
||||||
contentBinDuplicationUtility.duplicate(nodeRef);
|
|
||||||
verify(contentWriter, times(1)).putContent(contentReader);
|
verify(contentWriter, times(1)).putContent(contentReader);
|
||||||
checkBehaviours(1);
|
checkBehaviours(1);
|
||||||
}
|
}
|
||||||
@@ -99,9 +104,8 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testDuplicationDoesntHappenWithNoContent()
|
public void testDuplicationDoesntHappenWithNoContent()
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null);
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(null);
|
contentBinDuplicationUtility.duplicate(NODE_REF);
|
||||||
contentBinDuplicationUtility.duplicate(nodeRef);
|
|
||||||
verify(contentWriter, times(0)).putContent(contentReader);
|
verify(contentWriter, times(0)).putContent(contentReader);
|
||||||
checkBehaviours(1);
|
checkBehaviours(1);
|
||||||
}
|
}
|
||||||
@@ -112,32 +116,44 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testHasAtLeastOneOtherReference()
|
public void testHasAtLeastOneOtherReference()
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
Set<String> multipleReferences = new HashSet<>();
|
||||||
String contentUrl = "someContentUrl";
|
Collections.addAll(multipleReferences, NODE_REF.getId(), NODE_REF2.getId());
|
||||||
|
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(contentUrl);
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(CONTENT_URL);
|
||||||
when(recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl)).thenReturn(null);
|
when(recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(CONTENT_URL)).thenReturn(multipleReferences);
|
||||||
|
|
||||||
boolean hasReference = contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef);
|
assertTrue(contentBinDuplicationUtility.hasAtLeastOneOtherReference(NODE_REF));
|
||||||
assertTrue(hasReference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test hasAtLeastOneOtherReference returns false when node has no other reference to it
|
* Test hasAtLeastOneOtherReference returns false when node has no other reference to it other than its own content ref
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testHasNoOtherReference()
|
public void testHasNoOtherReference()
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
Set<String> singleReference = Collections.singleton(NODE_REF.getId());
|
||||||
String contentUrl = "someContentUrl";
|
|
||||||
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
|
||||||
|
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(contentUrl);
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(CONTENT_URL);
|
||||||
when(recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl)).thenReturn(contentUrlEntity);
|
when(recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(CONTENT_URL)).thenReturn(singleReference);
|
||||||
|
|
||||||
assertFalse(contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef));
|
assertFalse(contentBinDuplicationUtility.hasAtLeastOneOtherReference(NODE_REF));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test hasAtLeastOneOtherReference returns false when node has no references to it at all
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testHasNoReferences()
|
||||||
|
{
|
||||||
|
Set<String> noReferences = Collections.<String> emptySet();
|
||||||
|
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(CONTENT_URL);
|
||||||
|
when(recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(CONTENT_URL)).thenReturn(noReferences);
|
||||||
|
|
||||||
|
assertFalse(contentBinDuplicationUtility.hasAtLeastOneOtherReference(NODE_REF));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user