Search in sources :

Example 1 with SynapseArtifactListDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO in project carbon-apimgt by wso2.

the class RetrieveApiArtifactsApiServiceImpl method retrieveApiArtifactsPost.

public Response retrieveApiArtifactsPost(String xWSO2Tenant, String gatewayLabel, String type, UUIDListDTO uuidList, MessageContext messageContext) throws APIManagementException {
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    RuntimeArtifactDto runtimeArtifactDto = APIArtifactGeneratorUtil.generateAPIArtifact(uuidList.getUuids(), "", "", gatewayLabel, type, xWSO2Tenant);
    if (runtimeArtifactDto != null) {
        if (runtimeArtifactDto.isFile()) {
            File artifact = (File) runtimeArtifactDto.getArtifact();
            StreamingOutput streamingOutput = (outputStream) -> {
                try {
                    Files.copy(artifact.toPath(), outputStream);
                } finally {
                    Files.delete(artifact.toPath());
                }
            };
            return Response.ok(streamingOutput).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=apis.zip").header(RestApiConstants.HEADER_CONTENT_TYPE, APIConstants.APPLICATION_ZIP).build();
        } else {
            SynapseArtifactListDTO synapseArtifactListDTO = new SynapseArtifactListDTO();
            if (runtimeArtifactDto.getArtifact() instanceof List) {
                synapseArtifactListDTO.setList((List<String>) runtimeArtifactDto.getArtifact());
                synapseArtifactListDTO.setCount(((List<String>) runtimeArtifactDto.getArtifact()).size());
            }
            return Response.ok().entity(synapseArtifactListDTO).header(RestApiConstants.HEADER_CONTENT_TYPE, RestApiConstants.APPLICATION_JSON).build();
        }
    } else {
        return Response.status(Response.Status.NOT_FOUND).entity(RestApiUtil.getErrorDTO(ExceptionCodes.NO_API_ARTIFACT_FOUND)).build();
    }
}
Also used : SynapseArtifactListDTO(org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO) Files(java.nio.file.Files) RuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto) RuntimeArtifactGeneratorUtil(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.RuntimeArtifactGeneratorUtil) APIArtifactGeneratorUtil(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.APIArtifactGeneratorUtil) RestApiUtil(org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil) StreamingOutput(javax.ws.rs.core.StreamingOutput) File(java.io.File) APIConstants(org.wso2.carbon.apimgt.impl.APIConstants) ArrayList(java.util.ArrayList) SubscriptionValidationDataUtil(org.wso2.carbon.apimgt.internal.service.utils.SubscriptionValidationDataUtil) List(java.util.List) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) Response(javax.ws.rs.core.Response) RestApiConstants(org.wso2.carbon.apimgt.rest.api.common.RestApiConstants) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UUIDListDTO(org.wso2.carbon.apimgt.internal.service.dto.UUIDListDTO) ExceptionCodes(org.wso2.carbon.apimgt.api.ExceptionCodes) RetrieveApiArtifactsApiService(org.wso2.carbon.apimgt.internal.service.RetrieveApiArtifactsApiService) SynapseArtifactListDTO(org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO) RuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) StreamingOutput(javax.ws.rs.core.StreamingOutput) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 2 with SynapseArtifactListDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO in project carbon-apimgt by wso2.

the class RuntimeArtifactsApiServiceImpl method runtimeArtifactsGet.

public Response runtimeArtifactsGet(String xWSO2Tenant, String apiId, String gatewayLabel, String type, String name, String version, MessageContext messageContext) throws APIManagementException {
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    RuntimeArtifactDto runtimeArtifactDto = RuntimeArtifactGeneratorUtil.generateRuntimeArtifact(apiId, name, version, gatewayLabel, type, xWSO2Tenant);
    if (runtimeArtifactDto != null) {
        if (runtimeArtifactDto.isFile()) {
            File artifact = (File) runtimeArtifactDto.getArtifact();
            StreamingOutput streamingOutput = (outputStream) -> {
                try {
                    Files.copy(artifact.toPath(), outputStream);
                } finally {
                    Files.delete(artifact.toPath());
                }
            };
            return Response.ok(streamingOutput).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=apis.zip").header(RestApiConstants.HEADER_CONTENT_TYPE, APIConstants.APPLICATION_ZIP).build();
        } else {
            SynapseArtifactListDTO synapseArtifactListDTO = new SynapseArtifactListDTO();
            if (runtimeArtifactDto.getArtifact() instanceof List) {
                synapseArtifactListDTO.setList((List<String>) runtimeArtifactDto.getArtifact());
                synapseArtifactListDTO.setCount(((List<String>) runtimeArtifactDto.getArtifact()).size());
            }
            return Response.ok().entity(synapseArtifactListDTO).header(RestApiConstants.HEADER_CONTENT_TYPE, RestApiConstants.APPLICATION_JSON).build();
        }
    } else {
        return Response.status(Response.Status.NOT_FOUND).entity(RestApiUtil.getErrorDTO(ExceptionCodes.NO_API_ARTIFACT_FOUND)).build();
    }
}
Also used : SynapseArtifactListDTO(org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO) Files(java.nio.file.Files) RuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto) RuntimeArtifactGeneratorUtil(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.RuntimeArtifactGeneratorUtil) RestApiUtil(org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil) StreamingOutput(javax.ws.rs.core.StreamingOutput) File(java.io.File) APIConstants(org.wso2.carbon.apimgt.impl.APIConstants) SubscriptionValidationDataUtil(org.wso2.carbon.apimgt.internal.service.utils.SubscriptionValidationDataUtil) List(java.util.List) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) Response(javax.ws.rs.core.Response) RestApiConstants(org.wso2.carbon.apimgt.rest.api.common.RestApiConstants) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ExceptionCodes(org.wso2.carbon.apimgt.api.ExceptionCodes) RuntimeArtifactsApiService(org.wso2.carbon.apimgt.internal.service.RuntimeArtifactsApiService) SynapseArtifactListDTO(org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO) RuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto) StreamingOutput(javax.ws.rs.core.StreamingOutput) List(java.util.List) File(java.io.File)

Aggregations

File (java.io.File)2 Files (java.nio.file.Files)2 List (java.util.List)2 Response (javax.ws.rs.core.Response)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 ExceptionCodes (org.wso2.carbon.apimgt.api.ExceptionCodes)2 APIConstants (org.wso2.carbon.apimgt.impl.APIConstants)2 RuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto)2 RuntimeArtifactGeneratorUtil (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.RuntimeArtifactGeneratorUtil)2 SynapseArtifactListDTO (org.wso2.carbon.apimgt.internal.service.dto.SynapseArtifactListDTO)2 SubscriptionValidationDataUtil (org.wso2.carbon.apimgt.internal.service.utils.SubscriptionValidationDataUtil)2 RestApiConstants (org.wso2.carbon.apimgt.rest.api.common.RestApiConstants)2 RestApiUtil (org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil)2 ArrayList (java.util.ArrayList)1 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)1 APIArtifactGeneratorUtil (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.APIArtifactGeneratorUtil)1 RetrieveApiArtifactsApiService (org.wso2.carbon.apimgt.internal.service.RetrieveApiArtifactsApiService)1 RuntimeArtifactsApiService (org.wso2.carbon.apimgt.internal.service.RuntimeArtifactsApiService)1