use of com.bigcrowd.noticeBoard.dto.savesDTO.PrayerSaveDTO in project Notice-Board by FulvioFPimentel.
the class MeetingService method insert.
@Transactional
public MeetingSaveDTO insert(MeetingSaveDTO dto) {
Meeting meeting = new Meeting();
Assignment assignment = assignmentRepository.getById(dto.getPresidency().getDesignation().getAssignment().getId());
Person person = personRepository.getById(dto.getPresidency().getDesignation().getPerson().getId());
Designation designation = new Designation();
designation.setAssignment(assignment);
designation.setPerson(person);
Presidency presidency = new Presidency();
presidency.setDesignation(designation);
presidency.setMeeting(meeting);
presidency = presidencyRepository.saveAndFlush(presidency);
for (CanticleSaveDTO cDto : dto.getCanticles()) {
Canticle canticle = canticleRepository.getById(cDto.getId());
meeting.getCanticles().add(canticle);
}
for (PrayerSaveDTO pDto : dto.getPrayers()) {
Assignment prayerAssignment = assignmentRepository.getById(pDto.getDesignation().getAssignment().getId());
Person prayerPerson = personRepository.getById(pDto.getDesignation().getPerson().getId());
Designation prayerDesignation = new Designation();
prayerDesignation.setAssignment(prayerAssignment);
prayerDesignation.setPerson(prayerPerson);
Prayer prayer = new Prayer();
prayer.setMoment(pDto.getMoment());
prayer.setDesignation(prayerDesignation);
prayer.setMeeting(meeting);
prayer = prayerRepository.saveAndFlush(prayer);
meeting.getPrayers().add(prayer);
}
Session session;
for (SessionSaveDTO sDto : dto.getSessions()) {
if (sDto.getId() == null) {
session = new Session();
session.setSession(sDto.getSession());
sessionRepository.saveAndFlush(session);
} else {
session = sessionRepository.getById(sDto.getId());
}
for (SubSessionSaveDTO ssDto : sDto.getSubsessions()) {
SubSession subsession;
if (ssDto.getId() == null) {
subsession = new SubSession();
subsession.setSubSession(ssDto.getSubSession());
subSessionRepository.saveAndFlush(subsession);
} else {
subsession = subSessionRepository.getById(ssDto.getId());
}
Segmentation segmantation = new Segmentation();
segmantation.setMeeting(meeting);
segmantation.setSession(session);
segmantation.setSubSession(subsession);
segmantation = segmentationRepository.saveAndFlush(segmantation);
for (DesignationSaveDTO dDto : ssDto.getDesignations()) {
Person subPerson = personRepository.getById(dDto.getPerson().getId());
Assignment subAssignment = assignmentRepository.getById(dDto.getAssignment().getId());
Designation subDesignation = new Designation();
subDesignation.setPerson(subPerson);
subDesignation.setAssignment(subAssignment);
subDesignation.getSegmentations().add(segmantation);
subDesignation = designationRepository.saveAndFlush(subDesignation);
}
meeting.getSegmentations().add(segmantation);
}
}
meeting.setDate(dto.getDate());
meeting.setPresidency(presidency);
meeting = repository.saveAndFlush(meeting);
return new MeetingSaveDTO(meeting, presidency);
}
use of com.bigcrowd.noticeBoard.dto.savesDTO.PrayerSaveDTO in project Notice-Board by FulvioFPimentel.
the class MeetingService method update.
@Transactional
public MeetingSaveDTO update(Long id, MeetingSaveDTO dto) {
Meeting meeting = repository.getById(id);
Assignment assignment = assignmentRepository.getById(dto.getPresidency().getDesignation().getAssignment().getId());
Person person = personRepository.getById(dto.getPresidency().getDesignation().getPerson().getId());
Designation desigPresidency = designationRepository.getById(meeting.getPresidency().getDesignation().getId());
desigPresidency.setAssignment(assignment);
desigPresidency.setPerson(person);
desigPresidency = designationRepository.saveAndFlush(desigPresidency);
Presidency presidency = presidencyRepository.getById(meeting.getPresidency().getId());
presidency.setMeeting(meeting);
presidency.setDesignation(desigPresidency);
presidency = presidencyRepository.saveAndFlush(presidency);
meeting.getCanticles().clear();
for (CanticleSaveDTO cDto : dto.getCanticles()) {
Canticle canticle = canticleRepository.getById(cDto.getId());
canticle = canticleRepository.saveAndFlush(canticle);
meeting.getCanticles().add(canticle);
}
meeting.getPrayers().clear();
for (PrayerSaveDTO pDto : dto.getPrayers()) {
Assignment prayerAssignment = assignmentRepository.getById(pDto.getDesignation().getAssignment().getId());
Person prayerPerson = personRepository.getById(pDto.getDesignation().getPerson().getId());
Designation prayerDesignation = designationRepository.getById(pDto.getDesignation().getId());
prayerDesignation.setAssignment(prayerAssignment);
prayerDesignation.setPerson(prayerPerson);
Prayer prayer = prayerRepository.getById(pDto.getId());
prayer.setMoment(pDto.getMoment());
prayer.setDesignation(prayerDesignation);
prayer.setMeeting(meeting);
prayer = prayerRepository.saveAndFlush(prayer);
meeting.getPrayers().add(prayer);
}
long sessionID = 0;
for (SessionSaveDTO sDTO : dto.getSessions()) {
for (Segmentation s : meeting.getSegmentations()) {
if (sDTO.getId() == s.getSession().getId()) {
if (sessionID == 0 || sessionID != sDTO.getId()) {
Session session = sessionRepository.getById(s.getSession().getId());
sessionID = sDTO.getId();
session.setSession(sDTO.getSession());
session = sessionRepository.saveAndFlush(session);
}
}
}
for (SubSessionSaveDTO ssDTO : sDTO.getSubsessions()) {
for (Segmentation s : meeting.getSegmentations()) {
if (ssDTO.getId() == s.getSubSession().getId()) {
SubSession subsession = subSessionRepository.getById(s.getSubSession().getId());
subsession.setSubSession(ssDTO.getSubSession());
subsession = subSessionRepository.saveAndFlush(subsession);
}
}
for (DesignationSaveDTO dDTO : ssDTO.getDesignations()) {
long designationID = 0;
for (Segmentation s : meeting.getSegmentations()) {
for (Designation desig : s.getDesignations()) {
if (designationID != dDTO.getId() && desig.getId() == dDTO.getId()) {
Designation designation = designationRepository.getById(desig.getId());
Person personDesig = personRepository.getById(dDTO.getPerson().getId());
Assignment assignmentDesig = assignmentRepository.getById(dDTO.getAssignment().getId());
designation.setPerson(personDesig);
designation.setAssignment(assignmentDesig);
designation = designationRepository.saveAndFlush(designation);
}
}
}
}
}
}
meeting.setDate(dto.getDate());
meeting = repository.saveAndFlush(meeting);
return new MeetingSaveDTO(meeting);
}
Aggregations