DemandResponseEventService { @Transactional(readOnly = false) public DemandResponseEvent create(DemandResponseEventCreateDto dto) { DemandResponseEvent event = dtoMapper.map(dto, DemandResponseEvent.class); event.setCreatedTimestamp(System.currentTimeMillis()); event.setLastUpdateTimestamp(System.currentTimeMillis()); if (dto.isPublished()) { event.getDescriptor().setModificationNumber(0); } else { event.getDescriptor().setModificationNumber(-1); } Date dateStart = new Date(); dateStart.setTime(event.getActivePeriod().getStart()); Duration duration = datatypeFactory.newDuration(event.getActivePeriod().getDuration()); long durationInMillis = duration.getTimeInMillis(dateStart); event.getActivePeriod().setEnd(dateStart.getTime() + durationInMillis); Duration notificationDuration = datatypeFactory.newDuration(event.getActivePeriod().getNotificationDuration()); long notificationDurationInMillis = notificationDuration.getTimeInMillis(dateStart); event.getActivePeriod().setStartNotification(dateStart.getTime() - notificationDurationInMillis); DemandResponseEvent save = demandResponseEventDao.save(event); List<Ven> findByUsernameIn = findVenForTarget(event, dto.getTargets()); List<VenDemandResponseEvent> list = new ArrayList<>(); for (Ven ven : findByUsernameIn) { list.add(new VenDemandResponseEvent(event, ven)); } venDemandResponseEventDao.saveAll(list); event.getSignals().forEach(sig -> { sig.setEvent(save); }); demandResponseEventSignalDao.saveAll(event.getSignals()); for (Ven ven : findByUsernameIn) { if (demandResponseEventPublisher != null && event.isPublished()) { pushAsync(ven, event.getDescriptor().getOadrProfile()); } } return save; }  @PostConstruct void init(); @Transactional(readOnly = false) DemandResponseEvent create(DemandResponseEventCreateDto dto); @Transactional(readOnly = false) DemandResponseEvent update(DemandResponseEvent event, DemandResponseEventUpdateDto dto); void distributeEventToPushVen(DemandResponseEvent event); @Transactional(readOnly = false) DemandResponseEvent publish(DemandResponseEvent event); @Transactional(readOnly = false) DemandResponseEvent active(DemandResponseEvent event); @Transactional(readOnly = false) DemandResponseEvent cancel(DemandResponseEvent event); Optional<DemandResponseEvent> findById(Long id); List<DemandResponseEventSignal> getSignals(DemandResponseEvent event); boolean delete(Long id); void delete(Iterable<DemandResponseEvent> entities); boolean hasResponded(String venId, DemandResponseEvent event); void updateVenDemandResponseEvent(Long demandResponseEventId, Long modificationNumber, String venUsername,
			DemandResponseEventOptEnum venOpt); VenDemandResponseEvent getVenDemandResponseEvent(Long demandResponseEventId, String venUsername); DemandResponseEventOptEnum getVenDemandResponseEventOpt(Long demandResponseEventId, String venUsername); List<DemandResponseEvent> findToSentEventByVenUsername(String username); List<DemandResponseEvent> findToSentEventByVenUsername(String username, Long size); List<VenDemandResponseEvent> getVenDemandResponseEvent(Long demandResponseEventId); Page<DemandResponseEvent> search(List<DemandResponseEventFilter> filters, Long start, Long end); Page<DemandResponseEvent> search(List<DemandResponseEventFilter> filters, Long start, Long end, Integer page,
			Integer size);  }
@Test public void createTest() { long count = venDemandResponseEventDao.count(); assertEquals(4L, count); Iterable<VenDemandResponseEvent> findAll = venDemandResponseEventDao.findAll(); Iterator<VenDemandResponseEvent> iterator = findAll.iterator(); while (iterator.hasNext()) { VenDemandResponseEvent next = iterator.next(); assertEquals(-1, next.getLastSentModificationNumber()); assertNull(next.getVenOpt()); } }