Search in sources :

Example 1 with UpdateTagEntity

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;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NewTagEntity(io.gravitee.rest.api.model.NewTagEntity) TagEntity(io.gravitee.rest.api.model.TagEntity) UpdateTagEntity(io.gravitee.rest.api.model.UpdateTagEntity) Tag(io.gravitee.repository.management.model.Tag) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Tag (io.gravitee.repository.management.model.Tag)1 NewTagEntity (io.gravitee.rest.api.model.NewTagEntity)1 TagEntity (io.gravitee.rest.api.model.TagEntity)1 UpdateTagEntity (io.gravitee.rest.api.model.UpdateTagEntity)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1