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()); }
@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); } }