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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations