Search in sources :

Example 11 with WorkflowResponseDTO

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

the class WorkflowMappingUtil method toWorkflowDTO.

/**
 * Map Workflow to WorkflowDTO
 * @param response WorkflowResponse object
 * @return WorkflowResponseDTO mapped WorkflowResponseDTO
 */
public static WorkflowDTO toWorkflowDTO(Workflow response) {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    if (response != null) {
        workflowDTO.setCreatedTime(response.getCreatedTime().toString());
        workflowDTO.setDescription(response.getWorkflowDescription());
        workflowDTO.setType(response.getWorkflowType());
        workflowDTO.setReferenceId(response.getExternalWorkflowReference());
        workflowDTO.setWorkflowStatus(response.getStatus().toString());
    }
    return workflowDTO;
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO)

Example 12 with WorkflowResponseDTO

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

the class MiscMappingUtilTestCase method testFromWorkflowResponseToDTO.

@Test
public void testFromWorkflowResponseToDTO() {
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    WorkflowResponseDTO workflowResponseDTO = MiscMappingUtil.fromWorkflowResponseToDTO(workflowResponse);
    assertEquals(workflowResponseDTO.getWorkflowStatus().name(), workflowResponse.getWorkflowStatus().name());
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.store.dto.WorkflowResponseDTO) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) Test(org.testng.annotations.Test)

Example 13 with WorkflowResponseDTO

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

the class TestMappingUtilTestCase method testWorkflowResponseToWorkflowResponseDTOMapping.

@Test(description = "Workflow response to Workflow response DTO mapping ")
void testWorkflowResponseToWorkflowResponseDTOMapping() {
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    WorkflowResponseDTO workflowResponseDTO = MappingUtil.toWorkflowResponseDTO(workflowResponse);
    assertEquals(workflowResponse.getWorkflowStatus().name(), workflowResponseDTO.getWorkflowStatus().name());
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.WorkflowResponseDTO) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Test(org.testng.annotations.Test)

Example 14 with WorkflowResponseDTO

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

the class ApisApiServiceImpl method changeAPILifecycle.

@Override
public Response changeAPILifecycle(String action, String apiId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        ApiTypeWrapper apiWrapper = new ApiTypeWrapper(apiProvider.getAPIbyUUID(apiId, organization));
        APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, apiWrapper, lifecycleChecklist, organization);
        // returns the current lifecycle state
        // todo try to prevent this call
        LifecycleStateDTO stateDTO = getLifecycleState(apiId, organization);
        WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
        return Response.ok().entity(workflowResponseDTO).build();
    } catch (APIManagementException e) {
        // Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while updating the lifecycle of API " + apiId, e, log);
        } else {
            RestApiUtil.handleInternalServerError("Error while updating lifecycle of API " + apiId, e, log);
        }
    }
    return null;
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO) LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 15 with WorkflowResponseDTO

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

the class ApiProductsApiServiceImpl method changeAPIProductLifecycle.

@Override
public Response changeAPIProductLifecycle(String action, String apiProductId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    ApiTypeWrapper productWrapper = new ApiTypeWrapper(apiProvider.getAPIProductbyUUID(apiProductId, organization));
    APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, productWrapper, lifecycleChecklist, organization);
    LifecycleStateDTO stateDTO = getLifecycleState(apiProductId, organization);
    WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
    return Response.ok().entity(workflowResponseDTO).build();
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO) LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)6 HashMap (java.util.HashMap)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)5 WorkflowResponseDTO (org.wso2.carbon.apimgt.rest.api.store.dto.WorkflowResponseDTO)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 Map (java.util.Map)4 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)4 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)4 Test (org.testng.annotations.Test)3 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)3 Application (org.wso2.carbon.apimgt.core.models.Application)3 WorkflowResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.WorkflowResponseDTO)3 WorkflowResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO)3 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 APIStateChangeResponse (org.wso2.carbon.apimgt.api.model.APIStateChangeResponse)2 ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)2 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)2 ExceptionCodes (org.wso2.carbon.apimgt.core.exception.ExceptionCodes)2