use of org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse in project product-is by wso2.
the class ApplicationManagementSuccessTest method testGetAllApplications.
@Test
public void testGetAllApplications() throws IOException {
Response response = getResponseOfGet(APPLICATION_MANAGEMENT_API_BASE_PATH);
response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
ApplicationListResponse listResponse = jsonWriter.readValue(response.asString(), ApplicationListResponse.class);
assertNotNull(listResponse);
Assert.assertFalse(listResponse.getApplications().stream().anyMatch(appBasicInfo -> appBasicInfo.getName().equals(ApplicationConstants.LOCAL_SP)), "Default resident service provider '" + ApplicationConstants.LOCAL_SP + "' is listed by the API");
if (StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
// Check whether the default "My Account" app exists.
Assert.assertTrue(listResponse.getApplications().stream().anyMatch(appBasicInfo -> appBasicInfo.getName().equals(MY_ACCOUNT)), "Default application 'My Account' is not listed by the API.");
}
}
use of org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse in project identity-api-server by wso2.
the class ServerApplicationManagementService method getAllApplications.
public ApplicationListResponse getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String requiredAttributes) {
handleNotImplementedCapabilities(sortOrder, sortBy, requiredAttributes);
String tenantDomain = ContextLoader.getTenantDomainFromContext();
boolean isEqualFilterUsed = false;
limit = validateAndGetLimit(limit);
offset = validateAndGetOffset(offset);
// Format the filter to a value that can be interpreted by the backend.
ExpressionNode expressionNode = buildFilterNode(filter);
String formattedFilter = null;
if (expressionNode != null) {
// Handle eq operation as special case, there will be only one application with a given name in tenant.
if (isEqualOperation(expressionNode)) {
isEqualFilterUsed = true;
}
formattedFilter = generateFilterStringForBackend(expressionNode.getAttributeValue(), expressionNode.getOperation(), expressionNode.getValue());
}
String username = ContextLoader.getUsernameFromContext();
try {
int totalResults = getApplicationManagementService().getCountOfApplications(tenantDomain, username, formattedFilter);
ApplicationBasicInfo[] filteredAppList;
if (isEqualFilterUsed) {
ApplicationBasicInfo applicationBasicInfo = getApplicationManagementService().getApplicationBasicInfoByName(expressionNode.getValue(), tenantDomain);
if (applicationBasicInfo == null) {
filteredAppList = new ApplicationBasicInfo[0];
} else {
filteredAppList = new ApplicationBasicInfo[] { applicationBasicInfo };
}
} else {
filteredAppList = getApplicationManagementService().getApplicationBasicInfo(tenantDomain, username, formattedFilter, offset, limit);
}
int resultsInCurrentPage = filteredAppList.length;
return new ApplicationListResponse().totalResults(totalResults).startIndex(offset + 1).count(resultsInCurrentPage).applications(getApplicationListItems(filteredAppList)).links(Util.buildPaginationLinks(limit, offset, totalResults, APPLICATION_MANAGEMENT_PATH_COMPONENT).entrySet().stream().map(link -> new Link().rel(link.getKey()).href(link.getValue())).collect(Collectors.toList()));
} catch (IdentityApplicationManagementException e) {
String msg = "Error listing applications of tenantDomain: " + tenantDomain;
throw handleIdentityApplicationManagementException(e, msg);
}
}
Aggregations