Search in sources :

Example 1 with VIEW_CREATED

use of io.gravitee.repository.management.model.View.AuditEvent.VIEW_CREATED in project gravitee-management-rest-api by gravitee-io.

the class ViewServiceImpl method create.

@Override
public List<ViewEntity> create(final List<NewViewEntity> viewEntities) {
    // First we prevent the duplicate view name
    final List<String> viewNames = viewEntities.stream().map(NewViewEntity::getName).collect(Collectors.toList());
    final Optional<ViewEntity> optionalView = findAll().stream().filter(view -> viewNames.contains(view.getName())).findAny();
    if (optionalView.isPresent()) {
        throw new DuplicateViewNameException(optionalView.get().getName());
    }
    final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
    viewEntities.forEach(viewEntity -> {
        try {
            View view = convert(viewEntity);
            savedViews.add(convert(viewRepository.create(view)));
            auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_CREATED, new Date(), null, view);
        } catch (TechnicalException ex) {
            LOGGER.error("An error occurs while trying to create view {}", viewEntity.getName(), ex);
            throw new TechnicalManagementException("An error occurs while trying to create view " + viewEntity.getName(), ex);
        }
    });
    return savedViews;
}
Also used : ViewEntity(io.gravitee.management.model.ViewEntity) java.util(java.util) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) Logger(org.slf4j.Logger) ApiService(io.gravitee.management.service.ApiService) ViewService(io.gravitee.management.service.ViewService) VIEW_DELETED(io.gravitee.repository.management.model.View.AuditEvent.VIEW_DELETED) DuplicateViewNameException(io.gravitee.management.service.exceptions.DuplicateViewNameException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) VIEW(io.gravitee.repository.management.model.Audit.AuditProperties.VIEW) VIEW_UPDATED(io.gravitee.repository.management.model.View.AuditEvent.VIEW_UPDATED) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) View(io.gravitee.repository.management.model.View) Autowired(org.springframework.beans.factory.annotation.Autowired) NewViewEntity(io.gravitee.management.model.NewViewEntity) AuditService(io.gravitee.management.service.AuditService) Collectors(java.util.stream.Collectors) IdGenerator(io.gravitee.common.utils.IdGenerator) Component(org.springframework.stereotype.Component) VIEW_CREATED(io.gravitee.repository.management.model.View.AuditEvent.VIEW_CREATED) ViewRepository(io.gravitee.repository.management.api.ViewRepository) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) NewViewEntity(io.gravitee.management.model.NewViewEntity) DuplicateViewNameException(io.gravitee.management.service.exceptions.DuplicateViewNameException) View(io.gravitee.repository.management.model.View) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

IdGenerator (io.gravitee.common.utils.IdGenerator)1 NewViewEntity (io.gravitee.management.model.NewViewEntity)1 UpdateViewEntity (io.gravitee.management.model.UpdateViewEntity)1 ViewEntity (io.gravitee.management.model.ViewEntity)1 ApiService (io.gravitee.management.service.ApiService)1 AuditService (io.gravitee.management.service.AuditService)1 ViewService (io.gravitee.management.service.ViewService)1 DuplicateViewNameException (io.gravitee.management.service.exceptions.DuplicateViewNameException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 ViewRepository (io.gravitee.repository.management.api.ViewRepository)1 VIEW (io.gravitee.repository.management.model.Audit.AuditProperties.VIEW)1 View (io.gravitee.repository.management.model.View)1 VIEW_CREATED (io.gravitee.repository.management.model.View.AuditEvent.VIEW_CREATED)1 VIEW_DELETED (io.gravitee.repository.management.model.View.AuditEvent.VIEW_DELETED)1 VIEW_UPDATED (io.gravitee.repository.management.model.View.AuditEvent.VIEW_UPDATED)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1