use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsSubscriptionIdGet.
/**
* Retrieves a single subscription
*
* @param subscriptionId ID of the subscription
* @param ifNoneMatch If-Match header value
* @param ifModifiedSince If-Modified-Since value
* @param request ms4j request object
* @return Requested subscription details
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionsSubscriptionIdGet(String subscriptionId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String existingFingerprint = subscriptionsSubscriptionIdGetFingerprint(subscriptionId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
Subscription subscription = apiPublisher.getSubscriptionByUUID(subscriptionId);
if (subscription == null) {
String errorMessage = "Subscription not found : " + subscriptionId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.SUBSCRIPTION_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.SUBSCRIPTION_ID, subscriptionId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
SubscriptionDTO subscriptionDTO = MappingUtil.fromSubscription(subscription);
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(subscriptionDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting the subscription " + subscriptionId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.SUBSCRIPTION_ID, subscriptionId);
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.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionListToDTO.
/**
* Converts a List object of SubscribedAPIs into a DTO
*
* @param subscriptions a list of SubscribedAPI objects
* @param limit max number of objects returned
* @param offset starting index
* @return SubscriptionListDTO object containing SubscriptionDTOs
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset) throws APIManagementException {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
subscriptionListDTO.setList(subscriptionDTOs);
}
// identifying the proper start and end indexes
int size = subscriptions.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
SubscribedAPI subscription = subscriptions.get(i);
subscriptionDTOs.add(fromSubscriptionToDTO(subscription));
}
subscriptionListDTO.setCount(subscriptionDTOs.size());
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method blockSubscription.
/**
* Blocks a subscription
*
* @param subscriptionId Subscription identifier
* @param blockState block state; either BLOCKED or PROD_ONLY_BLOCKED
* @param ifMatch If-Match header value
* @return 200 response and the updated subscription if subscription block is successful
*/
public Response blockSubscription(String subscriptionId, String blockState, String ifMatch, MessageContext messageContext) {
String username = RestApiCommonUtil.getLoggedInUsername();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getProvider(username);
// validates the subscriptionId if it exists
SubscribedAPI currentSubscription = apiProvider.getSubscriptionByUUID(subscriptionId);
if (currentSubscription == null) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_SUBSCRIPTION, subscriptionId, log);
}
SubscribedAPI subscribedAPI = new SubscribedAPI(subscriptionId);
subscribedAPI.setSubStatus(blockState);
apiProvider.updateSubscription(subscribedAPI);
SubscribedAPI updatedSubscription = apiProvider.getSubscriptionByUUID(subscriptionId);
SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(updatedSubscription);
return Response.ok().entity(subscriptionDTO).build();
} catch (APIManagementException e) {
String msg = "Error while blocking the subscription " + subscriptionId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromSubscriptionToSubscriptionListDTO.
public static SubscriptionListDTO fromSubscriptionToSubscriptionListDTO(List<Subscription> model) {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
if (model != null) {
for (Subscription subsModel : model) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionUUID(subsModel.getSubscriptionUUID());
subscriptionDTO.setApplicationUUID(subsModel.getApplicationUUID());
subscriptionDTO.setApiUUID(subsModel.getApiUUID());
subscriptionDTO.setApiId(subsModel.getApiId());
subscriptionDTO.setAppId(subsModel.getAppId());
subscriptionDTO.setSubscriptionId(subsModel.getSubscriptionId());
subscriptionDTO.setPolicyId(subsModel.getPolicyId());
subscriptionDTO.setSubscriptionState(subsModel.getSubscriptionState());
subscriptionListDTO.getList().add(subscriptionDTO);
}
subscriptionListDTO.setCount(model.size());
} else {
subscriptionListDTO.setCount(0);
}
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsGet.
public Response subscriptionsGet(String apiUUID, String appUUID, String tenantDomain, MessageContext messageContext) {
tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
if (subscriptionDataStore == null) {
log.warn("Subscription data store is not initialized for " + tenantDomain);
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isNotEmpty(apiUUID) && StringUtils.isNotEmpty(appUUID)) {
Subscription subscription = subscriptionDataStore.getSubscriptionByUUID(apiUUID, appUUID);
if (subscription == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
SubscriptionDTO subscriptionDTO = GatewayUtils.convertToSubscriptionDto(subscription);
return Response.ok().entity(subscriptionDTO).build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
}
}
Aggregations