Add active content to hold through rest api

This commit is contained in:
cagache
2019-08-09 12:07:24 +03:00
parent dded7766c7
commit 2f88cee847
14 changed files with 208 additions and 23 deletions

View File

@@ -549,7 +549,7 @@
<many>true</many>
</source>
<target>
<class>rma:filePlanComponent</class>
<class>sys:base</class>
<mandatory>false</mandatory>
<many>true</many>
</target>

View File

@@ -1042,7 +1042,7 @@
<property name="objectDefinitionSource">
<value>
<![CDATA[
org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService.isRecordFolder=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService.isRecordFolder=ACL_NODE.0.sys:base.Read,RM.Read.0
org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService.isRecordFolderDeclared=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService.isRecordFolderClosed=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService.createRecordFolder=RM.Create.0
@@ -1535,6 +1535,7 @@
<property name="recordFolderService" ref="RecordFolderService" />
<property name="permissionService" ref="PermissionService"/>
<property name="recordsManagementAuditService" ref="RecordsManagementAuditService" />
<property name="capabilityService" ref="CapabilityService"/>
</bean>
<bean id="HoldService"

View File

@@ -633,6 +633,7 @@
<property name="recordService" ref="RecordService" />
<property name="recordFolderService" ref="RecordFolderService" />
<property name="nodeService" ref="NodeService" />
<property name="dictionaryService" ref="DictionaryService" />
</bean>
<!-- REST impl for POST Hold -->

View File

@@ -1,10 +1,10 @@
<webscript>
<shortname>Adds item(s) to the hold(s)</shortname>
<description><![CDATA[
WebScript to add item(s) (record(s) / record folder(s)) to the hold(s) in the holds container.<br/>
WebScript to add item(s) (record(s) / record folder(s) / active content(s)) to the hold(s) in the holds container.<br/>
The body of the post should be in the form<br/>
{<br/>
&nbsp;&nbsp;&nbsp;"nodeRefs" : array of nodeRefs for item(s) (record(s) / record folder(s)),<br/>
&nbsp;&nbsp;&nbsp;"nodeRefs" : array of nodeRefs for item(s) (record(s) / record folder(s) / active content(s)),<br/>
&nbsp;&nbsp;&nbsp;"holds" : array of nodeRefs for the hold(s)<br/>
}<br/>
]]>

View File

@@ -1,10 +1,10 @@
<webscript>
<shortname>Removes item(s) from the hold(s)</shortname>
<description><![CDATA[
WebScript to remove item(s) (record(s) / record folder(s)) from the hold(s) in the holds container.<br/>
WebScript to remove item(s) (record(s) / record folder(s) / active content(s)) from the hold(s) in the holds container.<br/>
The body of the put should be in the form<br/>
{<br/>
&nbsp;&nbsp;&nbsp;"nodeRefs" : array of nodeRefs for the item(s) (record(s) / record folder(s)),<br/>
&nbsp;&nbsp;&nbsp;"nodeRefs" : array of nodeRefs for the item(s) (record(s) / record folder(s) / active content(s)),<br/>
&nbsp;&nbsp;&nbsp;"holds" : array of nodeRefs for the hold(s)<br/>
}<br/>
]]>

View File

@@ -41,6 +41,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService;
import org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
@@ -108,6 +109,9 @@ public class HoldServiceImpl extends ServiceBaseImpl
/** records management audit service */
private RecordsManagementAuditService recordsManagementAuditService;
/** Capability service */
private CapabilityService capabilityService;
/**
* Set the file plan service
*
@@ -166,6 +170,14 @@ public class HoldServiceImpl extends ServiceBaseImpl
this.recordsManagementAuditService = recordsManagementAuditService;
}
/**
* @param capabilityService capability service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/**
* Initialise hold service
*/
@@ -563,7 +575,9 @@ public class HoldServiceImpl extends ServiceBaseImpl
throw new IntegrityException(I18NUtil.getMessage("rm.hold.not-hold", holdName), null);
}
if (permissionService.hasPermission(hold, RMPermissionModel.FILING) == AccessStatus.DENIED)
if (permissionService.hasPermission(hold, RMPermissionModel.FILING) == AccessStatus.DENIED ||
!AccessStatus.ALLOWED.equals(
capabilityService.getCapabilityAccessState(hold, RMPermissionModel.ADD_TO_HOLD)))
{
throw new AccessDeniedException(I18NUtil.getMessage(MSG_ERR_ACCESS_DENIED));
}

View File

@@ -33,9 +33,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.hold.HoldService;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.json.JSONArray;
@@ -68,6 +70,9 @@ public abstract class BaseHold extends DeclarativeWebScript
/** node service */
private NodeService nodeService;
/** Dictionary service */
private DictionaryService dictionaryService;
/**
* Set the hold service
*
@@ -95,13 +100,21 @@ public abstract class BaseHold extends DeclarativeWebScript
}
/**
* @param nodeService node service
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Returns the hold service
*
@@ -130,7 +143,8 @@ public abstract class BaseHold extends DeclarativeWebScript
* It will either add the item(s) to the hold(s) or remove it/them from the hold(s)
*
* @param holds List of hold {@link NodeRef}(s)
* @param nodeRefs List of item {@link NodeRef}(s) (record(s) / record folder(s)) which will be either added to the hold(s) or removed from the hold(s)
* @param nodeRefs List of item {@link NodeRef}(s) (record(s) / record folder(s) / active content(s)) which will be
* either added to the hold(s) or removed from the hold(s)
*/
abstract void doAction(List<NodeRef> holds, List<NodeRef> nodeRefs);
@@ -163,7 +177,8 @@ public abstract class BaseHold extends DeclarativeWebScript
}
/**
* Helper method to get the {@link NodeRef}s for the items(s) (record(s) / record folder(s)) which will be added to the hold(s)
* Helper method to get the {@link NodeRef}s for the items(s) (record(s) / record folder(s) / active content(s))
* which will be added to the hold(s)
*
* @param json The request content as JSON object
* @return List of item {@link NodeRef}s which will be added to the hold(s)
@@ -193,7 +208,7 @@ public abstract class BaseHold extends DeclarativeWebScript
/**
* Helper method for checking the node reference for an item
*
* @param nodeRef The {@link NodeRef} of an item (record / record folder)
* @param nodeRef The {@link NodeRef} of an item (record / record folder / active content)
*/
private void checkItemNodeRef(NodeRef nodeRef)
{
@@ -203,15 +218,16 @@ public abstract class BaseHold extends DeclarativeWebScript
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Item being added to hold does not exist.");
}
// ensure that the node we are adding to the hold is a record or record folder
if (!recordService.isRecord(nodeRef) && !recordFolderService.isRecordFolder(nodeRef))
// ensure that the node we are adding to the hold is a record or record folder or active content
if (!recordService.isRecord(nodeRef) && !recordFolderService.isRecordFolder(nodeRef) &&
!dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_CONTENT))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Items added to a hold must be either a record or record folder.");
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Items added to a hold must be either a record, a record folder or active content.");
}
}
/**
* Helper method to get the list of {@link NodeRef}(s) for the hold(s) which will contain the item (record / record folder)
* Helper method to get the list of {@link NodeRef}(s) for the hold(s) which will contain the item (record / record folder / active content)
*
* @param json The request content as JSON object
* @return List of {@link NodeRef}(s) of the hold(s)

View File

@@ -134,7 +134,7 @@ public class HoldsGet extends DeclarativeWebScript
List<Hold> holdObjects = new ArrayList<>(holds.size());
for (NodeRef nodeRef : holds)
{
// only add if user has filling permisson on the hold
// only add if user has filling permission on the hold
if (!fileOnly || permissionService.hasPermission(nodeRef, RMPermissionModel.FILING) == AccessStatus.ALLOWED)
{
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
@@ -215,7 +215,7 @@ public class HoldsGet extends DeclarativeWebScript
String includedInHold = req.getParameter("includedInHold");
if (StringUtils.isNotBlank(includedInHold))
{
result = Boolean.valueOf(includedInHold).booleanValue();
result = Boolean.parseBoolean(includedInHold);
}
return result;
}
@@ -226,7 +226,7 @@ public class HoldsGet extends DeclarativeWebScript
String fillingOnly = req.getParameter("fileOnly");
if (StringUtils.isNotBlank(fillingOnly))
{
result = Boolean.valueOf(fillingOnly).booleanValue();
result = Boolean.parseBoolean(fillingOnly);
}
return result;
}

View File

@@ -53,6 +53,7 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
@@ -69,6 +70,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -91,6 +93,8 @@ public class HoldServiceImplUnitTest extends BaseUnitTest
protected NodeRef hold2;
protected NodeRef activeContent;
@Mock (name="capabilityService")
protected CapabilityService mockedCapabilityService;
@Spy @InjectMocks HoldServiceImpl holdService;
@Before
@@ -104,6 +108,9 @@ public class HoldServiceImplUnitTest extends BaseUnitTest
hold = generateNodeRef(TYPE_HOLD);
hold2 = generateNodeRef(TYPE_HOLD);
when(mockedCapabilityService.getCapabilityAccessState(hold, RMPermissionModel.ADD_TO_HOLD)).thenReturn(AccessStatus.ALLOWED);
when(mockedCapabilityService.getCapabilityAccessState(hold2, RMPermissionModel.ADD_TO_HOLD)).thenReturn(AccessStatus.ALLOWED);
activeContent = generateNodeRef();
QName contentSubtype = QName.createQName("contentSubtype", "contentSubtype");
when(mockedNodeService.getType(activeContent)).thenReturn(contentSubtype);

View File

@@ -27,12 +27,17 @@
package org.alfresco.module.org_alfresco_module_rm.script.hold;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Base hold web script unit test.
@@ -45,10 +50,12 @@ public abstract class BaseHoldWebScriptUnitTest extends BaseWebScriptUnitTest
/** test holds */
protected NodeRef hold1NodeRef;
protected NodeRef hold2NodeRef;
protected NodeRef dmNodeRef;
protected List<NodeRef> holds;
protected List<NodeRef> records;
protected List<NodeRef> recordFolders;
protected List<NodeRef> filePlanComponents;
protected List<NodeRef> activeContents;
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
@@ -62,6 +69,14 @@ public abstract class BaseHoldWebScriptUnitTest extends BaseWebScriptUnitTest
hold1NodeRef = generateHoldNodeRef("hold1");
hold2NodeRef = generateHoldNodeRef("hold2");
// generate active content
dmNodeRef = generateNodeRef(TYPE_CONTENT);
when(mockedExtendedPermissionService.hasPermission(dmNodeRef, PermissionService.WRITE)).thenReturn(AccessStatus.ALLOWED);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(dmNodeRef), ContentModel.TYPE_CONTENT)).thenReturn(true);
// list of active contents
activeContents = Collections.singletonList(dmNodeRef);
// list of holds
holds = new ArrayList<>(2);
Collections.addAll(holds, hold1NodeRef, hold2NodeRef);

