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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations