use of org.alfresco.rest.workflow.api.model.Deployment in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeployments.
@Test
public void testGetDeployments() throws Exception {
// testGetDeployments#1: Getting deployments with admin-user
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
Map<String, Deployment> deploymentMap = new HashMap<String, Deployment>();
for (Deployment deployment : deploymentResponse.getList()) {
deploymentMap.put(deployment.getName(), deployment);
}
assertEquals(5, deploymentResponse.getList().size());
assertTrue(deploymentMap.containsKey("review-pooled.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("review.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("parallel-review-group.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("parallel-review.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("adhoc.bpmn20.xml"));
// testGetDeployments#2: Check all deployment fields in resulting deployment
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
assertNotNull(activitiDeployment);
Deployment adhocDeployment = deploymentMap.get("adhoc.bpmn20.xml");
assertEquals(activitiDeployment.getId(), adhocDeployment.getId());
assertEquals(activitiDeployment.getCategory(), adhocDeployment.getCategory());
assertEquals(activitiDeployment.getName(), adhocDeployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), adhocDeployment.getDeployedAt());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
JSONObject paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "2");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "5");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "0");
params.put("maxItems", "7");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
}
use of org.alfresco.rest.workflow.api.model.Deployment in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentById.
@Test
public void testGetDeploymentById() throws Exception {
// Use admin-user for tenant
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
// Fetch the actual deployment from activiti
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
assertNotNull(activitiDeployment);
// Do the actual API-call
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
Deployment deployment = deploymentsClient.findDeploymentById(activitiDeployment.getId());
assertNotNull(deployment);
assertEquals(activitiDeployment.getId(), deployment.getId());
assertEquals(activitiDeployment.getCategory(), deployment.getCategory());
assertEquals(activitiDeployment.getName(), deployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), deployment.getDeployedAt());
try {
deploymentsClient.findDeploymentById("fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// get deployment with default user
try {
publicApiClient.setRequestContext(requestContext);
deploymentsClient.findDeploymentById(activitiDeployment.getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.workflow.api.model.Deployment in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentsEmpty.
@Test
public void testGetDeploymentsEmpty() throws Exception {
// Create a new test-network, not added to the test-fixture to prevent being used
// in other tests
String networkName = AbstractTestFixture.TEST_DOMAIN_PREFIX + "999";
final TestNetwork testNetwork = repoService.createNetworkWithAlias(networkName, true);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@SuppressWarnings("synthetic-access")
public Void execute() throws Throwable {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
testNetwork.create();
return null;
}
}, false, true);
// Delete all deployments in the network
List<org.activiti.engine.repository.Deployment> deployments = activitiProcessEngine.getRepositoryService().createDeploymentQuery().processDefinitionKeyLike("@" + testNetwork.getId() + "@%").list();
for (org.activiti.engine.repository.Deployment deployment : deployments) {
activitiProcessEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
}
// Fetch deployments using tenant-admin
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + testNetwork.getId();
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), tenantAdmin));
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
assertEquals(0, deploymentResponse.getList().size());
}
use of org.alfresco.rest.workflow.api.model.Deployment in project alfresco-remote-api by Alfresco.
the class DeploymentsImpl method getDeployments.
@Override
public CollectionWithPagingInfo<Deployment> getDeployments(Paging paging) {
// Only admin-user is allowed to get deployments
if (!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
throw new PermissionDeniedException();
}
DeploymentQuery query = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentCategoryNotEquals(WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
query.orderByDeploymenTime().desc();
List<org.activiti.engine.repository.Deployment> deployments = query.listPage(paging.getSkipCount(), paging.getMaxItems());
int totalCount = (int) query.count();
List<Deployment> page = new ArrayList<Deployment>(deployments.size());
for (org.activiti.engine.repository.Deployment deployment : deployments) {
page.add(new Deployment(deployment));
}
return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
use of org.alfresco.rest.workflow.api.model.Deployment in project alfresco-remote-api by Alfresco.
the class DeploymentsImpl method getDeployment.
@Override
public Deployment getDeployment(String deploymentId) {
// Only admin-user is allowed to get deployments
if (!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
throw new PermissionDeniedException();
}
RepositoryService repositoryService = activitiProcessEngine.getRepositoryService();
DeploymentQuery query = repositoryService.createDeploymentQuery().deploymentId(deploymentId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
org.activiti.engine.repository.Deployment deployment = null;
try {
deployment = query.singleResult();
} catch (ActivitiException e) {
// The next exception will cause a response status 400: Bad request
throw new InvalidArgumentException("Invalid deployment id: " + deploymentId);
}
if (deployment == null) {
// The next exception will cause a response status 404: Not found
throw new EntityNotFoundException(deploymentId);
}
Deployment deploymentRest = new Deployment(deployment);
return deploymentRest;
}
Aggregations