View File

@@ -148,7 +148,7 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
}
/**
* Test for expected excpetion when the item being added to the hold
* Test for expected exception when the item being added to the hold
* does not exist.
*/
@SuppressWarnings("unchecked")
@@ -229,15 +229,14 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
/**
* Test for expected exception when adding an item to a hold
* that isn't a record or record folder.
* that isn't a record, record folder or active content.
*/
@SuppressWarnings("unchecked")
@Test
public void nodeRefIsNotARecordOrRecordFolder() throws Exception
public void nodeRefIsNotARecordOrRecordFolderOrActiveContent() throws Exception
{
// build json content to send to server
List<NodeRef> notAHold = Collections.singletonList(recordFolder);
String content = buildContent(filePlanComponents, notAHold);
String content = buildContent(filePlanComponents, holds);
// expected exception
exception.expect(WebScriptException.class);

View File

@@ -31,8 +31,11 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.service.cmr.repository.NodeRef;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -106,4 +109,40 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
// verify that the record was added to the holds
verify(mockedHoldService, times(1)).addToHolds(holds, recordFolders);
}
/**
* Test that active content can be added to holds.
*/
@Test
public void addActiveContentToHolds() throws Exception
{
// build json to send to server
String content = buildContent(activeContents, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was added to the holds
verify(mockedHoldService, times(1)).addToHolds(holds, activeContents);
}
/**
* Test that active content can be added to holds along with records and record folders.
*/
@Test
public void addActiveContentAndRecordsAndRecordFoldersToHolds() throws Exception
{
List<NodeRef> items = new ArrayList<>(3);
Collections.addAll(items, dmNodeRef, record, recordFolder);
// build json to send to server
String content = buildContent(items, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was added to the holds along with records and record folders
verify(mockedHoldService, times(1)).addToHolds(holds, items);
}
}

View File

@@ -31,8 +31,11 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.service.cmr.repository.NodeRef;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -106,4 +109,40 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
// verify that the record was removed from holds
verify(mockedHoldService, times(1)).removeFromHolds(holds, recordFolders);
}
/**
* Test that active content can be removed from holds.
*/
@Test
public void removeActiveContentFromHolds() throws Exception
{
// build json to send to server
String content = buildContent(activeContents, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was removed from holds
verify(mockedHoldService, times(1)).removeFromHolds(holds, activeContents);
}
/**
* Test that active content can be removed from holds along with records and record folders.
*/
@Test
public void removeActiveContentAndRecordsAndRecordFoldersToHolds() throws Exception
{
List<NodeRef> items = new ArrayList<>(3);
Collections.addAll(items, dmNodeRef, record, recordFolder);
// build json to send to server
String content = buildContent(items, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was removed from holds along with records and record folders
verify(mockedHoldService, times(1)).removeFromHolds(holds, items);
}
}

View File

@@ -215,6 +215,60 @@ public class HoldsGetUnitTest extends BaseHoldWebScriptUnitTest
// check the JSON result
testForBothHolds(json);
}
/**
* Test the retrieval of holds that hold active content.
*/
@Test
public void getHoldsThatActiveContentIsHeldBy() throws Exception
{
// setup interactions
doReturn(holds).when(mockedHoldService).heldBy(dmNodeRef, true);
// setup web script parameters
Map<String, String> parameters = buildParameters
(
"store_type", filePlan.getStoreRef().getProtocol(),
"store_id", filePlan.getStoreRef().getIdentifier(),
"id", filePlan.getId(),
"itemNodeRef", dmNodeRef.toString()
);
// execute web script
JSONObject json = executeJSONWebScript(parameters);
assertNotNull(json);
// check the JSON result
testForBothHolds(json);
}
/**
* Test the retrieval of holds that do not hold active content.
*/
@Test
public void getHoldsThatActiveContentIsNotHeldBy() throws Exception
{
// setup interactions
doReturn(holds).when(mockedHoldService).heldBy(dmNodeRef, false);
// setup web script parameters
Map<String, String> parameters = buildParameters
(
"store_type", filePlan.getStoreRef().getProtocol(),
"store_id", filePlan.getStoreRef().getIdentifier(),
"id", filePlan.getId(),
"itemNodeRef", dmNodeRef.toString(),
"includedInHold", "false"
);
// execute web script
JSONObject json = executeJSONWebScript(parameters);
assertNotNull(json);
// check the JSON result
testForBothHolds(json);
}
public void getFileOnlyHolds() throws Exception
{