Search in sources :

Example 6 with ServiceDTO

use of org.wso2.carbon.identity.user.export.core.dto.ServiceDTO in project carbon-apimgt by wso2.

the class ServicesApiServiceImpl method getServiceById.

@Override
public Response getServiceById(String serviceId, MessageContext messageContext) {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    try {
        ServiceEntry service = serviceCatalog.getServiceByUUID(serviceId, tenantId);
        ServiceDTO serviceDTO = ServiceEntryMappingUtil.fromServiceToDTO(service, false);
        return Response.ok().entity(serviceDTO).build();
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e)) {
            RestApiUtil.handleResourceNotFoundError("Service", serviceId, e, log);
        } else {
            RestApiUtil.handleInternalServerError("Error while fetching the Service with ID " + serviceId, e, log);
        }
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ServiceDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceDTO) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry)

Example 7 with ServiceDTO

use of org.wso2.carbon.identity.user.export.core.dto.ServiceDTO in project carbon-apimgt by wso2.

the class ServicesApiServiceImpl method searchServices.

@Override
public Response searchServices(String name, String version, String definitionType, String key, Boolean shrink, String sortBy, String sortOrder, Integer limit, Integer offset, MessageContext messageContext) throws APIManagementException {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    try {
        List<ServiceDTO> serviceDTOList = new ArrayList<>();
        ServiceFilterParams filterParams = ServiceEntryMappingUtil.getServiceFilterParams(name, version, definitionType, key, sortBy, sortOrder, limit, offset);
        List<ServiceEntry> services = serviceCatalog.getServices(filterParams, tenantId, shrink);
        int totalServices = serviceCatalog.getServicesCount(tenantId, filterParams);
        for (ServiceEntry service : services) {
            serviceDTOList.add(ServiceEntryMappingUtil.fromServiceToDTO(service, shrink));
        }
        ServiceListDTO serviceListDTO = new ServiceListDTO();
        serviceListDTO.setList(serviceDTOList);
        ServiceEntryMappingUtil.setPaginationParams(serviceListDTO, filterParams.getOffset(), filterParams.getLimit(), totalServices, filterParams);
        return Response.ok().entity(serviceListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Services";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : ServiceListDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceListDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) ServiceDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceDTO) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry) ServiceFilterParams(org.wso2.carbon.apimgt.api.model.ServiceFilterParams)

Aggregations

ServiceEntry (org.wso2.carbon.apimgt.api.model.ServiceEntry)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 ServiceDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceDTO)3 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 ServiceFilterParams (org.wso2.carbon.apimgt.api.model.ServiceFilterParams)1 ServiceListDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceListDTO)1 AddressDTO (org.wso2.carbon.identity.user.export.core.dto.AddressDTO)1 ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)1 PiiCategoryDTO (org.wso2.carbon.identity.user.export.core.dto.PiiCategoryDTO)1 PiiControllerDTO (org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO)1 PurposeDTO (org.wso2.carbon.identity.user.export.core.dto.PurposeDTO)1 ServiceDTO (org.wso2.carbon.identity.user.export.core.dto.ServiceDTO)1