Search in sources :

Example 1 with WorkflowListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO in project carbon-apimgt by wso2.

the class WorkflowMappingUtil method toWorkflowListDTO.

/**
 * Map Workflow list to WorkflowListDTO
 * @param workflowList list of Workflow
 * @return list of WorkflowDTO
 */
public static WorkflowListDTO toWorkflowListDTO(List<Workflow> workflowList) {
    WorkflowListDTO workflowListDTO = new WorkflowListDTO();
    workflowListDTO.setCount(workflowList.size());
    List<WorkflowDTO> list = new ArrayList<>();
    for (Workflow item : workflowList) {
        WorkflowDTO workflowDTO = new WorkflowDTO();
        workflowDTO.setCreatedTime(item.getCreatedTime().toString());
        workflowDTO.setDescription(item.getWorkflowDescription());
        workflowDTO.setType(item.getWorkflowType());
        workflowDTO.setReferenceId(item.getExternalWorkflowReference());
        workflowDTO.setWorkflowStatus(item.getStatus().toString());
        list.add(workflowDTO);
    }
    workflowListDTO.setList(list);
    return workflowListDTO;
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO) ArrayList(java.util.ArrayList) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) WorkflowListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowListDTO)

Example 2 with WorkflowListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO in project carbon-apimgt by wso2.

the class WorkflowsApiServiceImpl method workflowsGet.

@Override
public Response workflowsGet(String ifNoneMatch, String ifModifiedSince, String workflowType, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        List<Workflow> workflowList;
        if (workflowType == null) {
            workflowList = apiMgtAdminService.retrieveUncompletedWorkflows();
        } else {
            workflowList = apiMgtAdminService.retrieveUncompletedWorkflowsByType(workflowType);
        }
        WorkflowListDTO workflowListDTO = WorkflowMappingUtil.toWorkflowListDTO(workflowList);
        return Response.ok().entity(workflowListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while retrieving workflows list";
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow)

Example 3 with WorkflowListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO in project carbon-apimgt by wso2.

the class WorkflowMappingUtilTest method testToWorkflowListDTO.

@Test(description = "Convert List<Workflow> workflowList to WorkflowListDTO")
public void testToWorkflowListDTO() throws Exception {
    List<Workflow> wfList = new ArrayList<>();
    Workflow workflow1 = new ApplicationCreationWorkflow(null, null, null);
    workflow1.setStatus(WorkflowStatus.APPROVED);
    LocalDateTime date1 = LocalDateTime.now();
    workflow1.setCreatedTime(date1);
    workflow1.setWorkflowDescription("Description 1");
    workflow1.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
    String ref1 = UUID.randomUUID().toString();
    workflow1.setExternalWorkflowReference(ref1);
    wfList.add(workflow1);
    Workflow workflow2 = new SubscriptionCreationWorkflow(null, null, null);
    workflow2.setStatus(WorkflowStatus.APPROVED);
    LocalDateTime date2 = LocalDateTime.now();
    workflow2.setCreatedTime(date2);
    workflow2.setWorkflowDescription("Description 2");
    workflow2.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
    String ref2 = UUID.randomUUID().toString();
    workflow2.setExternalWorkflowReference(ref2);
    wfList.add(workflow2);
    WorkflowListDTO wfDtoList = WorkflowMappingUtil.toWorkflowListDTO(wfList);
    int count = wfDtoList.getCount();
    Assert.assertEquals(count, 2, "Mismatch in the workflow list item count");
    Assert.assertEquals(wfDtoList.getList().get(0).getDescription(), "Description 1", "Invalid description for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(0).getType(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION, "Invalid type for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(0).getWorkflowStatus(), WorkflowStatus.APPROVED.toString(), "Invalid status for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(0).getReferenceId(), ref1, "Invalid reference id for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(1).getDescription(), "Description 2", "Invalid description for workflow item 2");
    Assert.assertEquals(wfDtoList.getList().get(1).getType(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION, "Invalid type for workflow item 2");
    Assert.assertEquals(wfDtoList.getList().get(1).getWorkflowStatus(), WorkflowStatus.APPROVED.toString(), "Invalid status for workflow item 2");
    Assert.assertEquals(wfDtoList.getList().get(1).getReferenceId(), ref2, "Invalid reference id for workflow item 2");
}
Also used : LocalDateTime(java.time.LocalDateTime) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ArrayList(java.util.ArrayList) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) WorkflowListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowListDTO) Test(org.testng.annotations.Test)

