use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class APIProviderImpl method updateApiProductArtifact.
/**
* Update API Product Artifact in Registry
*
* @param apiProduct
* @param updateMetadata
* @param updatePermissions
* @throws APIManagementException
*/
private void updateApiProductArtifact(APIProduct apiProduct, boolean updateMetadata, boolean updatePermissions) throws APIManagementException {
// Validate Transports and Security
validateAndSetTransports(apiProduct);
validateAndSetAPISecurity(apiProduct);
PublisherAPIProduct publisherAPIProduct = APIProductMapper.INSTANCE.toPublisherApiProduct(apiProduct);
PublisherAPIProduct addedAPIProduct;
try {
publisherAPIProduct.setApiProductName(apiProduct.getId().getName());
publisherAPIProduct.setProviderName(apiProduct.getId().getProviderName());
publisherAPIProduct.setVersion(apiProduct.getId().getVersion());
addedAPIProduct = apiPersistenceInstance.updateAPIProduct(new Organization(CarbonContext.getThreadLocalCarbonContext().getTenantDomain()), publisherAPIProduct);
} catch (APIPersistenceException e) {
throw new APIManagementException("Error while creating API product ");
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class APIProviderImpl method updateAPIProductForStateChange.
/**
* Update API Product in registry for lifecycle state change
*
* @param apiProduct API Product Object
* @param currentStatus Current state of API Product
* @param newStatus New state of API Product
* @return boolean indicates success or failure
* @throws APIManagementException if there is an error when updating API Product for lifecycle state
* @throws FaultGatewaysException if there is an error when updating API Product for lifecycle state
*/
public void updateAPIProductForStateChange(APIProduct apiProduct, String currentStatus, String newStatus) throws APIManagementException, FaultGatewaysException {
String provider = apiProduct.getId().getProviderName();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(provider));
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
isTenantFlowStarted = true;
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
}
if (!currentStatus.equals(newStatus)) {
apiProduct.setState(newStatus);
// If API status changed to publish we should add it to recently added APIs list
// this should happen in store-publisher cluster domain if deployment is distributed
// IF new API published we will add it to recently added APIs
Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER).getCache(APIConstants.RECENTLY_ADDED_API_CACHE_NAME).removeAll();
if (APIConstants.RETIRED.equals(newStatus)) {
cleanUpPendingSubscriptionCreationProcessesByAPI(apiProduct.getUuid());
apiMgtDAO.removeAllSubscriptions(apiProduct.getUuid());
deleteAPIProductRevisions(apiProduct.getUuid(), tenantDomain);
}
PublisherAPIProduct publisherAPIProduct = APIProductMapper.INSTANCE.toPublisherApiProduct(apiProduct);
try {
apiPersistenceInstance.updateAPIProduct(new Organization(apiProduct.getOrganization()), publisherAPIProduct);
} catch (APIPersistenceException e) {
handleException("Error while persisting the updated API Product", e);
}
}
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException 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.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceUtil method getAPIForSearch.
public static PublisherAPI getAPIForSearch(GenericArtifact apiArtifact) throws APIPersistenceException {
PublisherAPI api = new PublisherAPI();
try {
api.setContext(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
api.setDescription(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
api.setId(apiArtifact.getId());
api.setStatus(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_STATUS));
api.setApiName(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME));
api.setProviderName(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER));
;
api.setVersion(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
api.setAdvertiseOnly(Boolean.parseBoolean(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_ADVERTISE_ONLY)));
} catch (GovernanceException e) {
throw new APIPersistenceException("Error while extracting api attributes ", e);
}
return api;
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceUtil method getDevPortalAPIForSearch.
public static DevPortalAPI getDevPortalAPIForSearch(GenericArtifact apiArtifact) throws APIPersistenceException {
DevPortalAPI api = new DevPortalAPI();
try {
api.setContext(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
api.setDescription(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
api.setId(apiArtifact.getId());
api.setStatus(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_STATUS));
api.setApiName(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME));
api.setProviderName(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER));
;
api.setVersion(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
} catch (GovernanceException e) {
throw new APIPersistenceException("Error while extracting api attributes ", e);
}
return api;
}
Aggregations