Search in sources :

Example 1 with ServiceDTO

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

the class ServiceCatalogUtils method createServiceFromDTO.

public static ServiceEntry createServiceFromDTO(ServiceDTO serviceDTO, byte[] definitionFileByteArray) {
    ServiceEntry service = new ServiceEntry();
    service.setName(serviceDTO.getName());
    service.setVersion(serviceDTO.getVersion());
    service.setDescription(serviceDTO.getDescription());
    service.setDefUrl(serviceDTO.getDefinitionUrl());
    service.setServiceUrl(serviceDTO.getServiceUrl());
    service.setDefinitionType(ServiceEntry.DefinitionType.valueOf(serviceDTO.getDefinitionType().value()));
    service.setSecurityType(ServiceEntry.SecurityType.valueOf(serviceDTO.getSecurityType().value()));
    String key = StringUtils.isNotEmpty(serviceDTO.getServiceKey()) ? serviceDTO.getServiceKey() : ServiceEntryMappingUtil.generateServiceKey(service);
    service.setKey(key);
    service.setMutualSSLEnabled(serviceDTO.isMutualSSLEnabled());
    service.setEndpointDef(new ByteArrayInputStream(definitionFileByteArray));
    service.setMd5(Md5HashGenerator.calculateMD5Hash(serviceDTO.toString().getBytes()) + Md5HashGenerator.calculateMD5Hash(definitionFileByteArray));
    return service;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry)

Example 2 with ServiceDTO

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

the class ServiceEntryMappingUtil method fromServiceToDTO.

public static ServiceDTO fromServiceToDTO(ServiceEntry service, boolean shrink) {
    ServiceDTO serviceDTO = new ServiceDTO();
    serviceDTO.setId(service.getUuid());
    serviceDTO.setName(service.getName());
    serviceDTO.setVersion(service.getVersion());
    serviceDTO.setMd5(service.getMd5());
    serviceDTO.setServiceKey(service.getKey());
    if (!shrink) {
        serviceDTO.setServiceUrl(service.getServiceUrl());
        serviceDTO.setDefinitionType(ServiceDTO.DefinitionTypeEnum.fromValue(service.getDefinitionType().toString()));
        serviceDTO.setDefinitionUrl(service.getDefUrl());
        serviceDTO.setDescription(service.getDescription());
        serviceDTO.setSecurityType(ServiceDTO.SecurityTypeEnum.fromValue(service.getSecurityType().toString()));
        serviceDTO.setMutualSSLEnabled(service.isMutualSSLEnabled());
        serviceDTO.setCreatedTime(String.valueOf(service.getCreatedTime()));
        serviceDTO.setLastUpdatedTime(String.valueOf(service.getLastUpdatedTime()));
        serviceDTO.setUsage(service.getUsage());
    }
    return serviceDTO;
}
Also used : ServiceDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceDTO)

Example 3 with ServiceDTO

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

the class ServicesApiServiceImpl method addService.

