Search in sources :

Example 1 with Person

use of com.bigcrowd.noticeBoard.entities.Person 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);
}
Also used : Designation(com.bigcrowd.noticeBoard.entities.Designation) DesignationSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.DesignationSaveDTO) Canticle(com.bigcrowd.noticeBoard.entities.Canticle) SubSession(com.bigcrowd.noticeBoard.entities.SubSession) Segmentation(com.bigcrowd.noticeBoard.entities.Segmentation) Meeting(com.bigcrowd.noticeBoard.entities.Meeting) SubSessionSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.SubSessionSaveDTO) SessionSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.SessionSaveDTO) Presidency(com.bigcrowd.noticeBoard.entities.Presidency) SubSessionSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.SubSessionSaveDTO) CanticleSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.CanticleSaveDTO) Assignment(com.bigcrowd.noticeBoard.entities.Assignment) MeetingSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.MeetingSaveDTO) PrayerSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.PrayerSaveDTO) Person(com.bigcrowd.noticeBoard.entities.Person) Prayer(com.bigcrowd.noticeBoard.entities.Prayer) SubSession(com.bigcrowd.noticeBoard.entities.SubSession) Session(com.bigcrowd.noticeBoard.entities.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Person

use of com.bigcrowd.noticeBoard.entities.Person in project Notice-Board by FulvioFPimentel.

the class JwtTokenEnhancer method enhance.

@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    Person person = personRepository.findByName(authentication.getName());
    System.out.println(person.getName());
    Map<String, Object> map = new HashMap<>();
    map.put("userName", person.getName());
    map.put("userId", person.getId());
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
    token.setAdditionalInformation(map);
    return accessToken;
}
Also used : HashMap(java.util.HashMap) Person(com.bigcrowd.noticeBoard.entities.Person) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)

Example 3 with Person

use of com.bigcrowd.noticeBoard.entities.Person in project Notice-Board by FulvioFPimentel.

the class PersonService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Person person = personRepository.findByName(username);
    if (person == null) {
        logger.error(" not found: " + username);
        throw new UsernameNotFoundException("Name not found");
    }
    logger.info("Person found: " + username);
    return person;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Person(com.bigcrowd.noticeBoard.entities.Person)

Example 4 with Person

use of com.bigcrowd.noticeBoard.entities.Person in project Notice-Board by FulvioFPimentel.

the class PersonService method updatePersonRole.

public PersonSaveDTO updatePersonRole(Long id, PersonSaveDTO dto) {
    authService.validateSelfOrAdmin(id);
    Person person = personRepository.getById(id);
    person.setName(dto.getName());
    person.setCellPhone(dto.getCellPhone());
    person.setPassword(passwordEncoder.encode(dto.getPassword()));
    person.getRoles().clear();
    for (RoleDTO roles : dto.getRoles()) {
        Role role = roleRepository.getById(roles.getId());
        role = roleRepository.saveAndFlush(role);
        person.getRoles().add(role);
    }
    person = personRepository.saveAndFlush(person);
    return new PersonSaveDTO(person);
}
Also used : RoleDTO(com.bigcrowd.noticeBoard.dto.RoleDTO) Role(com.bigcrowd.noticeBoard.entities.Role) PersonSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.PersonSaveDTO) Person(com.bigcrowd.noticeBoard.entities.Person)

Example 5 with Person

use of com.bigcrowd.noticeBoard.entities.Person 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);
}
Also used : Designation(com.bigcrowd.noticeBoard.entities.Designation) DesignationSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.DesignationSaveDTO) Canticle(com.bigcrowd.noticeBoard.entities.Canticle) Segmentation(com.bigcrowd.noticeBoard.entities.Segmentation) SubSession(com.bigcrowd.noticeBoard.entities.SubSession) Meeting(com.bigcrowd.noticeBoard.entities.Meeting) SubSessionSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.SubSessionSaveDTO) SessionSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.SessionSaveDTO) Presidency(com.bigcrowd.noticeBoard.entities.Presidency) SubSessionSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.SubSessionSaveDTO) CanticleSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.CanticleSaveDTO) Assignment(com.bigcrowd.noticeBoard.entities.Assignment) MeetingSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.MeetingSaveDTO) PrayerSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.PrayerSaveDTO) Person(com.bigcrowd.noticeBoard.entities.Person) Prayer(com.bigcrowd.noticeBoard.entities.Prayer) SubSession(com.bigcrowd.noticeBoard.entities.SubSession) Session(com.bigcrowd.noticeBoard.entities.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Person (com.bigcrowd.noticeBoard.entities.Person)10 Transactional (org.springframework.transaction.annotation.Transactional)6 Designation (com.bigcrowd.noticeBoard.entities.Designation)5 DesignationSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.DesignationSaveDTO)4 Assignment (com.bigcrowd.noticeBoard.entities.Assignment)4 Meeting (com.bigcrowd.noticeBoard.entities.Meeting)3 CanticleSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.CanticleSaveDTO)2 MeetingSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.MeetingSaveDTO)2 PersonSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.PersonSaveDTO)2 PrayerSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.PrayerSaveDTO)2 SessionSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.SessionSaveDTO)2 SubSessionSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.SubSessionSaveDTO)2 Canticle (com.bigcrowd.noticeBoard.entities.Canticle)2 Prayer (com.bigcrowd.noticeBoard.entities.Prayer)2 Presidency (com.bigcrowd.noticeBoard.entities.Presidency)2 Role (com.bigcrowd.noticeBoard.entities.Role)2 Segmentation (com.bigcrowd.noticeBoard.entities.Segmentation)2 Session (com.bigcrowd.noticeBoard.entities.Session)2 SubSession (com.bigcrowd.noticeBoard.entities.SubSession)2 Support (com.bigcrowd.noticeBoard.entities.Support)2