Search in sources :

Example 16 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvToEnvDTO.

/**
 * Convert Environment to EnvironmentDTO
 *
 * @param env Environment
 * @return EnvironmentDTO containing Environment
 */
public static EnvironmentDTO fromEnvToEnvDTO(Environment env) {
    EnvironmentDTO envDTO = new EnvironmentDTO();
    envDTO.setId(env.getUuid());
    envDTO.setName(env.getName());
    envDTO.setDisplayName(env.getDisplayName());
    envDTO.setDescription(env.getDescription());
    envDTO.setProvider(env.getProvider());
    envDTO.setIsReadOnly(env.isReadOnly());
    envDTO.setVhosts(env.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO).collect(Collectors.toList()));
    envDTO.setAdditionalProperties(fromAdditionalPropertiesToAdditionalPropertiesDTO(env.getAdditionalProperties()));
    return envDTO;
}
Also used : EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentDTO)

Example 17 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.

the class EnvironmentsApiServiceImpl method environmentsPost.

/**
 * Create a dynamic gateway environment
 * @param body environment to be created
 * @param messageContext message context
 * @return created environment
 * @throws APIManagementException if failed to create
 */
public Response environmentsPost(EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        // String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
        EnvironmentDTO envDTO = EnvironmentMappingUtil.fromEnvToEnvDTO(apiAdmin.addEnvironment(organization, env));
        URI location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + envDTO.getId());
        return Response.created(location).entity(envDTO).build();
    } catch (URISyntaxException e) {
        String errorMessage = "Error while adding gateway environment : " + body.getName() + "-" + e.getMessage();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentDTO) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 18 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment 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 19 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.

the class EnvironmentsApiServiceImpl method environmentsEnvironmentIdPut.

/**
 * Update gateway environment
 *
 * @param environmentId environment ID
 * @param body environment to be updated
 * @param messageContext message context
 * @return updated environment
 * @throws APIManagementException if failed to update
 */
public Response environmentsEnvironmentIdPut(String environmentId, EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    body.setId(environmentId);
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
    apiAdmin.updateEnvironment(organization, env);
    URI location = null;
    try {
        location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + environmentId);
    } catch (URISyntaxException e) {
        String errorMessage = "Error while updating Environment : " + environmentId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return Response.ok(location).entity(body).build();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 20 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.

the class ApiMgtDAO method getAllEnvironments.

/**
 * Returns the Environments List for the TenantId.
 *
 * @param tenantDomain The tenant domain.
 * @return List of Environments.
 */
public List<Environment> getAllEnvironments(String tenantDomain) throws APIManagementException {
    List<Environment> envList = new ArrayList<>();
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_ENVIRONMENT_BY_ORGANIZATION_SQL)) {
        prepStmt.setString(1, tenantDomain);
        try (ResultSet rs = prepStmt.executeQuery()) {
            while (rs.next()) {
                Integer id = rs.getInt("ID");
                String uuid = rs.getString("UUID");
                String name = rs.getString("NAME");
                String displayName = rs.getString("DISPLAY_NAME");
                String description = rs.getString("DESCRIPTION");
                String provider = rs.getString("PROVIDER");
                Environment env = new Environment();
                env.setId(id);
                env.setUuid(uuid);
                env.setName(name);
                env.setDisplayName(displayName);
                env.setDescription(description);
                env.setProvider(provider);
                env.setVhosts(getVhostGatewayEnvironments(connection, id));
                envList.add(env);
            }
        }
    } catch (SQLException e) {
        handleException("Failed to get Environments in tenant domain: " + tenantDomain, e);
    }
    return envList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Environment(org.wso2.carbon.apimgt.api.model.Environment) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)25 API (org.wso2.carbon.apimgt.api.model.API)22 IOException (java.io.IOException)19 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)19 Map (java.util.Map)15 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)12 JsonObject (com.google.gson.JsonObject)10 PreparedStatement (java.sql.PreparedStatement)10 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)10 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)10 Gson (com.google.gson.Gson)9 JSONObject (org.json.simple.JSONObject)9 Test (org.junit.Test)9 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)9