Example 4 with WorkflowListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO in project carbon-apimgt by wso2.

the class WorkflowsApiServiceImpl method workflowsGet.

/**
 * This is used to get the workflow pending requests
 *
 * @param limit        maximum number of workflow returns
 * @param offset       starting index
 * @param accept       accept header value
 * @param workflowType is the the type of the workflow request. (e.g: Application Creation, Application Subscription etc.)
 * @return
 */
@Override
public Response workflowsGet(Integer limit, Integer offset, String accept, String workflowType, MessageContext messageContext) throws APIManagementException {
    limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
    offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    WorkflowListDTO workflowListDTO;
    try {
        Workflow[] workflows;
        String status = "CREATED";
        APIAdmin apiAdmin = new APIAdminImpl();
        if (workflowType != null) {
            if (workflowType.equals("APPLICATION_CREATION")) {
                workflowType = "AM_APPLICATION_CREATION";
            } else if (workflowType.equals("SUBSCRIPTION_CREATION")) {
                workflowType = "AM_SUBSCRIPTION_CREATION";
            } else if (workflowType.equals("USER_SIGNUP")) {
                workflowType = "AM_USER_SIGNUP";
            } else if (workflowType.equals("APPLICATION_REGISTRATION_PRODUCTION")) {
                workflowType = "AM_APPLICATION_REGISTRATION_PRODUCTION";
            } else if (workflowType.equals("APPLICATION_REGISTRATION_SANDBOX")) {
                workflowType = "AM_APPLICATION_REGISTRATION_SANDBOX";
            } else if (workflowType.equals("API_STATE")) {
                workflowType = "AM_API_STATE";
            } else if (workflowType.equals("API_PRODUCT_STATE")) {
                workflowType = "AM_API_PRODUCT_STATE";
            }
        }
        workflows = apiAdmin.getworkflows(workflowType, status, tenantDomain);
        workflowListDTO = WorkflowMappingUtil.fromWorkflowsToDTO(workflows, limit, offset);
        WorkflowMappingUtil.setPaginationParams(workflowListDTO, limit, offset, workflows.length);
        return Response.ok().entity(workflowListDTO).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving workflow requests. ", e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Workflow(org.wso2.carbon.apimgt.api.model.Workflow) WorkflowListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 5 with WorkflowListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO in project carbon-apimgt by wso2.

the class WorkflowMappingUtil method fromWorkflowsToDTO.

public static WorkflowListDTO fromWorkflowsToDTO(Workflow[] workflows, int limit, int offset) {
    WorkflowListDTO workflowListDTO = new WorkflowListDTO();
    List<WorkflowInfoDTO> workflowInfoDTOs = workflowListDTO.getList();
    if (workflowInfoDTOs == null) {
        workflowInfoDTOs = new ArrayList<>();
        workflowListDTO.setList(workflowInfoDTOs);
    }
    // identifying the proper start and end indexes
    int start = offset < workflows.length && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= workflows.length - 1 ? offset + limit - 1 : workflows.length - 1;
    for (int i = start; i <= end; i++) {
        workflowInfoDTOs.add(fromWorkflowsToInfoDTO(workflows[i]));
    }
    workflowListDTO.setCount(workflowInfoDTOs.size());
    return workflowListDTO;
}
Also used : WorkflowInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowInfoDTO) WorkflowListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO)

Aggregations

Workflow (org.wso2.carbon.apimgt.core.workflow.Workflow)3 ArrayList (java.util.ArrayList)2 WorkflowListDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowListDTO)2 WorkflowListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowListDTO)2 LocalDateTime (java.time.LocalDateTime)1 Test (org.testng.annotations.Test)1 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 Workflow (org.wso2.carbon.apimgt.api.model.Workflow)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 ApplicationCreationWorkflow (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow)1 SubscriptionCreationWorkflow (org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow)1 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)1 WorkflowDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO)1 WorkflowInfoDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowInfoDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1