Skip to content

Commit

Permalink
Add minor changes
Browse files Browse the repository at this point in the history
Remove unused methods
Fix API total in GET key manager API usage response
Refactor code
  • Loading branch information
SavinduDimal committed Mar 22, 2024
1 parent 083fb16 commit 41ef483
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,12 @@ Map<String, Object> searchPaginatedApis(String searchQuery, String organization,

/**
* This method used to retrieve global key manager configurations with usage check
* @param organization organization
* @return KeyManagerConfigurationDTO list
* @throws APIManagementException if error occurred
*/
List<KeyManagerConfigurationDTO> getGlobalKeyManagerConfigurations(String organization) throws APIManagementException;
List<KeyManagerConfigurationDTO> getGlobalKeyManagerConfigurations(String organization)
throws APIManagementException;

/**
* This method used to retrieve global key manager with Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,17 +721,6 @@ ResourceFile getWSDL(API api, String environmentName, String environmentType, St
*/
String getRequestedTenant();

/**
* Get consumer key and key manager name by application id and key mapping id
* @param applicationId application id
* @param keyMappingId key mapping id
* @return KeyManagerApplicationInfo
*/
KeyManagerApplicationInfo getKeyManagerNameAndConsumerKeyByAppIDAndKeyMapping(int applicationId,
String keyMappingId)
throws APIManagementException;


/**
*
* @param apiId API UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,6 @@ public KeyManagerApplicationUsages getApplicationsOfKeyManager(String keyManager
return keyManagerApplicationUsages;

Check warning on line 679 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java#L674-L679

Added lines #L674 - L679 were not covered by tests
}

public List<ApplicationInfoKeyManager> getAllApplicationsOfKeyManager(String keyManagerId)
throws APIManagementException {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
return apiMgtDAO.getAllApplicationsOfKeyManager(keyManagerId);
}

private void validateKeyManagerEndpointConfiguration(KeyManagerConfigurationDTO keyManagerConfigurationDTO)
throws APIManagementException {
if (!APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(keyManagerConfigurationDTO.getName())) {
Expand Down Expand Up @@ -984,7 +978,7 @@ public void deleteKeyManagerConfigurationById(String organization, KeyManagerCon
ExceptionCodes.KEY_MANAGER_DELETE_FAILED);
}
} else {
throw new APIManagementException("Key Manager is already used by an API or and Application.",
throw new APIManagementException("Key Manager is already used by an API or an Application.",

Check warning on line 981 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java#L981

Added line #L981 was not covered by tests
ExceptionCodes.KEY_MANAGER_DELETE_FAILED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3602,6 +3602,7 @@ public void cleanUpApplicationRegistrationByApplicationIdAndKeyMappingId(int app

public boolean removalKeys(Application application, String keyMappingId, String xWSO2Tenant)
throws APIManagementException {

try {
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(this.username);

Check warning on line 3607 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java#L3607

Added line #L3607 was not covered by tests

Expand Down Expand Up @@ -3679,14 +3680,6 @@ public APIKey getApplicationKeyByAppIDAndKeyMapping(int applicationId, String ke
return apiKey;
}

@Override
public KeyManagerApplicationInfo getKeyManagerNameAndConsumerKeyByAppIDAndKeyMapping(int applicationId, String keyMappingId)
throws APIManagementException {
return apiMgtDAO
.getKeyManagerNameAndConsumerKeyByAppIdAndKeyMappingId(applicationId, keyMappingId);
}


@Override
public Set<Topic> getTopics(String apiId) throws APIManagementException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public Response keyManagersKeyManagerIdAppUsagesGet(String keyManagerId, Integer
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);

Check warning on line 192 in components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java#L192

Added line #L192 was not covered by tests
}
KeyManagerApplicationUsages result = apiAdmin.getApplicationsOfKeyManager(keyManagerId, offset, limit);
return Response.ok().entity(result).build();
return Response.ok().entity(KeyManagerMappingUtil.toKeyManagerAppUsagesDTO(result)).build();

Check warning on line 195 in components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java#L194-L195

Added lines #L194 - L195 were not covered by tests
}

public Response keyManagersPost(KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public static KeyManagerAPIUsagesDTO toKeyManagerAPIUsagesDTO(AdminContentSearch
apis.add(apiInfoKeyManagerDTO);

Check warning on line 398 in components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java#L398

Added line #L398 was not covered by tests
}
}
keyManagerAPIUsagesDTO.setApiCount(result.getApiCount());
keyManagerAPIUsagesDTO.setApiCount(result.getApiTotal());
keyManagerAPIUsagesDTO.setApis(apis);

Check warning on line 402 in components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java#L400-L402

Added lines #L400 - L402 were not covered by tests
}
return keyManagerAPIUsagesDTO;

Check warning on line 404 in components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java#L404

Added line #L404 was not covered by tests
Expand Down Expand Up @@ -444,7 +444,7 @@ public static ApplicationInfoKeyManagerDTO toApplicationInfoKeyManagerDTO(
ApplicationInfoKeyManager applicationInfoKeyManager) {

ApplicationInfoKeyManagerDTO applicationInfoKeyManagerDTO = new ApplicationInfoKeyManagerDTO();
applicationInfoKeyManagerDTO.setName(applicationInfoKeyManager.getUuid());
applicationInfoKeyManagerDTO.setName(applicationInfoKeyManager.getName());
applicationInfoKeyManagerDTO.setUuid(applicationInfoKeyManager.getUuid());
applicationInfoKeyManagerDTO.setOrganization(applicationInfoKeyManager.getOrganization());
applicationInfoKeyManagerDTO.setOrganizationId(applicationInfoKeyManager.getOrganizationId());
Expand Down

0 comments on commit 41ef483

Please sign in to comment.