RM-5655 - moved the query in community

This commit is contained in:
Ana Bozianu
2017-09-28 09:17:56 +03:00
parent 6d0ab4af8f
commit 63be351b34
6 changed files with 415 additions and 3 deletions

View File

@@ -19,5 +19,23 @@
prop.string_value = ?
</select>
<!-- Counts the children that have at least one of the provided property values for a given property qname -->
<select id="select_CountChildrenWithPropertyValues"
parameterType="org.alfresco.module.org_alfresco_module_rm.query.ChildrenWithPropertyValuesQueryParams"
resultType="java.lang.Long">
select
count( distinct assoc.child_node_id )
from
alf_child_assoc assoc
left join alf_node_properties childProp on assoc.child_node_id = childProp.node_id
where
assoc.parent_node_id = #{parentId}
and childProp.qname_id = #{propertyQnameId}
and childProp.string_value in
<foreach item="item" index="index" collection="propertyValues" open="(" separator="," close=")">
'${item}'
</foreach>
</select>
</mapper>

View File

@@ -19,6 +19,8 @@
<bean id="recordsManagementQueryDAO" class="org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAOImpl">
<property name="sqlSessionTemplate" ref="rmSqlSessionTemplate"/>
<property name="qnameDAO" ref="qnameDAO"/>
<property name="nodeDAO" ref="nodeDAO" />
<property name="tenantService" ref="tenantService" />
</bean>
</beans>

View File

@@ -0,0 +1,73 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.query;
import java.util.Collection;
/**
* Select parameter for <b>select_CountChildrenWithPropertyValues</b>.
*
* @author Ana Manolache
* @since 2.6
*/
public class ChildrenWithPropertyValuesQueryParams
{
private Long parentId;
private Long propertyQnameId;
private Collection propertyValues;
public Long getParentId()
{
return parentId;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getPropertyQnameId()
{
return propertyQnameId;
}
public void setPropertyQnameId(Long propertyQnameId)
{
this.propertyQnameId = propertyQnameId;
}
public Collection getPropertyValues()
{
return propertyValues;
}
public void setPropertyValues(Collection propertyValues)
{
this.propertyValues = propertyValues;
}
}

View File

@@ -27,6 +27,11 @@
package org.alfresco.module.org_alfresco_module_rm.query;
import java.util.Collection;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/**
* Records management query DAO
*
@@ -46,4 +51,15 @@ public interface RecordsManagementQueryDAO
* @return int count
*/
int getCountRmaIdentifier(String identifierValue);
/**
* Returns whether a given node contains children with one of the given values for the given property
*
* @param parent the parent to evaluate
* @param property the QName of the property to evaluate
* @param propertyValues the list of values to look for
* @return true if there is at least one child with one of the values from the list set on the given property
* false otherwise
*/
public boolean hasChildrenWithPropertyValues(NodeRef parent, QName property, Collection propertyValues);
}

View File

@@ -27,11 +27,16 @@
package org.alfresco.module.org_alfresco_module_rm.query;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.mybatis.spring.SqlSessionTemplate;
@@ -45,12 +50,15 @@ import org.mybatis.spring.SqlSessionTemplate;
public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO, RecordsManagementModel
{
private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
private static final String COUNT_CHILDREN_WITH_PROPERTY_VALUES = "select_CountChildrenWithPropertyValues";
/** SQL session template */
protected SqlSessionTemplate template;
/** QName DAO */
protected QNameDAO qnameDAO;
protected NodeDAO nodeDAO;
protected TenantService tenantService;
/**
* @param sqlSessionTemplate SQL session template
@@ -67,7 +75,17 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
{
this.qnameDAO = qnameDAO;
}
public void setNodeDAO(NodeDAO nodeDAO)
{
this.nodeDAO = nodeDAO;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getCountRmaIdentifier(java.lang.String)
*/
@@ -97,4 +115,39 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
return result;
}
@Override
public boolean hasChildrenWithPropertyValues(NodeRef parent, QName property, Collection propertyValues)
{
if(propertyValues.isEmpty())
{
return false;
}
ChildrenWithPropertyValuesQueryParams queryParams = new ChildrenWithPropertyValuesQueryParams();
// Set the parent node id
Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(tenantService.getName(parent));
if (nodePair == null)
{
throw new InvalidNodeRefException("The parent node does not exist.", parent);
}
Long parentNodeId = nodePair.getFirst();
queryParams.setParentId(parentNodeId);
// Set the property qname id
Pair<Long, QName> pair = qnameDAO.getQName(property);
if (pair == null)
{
return false;
}
queryParams.setPropertyQnameId(pair.getFirst());
// Set the property values
queryParams.setPropertyValues(propertyValues);
// Perform the query
Long count = template.selectOne(COUNT_CHILDREN_WITH_PROPERTY_VALUES, queryParams);
return count > 0;
}
}

View File

