@Override public PIICategory addPIICategory(PIICategory piiCategory) throws ConsentManagementException { PIICategory purposeResult; int insertedId; JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); try { insertedId = jdbcTemplate.executeInsert(INSERT_PII_CATEGORY_SQL, (preparedStatement -> { preparedStatement.setString(1, piiCategory.getName()); preparedStatement.setString(2, piiCategory.getDescription()); preparedStatement.setInt(3, piiCategory.getSensitive() ? 1 : 0); preparedStatement.setInt(4, piiCategory.getTenantId()); preparedStatement.setString(5, piiCategory.getDisplayName()); }), piiCategory, true); } catch (DataAccessException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_ADD_PII_CATEGORY, piiCategory.getName(), e); } purposeResult = new PIICategory(insertedId, piiCategory.getName(), piiCategory.getDescription(), piiCategory.getSensitive(), piiCategory.getTenantId(), piiCategory.getDisplayName()); return purposeResult; }
public PurposePIICategory(PIICategory piiCategory, Boolean mandatory) { super(piiCategory.getId(), piiCategory.getName(), piiCategory.getDescription(), piiCategory.getSensitive(), piiCategory.getTenantId(), piiCategory.getDisplayName()); this.mandatory = mandatory; }
private void validateInputParameters(PIICategory piiCategory) throws ConsentManagementException { if (isBlank(piiCategory.getName())) { if (log.isDebugEnabled()) { log.debug("PII Category name cannot be empty"); } throw handleClientException(ERROR_CODE_PII_CATEGORY_NAME_REQUIRED, null); } if (isPIICategoryExists(piiCategory.getName())) { if (log.isDebugEnabled()) { log.debug("A PII Category already exists with name: " + piiCategory.getName()); } throw handleClientException(ERROR_CODE_PII_CATEGORY_ALREADY_EXIST, piiCategory.getName()); } if (piiCategory.getSensitive() == null) { piiCategory.setSensitive(false); } // Set authenticated user's tenant id if it is not set. if (isBlank(piiCategory.getTenantDomain())) { piiCategory.setTenantId(getTenantIdFromCarbonContext()); piiCategory.setTenantDomain(getTenantDomainFromCarbonContext()); } else { piiCategory.setTenantId(getTenantId(realmService, piiCategory.getTenantDomain())); } if (log.isDebugEnabled()) { log.debug("PII category request validation success: " + piiCategory.getName()); } }
@Override public PIICategory getPIICategoryByName(String name, int tenantId) throws ConsentManagementException { JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); PIICategory piiCategory; try { piiCategory = jdbcTemplate.fetchSingleRecord(SELECT_PII_CATEGORY_BY_NAME_SQL, (resultSet, rowNumber) -> new PIICategory(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3), resultSet.getInt(4) == 1, resultSet.getInt(5), resultSet.getString(6)), preparedStatement -> { preparedStatement.setString(1, name); preparedStatement.setInt(2, tenantId); }); } catch (DataAccessException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_SELECT_PII_CATEGORY_BY_NAME, name, e); } return piiCategory; }
if (purposePIICategory.getId().equals(piiCategoryId.getId())) { isPiiCategoryAdded = true; break; piiCategories.add(new PurposePIICategory(piiCategoryId.getId(), piiCategoryDTO.isMandatory())); PIICategory piiCategory = new PIICategory(piiCategoryDTO.getName(), piiCategoryDTO.getDescription(), true, piiCategoryDTO.getDisplayName()); PIICategory piiCategoryResponse = getConsentManager().addPIICategory(piiCategory); boolean isPiiCategoryAdded = false; for (PurposePIICategory purposePIICategory : piiCategories) { if (purposePIICategory.getId().equals(piiCategoryResponse.getId())) { isPiiCategoryAdded = true; break; piiCategories.add(new PurposePIICategory(piiCategoryResponse.getId(), piiCategoryDTO.isMandatory()));
private List<PIICategoryValidity> getPiiCategoryValiditiesForClaims(List<ClaimMetaData> claims, String termination) throws SSOConsentServiceException { List<PIICategoryValidity> piiCategoryIds = new ArrayList<>(); for (ClaimMetaData claim : claims) { PIICategory piiCategory; try { piiCategory = getConsentManager().getPIICategoryByName(claim.getClaimUri()); } catch (ConsentManagementClientException e) { if (isInvalidPIICategoryError(e)) { piiCategory = addPIICategoryForClaim(claim); } else { throw new SSOConsentServiceException("Consent PII category error", "Error while retrieving" + " PII category: " + DEFAULT_PURPOSE_CATEGORY, e); } } catch (ConsentManagementException e) { throw new SSOConsentServiceException("Consent PII category error", "Error while retrieving " + "PII category: " + DEFAULT_PURPOSE_CATEGORY, e); } piiCategoryIds.add(new PIICategoryValidity(piiCategory.getId(), termination)); } return piiCategoryIds; }
/** * This API is used to add a new PII category. * * @param piiCategory PIICategory element with name and description. * @return 201 Created. Returns PII Category element with ID. * @throws ConsentManagementException Consent Management Exception. */ public PIICategory addPIICategory(PIICategory piiCategory) throws ConsentManagementException { validateInputParameters(piiCategory); PIICategory category = getPiiCategoryDAO(piiCategoryDAOs).addPIICategory(piiCategory); if (log.isDebugEnabled()) { log.debug("PII category added successfully with the name: " + category.getName()); } return category; }
@Override public PIICategory getPIICategoryById(int id) throws ConsentManagementException { JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); PIICategory piiCategory; try { piiCategory = jdbcTemplate.fetchSingleRecord(SELECT_PII_CATEGORY_BY_ID_SQL, (resultSet, rowNumber) -> new PIICategory(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3), resultSet.getInt(4) == 1, resultSet.getInt(5), resultSet.getString(6)), preparedStatement -> preparedStatement.setInt(1, id)); } catch (DataAccessException e) { throw ConsentUtils.handleServerException(ErrorMessages.ERROR_CODE_SELECT_PII_CATEGORY_BY_ID, String .valueOf(id), e); } return piiCategory; }
private List<PIICategoryValidity> getPiiCategoryValiditiesForClaims(List<ClaimMetaData> claims, String termination) throws SSOConsentServiceException { List<PIICategoryValidity> piiCategoryIds = new ArrayList<>(); for (ClaimMetaData claim : claims) { PIICategory piiCategory; try { piiCategory = getConsentManager().getPIICategoryByName(claim.getClaimUri()); } catch (ConsentManagementClientException e) { if (isInvalidPIICategoryError(e)) { piiCategory = addPIICategoryForClaim(claim); } else { throw new SSOConsentServiceException("Consent PII category error", "Error while retrieving" + " PII category: " + DEFAULT_PURPOSE_CATEGORY, e); } } catch (ConsentManagementException e) { throw new SSOConsentServiceException("Consent PII category error", "Error while retrieving " + "PII category: " + DEFAULT_PURPOSE_CATEGORY, e); } piiCategoryIds.add(new PIICategoryValidity(piiCategory.getId(), termination)); } return piiCategoryIds; }
(resultSet, rowNumber) -> new PIICategory(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3),
private PIICategory addPIICategoryForClaim(ClaimMetaData claim) throws SSOConsentServiceException { PIICategory piiCategory; PIICategory piiCategoryInput = new PIICategory(claim.getClaimUri(), claim.getDescription(), false, claim .getDisplayName()); try { piiCategory = getConsentManager().addPIICategory(piiCategoryInput); } catch (ConsentManagementException e) { throw new SSOConsentServiceException("Consent PII category error", "Error while adding" + " PII category:" + DEFAULT_PURPOSE_CATEGORY, e); } return piiCategory; }
private PIICategory addPIICategoryForClaim(ClaimMetaData claim) throws SSOConsentServiceException { PIICategory piiCategory; PIICategory piiCategoryInput = new PIICategory(claim.getClaimUri(), claim.getDescription(), false, claim .getDisplayName()); try { piiCategory = getConsentManager().addPIICategory(piiCategoryInput); } catch (ConsentManagementException e) { throw new SSOConsentServiceException("Consent PII category error", "Error while adding" + " PII category:" + DEFAULT_PURPOSE_CATEGORY, e); } return piiCategory; }