use of io.gravitee.repository.management.model.Tag in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method create.
@Override
public List<TagEntity> create(final List<NewTagEntity> tagEntities) {
// First we prevent the duplicate tag name
final List<String> tagNames = tagEntities.stream().map(NewTagEntity::getName).collect(Collectors.toList());
final Optional<TagEntity> optionalTag = findAll().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);
savedTags.add(convert(tagRepository.create(tag)));
auditService.createPortalAuditLog(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;
}
use of io.gravitee.repository.management.model.Tag in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method convert.
private Tag convert(final UpdateTagEntity tagEntity) {
final Tag tag = new Tag();
tag.setId(tagEntity.getId());
tag.setName(tagEntity.getName());
tag.setDescription(tagEntity.getDescription());
return tag;
}
use of io.gravitee.repository.management.model.Tag in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method convert.
private Tag convert(final NewTagEntity tagEntity) {
final Tag tag = new Tag();
tag.setId(IdGenerator.generate(tagEntity.getName()));
tag.setName(tagEntity.getName());
tag.setDescription(tagEntity.getDescription());
return tag;
}
use of io.gravitee.repository.management.model.Tag in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method delete.
@Override
public void delete(final String tagId) {
try {
Optional<Tag> tagOptional = tagRepository.findById(tagId);
if (tagOptional.isPresent()) {
tagRepository.delete(tagId);
// delete all reference on APIs
apiService.deleteTagFromAPIs(tagId);
auditService.createPortalAuditLog(Collections.singletonMap(TAG, tagId), TAG_DELETED, new Date(), null, tagOptional.get());
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete tag {}", tagId, ex);
throw new TechnicalManagementException("An error occurs while trying to delete tag " + tagId, ex);
}
}
use of io.gravitee.repository.management.model.Tag in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method update.
@Override
public List<TagEntity> update(final List<UpdateTagEntity> tagEntities) {
final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
tagEntities.forEach(tagEntity -> {
try {
Tag tag = convert(tagEntity);
Optional<Tag> tagOptional = tagRepository.findById(tag.getId());
if (tagOptional.isPresent()) {
savedTags.add(convert(tagRepository.update(tag)));
auditService.createPortalAuditLog(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