protected List<ReceiptService> getServiceInfoOfReceipt(String consentReceiptId, ReceiptContext receiptContext) throws ConsentManagementServerException { List<ReceiptService> receiptServices; JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); try { receiptServices = jdbcTemplate.withTransaction(template -> { List<ReceiptService> internalReceiptServices = template.executeQuery(GET_RECEIPT_SP_SQL, (resultSet, rowNumber) -> { ReceiptService receiptService = new ReceiptService(); receiptService.setReceiptToServiceId(resultSet.getInt(1)); receiptService.setService(resultSet.getString(2)); receiptService.setTenantId(resultSet.getInt(3)); receiptService.setSpDisplayName(resultSet.getString(4)); receiptService.setSpDescription(resultSet.getString(5)); return receiptService; }, preparedStatement -> preparedStatement.setString(1, consentReceiptId)); if (internalReceiptServices != null) { internalReceiptServices.forEach(rethrowConsumer(receiptService -> receiptService.setPurposes (getPurposeInfoOfService(receiptService.getReceiptToServiceId(), consentReceiptId, receiptContext)))); } return internalReceiptServices; }); } catch (TransactionException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_RETRIEVE_RECEIPT_INFO, consentReceiptId, e); } return receiptServices; }
public void deleteReceipt(String receiptID) throws ConsentManagementException { Receipt receipt = getReceipt(receiptID); if (receipt == null) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_DELETE_RECEIPT, String .valueOf(receiptID)); } JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); try { jdbcTemplate.withTransaction(template -> { receipt.getServices().forEach(rethrowConsumer(receiptService -> { int receiptToServiceId = receiptService.getReceiptToServiceId(); receiptService.getPurposes().forEach(rethrowConsumer(consentPurpose -> { int serviceToPurposeId = consentPurpose.getServiceToPurposeId(); deleteSpPurposeToPiiCategoryAssociation(serviceToPurposeId); deleteSpPurposeToPurposeCategoryAssociation(serviceToPurposeId); })); deleteSpToPurposeAssociation(receiptToServiceId); })); deleteReceiptSPAssociation(receiptID); deleteReceiptProperties(receiptID); deleteReceiptOnly(receiptID); return null; }); } catch (TransactionException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_DELETE_RECEIPT, receiptID, e); } }