use of io.gravitee.rest.api.model.UpdateTagEntity 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;
}
Aggregations