Skip to content

Commit

Permalink
Merge pull request wso2#6095 from piraveena/appuuidFromname
Browse files Browse the repository at this point in the history
Add new api to get application uuid from name
  • Loading branch information
piraveena authored Nov 2, 2024
2 parents 7f07a79 + 126c8cb commit ec9c490
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,21 @@ public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String te
throw new NotImplementedException();
}


/**
* Retrieve application UUID using the application name.
*
* @param name Name of the application
* @param tenantDomain Tenant domain of the application
* @return Application UUID
* @throws IdentityApplicationManagementException
*/
public String getApplicationUUIDByName(String name, String tenantDomain)
throws IdentityApplicationManagementException {

throw new NotImplementedException();
}
/**
* Get custom inbound authenticator configurations.
*
* @return custom inbound authenticator configs maps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,19 @@ public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String te
return basicAppInfo;
}

@Override
public String getApplicationUUIDByName(String name, String tenantDomain)
throws IdentityApplicationManagementException {

if (log.isDebugEnabled()) {
log.debug("Getting application UUID for name: " + name
+ " in tenantDomain: " + tenantDomain);
}

ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
return appDAO.getApplicationUUIDByName(name, tenantDomain);
}

/**
* Get count of all Application Basic Information.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ default ApplicationBasicInfo getApplicationBasicInfoByName(String name, String t
throw new NotImplementedException();
}

/**
* Retrieve application UUID using the application name.
*
* @param name Name of the application
* @param tenantDomain Tenant domain of the application
* @return Application UUID
* @throws IdentityApplicationManagementException
*/
default String getApplicationUUIDByName(String name, String tenantDomain)
throws IdentityApplicationManagementException {

throw new NotImplementedException();
}

default String addApplication(ServiceProvider application, String tenantDomain)
throws IdentityApplicationManagementException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5798,6 +5798,37 @@ public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String te
return applicationBasicInfo;
}

@Override
public String getApplicationUUIDByName(String name, String tenantDomain)
throws IdentityApplicationManagementException {

if (log.isDebugEnabled()) {
log.debug("Getting application UUID for name: " + name
+ " in tenantDomain: " + tenantDomain);
}

String applicationUuid = null;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement =
new NamedPreparedStatement(connection,
ApplicationMgtDBQueries.GET_APP_UUID_BY_TENANT_AND_NAME)) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setString(ApplicationTableColumns.APP_NAME, name);

try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
applicationUuid = resultSet.getString(ApplicationTableColumns.UUID);
}
}
}
} catch (SQLException e) {
String message = "Error while getting application uuid for name: %s in " +
"tenantDomain: %s";
throw new IdentityApplicationManagementException(String.format(message, name, tenantDomain), e);
}
return applicationUuid;
}

public String addApplication(ServiceProvider application,
String tenantDomain) throws IdentityApplicationManagementException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class ApplicationMgtDBQueries {
"IMAGE_URL, ACCESS_URL, IS_DISCOVERABLE, USERNAME, USER_STORE, TENANT_ID FROM SP_APP WHERE " +
"TENANT_ID = :TENANT_ID; AND APP_NAME = :APP_NAME;";

public static final String GET_APP_UUID_BY_TENANT_AND_NAME = "SELECT UUID FROM SP_APP WHERE " +
"TENANT_ID = :TENANT_ID; AND APP_NAME = :APP_NAME;";

// Load application basic information for listing with pagination
public static final String LOAD_APP_NAMES_BY_TENANT_MYSQL = "SELECT ID, APP_NAME, VERSION, DESCRIPTION, " +
"UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM SP_APP WHERE TENANT_ID = ? AND " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,25 @@ public void testGetSAMLApplicationBasicInfoWithFilterOffsetLimit(String filter,
applicationManagementService.deleteApplications(SUPER_TENANT_ID);
}

@Test()
public void testGetApplicationUUIDFromName()
throws IdentityApplicationManagementException {

ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(APPLICATION_NAME_1);
// Adding new application.
String resourceId = applicationManagementService.createApplication(serviceProvider,
SUPER_TENANT_DOMAIN_NAME, USERNAME_1);

// Retrieving added application info.
String applicationUUID = applicationManagementService.getApplicationUUIDByName(
serviceProvider.getApplicationName(), SUPER_TENANT_DOMAIN_NAME);
Assert.assertEquals(applicationUUID, resourceId);

// Deleting added application.
applicationManagementService.deleteApplications(SUPER_TENANT_ID);
}

@Test
public void testGetConfiguredAuthenticators() throws IdentityApplicationManagementException {

Expand Down

0 comments on commit ec9c490

Please sign in to comment.