@@ -27,10 +27,17 @@
package org.alfresco.module.org_alfresco_module_rm.test.legacy.service;
import java.util.ArrayList;
import java.util.Arrays;
import org.alfresco.model.ContentModel;
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;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
/**
* Records Management Query DAO
@@ -86,5 +93,248 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
});
}
/**
* Given a folder containing 3 files with the descriptions set
* When I check if the folder contains children having the description of file2 or file2
* Then the answer is positive
*/
@org.junit.Test
public void testHasChildrenWithPropertyValues_someChildrenWithValues() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
NodeRef parentFolder;
NodeRef file1;
NodeRef file2;
NodeRef file3;
String propValue1 = "descr1"; // set on file1
String propValue2 = "descr2"; // set on file2
String propValue3 = "descr3"; // set on file3
String propValue4 = "descr4"; // not set on any file
Boolean result;
@Override
public void given() throws Exception
{
setupCollaborationSiteTestDataImpl();
parentFolder = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file1 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file2 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file3 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
nodeService.setProperty(file1, PROP_DESCRIPTION, propValue1);
nodeService.setProperty(file2, PROP_DESCRIPTION, propValue2);
nodeService.setProperty(file3, PROP_DESCRIPTION, propValue3);
}
@Override
public void when() throws Exception
{
result = queryDAO.hasChildrenWithPropertyValues(parentFolder, PROP_DESCRIPTION, Arrays.asList(propValue1, propValue2, propValue4));
}
@Override
public void then() throws Exception
{
assertTrue(result);
}
@Override
public void after() throws Exception
{
if (parentFolder != null && nodeService.exists(parentFolder))
{
nodeService.deleteNode(parentFolder);
}
}
});
}
/**
* Given a folder containing 3 files with the descriptions unset
* When I check if the folder contains children having certain descriptions
* Then the answer is negative
*/
@org.junit.Test
public void testHasChildrenWithPropertyValues_propertyNotSetOnChildren() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
NodeRef parentFolder;
NodeRef file1;
NodeRef file2;
NodeRef file3;
Boolean result;
@Override
public void given() throws Exception
{
setupCollaborationSiteTestDataImpl();
parentFolder = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file1 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file2 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file3 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
}
@Override
public void when() throws Exception
{
result = queryDAO.hasChildrenWithPropertyValues(parentFolder, PROP_DESCRIPTION, Arrays.asList("descr1", "descr2", "descr3"));
}
@Override
public void then() throws Exception
{
assertFalse(result);
}
@Override
public void after() throws Exception
{
if (parentFolder != null && nodeService.exists(parentFolder))
{
nodeService.deleteNode(parentFolder);
}
}
});
}
/**
* Given a folder with no children but the property set on itself
* When I check if the folder contains children having certain descriptions
* Then the answer is negative
*/
@org.junit.Test
public void testHasChildrenWithPropertyValues_noChildren() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
NodeRef folder;
String propValue = "descr";
Boolean result;
@Override
public void given() throws Exception
{
setupCollaborationSiteTestDataImpl();
folder = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
nodeService.setProperty(folder, PROP_DESCRIPTION, propValue);
}
@Override
public void when() throws Exception
{
result = queryDAO.hasChildrenWithPropertyValues(folder, PROP_DESCRIPTION, Arrays.asList("descr"));
}
@Override
public void then() throws Exception
{
assertFalse(result);
}
@Override
public void after() throws Exception
{
if (folder != null && nodeService.exists(folder))
{
nodeService.deleteNode(folder);
}
}
});
}
/**
* Given a folder with children and an unused property
* When I check if the folder contains children having the unused property
* Then the answer is negative
*/
@org.junit.Test
public void testHasChildrenWithPropertyValues_propertyNotUsed() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
NodeRef parentFolder;
QName property;
Boolean result;
@Override
public void given() throws Exception
{
setupCollaborationSiteTestDataImpl();
parentFolder = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
property = QName.createQName(URI, "customProp-" + GUID.generate());
}
@Override
public void when() throws Exception
{
result = queryDAO.hasChildrenWithPropertyValues(folder, property, Arrays.asList("descr"));
}
@Override
public void then() throws Exception
{
assertFalse(result);
}
@Override
public void after() throws Exception
{
if (folder != null && nodeService.exists(folder))
{
nodeService.deleteNode(folder);
}
}
});
}
/**
* Given any folder and any property
* When I pass an empty array to the hasChildrenWithPropertyValues method
* Then the answer is negative
*/
@org.junit.Test
public void testHasChildrenWithPropertyValues_emptyArray() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
NodeRef parentFolder;
NodeRef file1;
Boolean result;
@Override
public void given() throws Exception
{
setupCollaborationSiteTestDataImpl();
parentFolder = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
file1 = fileFolderService.create(parentFolder, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
nodeService.setProperty(file1, PROP_DESCRIPTION, "descr1");
}
@Override
public void when() throws Exception
{
result = queryDAO.hasChildrenWithPropertyValues(folder, PROP_DESCRIPTION, new ArrayList());
}
@Override
public void then() throws Exception
{
assertFalse(result);
}
@Override
public void after() throws Exception
{
if (folder != null && nodeService.exists(folder))
{
nodeService.deleteNode(folder);
}
}
});
}
}