use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdGet.
/**
* Retrives an API by UUID
*
* @param apiId UUID of API
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return API which is identified by the given UUID
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response compositeApisApiIdGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
if (!RestApiUtil.getConsumer(username).isCompositeAPIExist(apiId)) {
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);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = compositeApisApiIdGetFingerprint(apiId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
CompositeAPIDTO apidto = CompositeAPIMappingUtil.toCompositeAPIDTO(RestApiUtil.getConsumer(username).getCompositeAPIbyId(apiId));
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(apidto).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();
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateAPIStatus.
/**
* @see org.wso2.carbon.apimgt.core.api.APIPublisher#updateAPIStatus(String, String, Map)
*/
@Override
public WorkflowResponse updateAPIStatus(String apiId, String status, Map<String, Boolean> checkListItemMap) throws APIManagementException {
WorkflowResponse workflowResponse = null;
try {
API api = getApiDAO().getAPI(apiId);
if (api != null && !APILCWorkflowStatus.PENDING.toString().equals(api.getWorkflowStatus())) {
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lastUpdatedTime(LocalDateTime.now());
apiBuilder.updatedBy(getUsername());
LifecycleState currentState = getApiLifecycleManager().getLifecycleDataForState(apiBuilder.getLifecycleInstanceId(), apiBuilder.getLifeCycleStatus());
apiBuilder.lifecycleState(currentState);
for (Map.Entry<String, Boolean> checkListItem : checkListItemMap.entrySet()) {
getApiLifecycleManager().checkListItemEvent(api.getLifecycleInstanceId(), api.getLifeCycleStatus(), checkListItem.getKey(), checkListItem.getValue());
}
API originalAPI = apiBuilder.build();
WorkflowExecutor executor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_STATE);
APIStateChangeWorkflow workflow = new APIStateChangeWorkflow(getApiDAO(), getApiSubscriptionDAO(), getWorkflowDAO(), getApiLifecycleManager(), getApiGateway(), getLabelDAO());
workflow.setApiName(originalAPI.getName());
workflow.setApiProvider(originalAPI.getProvider());
workflow.setApiVersion(originalAPI.getVersion());
workflow.setCurrentState(currentState.getState());
workflow.setTransitionState(status);
workflow.setWorkflowReference(originalAPI.getId());
workflow.setExternalWorkflowReference(UUID.randomUUID().toString());
workflow.setCreatedTime(LocalDateTime.now());
workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_API_STATE);
workflow.setInvoker(getUsername());
// setting attributes for internal use. These are set to use from outside the executor's method
// these will be saved in the AM_WORKFLOW table so these can be retrieved later
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_CUR_STATE, currentState.getState());
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_TARGET_STATE, status);
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_LC_INVOKER, getUsername());
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_NAME, originalAPI.getId());
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_HAS_OWN_GATEWAY, String.valueOf(originalAPI.hasOwnGateway()));
if (originalAPI.hasOwnGateway()) {
List<String> gwLabels = originalAPI.getLabels();
for (String label : gwLabels) {
if (label.contains(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX)) {
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_AUTOGEN_LABEL, label);
break;
}
}
}
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_HAS_OWN_GATEWAY, String.valueOf(originalAPI.hasOwnGateway()));
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_API_LAST_UPTIME, originalAPI.getLastUpdatedTime().toString());
String workflowDescription = "API [" + workflow.getApiName() + " - " + workflow.getApiVersion() + "] state change [" + workflow.getCurrentState() + " to " + workflow.getTransitionState() + "] request from " + getUsername();
workflow.setWorkflowDescription(workflowDescription);
workflowResponse = executor.execute(workflow);
workflow.setStatus(workflowResponse.getWorkflowStatus());
if (WorkflowStatus.CREATED != workflowResponse.getWorkflowStatus()) {
completeWorkflow(executor, workflow);
} else {
// add entry to workflow table if it is only in pending state
addWorkflowEntries(workflow);
getApiDAO().updateAPIWorkflowStatus(api.getId(), APILCWorkflowStatus.PENDING);
}
} else if (api != null && APILCWorkflowStatus.PENDING.toString().equals(api.getWorkflowStatus())) {
String message = "Pending state transition for api :" + api.getName();
log.error(message);
throw new APIManagementException(message, ExceptionCodes.WORKFLOW_PENDING);
} else {
throw new APIMgtResourceNotFoundException("Requested API " + apiId + " Not Available");
}
} catch (APIMgtDAOException e) {
String errorMsg = "Couldn't change the status of api ID " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (LifecycleException e) {
String errorMsg = "Couldn't change the status of api ID " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_LIFECYCLE_EXCEPTION);
}
return workflowResponse;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class APIStoreImpl method updateComment.
@Override
public void updateComment(Comment comment, String commentId, String apiId, String username) throws APICommentException, APIMgtResourceNotFoundException {
validateCommentMaxCharacterLength(comment.getCommentText());
try {
failIfApiNotExists(apiId);
Comment oldComment = getApiDAO().getCommentByUUID(commentId, apiId);
if (oldComment != null) {
// if the update operation is done by a user who isn't the owner of the comment
if (!oldComment.getCommentedUser().equals(username)) {
checkIfUserIsCommentModerator(username);
}
getApiDAO().updateComment(comment, commentId, apiId);
} else {
String errorMsg = "Couldn't find comment with comment_id : " + commentId + "and api_id : " + apiId;
log.error(errorMsg);
throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.COMMENT_NOT_FOUND);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating comment " + commentId;
log.error(errorMsg, e);
throw new APICommentException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class APIStoreImpl method updateRating.
@Override
public void updateRating(String apiId, String ratingId, Rating ratingFromPayload) throws APIRatingException, APIMgtResourceNotFoundException {
try {
validateMaxMinRatingValue(ratingFromPayload.getRating());
failIfApiNotExists(apiId);
getApiDAO().updateRating(apiId, ratingId, ratingFromPayload);
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating rating for user " + getUsername() + " for api " + apiId;
log.error(errorMsg, e);
throw new APIRatingException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class APIStoreImpl method getRatingByUUID.
@Override
public Rating getRatingByUUID(String apiId, String ratingId) throws APIRatingException, APIMgtResourceNotFoundException {
Rating rating;
try {
failIfApiNotExists(apiId);
rating = getApiDAO().getRatingByUUID(apiId, ratingId);
if (rating == null) {
String errorMsg = "Couldn't find rating with rating id - " + ratingId + " for api_id " + apiId;
log.error(errorMsg);
throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.RATING_NOT_FOUND);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving rating for rating id " + ratingId + " for api_id " + apiId;
log.error(errorMsg, e);
throw new APIRatingException(errorMsg, e, e.getErrorHandler());
}
return rating;
}
Aggregations