use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessItem.
@Test
public void testDeleteProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
try {
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
// Delete the item
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
// Fetching the item should result in 404
try {
publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: " + docNodeRefs[0].getId() + " was not found", expected.getHttpResponse());
}
// Deleting the item again should give an error
try {
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Expected not found");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testAddProcessItem.
@Test
@SuppressWarnings("unchecked")
public void testAddProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
// Add the item
processesClient.addProcessItem(newProcessInstanceId, createItemObject.toJSONString());
// Fetching the item
JSONObject itemJSON = publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
assertEquals("Test Doc1", itemJSON.get("name"));
assertEquals("Test Doc1 Title", itemJSON.get("title"));
assertEquals("Test Doc1 Description", itemJSON.get("description"));
assertNotNull(itemJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
assertNotNull(itemJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
assertNotNull(itemJSON.get("size"));
assertNotNull(itemJSON.get("mimeType"));
// add non existing item
createItemObject = new JSONObject();
createItemObject.put("id", "blablabla");
// Add the item
try {
processesClient.addProcessItem(newProcessInstanceId, createItemObject.toJSONString());
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testUpdateInitiatorAndGetProcessVariables.
// MNT-17918
@SuppressWarnings("unchecked")
@Test
public void testUpdateInitiatorAndGetProcessVariables() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
String processId = processRest.getId();
// Update initiator variable to "admin"
JSONObject variableJson = new JSONObject();
variableJson.put("name", "initiator");
variableJson.put("type", "d:noderef");
NodeRef personRef = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
String assignee = adminContext.getRunAsUser();
NodeRef personRef = getPersonNodeRef(assignee).getNodeRef();
variableJson.put("value", personRef.toString());
return personRef;
}
}, adminContext.getRunAsUser(), adminContext.getNetworkId());
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "initiator", variableJson);
assertNotNull(resultEntry);
final JSONObject updateInitiatorResult = (JSONObject) resultEntry.get("entry");
assertEquals("initiator", updateInitiatorResult.get("name"));
assertEquals("d:noderef", updateInitiatorResult.get("type"));
assertNotNull("Variable value should be returned", updateInitiatorResult.get("value"));
assertEquals(personRef.getId(), updateInitiatorResult.get("value"));
// Get process variables after updating "initiator"
publicApiClient.setRequestContext(adminContext);
resultEntry = publicApiClient.processesClient().getProcessvariables(processId);
assertNotNull(resultEntry);
validateVariableField(resultEntry, "initiator", adminContext.getRunAsUser());
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessItem.
@Test
public void testGetProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject itemJSON = processesClient.findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
assertNotNull(itemJSON);
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
assertEquals("Test Doc1", itemJSON.get("name"));
assertEquals("Test Doc1 Title", itemJSON.get("title"));
assertEquals("Test Doc1 Description", itemJSON.get("description"));
assertNotNull(itemJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
assertNotNull(itemJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
assertNotNull(itemJSON.get("size"));
assertNotNull(itemJSON.get("mimeType"));
cleanupProcessInstance(processRest.getId());
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUploadUsingRelativePath.
/**
* Test upload using relativePath
*/
@Test
public void testUploadUsingRelativePath() throws Exception {
setRequestContext(user1);
// user1 creates a private site and adds user2 as a site consumer
String site1Title = "site-testGetPathElements_DocLib-" + RUNID;
String site1Id = createSite(site1Title, SiteVisibility.PRIVATE).getId();
addSiteMember(site1Id, user2, SiteRole.SiteConsumer);
String site1DocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
// /Company
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
String folderA = "folder" + RUNID + "_A";
String folderA_Id = createFolder(site1DocLibNodeId, folderA).getId();
// /Company
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
String folderB = "folder" + RUNID + "_B";
String folderB_Id = createFolder(folderA_Id, folderB).getId();
NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB_Id);
// /Company
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
String folderC = "folder" + RUNID + "_C";
String folderC_Id = createFolder(folderB_Id, folderC).getId();
NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderC_Id);
// /Company
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
String content = "content" + RUNID;
String content_Id = createTextFile(folderC_Id, content, "The quick brown fox jumps over the lazy dog.").getId();
Map<String, String> params = new HashMap<>();
params.put("include", "path");
params.put("relativePath", folderA + "/" + folderB + "/" + folderC);
// call get with relativePathParam
HttpResponse response = getAll(getNodeChildrenUrl(site1DocLibNodeId), null, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
assertEquals("/" + folderA + "/" + folderB + "/" + folderC, ((Node) (nodes.get(0))).getPath().getRelativePath());
}
Aggregations