/** * If the consent is not given for a PII * * @param keySet * @param receipt * @return * @throws ConsentUtilityServiceException */ public Set<String> filterPIIsFromReceipt(Set<String> keySet, ReceiptInput receipt) throws ConsentUtilityServiceException { if (keySet == null || receipt == null) { throw new ConsentUtilityServiceException("Key set and receipt should not be null"); } List<ReceiptServiceInput> services = receipt.getServices(); Set<String> consentedPIIs = new HashSet<>(); for (ReceiptServiceInput service : services) { List<ReceiptPurposeInput> purposes = service.getPurposes(); for (ReceiptPurposeInput consentPurpose : purposes) { List<PIICategoryValidity> piiCategories = consentPurpose.getPiiCategory(); for (PIICategoryValidity piiCategory : piiCategories) { consentedPIIs.add(getPIIName(consentPurpose.getPurposeId(), piiCategory.getId())); } } } keySet.retainAll(consentedPIIs); return keySet; }
/** * If the consent is not given for a PII * * @param keySet * @param receipt * @return * @throws ConsentUtilityServiceException */ public Set<String> filterPIIsFromReceipt(Set<String> keySet, ReceiptInput receipt) throws ConsentUtilityServiceException { if (keySet == null || receipt == null) { throw new ConsentUtilityServiceException("Key set and receipt should not be null"); } List<ReceiptServiceInput> services = receipt.getServices(); Set<String> consentedPIIs = new HashSet<>(); for (ReceiptServiceInput service : services) { List<ReceiptPurposeInput> purposes = service.getPurposes(); for (ReceiptPurposeInput consentPurpose : purposes) { List<PIICategoryValidity> piiCategories = consentPurpose.getPiiCategory(); for (PIICategoryValidity piiCategory : piiCategories) { consentedPIIs.add(getPIIName(consentPurpose.getPurposeId(), piiCategory.getId())); } } } keySet.retainAll(consentedPIIs); return keySet; }
List<ReceiptPurposeInput> consentPurposes = service.getPurposes(); for (ReceiptPurposeInput consentPurpose : consentPurposes) { if (consentPurpose.getPurposeId() == purpose.getId()) {
List<ReceiptPurposeInput> consentPurposes = service.getPurposes(); for (ReceiptPurposeInput consentPurpose : consentPurposes) { if (consentPurpose.getPurposeId() == purpose.getId()) {
private void validateRequiredParametersInService(ReceiptServiceInput receiptServiceInput) throws ConsentManagementException { if (isBlank(receiptServiceInput.getService())) { throw handleClientException(ERROR_CODE_SERVICE_NAME_REQUIRED, null); } if (isEmpty(receiptServiceInput.getPurposes())) { throw handleClientException(ERROR_CODE_AT_LEAST_ONE_PURPOSE_REQUIRED, null); } // Set authenticated user's tenant id if it is not set. if (isBlank(receiptServiceInput.getTenantDomain())) { receiptServiceInput.setTenantId(getTenantIdFromCarbonContext()); receiptServiceInput.setTenantDomain(getTenantDomainFromCarbonContext()); } else { receiptServiceInput.setTenantId(getTenantId(realmService, receiptServiceInput.getTenantDomain())); } }
private void validateInputParameters(ReceiptInput receiptInput) throws ConsentManagementException { //Set authenticated user. if (isBlank(receiptInput.getPiiPrincipalId())) { receiptInput.setPiiPrincipalId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); } // Set authenticated user's tenant id if it is not set. if (isBlank(receiptInput.getTenantDomain())) { receiptInput.setTenantId(getTenantIdFromCarbonContext()); receiptInput.setTenantDomain(getTenantDomainFromCarbonContext()); } else { receiptInput.setTenantId(getTenantId(realmService, receiptInput.getTenantDomain())); } validateRequiredParametersInConsent(receiptInput); receiptInput.getServices().forEach(rethrowConsumer(receiptServiceInput -> { validateRequiredParametersInService(receiptServiceInput); receiptServiceInput.getPurposes().forEach(rethrowConsumer(receiptPurposeInput -> validateRequiredParametersInPurpose(receiptServiceInput, receiptPurposeInput))); })); if (log.isDebugEnabled()) { log.debug("Consent adding request validation success"); } }
@Override public void addReceipt(ReceiptInput receiptInput) throws ConsentManagementException { JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); try { jdbcTemplate.withTransaction(template -> { revokeActiveReceipts(receiptInput); addReceiptInfo(receiptInput); receiptInput.getServices().forEach(rethrowConsumer(receiptServiceInput -> { int receiptToSPAssocId = addReceiptSPAssociation(receiptInput.getConsentReceiptId(), receiptServiceInput); receiptServiceInput.getPurposes().forEach(rethrowConsumer(receiptPurposeInput -> { int spToPurposeAssocId = addSpToPurposeAssociation(receiptToSPAssocId, receiptPurposeInput); receiptPurposeInput.getPurposeCategoryId().forEach(rethrowConsumer(id -> addSpPurposeToPurposeCategoryAssociation(spToPurposeAssocId, id))); receiptPurposeInput.getPiiCategory().forEach(rethrowConsumer(piiCategoryValidity -> addSpPurposeToPiiCategoryAssociation(spToPurposeAssocId, piiCategoryValidity.getId(), piiCategoryValidity.getValidity()))); })); })); if (receiptInput.getProperties() != null) { addReceiptProperties(receiptInput.getConsentReceiptId(), receiptInput.getProperties()); } return null; }); } catch (TransactionException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_ADD_CONSENT_RECEIPT, receiptInput.getPiiPrincipalId(), e); } }