use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method updateTopics.
@Override
public Response updateTopics(String apiId, TopicListDTO topicListDTO, String ifMatch, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate if api exists
validateAPIExistence(apiId);
API existingAPI = apiProvider.getAPIbyUUID(apiId, organization);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(existingAPI.getStatus());
Set<URITemplate> uriTemplates = existingAPI.getUriTemplates();
uriTemplates.clear();
for (TopicDTO topicDTO : topicListDTO.getList()) {
URITemplate uriTemplate = new URITemplate();
uriTemplate.setUriTemplate(topicDTO.getName());
uriTemplate.setHTTPVerb(topicDTO.getMode().toUpperCase());
// TODO: Get these from proper locations
uriTemplate.setAuthType(APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN);
uriTemplate.setThrottlingTier(APIConstants.UNLIMITED_TIER);
uriTemplates.add(uriTemplate);
}
existingAPI.setUriTemplates(uriTemplates);
// TODO: Add scopes
existingAPI.setOrganization(organization);
try {
apiProvider.updateAPI(existingAPI);
} catch (FaultGatewaysException e) {
String errorMessage = "Error while updating API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return Response.ok().build();
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO in project carbon-apimgt by wso2.
the class AsyncAPIMappingUtil method fromTopicListToDTO.
/**
* Converts Set of Topic objects to DTO.
*
* @param topics set of Topic objects
* @return TopicListDTO containing TopicDTOs
*/
public static TopicListDTO fromTopicListToDTO(Set<Topic> topics) {
TopicListDTO topicListDTO = new TopicListDTO();
List<TopicDTO> topicDTOs = topicListDTO.getList();
topicListDTO.setCount(topics.size());
if (topicDTOs == null) {
topicDTOs = new ArrayList<>();
topicListDTO.setList(topicDTOs);
}
for (Topic topic : topics) {
topicDTOs.add(fromTopicToDTO(topic));
}
return topicListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdTopicsGet.
@Override
public Response apisApiIdTopicsGet(String apiId, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
if (org.apache.commons.lang.StringUtils.isNotEmpty(apiId)) {
String username = RestApiCommonUtil.getLoggedInUsername();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Set<Topic> topics;
try {
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
TopicListDTO topicListDTO;
if (apiTypeWrapper.isAPIProduct()) {
topics = apiConsumer.getTopics(apiTypeWrapper.getApiProduct().getUuid());
} else {
topics = apiConsumer.getTopics(apiTypeWrapper.getApi().getUuid());
}
topicListDTO = AsyncAPIMappingUtil.fromTopicListToDTO(topics);
return Response.ok().entity(topicListDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get topics of Async API " + apiId, e, log);
}
}
} else {
RestApiUtil.handleBadRequest("API Id is missing in request", log);
}
return null;
}
Aggregations