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;
}
Aggregations