modify the hasChildrenWithPropertyValues to getChildrenPropertyValues in order to return the query result

update the implementation where the modified method is used
update tests
This commit is contained in:
Rodica Sutu
2018-01-26 10:57:49 +02:00
parent 0de2737529
commit 245ffee3e0
3 changed files with 20 additions and 24 deletions

View File

@@ -27,7 +27,7 @@
package org.alfresco.module.org_alfresco_module_rm.query; package org.alfresco.module.org_alfresco_module_rm.query;
import java.util.Collection; import java.util.List;
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;
@@ -53,13 +53,11 @@ public interface RecordsManagementQueryDAO
int getCountRmaIdentifier(String identifierValue); int getCountRmaIdentifier(String identifierValue);
/** /**
* Returns whether a given node contains children with one of the given values for the given property * Returns the property values from children for the given property
* *
* @param parent the parent to evaluate * @param parent the parent to evaluate
* @param property the QName of the property to evaluate * @param property the QName of the property to evaluate
* @param propertyValues the list of values to look for * @return list of property values
* @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); public List<String> getChildrenPropertyValues(NodeRef parent, QName property);
} }

View File

@@ -27,7 +27,6 @@
package org.alfresco.module.org_alfresco_module_rm.query; package org.alfresco.module.org_alfresco_module_rm.query;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -118,13 +117,8 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
} }
@Override @Override
public boolean hasChildrenWithPropertyValues(NodeRef parent, QName property, Collection propertyValues) public List<String> getChildrenPropertyValues(NodeRef parent, QName property)
{ {
if (propertyValues.isEmpty())
{
return false;
}
PropertyValuesOfChildrenQueryParams queryParams = new PropertyValuesOfChildrenQueryParams(); PropertyValuesOfChildrenQueryParams queryParams = new PropertyValuesOfChildrenQueryParams();
// Set the parent node id // Set the parent node id
@@ -140,15 +134,12 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
Pair<Long, QName> pair = qnameDAO.getQName(property); Pair<Long, QName> pair = qnameDAO.getQName(property);
if (pair == null) if (pair == null)
{ {
return false; return Collections.emptyList();
} }
queryParams.setPropertyQnameId(pair.getFirst()); queryParams.setPropertyQnameId(pair.getFirst());
// Perform the query // Perform the query
List<String> childrenPropertyValues = template.selectList(GET_CHILDREN_PROPERTY_VALUES, queryParams); return template.selectList(GET_CHILDREN_PROPERTY_VALUES, queryParams);
//check if any propertyValues is in the childrenPropertyValues
return !Collections.disjoint(propertyValues, childrenPropertyValues);
} }
} }

View File

@@ -29,6 +29,8 @@ package org.alfresco.module.org_alfresco_module_rm.test.legacy.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.alfresco.model.ContentModel; 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;
@@ -130,7 +132,8 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
@Override @Override
public void when() throws Exception public void when() throws Exception
{ {
result = queryDAO.hasChildrenWithPropertyValues(parentFolder, PROP_DESCRIPTION, Arrays.asList(propValue1, propValue2, propValue4)); List<String> propertyValues = queryDAO.getChildrenPropertyValues(parentFolder, PROP_DESCRIPTION);
result = !Collections.disjoint(Arrays.asList(propValue1, propValue2, propValue4),propertyValues);
} }
@Override @Override
@@ -179,7 +182,8 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
@Override @Override
public void when() throws Exception public void when() throws Exception
{ {
result = queryDAO.hasChildrenWithPropertyValues(parentFolder, PROP_DESCRIPTION, Arrays.asList("descr1", "descr2", "descr3")); List<String> propertyValues = queryDAO.getChildrenPropertyValues(parentFolder, PROP_DESCRIPTION);
result = !Collections.disjoint(Arrays.asList("descr1", "descr2", "descr3"), propertyValues);
} }
@Override @Override
@@ -224,7 +228,8 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
@Override @Override
public void when() throws Exception public void when() throws Exception
{ {
result = queryDAO.hasChildrenWithPropertyValues(folder, PROP_DESCRIPTION, Arrays.asList("descr")); List<String> propertyValues = queryDAO.getChildrenPropertyValues(folder, PROP_DESCRIPTION);
result = !Collections.disjoint(Arrays.asList("descr"), propertyValues);
} }
@Override @Override
@@ -271,7 +276,8 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
@Override @Override
public void when() throws Exception public void when() throws Exception
{ {
result = queryDAO.hasChildrenWithPropertyValues(folder, property, Arrays.asList("descr")); List<String> propertyValues = queryDAO.getChildrenPropertyValues(folder, property);
result = !Collections.disjoint(Arrays.asList("descr"), propertyValues);
} }
@Override @Override
@@ -293,7 +299,7 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
/** /**
* Given any folder and any property * Given any folder and any property
* When I pass an empty array to the hasChildrenWithPropertyValues method * When I pass an empty array to the getChildrenPropertyValues method
* Then the answer is negative * Then the answer is negative
*/ */
@org.junit.Test @org.junit.Test
@@ -318,7 +324,8 @@ public class RecordsManagementQueryDAOImplTest extends BaseRMTestCase implements
@Override @Override
public void when() throws Exception public void when() throws Exception
{ {
result = queryDAO.hasChildrenWithPropertyValues(folder, PROP_DESCRIPTION, new ArrayList()); List<String> propertyValues = queryDAO.getChildrenPropertyValues(folder, PROP_DESCRIPTION);
result = !Collections.disjoint(new ArrayList(), propertyValues);
} }
@Override @Override