use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method decodeApiInformationFromDirectoryStructure.
/**
* Reads and decodes APIs and relevant information from the given set of paths
*
* @param apiArtifactsBasePath path to the directory with API related artifacts
* @param newApiProvider API newApiProvider to be updated
* @return Set of {@link APIDetails} objects
* @throws APIMgtEntityImportExportException if any error occurs while decoding the APIs
*/
public Set<APIDetails> decodeApiInformationFromDirectoryStructure(String apiArtifactsBasePath, String newApiProvider) throws APIMgtEntityImportExportException {
Set<String> apiDefinitionsRootDirectoryPaths = null;
try {
apiDefinitionsRootDirectoryPaths = APIFileUtils.getDirectoryList(apiArtifactsBasePath);
} catch (APIMgtDAOException e) {
String errorMsg = "Unable to find API definitions at: " + apiArtifactsBasePath;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
if (apiDefinitionsRootDirectoryPaths.isEmpty()) {
try {
APIFileUtils.deleteDirectory(path);
} catch (APIMgtDAOException e) {
log.warn("Unable to remove directory " + path);
}
String errorMsg = "Unable to find API definitions at: " + apiArtifactsBasePath;
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
Set<APIDetails> apiDetailsSet = new HashSet<>();
for (String apiDefinitionDirectoryPath : apiDefinitionsRootDirectoryPaths) {
File apiDefinitionFile = getFileFromPrefix(apiDefinitionDirectoryPath, APIMgtConstants.APIFileUtilConstants.API_DEFINITION_FILE_PREFIX);
File swaggerDefinitionFile = getFileFromPrefix(apiDefinitionDirectoryPath, APIMgtConstants.APIFileUtilConstants.SWAGGER_DEFINITION_FILE_PREFIX);
API api;
String swaggerDefinition, gatewayConfiguration;
Set<Endpoint> endpoints;
try {
api = getApiDefinitionFromExtractedArchive(apiDefinitionFile.getPath());
swaggerDefinition = getSwaggerDefinitionFromExtractedArchive(swaggerDefinitionFile.getPath());
gatewayConfiguration = getGatewayConfigurationFromExtractedArchive(apiDefinitionDirectoryPath + File.separator + APIMgtConstants.APIFileUtilConstants.GATEWAY_CONFIGURATION_DEFINITION_FILE);
endpoints = getEndpointsFromExtractedArchive(apiDefinitionDirectoryPath + File.separator + ENDPOINTS_ROOT_DIRECTORY, api.getName(), api.getVersion());
} catch (APIManagementException e) {
log.error("Error occurred while importing api from path: " + apiDefinitionDirectoryPath, e);
// skip this API
continue;
}
if (newApiProvider != null && !newApiProvider.isEmpty()) {
// update the newApiProvider
api = new API.APIBuilder(api).provider(newApiProvider).build();
}
String documentsRootDirectory = apiDefinitionDirectoryPath + File.separator + DOCUMENTS_ROOT_DIRECTORY;
Set<DocumentInfo> documentInfoSet = getDocumentInfoFromExtractedArchive(documentsRootDirectory, api.getName(), api.getVersion());
Set<DocumentContent> documentContents = new HashSet<>();
for (DocumentInfo aDocumentInfo : documentInfoSet) {
DocumentContent aDocumentContent = getDocumentContentFromExtractedArchive(aDocumentInfo, documentsRootDirectory + File.separator + aDocumentInfo.getId());
if (aDocumentContent != null) {
documentContents.add(aDocumentContent);
}
}
InputStream thumbnailStream = null;
try {
thumbnailStream = APIFileUtils.getThumbnailImage(apiDefinitionDirectoryPath + File.separator + APIMgtConstants.APIFileUtilConstants.THUMBNAIL_FILE_NAME);
} catch (APIMgtDAOException e) {
// log and ignore
log.error("Error occurred while reading thumbnail image.", e);
}
APIDetails apiDetails = new APIDetails(api, swaggerDefinition);
apiDetails.setGatewayConfiguration(gatewayConfiguration);
apiDetails.setEndpoints(endpoints);
if (!documentInfoSet.isEmpty()) {
apiDetails.addDocumentInformation(documentInfoSet);
}
if (!documentContents.isEmpty()) {
apiDetails.addDocumentContents(documentContents);
}
if (thumbnailStream != null) {
apiDetails.setThumbnailStream(thumbnailStream);
}
apiDetailsSet.add(apiDetails);
}
return apiDetailsSet;
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts 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.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class APIPublisherImpl method addAPIFromWSDLArchive.
@Override
public String addAPIFromWSDLArchive(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
WSDLArchiveInfo archiveInfo = extractAndValidateWSDLArchive(inputStream);
if (log.isDebugEnabled()) {
log.debug("Successfully extracted and validated WSDL file. Location: " + archiveInfo.getAbsoluteFilePath());
}
apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(archiveInfo.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
String uuid = addAPI(apiBuilder);
if (log.isDebugEnabled()) {
log.debug("Successfully added the API. uuid: " + uuid);
}
try (InputStream fileInputStream = new FileInputStream(archiveInfo.getAbsoluteFilePath())) {
getApiDAO().addOrUpdateWSDLArchive(uuid, fileInputStream, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully added/updated the WSDL archive. uuid: " + uuid);
}
if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(archiveInfo.getWsdlInfo().getVersion())) {
log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
}
return uuid;
} catch (IOException e) {
throw new APIMgtWSDLException("Unable to process WSDL archive at " + archiveInfo.getAbsoluteFilePath(), e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
} finally {
try {
APIFileUtils.deleteDirectory(archiveInfo.getLocation());
} catch (APIMgtDAOException e) {
// This is not a blocker. Give a warning and continue
log.warn("Error occured while deleting processed WSDL artifacts folder : " + archiveInfo.getLocation());
}
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class RegistryPersistenceUtil method notifyAPIStateChangeToAssociatedDocuments.
/**
* Notify document artifacts if an api state change occured. This change is required to re-trigger the document
* indexer so that the documnet indexes will be updated with the new associated api status.
*
* @param apiArtifact
* @param registry
* @throws RegistryException
* @throws APIManagementException
*/
public static void notifyAPIStateChangeToAssociatedDocuments(GenericArtifact apiArtifact, Registry registry) throws RegistryException, APIManagementException {
Association[] docAssociations = registry.getAssociations(apiArtifact.getPath(), APIConstants.DOCUMENTATION_ASSOCIATION);
for (Association association : docAssociations) {
String documentResourcePath = association.getDestinationPath();
Resource docResource = registry.get(documentResourcePath);
String oldStateChangeIndicatorStatus = docResource.getProperty(APIConstants.API_STATE_CHANGE_INDICATOR);
String newStateChangeIndicatorStatus = "false";
if (oldStateChangeIndicatorStatus != null) {
newStateChangeIndicatorStatus = String.valueOf(!Boolean.parseBoolean(oldStateChangeIndicatorStatus));
}
docResource.setProperty(APIConstants.API_STATE_CHANGE_INDICATOR, "false");
registry.put(documentResourcePath, docResource);
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class GatewayUtils method retrieveDeployedAPI.
public static String retrieveDeployedAPI(String apiName, String version, String tenantDomain) throws APIManagementException {
try {
MessageContext.setCurrentMessageContext(createAxis2MessageContext());
RESTAPIAdminServiceProxy restapiAdminServiceProxy = new RESTAPIAdminServiceProxy(tenantDomain);
String qualifiedName = GatewayUtils.getQualifiedApiName(apiName, version);
OMElement api = restapiAdminServiceProxy.getApiContent(qualifiedName);
if (api != null) {
return api.toString();
}
return null;
} catch (AxisFault axisFault) {
throw new APIManagementException("Error while retrieving API Artifacts", axisFault, ExceptionCodes.INTERNAL_ERROR);
} finally {
MessageContext.destroyCurrentMessageContext();
}
}
Aggregations