Skip to content

Commit

Permalink
Merge pull request #6209 from ashanthamara/action-properties
Browse files Browse the repository at this point in the history
Rename IDN_ACTION_ENDPOINT table to IDN_ACTION_PROPERTIES
  • Loading branch information
ashanthamara authored Dec 17, 2024
2 parents 0ab1c6f + 810ef1f commit 6995e97
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 80 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS IDN_ACTION (
PRIMARY KEY (UUID)
);

CREATE TABLE IF NOT EXISTS IDN_ACTION_ENDPOINT (
CREATE TABLE IF NOT EXISTS IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ CREATE TABLE IDN_ACTION (
PRIMARY KEY (UUID)
)
/
CREATE TABLE IDN_ACTION_ENDPOINT (
CREATE TABLE IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -2276,7 +2276,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME);
-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID);
/
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID);
/

-- CERTIFICATE --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ CREATE TABLE IF NOT EXISTS IDN_ACTION (
PRIMARY KEY (UUID)
);

CREATE TABLE IF NOT EXISTS IDN_ACTION_ENDPOINT (
CREATE TABLE IF NOT EXISTS IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -1496,7 +1496,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME);

-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID);

-- CERTIFICATE --
CREATE INDEX IDX_IDN_CERTIFICATE_ID_TID ON IDN_CERTIFICATE (ID, TENANT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,8 +1519,8 @@ CREATE TABLE IDN_ACTION (
PRIMARY KEY (UUID)
);

IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_ACTION_ENDPOINT]') AND TYPE in (N'U'))
CREATE TABLE IDN_ACTION_ENDPOINT (
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_ACTION_PROPERTIES]') AND TYPE in (N'U'))
CREATE TABLE IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -1647,7 +1647,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME);

-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID);

-- CERTIFICATE --
CREATE INDEX IDX_IDN_CERTIFICATE_ID_TID ON IDN_CERTIFICATE (ID, TENANT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ CREATE TABLE IF NOT EXISTS IDN_ACTION (
PRIMARY KEY (UUID)
)ENGINE NDB;

CREATE TABLE IF NOT EXISTS IDN_ACTION_ENDPOINT (
CREATE TABLE IF NOT EXISTS IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -1688,7 +1688,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME);

-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID);

-- CERTIFICATE --
CREATE INDEX IDX_IDN_CERTIFICATE_ID_TID ON IDN_CERTIFICATE (ID, TENANT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ CREATE TABLE IF NOT EXISTS IDN_ACTION (
PRIMARY KEY (UUID)
)DEFAULT CHARACTER SET latin1 ENGINE INNODB;

CREATE TABLE IF NOT EXISTS IDN_ACTION_ENDPOINT (
CREATE TABLE IF NOT EXISTS IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -1524,7 +1524,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME);

-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID);

-- CERTIFICATE --
CREATE INDEX IDX_IDN_CERTIFICATE_ID_TID ON IDN_CERTIFICATE (ID, TENANT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ CREATE TABLE IDN_ACTION (
PRIMARY KEY (UUID)
)
/
CREATE TABLE IDN_ACTION_ENDPOINT (
CREATE TABLE IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -2333,7 +2333,7 @@ CREATE INDEX IDX_CON_FILE_RES_ID ON IDN_CONFIG_FILE (RESOURCE_ID)
-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID)
/
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID)
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID)
/

-- CERTIFICATE --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ CREATE TABLE IDN_ACTION (
PRIMARY KEY (UUID)
)
/
CREATE TABLE IDN_ACTION_ENDPOINT (
CREATE TABLE IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -2238,7 +2238,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME)
-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID)
/
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID)
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID)
/

-- CERTIFICATE --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,8 @@ CREATE TABLE IF NOT EXISTS IDN_ACTION (
PRIMARY KEY (UUID)
);

DROP TABLE IF EXISTS IDN_ACTION_ENDPOINT;
CREATE TABLE IF NOT EXISTS IDN_ACTION_ENDPOINT (
DROP TABLE IF EXISTS IDN_ACTION_PROPERTIES;
CREATE TABLE IF NOT EXISTS IDN_ACTION_PROPERTIES (
ACTION_UUID CHAR(36) NOT NULL,
PROPERTY_NAME VARCHAR(100) NOT NULL,
PROPERTY_VALUE VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -1771,7 +1771,7 @@ CREATE INDEX API_ID_NAME_INDEX ON SCOPE (API_ID, NAME);

-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_ENDPOINT_AU_TI ON IDN_ACTION_ENDPOINT (ACTION_UUID, TENANT_ID);
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID);

-- CERTIFICATE --
CREATE INDEX IDX_IDN_CERTIFICATE_ID_TID ON IDN_CERTIFICATE (ID, TENANT_ID);
Expand Down

0 comments on commit 6995e97

Please sign in to comment.