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;
}
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;
}
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();
}
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();
}
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;
}
Aggregations