Search in sources :

Example 6 with ApplicationListDTO

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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.PaginationDTO)

Example 7 with ApplicationListDTO

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;
}
Also used : ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationInfoDTO) Application(org.wso2.carbon.apimgt.api.model.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO)

Example 8 with 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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 9 with ApplicationListDTO

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;
}
Also used : GroupIdDTO(org.wso2.carbon.apimgt.internal.service.dto.GroupIdDTO) ApplicationDTO(org.wso2.carbon.apimgt.internal.service.dto.ApplicationDTO) Application(org.wso2.carbon.apimgt.api.model.subscription.Application) ApplicationListDTO(org.wso2.carbon.apimgt.internal.service.dto.ApplicationListDTO)

Example 10 with 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();
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO) ArrayList(java.util.ArrayList) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)

Aggregations

ArrayList (java.util.ArrayList)5 Application (org.wso2.carbon.apimgt.api.model.Application)4 Application (org.wso2.carbon.apimgt.core.models.Application)4 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationListDTO)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationListDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationListDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO)2 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)2 Response (javax.ws.rs.core.Response)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)1 Application (org.wso2.carbon.apimgt.api.model.subscription.Application)1