Search in sources :

Example 1 with Deployment

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"));
}
Also used : HashMap(java.util.HashMap) DeploymentsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient) Deployment(org.alfresco.rest.workflow.api.model.Deployment) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 2 with Deployment

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());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) DeploymentsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient) Deployment(org.alfresco.rest.workflow.api.model.Deployment) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 3 with Deployment

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());
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) Deployment(org.alfresco.rest.workflow.api.model.Deployment) DeploymentsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 4 with Deployment

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);
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ArrayList(java.util.ArrayList) Deployment(org.alfresco.rest.workflow.api.model.Deployment) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)

Example 5 with Deployment

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;
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ActivitiException(org.activiti.engine.ActivitiException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Deployment(org.alfresco.rest.workflow.api.model.Deployment) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) RepositoryService(org.activiti.engine.RepositoryService)

Aggregations

Deployment (org.alfresco.rest.workflow.api.model.Deployment)6 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)3 DeploymentsClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient)3 Test (org.junit.Test)3 DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ActivitiException (org.activiti.engine.ActivitiException)1 RepositoryService (org.activiti.engine.RepositoryService)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 JSONObject (org.json.simple.JSONObject)1