Search in sources :

Example 1 with EnvironmentListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO in project carbon-apimgt by wso2.

the class EnvironmentsApiServiceImpl method environmentsGet.

/**
 * Get list of gateway environments from config api-manager.xml and dynamic environments (from DB)
 *
 * @param messageContext message context
 * @return created environment
 * @throws APIManagementException if failed to get list
 */
public Response environmentsGet(MessageContext messageContext) throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    List<Environment> envList = apiAdmin.getAllEnvironments(organization);
    EnvironmentListDTO envListDTO = EnvironmentMappingUtil.fromEnvListToEnvListDTO(envList);
    return Response.ok().entity(envListDTO).build();
}
Also used : EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 2 with EnvironmentListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvironmentCollectionToDTO.

/**
 * Converts a List object of SubscribedAPIs into a DTO.
 *
 * @param environmentCollection a collection of Environment objects
 * @return EnvironmentListDTO object containing EnvironmentDTOs
 */
public static EnvironmentListDTO fromEnvironmentCollectionToDTO(Collection<Environment> environmentCollection) {
    EnvironmentListDTO environmentListDTO = new EnvironmentListDTO();
    List<EnvironmentDTO> environmentDTOs = environmentListDTO.getList();
    if (environmentDTOs == null) {
        environmentDTOs = new ArrayList<>();
        environmentListDTO.setList(environmentDTOs);
    }
    for (Environment environment : environmentCollection) {
        environmentDTOs.add(fromEnvironmentToDTO(environment));
    }
    environmentListDTO.setCount(environmentDTOs.size());
    return environmentListDTO;
}
Also used : EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO) EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO) ExternalEnvironment(org.wso2.carbon.apimgt.impl.ExternalEnvironment) Environment(org.wso2.carbon.apimgt.api.model.Environment)

Example 3 with EnvironmentListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO in project carbon-apimgt by wso2.

the class SettingsMappingUtil method fromSettingstoDTO.

/**
 * This method feeds data into the settingsDTO.
 *
 * @param isUserAvailable check if user is logged in
 * @return SettingsDTO
 * @throws APIManagementException,IOException
 */
public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, String organization) throws APIManagementException, IOException {
    SettingsDTO settingsDTO = new SettingsDTO();
    EnvironmentListDTO environmentListDTO = new EnvironmentListDTO();
    if (isUserAvailable) {
        Map<String, Environment> environments = APIUtil.getEnvironments(organization);
        if (environments != null) {
            environmentListDTO = EnvironmentMappingUtil.fromEnvironmentCollectionToDTO(environments.values());
        }
        settingsDTO.setEnvironment(environmentListDTO.getList());
        String storeUrl = APIUtil.getStoreUrl();
        String loggedInUserTenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        Map<String, String> domainMappings = APIUtil.getDomainMappings(loggedInUserTenantDomain, APIConstants.API_DOMAIN_MAPPINGS_STORE);
        if (domainMappings.size() != 0) {
            Iterator entries = domainMappings.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry thisEntry = (Map.Entry) entries.next();
                storeUrl = "https://" + thisEntry.getValue();
                break;
            }
        }
        settingsDTO.setDevportalUrl(storeUrl);
        settingsDTO.setMonetizationAttributes(getMonetizationAttributes());
        settingsDTO.setSecurityAuditProperties(getSecurityAuditProperties());
        settingsDTO.setExternalStoresEnabled(APIUtil.isExternalStoresEnabled(RestApiCommonUtil.getLoggedInUserTenantDomain()));
        settingsDTO.setDocVisibilityEnabled(APIUtil.isDocVisibilityLevelsEnabled());
        settingsDTO.setCrossTenantSubscriptionEnabled(APIUtil.isCrossTenantSubscriptionsEnabled());
        Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
        String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain, APIConstants.AUTHORIZATION_HEADER);
        if (authorizationHeader == null) {
            authorizationHeader = APIConstants.AUTHORIZATION_HEADER_DEFAULT;
        }
        settingsDTO.setAuthorizationHeader(authorizationHeader);
    }
    return settingsDTO;
}
Also used : SettingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SettingsDTO) EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO) Iterator(java.util.Iterator) Environment(org.wso2.carbon.apimgt.api.model.Environment) Map(java.util.Map)

Example 4 with EnvironmentListDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvListToEnvListDTO.

/**
 * Convert list of Environment to EnvironmentListDTO
 *
 * @param envList List of Environment
 * @return EnvironmentListDTO containing Environment list
 */
public static EnvironmentListDTO fromEnvListToEnvListDTO(List<Environment> envList) {
    EnvironmentListDTO envListDTO = new EnvironmentListDTO();
    envListDTO.setCount(envList.size());
    envListDTO.setList(envList.stream().map(EnvironmentMappingUtil::fromEnvToEnvDTO).collect(Collectors.toList()));
    return envListDTO;
}
Also used : EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)3 EnvironmentListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO)2 EnvironmentListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)1 ExternalEnvironment (org.wso2.carbon.apimgt.impl.ExternalEnvironment)1 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO)1 SettingsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SettingsDTO)1