Merge remote-tracking branch 'remotes/origin/master' into xperimental/RM-6313UpgradeRMSchedulers_remote

This commit is contained in:
Rodica Sutu
2018-05-31 10:49:11 +03:00
5 changed files with 207 additions and 53 deletions

View File

@@ -121,6 +121,37 @@ public abstract class BaseAPI
return results;
}
/**
* Helper method to extract the property value for the given nodeRef and property name
*
* @param result
* @param nodeRef
* @param propertyName
* @return
*/
protected String getPropertyValue(JSONObject result, String nodeRef, String propertyName)
{
String propertyValue = "";
try
{
JSONArray items = result.getJSONArray("items");
for (int i = 0; i < items.length(); i++)
{
JSONObject item = items.getJSONObject(i);
if(nodeRef.equals(item.getString("nodeRef")))
{
propertyValue = item.getJSONObject("properties").getString(propertyName);
}
}
}
catch (JSONException error)
{
throw new RuntimeException("Unable to parse result", error);
}
return propertyValue;
}
/**
* Helper method to extract property values from request result and put them in map as a list that corresponds to a unique property value.
*

View File

@@ -63,7 +63,7 @@ public class SearchAPI extends BaseAPI
/** RM search URL template */
private static final String RM_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/{1}?{2}";
/** RM document search filters */
/** RM all nodes search filters */
private static final String RM_DEFAULT_NODES_FILTERS =
"records/true,undeclared/true,vital/false,folders/{0},categories/{1},frozen/false,cutoff/false";
@@ -123,23 +123,46 @@ public class SearchAPI extends BaseAPI
* Search as a user for nodes on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS and sorted
* by sortby
* <br>
* If more fine-grained control of search parameters is required, use rmSearch() directly.
*
* @param username
* @param password
* @param query
* @param sortby
* @return list of record names
* @return list of node names
*/
public List<String> searchForRecordsAsUser(
String username, String password,
String query, String sortby,
boolean includeCategories, boolean includeFolders)
public List<String> searchForNodeNamesAsUser(String username, String password, String query, String sortby,
boolean includeCategories, boolean includeFolders)
{
String searchFilterParamaters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders), Boolean.toString(includeCategories));
String searchFilterParamaters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders),
Boolean.toString(includeCategories));
return getItemNames(rmSearch(username, password, "rm", query, searchFilterParamaters, sortby));
}
/**
* Search as a user for nodes on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS and sorted
* by sortby and returns the property value for the given nodeRef and property name
*
* @param username
* @param password
* @param query
* @param sortby
* @param includeCategories
* @param includeFolders
* @return list of node properties
*/
public String searchForNodePropertyAsUser(String username, String password, String nodeRef, String propertyName, String query, String sortby,
boolean includeCategories, boolean includeFolders)
{
String searchFilterParamaters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders),
Boolean.toString(includeCategories));
return getItemProperty(rmSearch(username, password, "rm", query, searchFilterParamaters, sortby), nodeRef, propertyName);
}
/**
* Generic faceted search.
* @param username
* @param password
@@ -208,12 +231,35 @@ public class SearchAPI extends BaseAPI
/**
* Helper method to extract list of names from search result.
*
* @param searchResult
* @return list of document or record names in search result
* @throws FileNotFoundException
* @throws JsonSyntaxException
* @throws JsonIOException
* @throws RuntimeException for malformed search response
*/
/**
* Helper method to extract list of names from search result.
*
* @param searchResult
* @param getProperties
* @return
*/
private List<String> getItemNames(JSONObject searchResult)
{
return getPropertyValues(searchResult, "name");
}
/**
* Helper method to extract list of property values from search result for the given nodeRef.
*
* @param searchResult
* @param getProperties
* @return
*/
private String getItemProperty(JSONObject searchResult, String nodeRef, String propertyName)
{
return getPropertyValue(searchResult, nodeRef, propertyName);
}
}

View File

