/** * Creation d'une nouvelle talk * * @param event * @return */ @Override public CreatedEvent<Talk> createTalk(Talk event) { Preconditions.checkNotNull(event); Preconditions.checkNotNull(event.getName(), "talk is required to create it"); CreatedEvent<Talk> eventReturned = new CreatedEvent(transformAndSaveTalkDetailToTalk(event, true)); LOG.debug( String.format( "Creation du talk ayant id=[%d] name=[%s] UUID:%s", ((Talk) eventReturned.getValue()).getId(), event.getName(), eventReturned.getKey().toString())); return eventReturned; }
@Override public UpdatedEvent<Talk> updateTalk(Talk event) { Preconditions.checkNotNull(event); Preconditions.checkNotNull(event.getId(), "talk is required to update it"); Talk talkUpdated = transformAndSaveTalkDetailToTalk(event, false); UpdatedEvent<Talk> eventReturned = new UpdatedEvent(talkUpdated != null, talkUpdated); LOG.debug( String.format( "Modification du talk ayant id=[%d] name=[%s] UUID:%s", talkUpdated != null ? talkUpdated.getId() : null, talkUpdated != null ? talkUpdated.getName() : null, eventReturned.getKey().toString())); return eventReturned; }
/** * Permet de convertir la donnée reçue * * @param talk * @return */ private Talk transformAndSaveTalkDetailToTalk(Talk talk, boolean creation) { // Si pas en creation on regarde si enreg existe if (!creation) { Talk talkToPersist = talkRepository.findOne(talk.getId()); if (talkToPersist == null) { return null; } talkToPersist.setLevel(talk.getLevel()); talkToPersist.setNbpeoplemax(talk.getNbpeoplemax()); talkToPersist.setPlace(talk.getPlace()); talkToPersist.setDescription(talk.getDescription()); talkToPersist.setName(talk.getName()); return talkToPersist; } else { // On enregistre return talkRepository.save(talk); } }