Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ void updateAuthorizationUser(Connection connection, String authorizationID, Stri
boolean updateAuthorizationResources(Connection connection, List<AuthorizationResource> authorizationResources)
throws ConsentDataUpdationException;

/**
* This method is used to delete the given list of authorization resources.
*
* @param connection connection object
* @param authorizationResourceIds a list of authorization resource IDs that should be deleted
* @throws ConsentDataDeletionException thrown if a database error occurs
*/
boolean deleteAuthorizationResources(Connection connection, List<String> authorizationResourceIds)
throws ConsentDataDeletionException;

/**
* This method is used to store the consent mapping resource in the database. The request consent mapping object
* must contain all the data in it without the consent mapping ID. It will be generated and set to the response
Expand Down Expand Up @@ -259,6 +269,16 @@ void updateConsentMappingStatus(Connection connection, ArrayList<String> mapping
public boolean updateConsentMappingResources(Connection connection, List<ConsentMappingResource>
consentMappingResources) throws ConsentDataUpdationException;

/**
* This method is used to delete the given list of consent mapping resource Ids.
*
* @param connection connection object
* @param consentMappingResourceIds a list of consent mapping resource Ids that should be deleted
* @throws ConsentDataDeletionException thrown if a database error occurs
*/
boolean deleteConsentMappingResources(Connection connection, List<String> consentMappingResourceIds)
throws ConsentDataDeletionException;

/**
* This method is used to store the consent attributes in the database. The request consent attributes object
* must be set with a consent ID and consent attribute map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public class ConsentMgtDAOConstants {
"authorization user in the database";
public static final String CONSENT_AUTHORIZATION_RESOURCE_UPDATE_ERROR_MSG = "Error occurred while updating " +
"authorization resource in the database";
public static final String CONSENT_AUTHORIZATION_RESOURCE_DELETE_ERROR_MSG = "Error occurred while deleting " +
"authorization resource in the database";
public static final String CONSENT_MAPPING_RESOURCE_STORE_ERROR_MSG = "Error occurred while storing consent " +
"mapping resource in the database";
public static final String CONSENT_MAPPING_RETRIEVE_ERROR_MSG = "Error occurred while retrieving consent mapping " +
Expand All @@ -134,6 +136,8 @@ public class ConsentMgtDAOConstants {
"mapping status in the database";
public static final String CONSENT_MAPPING_RESOURCE_UPDATE_ERROR_MSG = "Error occurred while updating consent " +
"mapping resource in the database";
public static final String CONSENT_MAPPING_RESOURCE_DELETE_ERROR_MSG = "Error occurred while deleting consent " +
"mapping resource in the database";
public static final String CONSENT_ATTRIBUTES_STORE_ERROR_MSG = "Error occurred while storing consent attributes " +
"in the database";
public static final String CONSENT_ATTRIBUTES_RETRIEVE_ERROR_MSG = "Error occurred while retrieving consent " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,40 @@ public boolean updateAuthorizationResources(Connection connection, List<Authoriz
return true;
}

@Override
public boolean deleteAuthorizationResources(Connection connection, List<String> authorizationResourceIds)
throws ConsentDataDeletionException {

log.info(String.format("Deleting authorization resources. Count: %s", authorizationResourceIds.size()));
String deleteAuthorizationResourcePrepStatement =
sqlStatements.getDeleteAuthorizationResourcePreparedStatement();

try (PreparedStatement deleteAuthorizationResourcePreparedStmt =
connection.prepareStatement(deleteAuthorizationResourcePrepStatement)) {

log.debug("Setting parameters to prepared statement to batch delete authorization resources");

for (String authId : authorizationResourceIds) {
deleteAuthorizationResourcePreparedStmt.setString(1, authId);
deleteAuthorizationResourcePreparedStmt.addBatch();
}

int[] results = deleteAuthorizationResourcePreparedStmt.executeBatch();
boolean allUpdated = Arrays.stream(results).allMatch(result -> result > 0);
if (allUpdated) {
log.debug("Batch delete for authorization resources completed successfully.");
return true;
} else {
log.error("Some or all rows were not deleted in batch delete for authorization resources.");
throw new ConsentDataDeletionException("Failed to delete one or more authorization resources.");
}
} catch (SQLException e) {
log.error(ConsentMgtDAOConstants.CONSENT_AUTHORIZATION_RESOURCE_DELETE_ERROR_MSG, e);
throw new ConsentDataDeletionException(
ConsentMgtDAOConstants.CONSENT_AUTHORIZATION_RESOURCE_DELETE_ERROR_MSG, e);
}
}


@Override
public ConsentMappingResource storeConsentMappingResource(Connection connection,
Expand Down Expand Up @@ -733,6 +767,39 @@ public boolean updateConsentMappingResources(Connection connection, List<Consent
return true;
}

@Override
public boolean deleteConsentMappingResources(Connection connection, List<String> consentMappingResourceIds)
throws ConsentDataDeletionException {

log.info(String.format("Deleting consent mapping resources. Count: %s", consentMappingResourceIds.size()));
String deleteConsentMappingResourcePrepStatement =
sqlStatements.getDeleteConsentMappingResourcePreparedStatement();

try (PreparedStatement deleteConsentMappingResourcePreparedStmt =
connection.prepareStatement(deleteConsentMappingResourcePrepStatement)) {

log.debug("Setting parameters to prepared statement to batch delete consent mapping resources");

for (String mappingId : consentMappingResourceIds) {
deleteConsentMappingResourcePreparedStmt.setString(1, mappingId);
deleteConsentMappingResourcePreparedStmt.addBatch();
}

int[] results = deleteConsentMappingResourcePreparedStmt.executeBatch();
boolean allDeleted = Arrays.stream(results).allMatch(result -> result > 0);
if (allDeleted) {
log.debug("Batch delete for consent mapping resources completed successfully.");
return true;
} else {
log.error("Some or all rows were not deleted in batch delete for consent mapping resources.");
throw new ConsentDataDeletionException("Failed to delete one or more consent mapping resources.");
}
} catch (SQLException e) {
log.error(ConsentMgtDAOConstants.CONSENT_MAPPING_RESOURCE_DELETE_ERROR_MSG, e);
throw new ConsentDataDeletionException(ConsentMgtDAOConstants.CONSENT_MAPPING_RESOURCE_DELETE_ERROR_MSG, e);
}
}


@Override
public boolean storeConsentAttributes(Connection connection, ConsentAttributes consentAttributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getGetConsentWithConsentAttributesPreparedStatement() {

return "SELECT FS_CONSENT.CONSENT_ID, RECEIPT, CREATED_TIME, UPDATED_TIME, CLIENT_ID, CONSENT_TYPE, " +
"CURRENT_STATUS, CONSENT_FREQUENCY, VALIDITY_TIME, RECURRING_INDICATOR, " +
"FS_CONSENT_ATTRIBUTE.ATT_KEY, FS_CONSENT_ATTRIBUTE.ATT_VALUE FROM FS_CONSENT RIGHT JOIN " +
"FS_CONSENT_ATTRIBUTE.ATT_KEY, FS_CONSENT_ATTRIBUTE.ATT_VALUE FROM FS_CONSENT LEFT JOIN " +
"FS_CONSENT_ATTRIBUTE ON FS_CONSENT.CONSENT_ID = FS_CONSENT_ATTRIBUTE.CONSENT_ID WHERE FS_CONSENT" +
".CONSENT_ID = ?";
}
Expand Down Expand Up @@ -125,6 +125,11 @@ public String getUpdateAuthorizationResourcePreparedStatement() {
"WHERE AUTH_ID = ?";
}

public String getDeleteAuthorizationResourcePreparedStatement() {

return "DELETE FROM FS_CONSENT_AUTH_RESOURCE WHERE AUTH_ID = ?";
}

public String getStoreConsentMappingPreparedStatement() {

return "INSERT INTO FS_CONSENT_MAPPING (MAPPING_ID, AUTH_ID, ACCOUNT_ID, PERMISSION, MAPPING_STATUS) VALUES " +
Expand All @@ -146,6 +151,12 @@ public String getUpdateConsentMappingResourcePreparedStatement() {
return "UPDATE FS_CONSENT_MAPPING SET PERMISSION = ?, MAPPING_STATUS = ? WHERE MAPPING_ID = ?";
}

public String getDeleteConsentMappingResourcePreparedStatement() {

return "DELETE FROM FS_CONSENT_MAPPING WHERE MAPPING_ID = ? ";
}


public String getStoreConsentAttributesPreparedStatement() {

return "INSERT INTO FS_CONSENT_ATTRIBUTE (CONSENT_ID, ATT_KEY, ATT_VALUE) VALUES (?, ?, ?)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -675,6 +676,44 @@ public void testUpdateAuthorizationUserWithUnmatchedAuthID() throws Exception {
}
}

@Test
public void testDeleteAuthorizationResource() throws Exception {

ConsentResource storedConsentResource;
AuthorizationResource storedAuthorizationResource;
ConsentResource consentResource = ConsentMgtDAOTestData.getSampleTestConsentResource();

try (Connection connection = DAOUtils.getConnection(DB_NAME)) {

storedConsentResource = consentCoreDAO.storeConsentResource(connection, consentResource);
Assert.assertNotNull(storedConsentResource.getConsentID());

AuthorizationResource authorizationResource = new AuthorizationResource();
authorizationResource.setConsentID(storedConsentResource.getConsentID());
authorizationResource.setAuthorizationType(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_TYPE);
authorizationResource.setUserID(ConsentMgtDAOTestData.SAMPLE_USER_ID);
authorizationResource.setAuthorizationStatus(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_STATUS);

storedAuthorizationResource = consentCoreDAO.storeAuthorizationResource(connection,
authorizationResource);

Assert.assertNotNull(storedAuthorizationResource.getConsentID());
Assert.assertNotNull(storedAuthorizationResource.getAuthorizationID());

boolean result = consentCoreDAO.deleteAuthorizationResources(connection,
Collections.singletonList(storedAuthorizationResource.getAuthorizationID()));
Assert.assertTrue(result);
}
}

@Test(expectedExceptions = ConsentDataDeletionException.class)
public void testDeleteAuthorizationResourceError() throws Exception {

Mockito.doThrow(SQLException.class).when(mockedConnection).prepareStatement(Mockito.anyString());

consentCoreDAO.deleteAuthorizationResources(mockedConnection, Collections.singletonList("1234"));
}

@Test
public void testStoreConsentMappingResource() throws Exception {

Expand Down Expand Up @@ -850,6 +889,57 @@ public void testUpdateConsentMappingStatusSQLError() throws Exception {
ConsentMgtDAOTestData.SAMPLE_MAPPING_STATUS);
}

@Test
public void testDeleteConsentMappingResource() throws Exception {

ConsentResource storedConsentResource;
AuthorizationResource storedAuthorizationResource;
ConsentMappingResource storedConsentMappingResource;
ConsentResource consentResource = ConsentMgtDAOTestData.getSampleTestConsentResource();

try (Connection connection = DAOUtils.getConnection(DB_NAME)) {

storedConsentResource = consentCoreDAO.storeConsentResource(connection, consentResource);
Assert.assertNotNull(storedConsentResource.getConsentID());

AuthorizationResource authorizationResource = new AuthorizationResource();
authorizationResource.setConsentID(storedConsentResource.getConsentID());
authorizationResource.setAuthorizationType(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_TYPE);
authorizationResource.setUserID(ConsentMgtDAOTestData.SAMPLE_USER_ID);
authorizationResource.setAuthorizationStatus(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_STATUS);

storedAuthorizationResource = consentCoreDAO.storeAuthorizationResource(connection,
authorizationResource);

Assert.assertNotNull(storedAuthorizationResource.getConsentID());
Assert.assertNotNull(storedAuthorizationResource.getAuthorizationID());

ConsentMappingResource consentMappingResource = new ConsentMappingResource();
consentMappingResource.setAuthorizationID(storedAuthorizationResource.getAuthorizationID());
consentMappingResource.setAccountID(ConsentMgtDAOTestData.SAMPLE_ACCOUNT_ID);
consentMappingResource.setPermission(ConsentMgtDAOTestData.SAMPLE_PERMISSION);
consentMappingResource.setMappingStatus(ConsentMgtDAOTestData.SAMPLE_MAPPING_STATUS);

storedConsentMappingResource = consentCoreDAO.storeConsentMappingResource(connection,
consentMappingResource);

Assert.assertNotNull(storedConsentMappingResource.getMappingID());
Assert.assertNotNull(storedConsentMappingResource.getAuthorizationID());

boolean result = consentCoreDAO.deleteConsentMappingResources(connection,
Collections.singletonList(storedConsentMappingResource.getMappingID()));
Assert.assertTrue(result);
}
}

@Test(expectedExceptions = ConsentDataDeletionException.class)
public void testDeleteConsentMappingResourceError() throws Exception {

Mockito.doThrow(SQLException.class).when(mockedConnection).prepareStatement(Mockito.anyString());

consentCoreDAO.deleteConsentMappingResources(mockedConnection, Collections.singletonList("1234"));
}

@Test
public void testStoreConsentAttributes() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class ConsentExtensionConstants {
public static final String ACCOUNTS = "accounts";
public static final String PAYMENTS = "payments";
public static final String FUNDS_CONFIRMATIONS = "fundsconfirmations";
public static final String INTERNAL_UPDATE = "internal-consent-update";
public static final String DEFAULT = "default";
public static final String ACCOUNT_CONSENT_PATH = "account-access-consents";
public static final String COF_CONSENT_PATH = "funds-confirmation-consents";
public static final String PAYMENT_CONSENT_PATH = "payment-consents";
public static final String CONSENT_UPDATE_PATH = "^consent/([^/?]+)$";
public static final String CONSENT_DATA = "consentData";
public static final String CONSUMER_DATA = "consumerData";
public static final String TITLE = "title";
Expand Down
Loading
Loading