private void validateRequiredParametersInConsent(ReceiptInput receiptInput) throws ConsentManagementClientException { if (isBlank(receiptInput.getPiiPrincipalId())) { throw handleClientException(ERROR_CODE_PII_PRINCIPAL_ID_REQUIRED, null); } if (isBlank(receiptInput.getCollectionMethod())) { throw handleClientException(ERROR_CODE_PII_COLLECTION_METHOD_REQUIRED, null); } if (isEmpty(receiptInput.getServices())) { throw handleClientException(ERROR_CODE_AT_LEAST_ONE_SERVICE_REQUIRED, null); } }
protected void addReceiptInfo(ReceiptInput receiptInput) throws ConsentManagementServerException { JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); try { jdbcTemplate.withTransaction(template -> { template.executeInsert(INSERT_RECEIPT_SQL, (preparedStatement -> { preparedStatement.setString(1, receiptInput.getConsentReceiptId()); preparedStatement.setString(2, receiptInput.getVersion()); preparedStatement.setString(3, receiptInput.getJurisdiction()); preparedStatement.setTimestamp(4, new java.sql.Timestamp(new Date().getTime()), Calendar.getInstance(TimeZone.getTimeZone(UTC))); preparedStatement.setString(5, receiptInput.getCollectionMethod()); preparedStatement.setString(6, receiptInput.getLanguage()); preparedStatement.setString(7, receiptInput.getPiiPrincipalId()); preparedStatement.setInt(8, receiptInput.getTenantId()); preparedStatement.setString(9, receiptInput.getPolicyUrl()); preparedStatement.setString(10, ACTIVE_STATE); preparedStatement.setString(11, receiptInput.getPiiControllerInfo()); }), receiptInput, false); return null; }); } catch (TransactionException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_ADD_RECEIPT, receiptInput.getPiiPrincipalId(), e); } }
/** * This API is used to verify and store consent input. * * @param receiptInput consent input. * @throws ConsentManagementException Consent Management Exception. */ public AddReceiptResponse addConsent(ReceiptInput receiptInput) throws ConsentManagementException { validateInputParameters(receiptInput); receiptInput.setConsentReceiptId(generateConsentReceiptId()); setAPIVersion(receiptInput); setPIIControllerInfo(receiptInput); getReceiptsDAO(receiptDAOs).addReceipt(receiptInput); if (log.isDebugEnabled()) { log.debug("Consent stored successfully with the Id: " + receiptInput.getConsentReceiptId()); } return new AddReceiptResponse(receiptInput.getConsentReceiptId(), receiptInput.getCollectionMethod(), receiptInput.getLanguage(), receiptInput.getPiiPrincipalId(), receiptInput.getTenantDomain()); }