use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a ApplicationListDTO object given pagination parameters and url parameters
*
* @param applicationListDTO a SubscriptionListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(ApplicationListDTO applicationListDTO, int limit, int offset, int size) {
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getApplicationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), null);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getApplicationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), null);
}
PaginationDTO paginationDTO = getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
applicationListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationsToDTO.
/**
* Converts an Application[] array into a corresponding ApplicationListDTO
*
* @param applications array of Application objects
* @return ApplicationListDTO object corresponding to Application[] array
*/
public static ApplicationListDTO fromApplicationsToDTO(Application[] applications) throws APIManagementException {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
List<ApplicationInfoDTO> applicationInfoDTOs = applicationListDTO.getList();
if (applicationInfoDTOs == null) {
applicationInfoDTOs = new ArrayList<>();
applicationListDTO.setList(applicationInfoDTOs);
}
for (Application application : applications) {
ApplicationInfoDTO applicationInfoDTO = fromApplicationToInfoDTO(application);
applicationInfoDTOs.add(applicationInfoDTO);
}
applicationListDTO.setCount(applicationInfoDTOs.size());
return applicationListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method setPaginationParamsWithSortParams.
/**
* Sets pagination urls for a ApplicationListDTO object given pagination parameters and url parameters with
* sortOrder and sortBy params.
*
* @param applicationListDTO a SubscriptionListDTO object
* @param groupId group id of the applications to be returned
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
* @param sortOrder sorting order
* @param sortBy specified sort param
*/
public static void setPaginationParamsWithSortParams(ApplicationListDTO applicationListDTO, String groupId, int limit, int offset, int size, String sortOrder, String sortBy) {
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getApplicationPaginatedURLWithSortParams(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), groupId, sortOrder, sortBy);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getApplicationPaginatedURLWithSortParams(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), groupId, sortOrder, sortBy);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
applicationListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromApplicationToApplicationListDTO.
public static ApplicationListDTO fromApplicationToApplicationListDTO(List<Application> model) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
if (model != null) {
for (Application appModel : model) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setUuid(appModel.getUuid());
applicationDTO.setId(appModel.getId());
applicationDTO.setName(appModel.getName());
applicationDTO.setPolicy(appModel.getPolicy());
applicationDTO.setSubName(appModel.getSubName());
applicationDTO.setTokenType(appModel.getTokenType());
applicationDTO.setOrganization(appModel.getOrganization());
Set<String> groupIds = appModel.getGroupIds();
for (String grp : groupIds) {
GroupIdDTO groupIdDTO = new GroupIdDTO();
groupIdDTO.setApplicationId(appModel.getId());
groupIdDTO.setGroupId(grp);
applicationDTO.getGroupIds().add(groupIdDTO);
}
Map<String, String> attributes = appModel.getAttributes();
applicationDTO.setAttributes(attributes);
applicationListDTO.getList().add(applicationDTO);
}
applicationListDTO.setCount(model.size());
} else {
applicationListDTO.setCount(0);
}
return applicationListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
public Response applicationsGet(String name, String uuid, 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();
}
List<Application> applicationList;
if (StringUtils.isNotEmpty(name)) {
applicationList = subscriptionDataStore.getApplicationsByName(name);
} else if (StringUtils.isNotEmpty(uuid)) {
applicationList = new ArrayList<>();
if (subscriptionDataStore.getApplicationByUUID(uuid) != null) {
applicationList.add(subscriptionDataStore.getApplicationByUUID(uuid));
}
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
}
if (applicationList == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
ApplicationListDTO applicationListDTO = GatewayUtils.generateApplicationList(applicationList, subscriptionDataStore);
return Response.ok().entity(applicationListDTO).build();
}
Aggregations