use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateCheckListItemException.
@Test(description = "Exception when updating checklist item", expectedExceptions = APIManagementException.class)
public void testUpdateCheckListItemException() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(apiLifecycleManager.checkListItemEvent(lifecycleId, APIStatus.CREATED.getStatus(), APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true)).thenThrow(new LifecycleException("Couldn't get the lifecycle status of api ID " + uuid));
Map<String, Boolean> checklist = new HashMap<>();
checklist.put(APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true);
apiPublisher.updateCheckListItem(uuid, APIStatus.CREATED.getStatus(), checklist);
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetAPILifeCycleDataExceptionWhenRetrievingAPILifeCycle.
@Test(description = "Could not retrieve api lifecycle when Getting api lifecycle data", expectedExceptions = APIManagementException.class)
public void testGetAPILifeCycleDataExceptionWhenRetrievingAPILifeCycle() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPISummary(uuid)).thenReturn(api);
Mockito.doThrow(new LifecycleException("Couldn't retrieve API Lifecycle for " + uuid)).when(apiLifecycleManager).getLifecycleDataForState(lifecycleId, lcState);
apiPublisher.getAPILifeCycleData(uuid);
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisChangeLifecyclePost.
/**
* Change the lifecycle state of an API
*
* @param action lifecycle action
* @param apiId UUID of API
* @param lifecycleChecklist lifecycle check list items
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return 200 OK if the operation is succesful
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisChangeLifecyclePost(String action, String apiId, String lifecycleChecklist, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
WorkflowResponseDTO response = null;
try {
if (lifecycleChecklist != null) {
String[] checkList = lifecycleChecklist.split(",");
for (String checkList1 : checkList) {
StringTokenizer attributeTokens = new StringTokenizer(checkList1, ":");
String attributeName = attributeTokens.nextToken();
Boolean attributeValue = Boolean.valueOf(attributeTokens.nextToken());
lifecycleChecklistMap.put(attributeName, attributeValue);
}
}
if (action.trim().equals(APIMgtConstants.CHECK_LIST_ITEM_CHANGE_EVENT)) {
RestAPIPublisherUtil.getApiPublisher(username).updateCheckListItem(apiId, action, lifecycleChecklistMap);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
// since workflows are not defined for checklist items
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
response = MappingUtil.toWorkflowResponseDTO(workflowResponse);
return Response.ok().entity(response).build();
} else {
WorkflowResponse workflowResponse = RestAPIPublisherUtil.getApiPublisher(username).updateAPIStatus(apiId, action, lifecycleChecklistMap);
response = MappingUtil.toWorkflowResponseDTO(workflowResponse);
// be in either pending or approved state) send back the workflow response
if (WorkflowStatus.CREATED == workflowResponse.getWorkflowStatus()) {
URI location = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId);
return Response.status(Response.Status.ACCEPTED).header(RestApiConstants.LOCATION_HEADER, location).entity(response).build();
} else {
return Response.ok().entity(response).build();
}
}
} catch (APIManagementException e) {
String errorMessage = "Error while updating lifecycle of API" + apiId + " to " + action;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (URISyntaxException e) {
String errorMessage = "Error while adding location header in response for api : " + apiId;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorHandler errorHandler = ExceptionCodes.LOCATION_HEADER_INCORRECT;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler, paramList);
log.error(errorMessage, e);
return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdLifecycleLifecyclePendingTaskDelete.
/**
* Remove pending lifecycle state change workflow tasks.
*
* @param apiId api id
* @param request msf4j request object
* @return Empty payload
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdLifecycleLifecyclePendingTaskDelete(String apiId, Request request) throws NotFoundException {
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
apiPublisher.removePendingLifecycleWorkflowTaskForAPI(apiId);
return Response.ok().build();
} catch (APIManagementException e) {
String errorMessage = "Error while removing pending task for API state change for api " + apiId;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdLifecycleHistoryGet.
/**
* Retrieves the lifecycle history of the API
*
* @param apiId UUID of the API
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return lifecycle history of the API
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdLifecycleHistoryGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
if (RestAPIPublisherUtil.getApiPublisher(username).isAPIExists(apiId)) {
String lifecycleInstanceId = RestAPIPublisherUtil.getApiPublisher(username).getAPIbyUUID(apiId).getLifecycleInstanceId();
if (lifecycleInstanceId != null) {
List lifecyclestatechangehistory = RestAPIPublisherUtil.getApiPublisher(username).getLifeCycleHistoryFromUUID(lifecycleInstanceId);
return Response.ok().entity(lifecyclestatechangehistory).build();
} else {
throw new APIManagementException("Could not find lifecycle information for the requested API" + apiId, ExceptionCodes.APIMGT_LIFECYCLE_EXCEPTION);
}
} else {
String errorMessage = "API Not found : " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.API_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations