Search in sources :

Example 6 with ViewEntity

use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.

the class ViewServiceImpl method convert.

private ViewEntity convert(final View view) {
    final ViewEntity viewEntity = new ViewEntity();
    viewEntity.setId(view.getId());
    viewEntity.setName(view.getName());
    viewEntity.setDescription(view.getDescription());
    viewEntity.setDefaultView(view.isDefaultView());
    viewEntity.setOrder(view.getOrder());
    viewEntity.setHidden(view.isHidden());
    viewEntity.setUpdatedAt(view.getUpdatedAt());
    viewEntity.setCreatedAt(view.getCreatedAt());
    return viewEntity;
}
Also used : ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) NewViewEntity(io.gravitee.management.model.NewViewEntity)

Example 7 with ViewEntity

use of io.gravitee.management.model.ViewEntity in project gravitee-management-rest-api by gravitee-io.

the class ViewServiceImpl method update.

@Override
public List<ViewEntity> update(final List<UpdateViewEntity> viewEntities) {
    final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
    viewEntities.forEach(viewEntity -> {
        try {
            View view = convert(viewEntity);
            Optional<View> viewOptional = viewRepository.findById(view.getId());
            if (viewOptional.isPresent()) {
                savedViews.add(convert(viewRepository.update(view)));
                auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_UPDATED, new Date(), viewOptional.get(), view);
            }
        } catch (TechnicalException ex) {
            LOGGER.error("An error occurs while trying to update view {}", viewEntity.getName(), ex);
            throw new TechnicalManagementException("An error occurs while trying to update view " + viewEntity.getName(), ex);
        }
    });
    return savedViews;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ViewEntity(io.gravitee.management.model.ViewEntity) UpdateViewEntity(io.gravitee.management.model.UpdateViewEntity) NewViewEntity(io.gravitee.management.model.NewViewEntity) View(io.gravitee.repository.management.model.View) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

ViewEntity (io.gravitee.management.model.ViewEntity)7 UpdateViewEntity (io.gravitee.management.model.UpdateViewEntity)5 View (io.gravitee.repository.management.model.View)5 NewViewEntity (io.gravitee.management.model.NewViewEntity)4 Test (org.junit.Test)4 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 Date (java.util.Date)2 IdGenerator (io.gravitee.common.utils.IdGenerator)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 ViewRepository (io.gravitee.repository.management.api.ViewRepository)1 VIEW (io.gravitee.repository.management.model.Audit.AuditProperties.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