use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeInfoDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdGet.
@Override
public Response applicationsApplicationIdGet(String applicationId, MessageContext messageContext) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
String organization = RestApiUtil.getOrganization(messageContext);
try {
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
Application application = apiConsumer.getApplicationByUUID(applicationId, organization);
if (application != null) {
String applicationTenantDomain = MultitenantUtils.getTenantDomain(application.getOwner());
// and verify that the invoking user's tenant domain has an API subscribed by this application
if (tenantDomain.equals(applicationTenantDomain)) {
// Remove hidden attributes and set the rest of the attributes from config
JSONArray applicationAttributesFromConfig = apiConsumer.getAppAttributesFromConfig(username);
Map<String, String> existingApplicationAttributes = application.getApplicationAttributes();
Map<String, String> applicationAttributes = new HashMap<>();
if (existingApplicationAttributes != null && applicationAttributesFromConfig != null) {
for (Object object : applicationAttributesFromConfig) {
JSONObject attribute = (JSONObject) object;
Boolean hidden = (Boolean) attribute.get(APIConstants.ApplicationAttributes.HIDDEN);
String attributeName = (String) attribute.get(APIConstants.ApplicationAttributes.ATTRIBUTE);
if (!BooleanUtils.isTrue(hidden)) {
String attributeVal = existingApplicationAttributes.get(attributeName);
if (attributeVal != null) {
applicationAttributes.put(attributeName, attributeVal);
} else {
applicationAttributes.put(attributeName, "");
}
}
}
}
application.setApplicationAttributes(applicationAttributes);
ApplicationDTO applicationDTO = ApplicationMappingUtil.fromApplicationtoDTO(application);
Set<Scope> scopes = apiConsumer.getScopesForApplicationSubscription(username, application.getId(), organization);
List<ScopeInfoDTO> scopeInfoList = ApplicationMappingUtil.getScopeInfoDTO(scopes);
applicationDTO.setSubscriptionScopes(scopeInfoList);
return Response.ok().entity(applicationDTO).build();
}
}
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving application " + applicationId, e, log);
}
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
return null;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeInfoDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method getScopeInfoDTO.
public static List<ScopeInfoDTO> getScopeInfoDTO(Set<Scope> scopes) {
List<ScopeInfoDTO> scopeDto = new ArrayList<ScopeInfoDTO>();
for (Scope scope : scopes) {
ScopeInfoDTO scopeInfoDTO = new ScopeInfoDTO();
scopeInfoDTO.setKey(scope.getKey());
scopeInfoDTO.setName(scope.getName());
scopeInfoDTO.setDescription(scope.getDescription());
if (StringUtils.isNotBlank(scope.getRoles())) {
scopeInfoDTO.setRoles(Arrays.asList(scope.getRoles().trim().split(",")));
}
scopeDto.add(scopeInfoDTO);
}
return scopeDto;
}
Aggregations