use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testIsAPIProductAvailable.
@Test
public void testIsAPIProductAvailable() throws APIManagementException {
APIProductIdentifier apiProductIdentifier = getAPIProductIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
String organization = "carbon.super";
String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getName() + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getVersion();
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(apiMgtDAO);
Mockito.when(apiMgtDAO.getUUIDFromIdentifier(apiProductIdentifier, organization)).thenReturn("xxxxx");
Assert.assertTrue(abstractAPIManager.isAPIProductAvailable(apiProductIdentifier, organization));
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIProviderImpl method deleteAPIProduct.
public void deleteAPIProduct(APIProduct apiProduct) throws APIManagementException {
APIProductIdentifier identifier = apiProduct.getId();
try {
// int apiId = apiMgtDAO.getAPIID(identifier, null);
long subsCount = apiMgtDAO.getAPISubscriptionCountByAPI(identifier);
if (subsCount > 0) {
// Logging as a WARN since this isn't an error scenario.
String message = "Cannot remove the API Product as active subscriptions exist.";
log.warn(message);
throw new APIManagementException(message);
}
// gatewayType check is required when API Management is deployed on
// other servers to avoid synapse
deleteAPIProductRevisions(apiProduct.getUuid(), apiProduct.getOrganization());
apiPersistenceInstance.deleteAPIProduct(new Organization(apiProduct.getOrganization()), apiProduct.getUuid());
apiMgtDAO.deleteAPIProduct(identifier);
cleanUpPendingAPIStateChangeTask(apiProduct.getProductId(), true);
if (log.isDebugEnabled()) {
String logMessage = "API Product Name: " + identifier.getName() + ", API Product Version " + identifier.getVersion() + " successfully removed from the database.";
log.debug(logMessage);
}
JSONObject apiLogObject = new JSONObject();
apiLogObject.put(APIConstants.AuditLogConstants.NAME, identifier.getName());
apiLogObject.put(APIConstants.AuditLogConstants.VERSION, identifier.getVersion());
apiLogObject.put(APIConstants.AuditLogConstants.PROVIDER, identifier.getProviderName());
APIUtil.logAuditMessage(APIConstants.AuditLogConstants.API_PRODUCT, apiLogObject.toString(), APIConstants.AuditLogConstants.DELETED, this.username);
GatewayArtifactsMgtDAO.getInstance().deleteGatewayArtifacts(apiProduct.getUuid());
} catch (APIPersistenceException e) {
handleException("Failed to remove the API product", e);
} catch (WorkflowException e) {
handleException("Error while removing the pending workflows of API Product", e);
}
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIProviderImpl method updateAPIProductDisplayOnDevportal.
@Override
public void updateAPIProductDisplayOnDevportal(String apiProductId, String apiRevisionId, APIRevisionDeployment apiRevisionDeployment) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
if (apiProductIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiProductId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
List<APIRevisionDeployment> currentApiRevisionDeploymentList = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiProductId);
Set<APIRevisionDeployment> environmentsToUpdate = new HashSet<>();
for (APIRevisionDeployment currentapiRevisionDeployment : currentApiRevisionDeploymentList) {
if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), apiRevisionDeployment.getDeployment())) {
environmentsToUpdate.add(apiRevisionDeployment);
}
}
if (environmentsToUpdate.size() > 0) {
apiMgtDAO.updateAPIRevisionDeployment(apiProductId, environmentsToUpdate);
} else {
throw new APIMgtResourceNotFoundException("deployment with " + apiRevisionDeployment.getDeployment() + " not found", ExceptionCodes.from(ExceptionCodes.EXISTING_DEPLOYMENT_NOT_FOUND, apiRevisionDeployment.getDeployment()));
}
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIProviderImpl method searchPaginatedContent.
@Override
public Map<String, Object> searchPaginatedContent(String searchQuery, String organization, int start, int end) throws APIManagementException {
ArrayList<Object> compoundResult = new ArrayList<Object>();
Map<Documentation, API> docMap = new HashMap<Documentation, API>();
Map<Documentation, APIProduct> productDocMap = new HashMap<Documentation, APIProduct>();
Map<String, Object> result = new HashMap<String, Object>();
SortedSet<API> apiSet = new TreeSet<API>(new APINameComparator());
SortedSet<APIProduct> apiProductSet = new TreeSet<APIProduct>(new APIProductNameComparator());
String userame = userNameWithoutChange;
Organization org = new Organization(organization);
Map<String, Object> properties = APIUtil.getUserProperties(userame);
String[] roles = APIUtil.getFilteredUserRoles(userame);
UserContext ctx = new UserContext(userame, org, properties, roles);
try {
PublisherContentSearchResult results = apiPersistenceInstance.searchContentForPublisher(org, searchQuery, start, end, ctx);
if (results != null) {
List<SearchContent> resultList = results.getResults();
for (SearchContent item : resultList) {
if ("API".equals(item.getType())) {
PublisherSearchContent publiserAPI = (PublisherSearchContent) item;
API api = new API(new APIIdentifier(publiserAPI.getProvider(), publiserAPI.getName(), publiserAPI.getVersion()));
api.setUuid(publiserAPI.getId());
api.setContext(publiserAPI.getContext());
api.setContextTemplate(publiserAPI.getContext());
api.setStatus(publiserAPI.getStatus());
apiSet.add(api);
} else if ("APIProduct".equals(item.getType())) {
PublisherSearchContent publiserAPI = (PublisherSearchContent) item;
APIProduct api = new APIProduct(new APIProductIdentifier(publiserAPI.getProvider(), publiserAPI.getName(), publiserAPI.getVersion()));
api.setUuid(publiserAPI.getId());
api.setContextTemplate(publiserAPI.getContext());
api.setState(publiserAPI.getStatus());
apiProductSet.add(api);
} else if (item instanceof DocumentSearchContent) {
// doc item
DocumentSearchContent docItem = (DocumentSearchContent) item;
Documentation doc = new Documentation(DocumentationType.valueOf(docItem.getDocType().toString()), docItem.getName());
doc.setSourceType(DocumentSourceType.valueOf(docItem.getSourceType().toString()));
doc.setVisibility(DocumentVisibility.valueOf(docItem.getVisibility().toString()));
doc.setId(docItem.getId());
if ("API".equals(docItem.getAssociatedType())) {
API api = new API(new APIIdentifier(docItem.getApiProvider(), docItem.getApiName(), docItem.getApiVersion()));
api.setUuid(docItem.getApiUUID());
docMap.put(doc, api);
} else if ("APIProduct".equals(docItem.getAssociatedType())) {
APIProduct api = new APIProduct(new APIProductIdentifier(docItem.getApiProvider(), docItem.getApiName(), docItem.getApiVersion()));
api.setUuid(docItem.getApiUUID());
productDocMap.put(doc, api);
}
}
}
compoundResult.addAll(apiSet);
compoundResult.addAll(apiProductSet);
compoundResult.addAll(docMap.entrySet());
compoundResult.addAll(productDocMap.entrySet());
compoundResult.sort(new ContentSearchResultNameComparator());
result.put("length", results.getTotalCount());
} else {
result.put("length", compoundResult.size());
}
} catch (APIPersistenceException e) {
throw new APIManagementException("Error while searching content ", e);
}
result.put("apis", compoundResult);
return result;
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIGatewayManager method unDeployFromGateway.
public void unDeployFromGateway(APIProduct apiProduct, String tenantDomain, Set<API> associatedAPIs, Set<String> gatewaysToRemove) throws APIManagementException {
String apiProductUuid = apiProduct.getUuid();
APIProductIdentifier apiProductIdentifier = apiProduct.getId();
try {
if (artifactSaver != null) {
artifactSaver.removeArtifact(apiProductUuid, apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), APIConstants.API_PRODUCT_REVISION, tenantDomain);
}
GatewayArtifactsMgtDAO.getInstance().deleteGatewayArtifact(apiProductUuid, APIConstants.API_PRODUCT_REVISION);
GatewayArtifactsMgtDAO.getInstance().removePublishedGatewayLabels(apiProductUuid, APIConstants.API_PRODUCT_REVISION);
} catch (ArtifactSynchronizerException e) {
throw new APIManagementException("API " + apiProductIdentifier + "couldn't get unDeployed", e);
}
if (debugEnabled) {
log.debug("Status of " + apiProductIdentifier + " has been updated to DB");
}
sendUnDeploymentEvent(apiProduct, tenantDomain, gatewaysToRemove, associatedAPIs);
}
Aggregations