Search in sources :

Example 1 with TAG

use of io.gravitee.repository.management.model.Audit.AuditProperties.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;
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) NewTagEntity(io.gravitee.management.model.NewTagEntity) ApiService(io.gravitee.management.service.ApiService) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditService(io.gravitee.management.service.AuditService) TagEntity(io.gravitee.management.model.TagEntity) Collectors(java.util.stream.Collectors) AuditEvent(io.gravitee.repository.management.model.Tag.AuditEvent) TagRepository(io.gravitee.repository.management.api.TagRepository) IdGenerator(io.gravitee.common.utils.IdGenerator) Tag(io.gravitee.repository.management.model.Tag) Component(org.springframework.stereotype.Component) TagService(io.gravitee.management.service.TagService) DuplicateTagNameException(io.gravitee.management.service.exceptions.DuplicateTagNameException) UpdateTagEntity(io.gravitee.management.model.UpdateTagEntity) TAG(io.gravitee.repository.management.model.Audit.AuditProperties.TAG) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NewTagEntity(io.gravitee.management.model.NewTagEntity) TagEntity(io.gravitee.management.model.TagEntity) UpdateTagEntity(io.gravitee.management.model.UpdateTagEntity) DuplicateTagNameException(io.gravitee.management.service.exceptions.DuplicateTagNameException) Tag(io.gravitee.repository.management.model.Tag) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

IdGenerator (io.gravitee.common.utils.IdGenerator)1 NewTagEntity (io.gravitee.management.model.NewTagEntity)1 TagEntity (io.gravitee.management.model.TagEntity)1 UpdateTagEntity (io.gravitee.management.model.UpdateTagEntity)1 ApiService (io.gravitee.management.service.ApiService)1 AuditService (io.gravitee.management.service.AuditService)1 TagService (io.gravitee.management.service.TagService)1 DuplicateTagNameException (io.gravitee.management.service.exceptions.DuplicateTagNameException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 TagRepository (io.gravitee.repository.management.api.TagRepository)1 TAG (io.gravitee.repository.management.model.Audit.AuditProperties.TAG)1 Tag (io.gravitee.repository.management.model.Tag)1 AuditEvent (io.gravitee.repository.management.model.Tag.AuditEvent)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1