Search in sources :

Example 6 with ScopeInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.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;
}
Also used : ApplicationDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationDTO) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) ScopeInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeInfoDTO) JSONObject(org.json.simple.JSONObject) Scope(org.wso2.carbon.apimgt.api.model.Scope) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) JSONObject(org.json.simple.JSONObject) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 7 with ScopeInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.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;
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopeInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeInfoDTO) ArrayList(java.util.ArrayList)

Aggregations

Scope (org.wso2.carbon.apimgt.api.model.Scope)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 JSONObject (org.json.simple.JSONObject)4 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)4 ScopeInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ScopeInfoDTO)4 JsonObject (com.google.gson.JsonObject)3 JSONArray (org.json.simple.JSONArray)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 Application (org.wso2.carbon.apimgt.api.model.Application)2 Tier (org.wso2.carbon.apimgt.api.model.Tier)2 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)2 ScopeInfoDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeInfoDTO)2 APIAdditionalPropertiesDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIAdditionalPropertiesDTO)2 APIBusinessInformationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO)2 APIDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIDTO)2 APIMonetizationAttributesDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIMonetizationAttributesDTO)2 APIMonetizationInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIMonetizationInfoDTO)2 APIOperationsDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIOperationsDTO)2 APITiersDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APITiersDTO)2