Search in sources :

Example 56 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class MappingUtil method toScope.

/**
 * This method convert {@link ScopeDTO} to {@link Scope}
 * @param body scopeDto Object
 * @return scope object
 */
public static Scope toScope(ScopeDTO body) {
    Scope scope = new Scope();
    scope.setName(body.getName());
    scope.setDescription(body.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = body.getBindings();
    if (scopeBindingsDTO != null) {
        scope.setBindings(scopeBindingsDTO.getValues());
    }
    return scope;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO)

Example 57 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ApiImportExportManager method addAPIDetails.

/**
 * Adds the API details
 *
 * @param apiDetails {@link APIDetails} instance
 * @throws APIManagementException if an error occurs while adding API details
 */
public void addAPIDetails(APIDetails apiDetails) throws APIManagementException {
    // update everything
    String swaggerDefinition = apiDetails.getSwaggerDefinition();
    String gatewayConfig = apiDetails.getGatewayConfiguration();
    Map<String, Endpoint> endpointTypeToIdMap = apiDetails.getApi().getEndpoint();
    Map<String, UriTemplate> uriTemplateMap = apiDetails.getApi().getUriTemplates();
    // endpoints
    for (Endpoint endpoint : apiDetails.getEndpoints()) {
        try {
            Endpoint existingEndpoint = apiPublisher.getEndpointByName(endpoint.getName());
            String endpointId;
            if (existingEndpoint == null) {
                // no endpoint by that name, add it
                endpointId = apiPublisher.addEndpoint(endpoint);
            } else {
                endpointId = existingEndpoint.getId();
                if (log.isDebugEnabled()) {
                    log.debug("Endpoint with id " + endpoint.getId() + " already exists, not adding again");
                }
            // endpoint with same name exists, add to endpointTypeToIdMap
            // endpointTypeToIdMap.put(endpoint.getType(), existingEndpoint.getId());
            }
            endpointTypeToIdMap.forEach((String k, Endpoint v) -> {
                if (endpoint.getName().equals(v.getName())) {
                    Endpoint replacedEndpoint = new Endpoint.Builder(v).id(endpointId).build();
                    endpointTypeToIdMap.replace(k, replacedEndpoint);
                }
            });
            uriTemplateMap.forEach(((String templateId, UriTemplate uriTemplate) -> {
                UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(uriTemplate);
                Map<String, Endpoint> uriEndpointMap = uriTemplateBuilder.getEndpoint();
                uriEndpointMap.forEach((String type, Endpoint endpoint1) -> {
                    if (endpoint.getName().equals(endpoint1.getName())) {
                        Endpoint replacedEndpoint = new Endpoint.Builder(endpoint1).id(endpointId).build();
                        uriEndpointMap.replace(type, replacedEndpoint);
                    }
                });
                uriTemplateMap.replace(templateId, uriTemplateBuilder.endpoint(uriEndpointMap).build());
            }));
        } catch (APIManagementException e) {
            // skip adding this API; log and continue
            log.error("Error while adding the endpoint with id: " + endpoint.getId() + ", type: " + endpoint.getType() + " for API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
        }
    }
    API.APIBuilder apiBuilder = new API.APIBuilder(apiDetails.getApi());
    apiPublisher.addAPI(apiBuilder.apiDefinition(swaggerDefinition).gatewayConfig(gatewayConfig).endpoint(endpointTypeToIdMap).uriTemplates(uriTemplateMap));
    // docs
    try {
        Set<DocumentInfo> documentInfo = apiDetails.getAllDocumentInformation();
        for (DocumentInfo aDocInfo : documentInfo) {
            apiPublisher.addDocumentationInfo(apiDetails.getApi().getId(), aDocInfo);
        }
        for (DocumentContent aDocContent : apiDetails.getDocumentContents()) {
            // add documentation
            if (aDocContent.getDocumentInfo().getSourceType().equals(DocumentInfo.SourceType.FILE)) {
                apiPublisher.uploadDocumentationFile(aDocContent.getDocumentInfo().getId(), aDocContent.getFileContent(), URLConnection.guessContentTypeFromStream(aDocContent.getFileContent()));
            } else if (aDocContent.getDocumentInfo().getSourceType().equals(DocumentInfo.SourceType.INLINE)) {
                apiPublisher.addDocumentationContent(aDocContent.getDocumentInfo().getId(), aDocContent.getInlineContent());
            }
        }
    } catch (APIManagementException e) {
        // no need to throw, log and continue
        log.error("Error while adding Document details for API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion(), e);
    } catch (IOException e) {
        // no need to throw, log and continue
        log.error("Error while retrieving content type of the File documentation of API : " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion(), e);
    }
    // add thumbnail
    try {
        apiPublisher.saveThumbnailImage(apiDetails.getApi().getId(), apiDetails.getThumbnailStream(), "thumbnail");
    } catch (APIManagementException e) {
        // no need to throw, log and continue
        log.error("Error while adding thumbnail for API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion(), e);
    }
}
Also used : IOException(java.io.IOException) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) DocumentContent(org.wso2.carbon.apimgt.core.models.DocumentContent) API(org.wso2.carbon.apimgt.core.models.API) HashMap(java.util.HashMap) Map(java.util.Map) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 58 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class FileBasedApplicationImportExportManager method exportApplication.

/**
 * Export a given Application to a file system as zip archive.
 * The export root location is given by {@link FileBasedApplicationImportExportManager#path}/exported-application.
 *
 * @param application         Application{@link Application} to be exported
 * @param exportDirectoryName Name of directory to be exported
 * @return path to the exported directory with exported artifacts
 * @throws APIMgtEntityImportExportException
 */
public String exportApplication(Application application, String exportDirectoryName) throws APIMgtEntityImportExportException {
    String applicationArtifactBaseDirectoryPath = path + File.separator + exportDirectoryName;
    try {
        Files.createDirectories(Paths.get(applicationArtifactBaseDirectoryPath));
    } catch (IOException e) {
        String errorMsg = "Unable to create the directory for export Application at :" + applicationArtifactBaseDirectoryPath;
        log.error(errorMsg, e);
        throw new APIMgtEntityImportExportException(errorMsg, e);
    }
    Application exportApplication = application;
    String applicationExportDirectory = applicationArtifactBaseDirectoryPath + File.separator + exportApplication.getName();
    try {
        // create directory per application
        Files.createDirectories(Paths.get(applicationExportDirectory));
        // export application details
        exportApplicationDetailsToFileSystem(exportApplication, applicationExportDirectory);
    } catch (IOException e) {
        log.error("Error while exporting Application: " + exportApplication.getName(), e);
    }
    // Check if no application is exported
    try {
        if (APIFileUtils.getDirectoryList(applicationArtifactBaseDirectoryPath).isEmpty()) {
            // cleanup the archive root directory
            APIFileUtils.deleteDirectory(path);
        }
    } catch (APIManagementException e) {
        String errorMsg = "Unable to find Application Details at: " + applicationArtifactBaseDirectoryPath;
        throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.APPLICATION_EXPORT_ERROR);
    }
    return applicationArtifactBaseDirectoryPath;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) IOException(java.io.IOException) Application(org.wso2.carbon.apimgt.core.models.Application) APIMgtEntityImportExportException(org.wso2.carbon.apimgt.core.exception.APIMgtEntityImportExportException)

Example 59 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class CompositeAPIMappingUtil method toCompositeAPIInfo.

/**
 * Converts {@link CompositeAPI} List to an {@link CompositeAPIInfoDTO} List.
 *
 * @param apiSummaryList
 * @return
 */
private static List<CompositeAPIInfoDTO> toCompositeAPIInfo(List<CompositeAPI> apiSummaryList) {
    List<CompositeAPIInfoDTO> apiInfoList = new ArrayList<>();
    for (CompositeAPI apiSummary : apiSummaryList) {
        CompositeAPIInfoDTO apiInfo = new CompositeAPIInfoDTO();
        apiInfo.setId(apiSummary.getId());
        apiInfo.setContext(apiSummary.getContext());
        apiInfo.setDescription(apiSummary.getDescription());
        apiInfo.setName(apiSummary.getName());
        apiInfo.setProvider(apiSummary.getProvider());
        apiInfo.setVersion(apiSummary.getVersion());
        apiInfo.setApplicationId(apiSummary.getApplicationId());
        apiInfoList.add(apiInfo);
    }
    return apiInfoList;
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) CompositeAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIInfoDTO)

Example 60 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class APIMappingUtil method toAPIListDTO.

/**
 * Converts {@code List<API>} to {@link APIListDTO} DTO.
 *
 * @param apisResult List of APIs
 * @return APIListDTO
 */
public static APIListDTO toAPIListDTO(List<API> apisResult) {
    APIListDTO apiListDTO = new APIListDTO();
    apiListDTO.setCount(apisResult.size());
    // apiListDTO.setNext(next);
    // apiListDTO.setPrevious(previous);
    apiListDTO.setList(toAPIInfo(apisResult));
    return apiListDTO;
}
Also used : APIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10