@Override
public Response addService(ServiceDTO serviceDTO, InputStream definitionFileInputStream, Attachment definitionFileDetail, String inlineContent, MessageContext messageContext) {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    try {
        validateInputParams(definitionFileInputStream, definitionFileDetail, inlineContent);
        ServiceEntry existingService = serviceCatalog.getServiceByKey(serviceDTO.getServiceKey(), tenantId);
        if (existingService != null) {
            RestApiUtil.handleResourceAlreadyExistsError("Error while adding Service : A service already " + "exists with key: " + serviceDTO.getServiceKey(), log);
        }
        byte[] definitionFileByteArray;
        if (definitionFileInputStream != null) {
            definitionFileByteArray = getDefinitionFromInput(definitionFileInputStream);
        } else {
            definitionFileByteArray = inlineContent.getBytes();
        }
        ServiceEntry service = ServiceCatalogUtils.createServiceFromDTO(serviceDTO, definitionFileByteArray);
        if (!validateAndRetrieveServiceDefinition(definitionFileByteArray, serviceDTO.getServiceUrl(), service.getDefinitionType()).isValid()) {
            String errorMsg = "The Service import has been failed as invalid service definition provided";
            return Response.status(Response.Status.BAD_REQUEST).entity(getErrorDTO(RestApiConstants.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400L, errorMsg, StringUtils.EMPTY)).build();
        }
        String serviceId = serviceCatalog.addService(service, tenantId, userName);
        ServiceEntry createdService = serviceCatalog.getServiceByUUID(serviceId, tenantId);
        return Response.ok().entity(ServiceEntryMappingUtil.fromServiceToDTO(createdService, false)).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error when validating the service definition", log);
    } catch (IOException e) {
        RestApiUtil.handleInternalServerError("Error when reading the file content", log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) IOException(java.io.IOException) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry)

Example 4 with ServiceDTO

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

the class Utils method getConsentReceiptDTO.

/**
 * This API is used to get ConsentReceiptDTO response.
 *
 * @param receipt Receipt instance.
 * @return ConsentReceiptDTO.
 */
public static ConsentReceiptDTO getConsentReceiptDTO(Receipt receipt) {
    ConsentReceiptDTO consentReceiptDTO = new ConsentReceiptDTO();
    consentReceiptDTO.setCollectionMethod(receipt.getCollectionMethod());
    consentReceiptDTO.setConsentReceiptID(receipt.getConsentReceiptId());
    consentReceiptDTO.setJurisdiction(receipt.getJurisdiction());
    consentReceiptDTO.setConsentTimestamp(receipt.getConsentTimestamp());
    consentReceiptDTO.setLanguage(receipt.getLanguage());
    consentReceiptDTO.setPiiPrincipalId(receipt.getPiiPrincipalId());
    consentReceiptDTO.setPolicyUrl(receipt.getPolicyUrl());
    consentReceiptDTO.setSensitive(receipt.isSensitive());
    consentReceiptDTO.setTenantDomain(receipt.getTenantDomain());
    consentReceiptDTO.setVersion(receipt.getVersion());
    consentReceiptDTO.setState(receipt.getState());
    consentReceiptDTO.setServices(receipt.getServices().stream().map(receiptService -> {
        ServiceDTO serviceDTO = new ServiceDTO();
        serviceDTO.setService(receiptService.getService());
        serviceDTO.setTenantDomain(receiptService.getTenantDomain());
        serviceDTO.setPurposes(receiptService.getPurposes().stream().map(consentPurpose -> {
            PurposeDTO purposeDTO = new PurposeDTO();
            purposeDTO.setConsentType(consentPurpose.getConsentType());
            purposeDTO.setPiiCategory(consentPurpose.getPiiCategory().stream().map(piiCategoryValidity -> {
                PiiCategoryDTO piiCategoryDTO = new PiiCategoryDTO();
                piiCategoryDTO.setPiiCategory(piiCategoryValidity.getName());
                piiCategoryDTO.setValidity(piiCategoryValidity.getValidity());
                return piiCategoryDTO;
            }).collect(Collectors.toList()));
            purposeDTO.setPrimaryPurpose(consentPurpose.isPrimaryPurpose());
            purposeDTO.setPurpose(consentPurpose.getPurpose());
            purposeDTO.setPurposeCategory(consentPurpose.getPurposeCategory());
            purposeDTO.setTermination(consentPurpose.getTermination());
            purposeDTO.setThirdPartyDisclosure(consentPurpose.isThirdPartyDisclosure());
            purposeDTO.setThirdPartyName(consentPurpose.getThirdPartyName());
            return purposeDTO;
        }).collect(Collectors.toList()));
        return serviceDTO;
    }).collect(Collectors.toList()));
    consentReceiptDTO.setSpiCat(receipt.getSpiCat());
    consentReceiptDTO.setPiiControllers(receipt.getPiiControllers().stream().map(piiController -> {
        PiiControllerDTO piiControllerDTO = new PiiControllerDTO();
        AddressDTO addressDTO = new AddressDTO();
        consentReceiptDTO.setPublicKey(receipt.getPublicKey());
        addressDTO.setAddressCountry(piiController.getAddress().getAddressCountry());
        addressDTO.setAddressLocality(piiController.getAddress().getAddressLocality());
        addressDTO.setAddressRegion(piiController.getAddress().getAddressRegion());
        addressDTO.setPostalCode(piiController.getAddress().getPostalCode());
        addressDTO.setPostOfficeBoxNumber(piiController.getAddress().getPostOfficeBoxNumber());
        addressDTO.setStreetAddress(piiController.getAddress().getStreetAddress());
        piiControllerDTO.setAddress(addressDTO);
        piiControllerDTO.setContact(piiController.getContact());
        piiControllerDTO.setEmail(piiController.getEmail());
        piiControllerDTO.setPhone(piiController.getPhone());
        piiControllerDTO.setPiiController(piiController.getPiiController());
        piiControllerDTO.setPiiControllerUrl(piiController.getPiiControllerUrl());
        piiControllerDTO.setOnBehalf(piiController.isOnBehalf());
        return piiControllerDTO;
    }).collect(Collectors.toList()));
    return consentReceiptDTO;
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) PurposeDTO(org.wso2.carbon.identity.user.export.core.dto.PurposeDTO) PiiControllerDTO(org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO) ServiceDTO(org.wso2.carbon.identity.user.export.core.dto.ServiceDTO) PiiCategoryDTO(org.wso2.carbon.identity.user.export.core.dto.PiiCategoryDTO) AddressDTO(org.wso2.carbon.identity.user.export.core.dto.AddressDTO)

Example 5 with ServiceDTO

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

the class ServicesApiServiceImpl method updateService.

@Override
public Response updateService(String serviceId, ServiceDTO serviceDTO, InputStream definitionFileInputStream, Attachment definitionFileDetail, String inlineContent, MessageContext messageContext) {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    if (StringUtils.isEmpty(serviceId)) {
        RestApiUtil.handleBadRequest("The service Id should not be empty", log);
    }
    validateInputParams(definitionFileInputStream, definitionFileDetail, inlineContent);
    try {
        ServiceEntry existingService = serviceCatalog.getServiceByUUID(serviceId, tenantId);
        byte[] definitionFileByteArray;
        if (definitionFileInputStream != null) {
            definitionFileByteArray = getDefinitionFromInput(definitionFileInputStream);
        } else {
            definitionFileByteArray = inlineContent.getBytes();
        }
        ServiceEntry service = ServiceCatalogUtils.createServiceFromDTO(serviceDTO, definitionFileByteArray);
        if (!validateAndRetrieveServiceDefinition(definitionFileByteArray, serviceDTO.getServiceUrl(), service.getDefinitionType()).isValid()) {
            String errorMsg = "The Service import has been failed as invalid service definition provided";
            return Response.status(Response.Status.BAD_REQUEST).entity(getErrorDTO(RestApiConstants.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400L, errorMsg, StringUtils.EMPTY)).build();
        }
        if (!existingService.getKey().equals(service.getKey()) || !existingService.getName().equals(service.getName()) || !existingService.getDefinitionType().equals(service.getDefinitionType()) || !existingService.getVersion().equals(service.getVersion())) {
            RestApiUtil.handleBadRequest("Cannot update the name or version or key or definition type of an " + "existing service", log);
        }
        service.setUuid(existingService.getUuid());
        serviceCatalog.updateService(service, tenantId, userName);
        ServiceEntry createdService = serviceCatalog.getServiceByUUID(serviceId, tenantId);
        return Response.ok().entity(ServiceEntryMappingUtil.fromServiceToDTO(createdService, false)).build();
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e)) {
            RestApiUtil.handleResourceNotFoundError("Service", serviceId, e, log);
        }
        RestApiUtil.handleInternalServerError("Error when validating the service definition", log);
    } catch (IOException e) {
        RestApiUtil.handleInternalServerError("Error when reading the file content", log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) IOException(java.io.IOException) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry)

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