use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestFavourites method testPUBLICAPI141.
@Test
public void testPUBLICAPI141() throws Exception {
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// person1's public site
final TestSite publicSite1 = person1PublicSites.get(1);
// person1's private site
final TestSite privateSite = person1PrivateSites.get(0);
// person1's folder
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file in the folder
final NodeRef nodeRef = person1PublicDocs.get(1);
final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
// invite to another user's public site
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(publicSite.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person12Id, siteMembershipRequest);
// favourite other users site, folder and file
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
favouritesProxy.createFavourite(person12Id, folderFavourite);
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
favouritesProxy.createFavourite(person12Id, fileFavourite);
final Favourite siteFavourite = makeSiteFavourite(publicSite);
favouritesProxy.createFavourite(person12Id, siteFavourite);
expectedFavourites.add(siteFavourite);
final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
favouritesProxy.createFavourite(person12Id, siteFavourite1);
expectedFavourites.add(siteFavourite1);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// move the folder and file to person1's private site
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
NodeRef documentLibraryNodeRef = privateSite.getContainerNodeRef("documentLibrary");
repoService.moveNode(folderNodeRef, documentLibraryNodeRef);
return null;
}
}, person11Id, network1.getId());
try {
favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
favouritesProxy.getFavourite(person12Id, fileFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// make the public sites private
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
publicSite.setSiteVisibility(SiteVisibility.PRIVATE);
publicSite1.setSiteVisibility(SiteVisibility.PRIVATE);
return null;
}
}, person11Id, network1.getId());
expectedFavourites.remove(siteFavourite1);
// Given that person2Id is still a member of 'publicSite', they should still have access and therefore
// it should show up in their favourites. But person2Id is not a member of 'publicSite1', they should
// not have access and therefore it should not show up in their favourites.
{
Favourite actual = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid());
siteFavourite.expected(actual);
try {
favouritesProxy.getFavourite(person12Id, siteFavourite1.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestNodeComments method setup.
@Override
@Before
public void setup() throws Exception {
// init networks
super.setup();
Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
this.network1 = accountsIt.next();
this.network2 = accountsIt.next();
// Create users in different networks and a site
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
return null;
}
}, network1.getId());
this.person11 = people.get(0);
this.person12 = people.get(1);
this.person13 = people.get(2);
this.person14 = people.get(3);
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
this.person21 = people.get(4);
this.person22 = people.get(5);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
sites.add(site);
site.updateMember(person13.getId(), SiteRole.SiteCollaborator);
site.updateMember(person14.getId(), SiteRole.SiteCollaborator);
return null;
}
}, person11.getId(), network1.getId());
final TestSite site1 = sites.get(0);
final List<NodeRef> nodes = new ArrayList<NodeRef>();
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
NodeRef nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
nodes.add(nodeRef);
NodeRef folderNodeRef = repoService.createFolder(site1.getContainerNodeRef("documentLibrary"), "Test Folder");
nodeRef = folderNodeRef;
nodes.add(nodeRef);
nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc 1", "Test Content 1");
nodes.add(nodeRef);
nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc 2", "Test Content 2");
nodes.add(nodeRef);
nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc 3", "Test Content 3");
nodes.add(nodeRef);
nodeRef = repoService.createCmObject(site1.getContainerNodeRef("documentLibrary"), "CM Object");
nodes.add(nodeRef);
nodeRef = repoService.createObjectOfCustomType(site1.getContainerNodeRef("documentLibrary"), "Custom type object", "{custom.model}sop");
nodes.add(nodeRef);
nodeRef = repoService.createDocument(folderNodeRef, "Test Doc 4", "Test Content 4 - in Test Folder");
nodes.add(nodeRef);
return null;
}
}, person11.getId(), network1.getId());
this.nodeRef1 = nodes.get(0);
this.folderNodeRef1 = nodes.get(1);
this.nodeRef2 = nodes.get(2);
this.nodeRef3 = nodes.get(3);
this.nodeRef4 = nodes.get(4);
this.cmObjectNodeRef = nodes.get(5);
this.customTypeObject = nodes.get(6);
this.nodeRef5 = nodes.get(7);
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ProcessesImplTest method setUp.
@Before
public void setUp() throws Exception {
applicationContext = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
processes = (Processes) applicationContext.getBean(PROCESSES_BEAN_NAME);
ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
workflowService = registry.getWorkflowService();
personService = registry.getPersonService();
transaction = registry.getTransactionService().getUserTransaction();
transaction.begin();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getAdminUserName());
NodeRef adminUserNodeRef = personService.getPerson(AuthenticationUtil.getAdminUserName());
WorkflowDefinition workflowDefinition = findAppropriateWorkflowDefinitionId();
for (int i = 0; i < ACTIVE_WORKFLOWS_INITIAL_AMOUNT; i++) {
startWorkflow(workflowDefinition, adminUserNodeRef);
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class EnterpriseWorkflowTestApi method startAdhocProcess.
/**
* Start an adhoc-process with possible business key through the public REST-API.
*/
@SuppressWarnings("unchecked")
protected ProcessInfo startAdhocProcess(final RequestContext requestContext, NodeRef[] documentRefs, String businessKey) throws PublicApiException {
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
ProcessesClient processesClient = publicApiClient.processesClient();
final JSONObject createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionId", processDefinition.getId());
if (businessKey != null) {
createProcessObject.put("businessKey", businessKey);
}
final JSONObject variablesObject = new JSONObject();
variablesObject.put("bpm_priority", 1);
variablesObject.put("wf_notifyMe", Boolean.FALSE);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
if (documentRefs != null && documentRefs.length > 0) {
final JSONArray itemsObject = new JSONArray();
for (NodeRef nodeRef : documentRefs) {
itemsObject.add(nodeRef.getId());
}
createProcessObject.put("items", itemsObject);
}
createProcessObject.put("variables", variablesObject);
return processesClient.createProcess(createProcessObject.toJSONString());
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessItemWithAdmin.
@Test
public void testDeleteProcessItemWithAdmin() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
publicApiClient.setRequestContext(adminContext);
// start process with admin user
NodeRef[] docNodeRefs = createTestDocuments(adminContext);
final ProcessInfo processRest = startAdhocProcess(adminContext, 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());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
// start process with default user and delete item with admin
publicApiClient.setRequestContext(requestContext);
docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRestDefaultUser = startAdhocProcess(requestContext, docNodeRefs);
try {
assertNotNull(processRestDefaultUser);
publicApiClient.setRequestContext(adminContext);
final String newProcessInstanceId = processRestDefaultUser.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());
}
} finally {
cleanupProcessInstance(processRestDefaultUser.getId());
}
}
Aggregations