use of io.gravitee.rest.api.model.api.UpdateApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiDuplicatorServiceImpl method createWithImportedDefinition.
@Override
public ApiEntity createWithImportedDefinition(String apiDefinitionOrURL, String userId, String organizationId, String environmentId) {
String apiDefinition = fetchApiDefinitionContentFromURL(apiDefinitionOrURL);
try {
// Read the whole definition
final JsonNode jsonNode = objectMapper.readTree(apiDefinition);
UpdateApiEntity importedApi = convertToEntity(apiDefinition, jsonNode);
ApiEntity createdApiEntity = apiService.createWithApiDefinition(importedApi, userId, jsonNode);
createPageAndMedia(createdApiEntity, jsonNode, environmentId);
updateApiReferences(createdApiEntity, jsonNode, organizationId, environmentId, false);
return createdApiEntity;
} catch (JsonProcessingException e) {
LOGGER.error("An error occurs while trying to JSON deserialize the API {}", apiDefinition, e);
throw new TechnicalManagementException("An error occurs while trying to JSON deserialize the API definition.");
}
}
use of io.gravitee.rest.api.model.api.UpdateApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiDuplicatorServiceImpl method updateWithImportedDefinition.
@Override
public ApiEntity updateWithImportedDefinition(String apiId, String apiDefinitionOrURL, String userId, String organizationId, String environmentId) {
String apiDefinition = fetchApiDefinitionContentFromURL(apiDefinitionOrURL);
try {
// Read the whole definition
final JsonNode jsonNode = objectMapper.readTree(apiDefinition);
UpdateApiEntity importedApi = convertToEntity(apiDefinition, jsonNode);
ApiEntity updatedApiEntity = apiService.update(apiId, importedApi, false);
updateApiReferences(updatedApiEntity, jsonNode, organizationId, environmentId, true);
return updatedApiEntity;
} catch (JsonProcessingException e) {
LOGGER.error("An error occurs while trying to JSON deserialize the API {}", apiDefinition, e);
throw new TechnicalManagementException("An error occurs while trying to JSON deserialize the API definition.");
}
}
use of io.gravitee.rest.api.model.api.UpdateApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiDuplicatorServiceImpl method convert.
private UpdateApiEntity convert(final ApiEntity apiEntity) {
final UpdateApiEntity updateApiEntity = new UpdateApiEntity();
updateApiEntity.setDescription(apiEntity.getDescription());
updateApiEntity.setName(apiEntity.getName());
updateApiEntity.setVersion(apiEntity.getVersion());
updateApiEntity.setGraviteeDefinitionVersion(apiEntity.getGraviteeDefinitionVersion());
updateApiEntity.setGroups(apiEntity.getGroups());
updateApiEntity.setLabels(apiEntity.getLabels());
updateApiEntity.setLifecycleState(apiEntity.getLifecycleState());
updateApiEntity.setPicture(apiEntity.getPicture());
updateApiEntity.setBackground(apiEntity.getBackground());
updateApiEntity.setProperties(apiEntity.getProperties());
updateApiEntity.setProxy(apiEntity.getProxy());
updateApiEntity.setResources(apiEntity.getResources());
updateApiEntity.setResponseTemplates(apiEntity.getResponseTemplates());
updateApiEntity.setServices(apiEntity.getServices());
updateApiEntity.setTags(apiEntity.getTags());
updateApiEntity.setCategories(apiEntity.getCategories());
updateApiEntity.setVisibility(apiEntity.getVisibility());
updateApiEntity.setPaths(apiEntity.getPaths());
updateApiEntity.setFlows(apiEntity.getFlows());
updateApiEntity.setPathMappings(apiEntity.getPathMappings());
updateApiEntity.setDisableMembershipNotifications(apiEntity.isDisableMembershipNotifications());
updateApiEntity.setPlans(apiEntity.getPlans());
return updateApiEntity;
}
use of io.gravitee.rest.api.model.api.UpdateApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PlanServiceImpl method create.
@Override
public PlanEntity create(NewPlanEntity newPlan) {
try {
logger.debug("Create a new plan {} for API {}", newPlan.getName(), newPlan.getApi());
assertPlanSecurityIsAllowed(newPlan.getSecurity());
final ApiEntity api = apiService.findById(newPlan.getApi());
if (ApiLifecycleState.DEPRECATED.equals(api.getLifecycleState())) {
throw new ApiDeprecatedException(api.getName());
}
String id = newPlan.getId() != null && UUID.fromString(newPlan.getId()) != null ? newPlan.getId() : UuidString.generateRandom();
Plan plan = new Plan();
plan.setId(id);
plan.setApi(newPlan.getApi());
plan.setName(newPlan.getName());
plan.setDescription(newPlan.getDescription());
plan.setCreatedAt(new Date());
plan.setUpdatedAt(plan.getCreatedAt());
plan.setNeedRedeployAt(plan.getCreatedAt());
plan.setType(Plan.PlanType.valueOf(newPlan.getType().name()));
plan.setSecurity(Plan.PlanSecurityType.valueOf(newPlan.getSecurity().name()));
plan.setSecurityDefinition(newPlan.getSecurityDefinition());
plan.setStatus(Plan.Status.valueOf(newPlan.getStatus().name()));
plan.setExcludedGroups(newPlan.getExcludedGroups());
plan.setCommentRequired(newPlan.isCommentRequired());
plan.setCommentMessage(newPlan.getCommentMessage());
plan.setTags(newPlan.getTags());
plan.setSelectionRule(newPlan.getSelectionRule());
plan.setGeneralConditions(newPlan.getGeneralConditions());
if (plan.getSecurity() == Plan.PlanSecurityType.KEY_LESS) {
// There is no need for a validation when authentication is KEY_LESS, force to AUTO
plan.setValidation(Plan.PlanValidationType.AUTO);
} else {
plan.setValidation(Plan.PlanValidationType.valueOf(newPlan.getValidation().name()));
}
plan.setCharacteristics(newPlan.getCharacteristics());
if (!DefinitionVersion.V2.equals(DefinitionVersion.valueOfLabel(api.getGraviteeDefinitionVersion()))) {
String planPolicies = objectMapper.writeValueAsString(newPlan.getPaths());
plan.setDefinition(planPolicies);
}
plan = planRepository.create(plan);
if (DefinitionVersion.V2.equals(DefinitionVersion.valueOfLabel(api.getGraviteeDefinitionVersion()))) {
UpdateApiEntity updateApi = ApiService.convert(api);
updateApi.addPlan(fillApiDefinitionPlan(new io.gravitee.definition.model.Plan(), plan, newPlan.getFlows()));
apiService.update(api.getId(), updateApi);
}
auditService.createApiAuditLog(newPlan.getApi(), Collections.singletonMap(PLAN, plan.getId()), PLAN_CREATED, plan.getCreatedAt(), null, plan);
return convert(plan);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to create a plan {} for API {}", newPlan.getName(), newPlan.getApi(), ex);
throw new TechnicalManagementException(String.format("An error occurs while trying to create a plan %s for API %s", newPlan.getName(), newPlan.getApi()), ex);
} catch (JsonProcessingException jse) {
logger.error("Unexpected error while generating plan definition", jse);
throw new TechnicalManagementException(String.format("An error occurs while trying to create a plan %s for API %s", newPlan.getName(), newPlan.getApi()), jse);
}
}
use of io.gravitee.rest.api.model.api.UpdateApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPlansResource method removePlanFromApiDefinition.
private void removePlanFromApiDefinition(String planId, String apiId) {
// Remove plan from api definition
if (apiId != null) {
ApiEntity api = apiService.findById(apiId);
if (DefinitionVersion.V2.equals(DefinitionVersion.valueOfLabel(api.getGraviteeDefinitionVersion()))) {
List<io.gravitee.definition.model.Plan> plans = api.getPlans().stream().filter(plan1 -> plan1.getId() != null && !plan1.getId().equals(planId)).collect(Collectors.toList());
UpdateApiEntity updateApiEntity = ApiService.convert(api);
updateApiEntity.setPlans(plans);
if (api.getPlans().size() != updateApiEntity.getPlans().size()) {
apiService.update(apiId, updateApiEntity);
}
}
}
}
Aggregations