Skip to content

Commit

Permalink
Fix review comments. Add specific field names to SELECT queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
dushaniw committed May 5, 2020
1 parent 830f7f7 commit 95f3b97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8233,18 +8233,19 @@ public Set<String> getAllSharedScopeKeys(String tenantDomain) throws APIManageme
@Override
public Scope getSharedScopeByUUID(String sharedScopeId, String tenantDomain) throws APIManagementException {

Scope sharedScope;
if (log.isDebugEnabled()) {
log.debug("Retrieving shared scope: " + sharedScopeId);
}
Scope scope = ApiMgtDAO.getInstance().getSharedScope(sharedScopeId);
if (scope != null) {
scope = KeyManagerHolder.getKeyManagerInstance().getScopeByName(scope.getKey(), tenantDomain);
scope.setId(sharedScopeId);
String scopeKey = ApiMgtDAO.getInstance().getSharedScopeKeyByUUID(sharedScopeId);
if (scopeKey != null) {
sharedScope = KeyManagerHolder.getKeyManagerInstance().getScopeByName(scopeKey, tenantDomain);
sharedScope.setId(sharedScopeId);
} else {
throw new APIMgtResourceNotFoundException("Shared Scope not found for scope ID: " + sharedScopeId,
ExceptionCodes.from(ExceptionCodes.SHARED_SCOPE_NOT_FOUND, sharedScopeId));
}
return scope;
return sharedScope;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15095,29 +15095,27 @@ public void deleteSharedScope(String scopeName, String tenantDomain) throws APIM
}

/**
* Get shared scope by uuid.
* Get shared scope key by uuid.
*
* @param uuid UUID of shared scope
* @return Shared scope object with UUID and scope key
* @return Shared scope key
* @throws APIManagementException if an error occurs while getting shared scope
*/
public Scope getSharedScope(String uuid) throws APIManagementException {
public String getSharedScopeKeyByUUID(String uuid) throws APIManagementException {

Scope scope = null;
String scopeKey = null;
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(SQLConstants.GET_SHARED_SCOPE_BY_UUID)) {
statement.setString(1, uuid);
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
scope = new Scope();
scope.setKey(rs.getString("NAME"));
scope.setId(uuid);
scopeKey = rs.getString("NAME");
}
}
} catch (SQLException e) {
handleException("Failed to get Shared Scope : " + uuid, e);
}
return scope;
return scopeKey;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3445,7 +3445,7 @@ public static class RevokedJWTConstants {
//Shared Scopes related constants
public static final String ADD_SHARED_SCOPE = "INSERT INTO AM_SHARED_SCOPE (NAME, UUID, TENANT_ID) VALUES (?,?,?)";
public static final String DELETE_SHARED_SCOPE = "DELETE FROM AM_SHARED_SCOPE WHERE NAME = ? AND TENANT_ID = ?";
public static final String GET_SHARED_SCOPE_BY_UUID = "SELECT * FROM AM_SHARED_SCOPE WHERE UUID = ?";
public static final String GET_SHARED_SCOPE_BY_UUID = "SELECT NAME FROM AM_SHARED_SCOPE WHERE UUID = ?";
public static final String GET_ALL_SHARED_SCOPE_KEYS_BY_TENANT =
"SELECT NAME FROM AM_SHARED_SCOPE WHERE TENANT_ID = ?";
public static final String IS_SHARED_SCOPE_NAME_EXISTS =
Expand Down Expand Up @@ -3513,7 +3513,7 @@ public static class KeyMgtConstants {
"INSERT INTO AM_KM_MGT_APPLICATION (CONSUMER_KEY,CONSUMER_SECRET,TENANT_ID) VALUES (?,?,?)";

public static final String GET_KM_APPLICATION_FOR_TENANT =
"SELECT * FROM AM_KM_MGT_APPLICATION WHERE TENANT_ID = ?";
"SELECT CONSUMER_KEY, CONSUMER_SECRET FROM AM_KM_MGT_APPLICATION WHERE TENANT_ID = ?";
}

//TODO: Need remove after KM seperation
Expand Down

0 comments on commit 95f3b97

Please sign in to comment.