use of io.gravitee.rest.api.model.TagReferenceType 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