@@ -591,6 +591,17 @@ public class BaseRMRestTest extends RestTest
RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI();
recordFolderAPI.deleteRecordFolder(recordFolderId);
}
/**
* Delete a record
*
* @param recordId the id of the record to delete
*/
public void deleteRecord(String recordId)
{
RecordsAPI recordsAPI = restAPIFactory.getRecordsAPI();
recordsAPI.deleteRecord(recordId);
}
/**
* Delete a record category
@@ -670,13 +681,15 @@ public class BaseRMRestTest extends RestTest
}
/**
* Returns records search results for the given search term
*
* Returns the list of node names returned by search results for the given search term
*
* @param user
* @param term
* @param sortby
* @param includeFolders
* @param includeCategories
* @param expectedResults
* @return
* @return List<String>
*/
public List<String> searchForRMContentAsUser(UserModel user, String term, String sortby, boolean includeFolders,
boolean includeCategories, List<String> expectedResults)
@@ -697,8 +710,9 @@ public class BaseRMRestTest extends RestTest
{
}
}
results = searchApi.searchForRecordsAsUser(user.getUsername(), user.getPassword(), term, sortby,
includeFolders, includeCategories);
results = searchApi.searchForNodeNamesAsUser(user.getUsername(), user.getPassword(), term, sortby,
includeFolders, includeCategories);
if (!results.isEmpty() && results.containsAll(expectedResults))
{
break;
@@ -713,6 +727,54 @@ public class BaseRMRestTest extends RestTest
return results;
}
/**
* Returns the property value for the given property name and nodeRef of the search results
*
* @param user
* @param term
* @param nodeRef
* @param propertyName
* @param sortby
* @param includeFolders
* @param includeCategories
* @param expectedResults
* @return String
*/
public String searchForRMContentAsUser(UserModel user, String term, String nodeRef, String propertyName,
String sortby, boolean includeFolders, boolean includeCategories, String expectedResults)
{
String result = "";
// wait for solr indexing
int counter = 0;
int waitInMilliSeconds = 6000;
while (counter < 3)
{
synchronized (this)
{
try
{
this.wait(waitInMilliSeconds);
}
catch (InterruptedException e)
{
}
}
result = searchApi.searchForNodePropertyAsUser(user.getUsername(), user.getPassword(), nodeRef,
propertyName, term, sortby, includeFolders, includeCategories);
if (!result.isEmpty() && result.contains(expectedResults))
{
break;
}
else
{
counter++;
}
// double wait time to not overdo solr search
waitInMilliSeconds = (waitInMilliSeconds * 2);
}
return result;
}
/**
* Helper method to return site document library content model
*

View File

@@ -811,63 +811,77 @@ public class DispositionServiceImpl extends ServiceBaseImpl
public boolean isNextDispositionActionEligible(NodeRef nodeRef)
{
boolean result = false;
// Get the disposition instructions
DispositionSchedule di = getDispositionSchedule(nodeRef);
NodeRef nextDa = getNextDispositionActionNodeRef(nodeRef);
DispositionAction nextDa = getNextDispositionAction(nodeRef);
if (di != null &&
this.nodeService.hasAspect(nodeRef, ASPECT_DISPOSITION_LIFECYCLE) &&
nextDa != null)
{
// If it has an asOf date and it is greater than now the action is eligible
Date asOf = (Date)this.nodeService.getProperty(nextDa, PROP_DISPOSITION_AS_OF);
if (asOf != null &&
asOf.before(new Date()))
// for accession step we can have also AND between step conditions
Boolean combineSteps = false;
if (nextDa.getName().equals("accession"))
{
result = true;
}
if (!result)
{
DispositionAction da = new DispositionActionImpl(serviceRegistry, nextDa);
DispositionActionDefinition dad = da.getDispositionActionDefinition();
if (dad != null)
{
boolean firstComplete = dad.eligibleOnFirstCompleteEvent();
List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(nextDa, ASSOC_EVENT_EXECUTIONS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assoc : assocs)
NodeRef accessionNodeRef = di.getDispositionActionDefinitionByName("accession").getNodeRef();
if (accessionNodeRef != null) {
Boolean combineStepsProp = (Boolean)this.nodeService.getProperty(accessionNodeRef, PROP_COMBINE_DISPOSITION_STEP_CONDITIONS);
if (combineStepsProp != null)
{
NodeRef eventExecution = assoc.getChildRef();
Boolean isCompleteValue = (Boolean)this.nodeService.getProperty(eventExecution, PROP_EVENT_EXECUTION_COMPLETE);
boolean isComplete = false;
if (isCompleteValue != null)
{
isComplete = isCompleteValue.booleanValue();
combineSteps = combineStepsProp;
}
}
}
Date asOf = (Date)this.nodeService.getProperty(nextDa.getNodeRef(), PROP_DISPOSITION_AS_OF);
Boolean asOfDateInPast = false;
if (asOf != null)
{
asOfDateInPast = asOf.before(new Date());
}
if (asOfDateInPast && !combineSteps)
{
return true;
}
else if(!asOfDateInPast && combineSteps)
{
return false;
}
DispositionAction da = new DispositionActionImpl(serviceRegistry, nextDa.getNodeRef());
DispositionActionDefinition dad = da.getDispositionActionDefinition();
if (dad != null)
{
boolean firstComplete = dad.eligibleOnFirstCompleteEvent();
// implement AND and OR combination of event completions
if (isComplete)
List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(nextDa.getNodeRef(), ASSOC_EVENT_EXECUTIONS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assoc : assocs)
{
NodeRef eventExecution = assoc.getChildRef();
Boolean isCompleteValue = (Boolean)this.nodeService.getProperty(eventExecution, PROP_EVENT_EXECUTION_COMPLETE);
boolean isComplete = false;
if (isCompleteValue != null)
{
isComplete = isCompleteValue.booleanValue();
// implement AND and OR combination of event completions
if (isComplete)
{
result = true;
if (firstComplete)
{
result = true;
if (firstComplete)
{
break;
}
break;
}
else
}
else
{
result = false;
if (!firstComplete)
{
result = false;
if (!firstComplete)
{
break;
}
break;
}
}
}
}
}
}
return result;
}

View File

@@ -29,7 +29,7 @@ package org.alfresco.module.org_alfresco_module_rm.jscript.app;
import static org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel.READ_RECORDS;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_COMBINE_DISPOSITION_STEP_CONDITIONS;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_RS_DISPOSITION_EVENTS;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_DISPOSITION_EVENT_COMBINATION;
import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED;
import java.util.ArrayList;
@@ -485,6 +485,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS
HashMap properties = ((HashMap) rmNodeValues.get("properties"));
properties.put("combineDispositionStepConditions", nodeService.getProperty(dispositionService.getNextDispositionAction(nodeRef).getDispositionActionDefinition().getNodeRef(), PROP_COMBINE_DISPOSITION_STEP_CONDITIONS));
properties.put("incompleteDispositionEvent", details.getEventName());
properties.put("dispositionEventCombination", nodeService.getProperty(dispositionService.getNextDispositionAction(nodeRef).getDispositionActionDefinition().getNodeRef(), PROP_DISPOSITION_EVENT_COMBINATION));
break;
}
}