use of org.wso2.carbon.apimgt.impl.importexport.APIImportExportException in project carbon-apimgt by wso2.
the class ImportExportAPIServiceImpl method exportAPI.
@Override
public File exportAPI(String apiId, String revisionUUID, boolean preserveStatus, ExportFormat format, boolean preserveDocs, boolean preserveCredentials, String organization) throws APIManagementException, APIImportExportException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String userName = RestApiCommonUtil.getLoggedInUsername();
APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
API api = apiProvider.getAPIbyUUID(revisionUUID, organization);
api.setUuid(apiId);
apiIdentifier.setUuid(apiId);
APIDTO apiDtoToReturn = APIMappingUtil.fromAPItoDTO(api, preserveCredentials, apiProvider);
return ExportUtils.exportApi(apiProvider, apiIdentifier, apiDtoToReturn, api, userName, format, preserveStatus, preserveDocs, StringUtils.EMPTY, organization);
}
use of org.wso2.carbon.apimgt.impl.importexport.APIImportExportException in project carbon-apimgt by wso2.
the class APIProviderImpl method addAPIProductRevision.
@Override
public String addAPIProductRevision(APIRevision apiRevision, String organization) throws APIManagementException {
int revisionCountPerAPI = apiMgtDAO.getRevisionCountByAPI(apiRevision.getApiUUID());
if (revisionCountPerAPI > 4) {
String errorMessage = "Maximum number of revisions per API Product has reached. " + "Need to remove stale revision to create a new Revision for API Product with id:" + apiRevision.getApiUUID();
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.MAXIMUM_REVISIONS_REACHED, apiRevision.getApiUUID()));
}
int revisionId = apiMgtDAO.getMostRecentRevisionId(apiRevision.getApiUUID()) + 1;
apiRevision.setId(revisionId);
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiRevision.getApiUUID());
if (apiProductIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiRevision.getApiUUID(), ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiRevision.getApiUUID()));
}
apiProductIdentifier.setUUID(apiRevision.getApiUUID());
String revisionUUID;
try {
revisionUUID = apiPersistenceInstance.addAPIRevision(new Organization(tenantDomain), apiProductIdentifier.getUUID(), revisionId);
} catch (APIPersistenceException e) {
String errorMessage = "Failed to add revision registry artifacts";
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.ERROR_CREATING_API_REVISION, apiRevision.getApiUUID()));
}
if (StringUtils.isEmpty(revisionUUID)) {
String errorMessage = "Failed to retrieve revision uuid";
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.API_REVISION_UUID_NOT_FOUND));
}
apiRevision.setRevisionUUID(revisionUUID);
apiMgtDAO.addAPIProductRevision(apiRevision);
try {
File artifact = importExportAPI.exportAPIProduct(apiRevision.getApiUUID(), revisionUUID, true, ExportFormat.JSON, false, true, organization);
gatewayArtifactsMgtDAO.addGatewayAPIArtifactAndMetaData(apiRevision.getApiUUID(), apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), apiRevision.getRevisionUUID(), tenantDomain, APIConstants.API_PRODUCT, artifact);
if (artifactSaver != null) {
artifactSaver.saveArtifact(apiRevision.getApiUUID(), apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), apiRevision.getRevisionUUID(), tenantDomain, artifact);
}
} catch (APIImportExportException | ArtifactSynchronizerException e) {
throw new APIManagementException("Error while Store the Revision Artifact", ExceptionCodes.from(ExceptionCodes.API_REVISION_UUID_NOT_FOUND));
}
return revisionUUID;
}
Aggregations