Skip to content

Commit

Permalink
Remove fallback logic to IDN_ACTION_ENDPOINT table
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanthamara committed Dec 17, 2024
1 parent d7512c2 commit 810ef1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ private ActionMgtSQLConstants() {

}

public static final String IDN_ACTION_PROPERTIES_TABLE = "IDN_ACTION_PROPERTIES";
public static final String IDN_ACTION_ENDPOINT_TABLE = "IDN_ACTION_ENDPOINT";

/**
* Column Names.
*/
Expand Down Expand Up @@ -81,19 +78,6 @@ public static class Query {
"PROPERTY_VALUE = :PROPERTY_VALUE; WHERE ACTION_UUID = :ACTION_UUID; AND " +
"TENANT_ID = :TENANT_ID; AND PROPERTY_NAME = :PROPERTY_NAME;";

// TODO: Remove this temporary queries once the IDN_ACTION_PROPERTIES table is created.
public static final String ADD_ACTION_ENDPOINT = "INSERT INTO IDN_ACTION_ENDPOINT (ACTION_UUID, " +
"PROPERTY_NAME, PROPERTY_VALUE, TENANT_ID) VALUES (:ACTION_UUID;, :PROPERTY_NAME;, :PROPERTY_VALUE;, " +
":TENANT_ID;)";
public static final String GET_ACTION_ENDPOINT_INFO_BY_ID = "SELECT PROPERTY_NAME, PROPERTY_VALUE FROM " +
"IDN_ACTION_ENDPOINT WHERE ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ACTION_ENDPOINT_PROPERTY = "DELETE FROM IDN_ACTION_ENDPOINT WHERE " +
"PROPERTY_NAME = :PROPERTY_NAME; AND ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_ACTION_ENDPOINT_PROPERTY = "UPDATE IDN_ACTION_ENDPOINT SET " +
"PROPERTY_VALUE = :PROPERTY_VALUE; WHERE ACTION_UUID = :ACTION_UUID; AND " +
"TENANT_ID = :TENANT_ID; AND PROPERTY_NAME = :PROPERTY_NAME;";


private Query() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ private void addActionPropertiesToDB(String actionId, Map<String, String> action

NamedJdbcTemplate jdbcTemplate = new NamedJdbcTemplate(IdentityDatabaseUtil.getDataSource());
jdbcTemplate.withTransaction(template -> {
String query = isPropertiesTableExists() ? ActionMgtSQLConstants.Query.ADD_ACTION_PROPERTIES
: ActionMgtSQLConstants.Query.ADD_ACTION_ENDPOINT;
template.executeBatchInsert(query,
template.executeBatchInsert(ActionMgtSQLConstants.Query.ADD_ACTION_PROPERTIES,
statement -> {
for (Map.Entry<String, String> property : actionProperties.entrySet()) {
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_UUID, actionId);
Expand Down Expand Up @@ -511,10 +509,8 @@ private Map<String, String> getActionPropertiesFromDB(String actionId, Integer t
NamedJdbcTemplate jdbcTemplate = new NamedJdbcTemplate(IdentityDatabaseUtil.getDataSource());
Map<String, String> actionEndpointProperties = new HashMap<>();
try {
String query = isPropertiesTableExists() ? ActionMgtSQLConstants.Query.GET_ACTION_PROPERTIES_INFO_BY_ID
: ActionMgtSQLConstants.Query.GET_ACTION_ENDPOINT_INFO_BY_ID;
jdbcTemplate.withTransaction(template ->
template.executeQuery(query,
template.executeQuery(ActionMgtSQLConstants.Query.GET_ACTION_PROPERTIES_INFO_BY_ID,
(resultSet, rowNumber) -> {
actionEndpointProperties.put(
resultSet.getString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_PROPERTY_NAME),
Expand All @@ -527,7 +523,7 @@ private Map<String, String> getActionPropertiesFromDB(String actionId, Integer t
}));

return actionEndpointProperties;
} catch (SQLException | TransactionException e) {
} catch (TransactionException e) {
throw new ActionMgtServerException("Error while retrieving Action Properties from the system.", e);
}
}
Expand All @@ -544,22 +540,19 @@ private void updateActionPropertiesInDB(String actionId, Map<String, String> upd
Integer tenantId) throws TransactionException {

NamedJdbcTemplate jdbcTemplate = new NamedJdbcTemplate(IdentityDatabaseUtil.getDataSource());
jdbcTemplate.withTransaction(template -> {
String query = isPropertiesTableExists() ? ActionMgtSQLConstants.Query.UPDATE_ACTION_PROPERTY
: ActionMgtSQLConstants.Query.UPDATE_ACTION_ENDPOINT_PROPERTY;
return template.executeBatchInsert(query,
statement -> {
for (Map.Entry<String, String> property : updatingProperties.entrySet()) {
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_PROPERTY_VALUE,
property.getValue());
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_PROPERTY_NAME,
property.getKey());
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_UUID, actionId);
statement.setInt(ActionMgtSQLConstants.Column.TENANT_ID, tenantId);
statement.addBatch();
}
}, null);
});
jdbcTemplate.withTransaction(template ->
template.executeBatchInsert(ActionMgtSQLConstants.Query.UPDATE_ACTION_PROPERTY,
statement -> {
for (Map.Entry<String, String> property : updatingProperties.entrySet()) {
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_PROPERTY_VALUE,
property.getValue());
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_PROPERTY_NAME,
property.getKey());
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_UUID, actionId);
statement.setInt(ActionMgtSQLConstants.Column.TENANT_ID, tenantId);
statement.addBatch();
}
}, null));
}

/**
Expand All @@ -574,10 +567,8 @@ private void deleteActionPropertiesInDB(String actionId, List<String> deletingPr
throws TransactionException {

NamedJdbcTemplate jdbcTemplate = new NamedJdbcTemplate(IdentityDatabaseUtil.getDataSource());
jdbcTemplate.withTransaction(template -> {
String query = isPropertiesTableExists() ? ActionMgtSQLConstants.Query.DELETE_ACTION_PROPERTY
: ActionMgtSQLConstants.Query.DELETE_ACTION_ENDPOINT_PROPERTY;
return template.executeBatchInsert(query,
jdbcTemplate.withTransaction(template ->
template.executeBatchInsert(ActionMgtSQLConstants.Query.DELETE_ACTION_PROPERTY,
statement -> {
for (String property : deletingProperties) {
statement.setString(ActionMgtSQLConstants.Column.ACTION_PROPERTIES_PROPERTY_NAME,
Expand All @@ -586,8 +577,7 @@ private void deleteActionPropertiesInDB(String actionId, List<String> deletingPr
statement.setInt(ActionMgtSQLConstants.Column.TENANT_ID, tenantId);
statement.addBatch();
}
}, null);
});
}, null));
}

/**
Expand Down Expand Up @@ -622,20 +612,4 @@ private ActionDTO changeActionStatus(String actionType, String actionId, String
throw new ActionMgtServerException("Error while updating Action Status to " + status, e);
}
}

/**
* Check whether the IDN_ACTION_PROPERTIES table exists in the database.
* TODO: Remove this temporary method once the table is created.
*
* @return True if the table exists, False otherwise.
* @throws SQLException If an error occurs while checking the table existence.
*/
private boolean isPropertiesTableExists() throws SQLException {

try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
ResultSet resultSet = connection.getMetaData().getTables(null, null,
ActionMgtSQLConstants.IDN_ACTION_PROPERTIES_TABLE, null)) {
return resultSet.next();
}
}
}

0 comments on commit 810ef1f

Please sign in to comment.