use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class LifecycleModificationHandler method clearConfigCache.
private void clearConfigCache(RequestContext requestContext) {
Resource resource = requestContext.getResource();
if (resource instanceof ResourceImpl) {
ResourceImpl resourceImpl = (ResourceImpl) resource;
if (resourceImpl != null && APIConstants.API_LIFE_CYCLE.equals(resourceImpl.getName())) {
Cache lcCache = Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER).getCache(APIConstants.LC_CACHE_NAME);
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String cacheName = tenantDomain + "_" + APIConstants.LC_CACHE_NAME;
if (lcCache.containsKey(cacheName)) {
lcCache.remove(cacheName);
if (log.isDebugEnabled()) {
log.debug("Lifecycle cache cleared for tenant domain " + tenantDomain);
}
}
}
}
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPILifecycleHistory.
/**
* Retrieves API Lifecycle history information
*
* @param apiId API Id
* @param ifNoneMatch If-None-Match header value
* @return API Lifecycle history information
*/
@Override
public Response getAPILifecycleHistory(String apiId, String ifNoneMatch, MessageContext messageContext) {
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
API api;
APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiId);
if (apiRevision != null && apiRevision.getApiUUID() != null) {
api = apiProvider.getAPIbyUUID(apiRevision.getApiUUID(), organization);
} else {
api = apiProvider.getAPIbyUUID(apiId, organization);
}
return Response.ok().entity(PublisherCommonUtils.getLifecycleHistoryDTO(api.getUuid(), apiProvider)).build();
} catch (APIManagementException e) {
// Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving the lifecycle " + "events of API : " + apiId, e, log);
} else {
String errorMessage = "Error while retrieving the lifecycle events of API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method changeAPILifecycle.
@Override
public Response changeAPILifecycle(String action, String apiId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) {
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ApiTypeWrapper apiWrapper = new ApiTypeWrapper(apiProvider.getAPIbyUUID(apiId, organization));
APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, apiWrapper, lifecycleChecklist, organization);
// returns the current lifecycle state
// todo try to prevent this call
LifecycleStateDTO stateDTO = getLifecycleState(apiId, organization);
WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
return Response.ok().entity(workflowResponseDTO).build();
} catch (APIManagementException e) {
// Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while updating the lifecycle of API " + apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Error while updating lifecycle of API " + apiId, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeAPILCCheckListItems.
@Test
public void testChangeAPILCCheckListItems() throws APIManagementException, GovernanceException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
GenericArtifact apiArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
Mockito.when(apiArtifact.isLCItemChecked(10, "APILifeCycle")).thenThrow(GovernanceException.class).thenReturn(false, true);
String msg = "Error while setting registry lifecycle checklist items for the API: API1";
try {
apiProvider.changeAPILCCheckListItems(apiId, 10, true);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// status checked
assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
// status false
assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class APIMappingUtil method fromLifecycleHistoryModelToDTO.
/**
* Return the REST API DTO representation of API Lifecycle history information.
*
* @param lifeCycleEvents API lifecycle history information
* @return REST API DTO representation of API Lifecycle history information
*/
public static LifecycleHistoryDTO fromLifecycleHistoryModelToDTO(List<LifeCycleEvent> lifeCycleEvents) {
LifecycleHistoryDTO historyDTO = new LifecycleHistoryDTO();
historyDTO.setCount(lifeCycleEvents.size());
for (LifeCycleEvent event : lifeCycleEvents) {
LifecycleHistoryItemDTO historyItemDTO = new LifecycleHistoryItemDTO();
historyItemDTO.setPostState(event.getNewStatus());
historyItemDTO.setPreviousState(event.getOldStatus());
historyItemDTO.setUser(event.getUserId());
String updatedTime = RestApiCommonUtil.getRFC3339Date(event.getDate());
historyItemDTO.setUpdatedTime(updatedTime);
historyDTO.getList().add(historyItemDTO);
}
return historyDTO;
}
Aggregations