use of org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method changeAPILifeCycle.
@Override
public void changeAPILifeCycle(Organization org, String apiId, String status) throws APIPersistenceException {
GenericArtifactManager artifactManager = null;
boolean isTenantFlowStarted = false;
try {
RegistryHolder holder = getRegistry(org.getName());
Registry registry = holder.getRegistry();
isTenantFlowStarted = holder.isTenantFlowStarted();
if (GovernanceUtils.findGovernanceArtifactConfiguration(APIConstants.API_KEY, registry) != null) {
artifactManager = new GenericArtifactManager(registry, APIConstants.API_KEY);
GenericArtifact apiArtifact = artifactManager.getGenericArtifact(apiId);
String action = LCManagerFactory.getInstance().getLCManager().getTransitionAction(apiArtifact.getLifecycleState().toUpperCase(), status.toUpperCase());
apiArtifact.invokeAction(action, APIConstants.API_LIFE_CYCLE);
} else {
log.warn("Couldn't find GovernanceArtifactConfiguration of RXT: " + APIConstants.API_KEY + ". Tenant id set in registry : " + ((UserRegistry) registry).getTenantId() + ", Tenant domain set in PrivilegedCarbonContext: " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
}
} catch (GovernanceException e) {
throw new APIPersistenceException("Error while changing the lifecycle. ", e);
} catch (RegistryException e) {
throw new APIPersistenceException("Error while accessing the registry. ", e);
} catch (PersistenceException e) {
throw new APIPersistenceException("Error while accessing the lifecycle. ", e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException in project carbon-apimgt by wso2.
the class LCManagerFactory method getLCManager.
public RegistryLCManager getLCManager() throws PersistenceException {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String cacheName = tenantDomain + "_" + APIConstants.LC_CACHE_NAME;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Cache lcCache = Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER).getCache(APIConstants.LC_CACHE_NAME);
RegistryLCManager lcManager = (RegistryLCManager) lcCache.get(cacheName);
if (lcManager != null) {
log.debug("Lifecycle info servered from Cache.");
return lcManager;
} else {
try {
log.debug("Lifecycle info not found in Cache.");
lcManager = new RegistryLCManager(tenantId);
lcCache.put(cacheName, lcManager);
return lcManager;
} catch (RegistryException | XMLStreamException | ParserConfigurationException | SAXException | IOException e) {
throw new PersistenceException("Error while accessing the lifecycle resource ", e);
}
}
}
use of org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException in project carbon-apimgt by wso2.
the class APIProviderImpl method getApiOrApiProductLifecycleData.
private Map<String, Object> getApiOrApiProductLifecycleData(String status) throws APIManagementException {
Map<String, Object> lcData = new HashMap<String, Object>();
List<String> actionsList;
try {
actionsList = LCManagerFactory.getInstance().getLCManager().getAllowedActionsForState(status);
if (actionsList != null) {
String[] actionsArray = new String[actionsList.size()];
actionsArray = actionsList.toArray(actionsArray);
lcData.put(APIConstants.LC_NEXT_STATES, actionsArray);
}
ArrayList<CheckListItem> checkListItems = new ArrayList<CheckListItem>();
List<String> checklistItemsList = LCManagerFactory.getInstance().getLCManager().getCheckListItemsForState(status);
if (checklistItemsList != null) {
for (String name : checklistItemsList) {
CheckListItem item = new CheckListItem();
item.setName(name);
item.setValue("false");
checkListItems.add(item);
}
}
lcData.put("items", checkListItems);
} catch (PersistenceException e) {
throw new APIManagementException("Error while parsing the lifecycle ", e);
}
// First letter capital
status = status.substring(0, 1).toUpperCase() + status.substring(1).toLowerCase();
lcData.put(APIConstants.LC_STATUS, status);
return lcData;
}
use of org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException in project carbon-apimgt by wso2.
the class APIProviderImpl method changeLifeCycleStatus.
/**
* This method is to change registry lifecycle states for an API or API Product artifact
*
* @param orgId UUID of the organization
* @param apiTypeWrapper API Type Wrapper
* @param action Action which need to execute from registry lifecycle
* @param checklist checklist items
* @return APIStateChangeResponse API workflow state and WorkflowResponse
*/
@Override
public APIStateChangeResponse changeLifeCycleStatus(String orgId, ApiTypeWrapper apiTypeWrapper, String action, Map<String, Boolean> checklist) throws APIManagementException, FaultGatewaysException {
APIStateChangeResponse response = new APIStateChangeResponse();
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(this.username);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(this.tenantDomain, true);
String targetStatus;
String providerName;
String apiName;
String apiContext;
String apiType;
String apiVersion;
String currentStatus;
String uuid;
int apiOrApiProductId;
boolean isApiProduct = apiTypeWrapper.isAPIProduct();
String workflowType;
if (isApiProduct) {
APIProduct apiProduct = apiTypeWrapper.getApiProduct();
providerName = apiProduct.getId().getProviderName();
apiName = apiProduct.getId().getName();
apiContext = apiProduct.getContext();
apiType = apiProduct.getType();
apiVersion = apiProduct.getId().getVersion();
currentStatus = apiProduct.getState();
uuid = apiProduct.getUuid();
apiOrApiProductId = apiMgtDAO.getAPIProductId(apiTypeWrapper.getApiProduct().getId());
workflowType = WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE;
} else {
API api = apiTypeWrapper.getApi();
providerName = api.getId().getProviderName();
apiName = api.getId().getApiName();
apiContext = api.getContext();
apiType = api.getType();
apiVersion = api.getId().getVersion();
currentStatus = api.getStatus();
uuid = api.getUuid();
apiOrApiProductId = apiMgtDAO.getAPIID(uuid);
workflowType = WorkflowConstants.WF_TYPE_AM_API_STATE;
}
String gatewayVendor = apiMgtDAO.getGatewayVendorByAPIUUID(uuid);
WorkflowStatus apiWFState = null;
WorkflowDTO wfDTO = apiMgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(apiOrApiProductId), workflowType);
if (wfDTO != null) {
apiWFState = wfDTO.getStatus();
}
// if the workflow has started, then executor should not fire again
if (!WorkflowStatus.CREATED.equals(apiWFState)) {
response = executeStateChangeWorkflow(currentStatus, action, apiName, apiContext, apiType, apiVersion, providerName, apiOrApiProductId, uuid, gatewayVendor, workflowType);
// get the workflow state once the executor is executed.
wfDTO = apiMgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(apiOrApiProductId), workflowType);
if (wfDTO != null) {
apiWFState = wfDTO.getStatus();
response.setStateChangeStatus(apiWFState.toString());
} else {
response.setStateChangeStatus(WorkflowStatus.APPROVED.toString());
}
}
// apiWFState is null when simple wf executor is used because wf state is not stored in the db.
if (WorkflowStatus.APPROVED.equals(apiWFState) || apiWFState == null) {
targetStatus = LCManagerFactory.getInstance().getLCManager().getStateForTransition(action);
apiPersistenceInstance.changeAPILifeCycle(new Organization(orgId), uuid, targetStatus);
sendLCStateChangeNotification(apiName, apiType, apiContext, apiVersion, targetStatus, providerName, apiOrApiProductId, uuid);
if (!isApiProduct) {
API api = apiTypeWrapper.getApi();
api.setOrganization(orgId);
changeLifeCycle(api, currentStatus, targetStatus, checklist);
// Sending Notifications to existing subscribers
if (APIConstants.PUBLISHED.equals(targetStatus)) {
sendEmailNotification(api);
}
} else {
APIProduct apiProduct = apiTypeWrapper.getApiProduct();
apiProduct.setOrganization(orgId);
changeLifecycle(apiProduct, currentStatus, targetStatus);
}
addLCStateChangeInDatabase(currentStatus, targetStatus, uuid);
if (log.isDebugEnabled()) {
String logMessage = "LC Status changed successfully for artifact with name: " + apiName + ", version " + apiVersion + ", New Status : " + targetStatus;
log.debug(logMessage);
}
extractRecommendationDetails(apiTypeWrapper);
return response;
}
} catch (APIPersistenceException e) {
handleException("Error while accessing persistence layer", e);
} catch (PersistenceException e) {
handleException("Error while accessing lifecycle information ", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return response;
}
use of org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method addResourceFile.
protected String addResourceFile(String resourcePath, ResourceFile resourceFile, Registry registry, String tenantDomain) throws PersistenceException {
try {
Resource thumb = registry.newResource();
thumb.setContentStream(resourceFile.getContent());
thumb.setMediaType(resourceFile.getContentType());
registry.put(resourcePath, thumb);
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
return RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + RegistryConstants.PATH_SEPARATOR + "_system" + RegistryConstants.PATH_SEPARATOR + "governance" + resourcePath;
} else {
return "/t/" + tenantDomain + RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + RegistryConstants.PATH_SEPARATOR + "_system" + RegistryConstants.PATH_SEPARATOR + "governance" + resourcePath;
}
} catch (RegistryException e) {
String msg = "Error while adding the resource to the registry";
throw new PersistenceException(msg, e);
}
}
Aggregations