use of io.gravitee.rest.api.model.TagEntity in project gravitee-management-rest-api by gravitee-io.
the class FlowServiceImpl method getPlatformFlowSchemaForm.
@Override
public String getPlatformFlowSchemaForm() {
LOGGER.debug("Get platform schema form");
String fileContent = getFileContent("/flow/platform-flow-schema-form.json");
List<TagEntity> tags = tagService.findByReference(GraviteeContext.getCurrentOrganization(), TagReferenceType.ORGANIZATION);
if (tags.size() > 0) {
LOGGER.debug("Append {} tag(s) to platform schema form", tags.size());
try {
final ObjectMapper mapper = new ObjectMapper();
JsonNode jsonSchema = mapper.readTree(fileContent);
final ObjectNode consumers = (ObjectNode) jsonSchema.get("properties").get("consumers");
final ArrayNode enumNode = (ArrayNode) consumers.get("items").get("enum");
Map<String, String> titleMap = new HashMap<>();
tags.forEach(tagEntity -> titleMap.put(tagEntity.getId(), tagEntity.getName()));
titleMap.keySet().forEach(enumNode::add);
JsonNode titleMapNode = mapper.valueToTree(titleMap);
ObjectNode xSchemaForm = mapper.createObjectNode();
consumers.set("x-schema-form", xSchemaForm);
xSchemaForm.set("titleMap", titleMapNode);
return jsonSchema.toPrettyString();
} catch (JsonProcessingException ex) {
final String error = "An error occurs while append tags to platform flow schema form";
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
return fileContent;
}
use of io.gravitee.rest.api.model.TagEntity in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method update.
@Override
public List<TagEntity> update(final List<UpdateTagEntity> tagEntities, String referenceId, TagReferenceType referenceType) {
final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
tagEntities.forEach(tagEntity -> {
try {
Tag tag = convert(tagEntity);
Optional<Tag> tagOptional = tagRepository.findByIdAndReference(tag.getId(), referenceId, repoTagReferenceType(referenceType));
if (tagOptional.isPresent()) {
Tag existingTag = tagOptional.get();
tag.setReferenceId(existingTag.getReferenceId());
tag.setReferenceType(existingTag.getReferenceType());
savedTags.add(convert(tagRepository.update(tag)));
auditService.createOrganizationAuditLog(Collections.singletonMap(TAG, tag.getId()), TAG_UPDATED, new Date(), tagOptional.get(), tag);
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update tag {}", tagEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update tag " + tagEntity.getName(), ex);
}
});
return savedTags;
}
use of io.gravitee.rest.api.model.TagEntity in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method convert.
private TagEntity convert(final Tag tag) {
final TagEntity tagEntity = new TagEntity();
tagEntity.setId(tag.getId());
tagEntity.setName(tag.getName());
tagEntity.setDescription(tag.getDescription());
tagEntity.setRestrictedGroups(tag.getRestrictedGroups());
return tagEntity;
}
use of io.gravitee.rest.api.model.TagEntity in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method create.
@Override
public List<TagEntity> create(final List<NewTagEntity> tagEntities, String referenceId, TagReferenceType referenceType) {
// First we prevent the duplicate tag name
final List<String> tagNames = tagEntities.stream().map(NewTagEntity::getName).collect(toList());
final Optional<TagEntity> optionalTag = findByReference(referenceId, referenceType).stream().filter(tag -> tagNames.contains(tag.getName())).findAny();
if (optionalTag.isPresent()) {
throw new DuplicateTagNameException(optionalTag.get().getName());
}
final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
tagEntities.forEach(tagEntity -> {
try {
Tag tag = convert(tagEntity, referenceId, referenceType);
savedTags.add(convert(tagRepository.create(tag)));
auditService.createOrganizationAuditLog(Collections.singletonMap(TAG, tag.getId()), TAG_CREATED, new Date(), null, tag);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create tag {}", tagEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create tag " + tagEntity.getName(), ex);
}
});
return savedTags;
}
Aggregations