Search in sources :

Example 1 with ApplicationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class UserDetailsServiceImpl method loadUserByUsername.

@Override
public UserDetailsDTO loadUserByUsername(String username) throws UsernameNotFoundException {
    LOG.info("Loading user details: {}", username);
    UserEntity user = userRepository.findOneByUsername(username).orElseThrow(() -> new UsernameNotFoundException("Username not found " + username));
    List<UserRoleEntity> roles = userRoleRepo.findByUser(user);
    UserApplicationEntity userApp = userApplicationRepo.findByUser(user).orElseGet(UserApplicationEntity::new);
    Optional<OrganizationEntity> organization = userApp.getOrganizationOpt();
    Optional<ApplicationEntity> application = userApp.getApplicationOpt();
    return UserDetailsDTO.builder().username(user.getUsername()).password(user.getPass()).enabled(user.isActive()).application(application.map(applicationMapper::entityToDto).orElse(null)).organization(organization.map(organizationMapper::entityToDto).orElse(null)).grantedAuthorities(this.getGrantedAuthorities(roles)).build();
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserRoleEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Example 2 with ApplicationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class UserServiceImpl method createUserApplication.

private UserApplicationEntity createUserApplication(UserEntity user, UserRoleApplicationDTO userRoleApplicationDTO) {
    UserApplicationEntity userApplicationEntity = new UserApplicationEntity();
    userApplicationEntity.setUser(user);
    ApplicationEntity application = applicationRepository.findById(userRoleApplicationDTO.getApplicationId());
    userApplicationEntity.setApplication(application);
    return userApplicationRepository.save(userApplicationEntity);
}
Also used : ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Example 3 with ApplicationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SurveyOrganizationServiceImpl method crudSurveyOrganization.

@Override
public void crudSurveyOrganization(UserDetailsDTO details, Long surveyId, SurveyDefinition surveyDefinition, SurveyEntity surveyEntity) {
    ApplicationEntity applicationEntity;
    SurveyOrganizationEntity surveyOrganizationEntity;
    List<SurveyOrganizationEntity> surveyOrganizationEntityList = new ArrayList<SurveyOrganizationEntity>();
    List<SurveyOrganizationEntity> tempSurveyOrganizationEntityList;
    ApplicationDTO applicationDTOCheck = details.getApplication();
    // is hub_admin
    if (applicationDTOCheck != null) {
        // deletes former organizations assigned to a survey
        repo.deleteBySurveyIdAndApplicationIdAndOrganizationIsNotNull(surveyId, applicationDTOCheck.getId());
        for (OrganizationDTO organizationDTO : surveyDefinition.getOrganizations()) {
            surveyOrganizationEntity = new SurveyOrganizationEntity();
            surveyOrganizationEntity.setOrganization(organizationRepo.findById(organizationDTO.getId()));
            surveyOrganizationEntity.setApplication(applicationRepo.findById(applicationDTOCheck.getId()));
            surveyOrganizationEntity.setSurvey(surveyEntity);
            surveyOrganizationEntityList.add(surveyOrganizationEntity);
        }
        // saves the new list of organizations assigned to a survey
        repo.save(surveyOrganizationEntityList);
    }
    // is root
    if (applicationDTOCheck == null) {
        for (ApplicationDTO applicationDTO : surveyDefinition.getApplications()) {
            // brings all associated surveys with the corresponding applications and organizations
            tempSurveyOrganizationEntityList = repo.findBySurveyIdAndApplicationId(surveyId, applicationDTO.getId());
            if (tempSurveyOrganizationEntityList != null && tempSurveyOrganizationEntityList.size() > 0) {
                surveyOrganizationEntityList.addAll(tempSurveyOrganizationEntityList);
            } else {
                applicationEntity = applicationRepo.findById(applicationDTO.getId());
                surveyOrganizationEntity = new SurveyOrganizationEntity();
                surveyOrganizationEntity.setApplication(applicationEntity);
                surveyOrganizationEntity.setSurvey(surveyEntity);
                surveyOrganizationEntityList.add(surveyOrganizationEntity);
            }
        }
        // deletes old application list
        repo.deleteBySurveyId(surveyId);
        repo.flush();
        // saves new application list
        repo.save(surveyOrganizationEntityList);
    }
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) ArrayList(java.util.ArrayList) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) SurveyOrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.SurveyOrganizationDTO) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)

Example 4 with ApplicationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class OrganizationServiceImpl method addOrganization.

@Override
public OrganizationDTO addOrganization(OrganizationDTO organizationDTO) {
    organizationRepository.findOneByName(organizationDTO.getName()).ifPresent(organization -> {
        throw new CustomParameterizedException("Organisation already exists", new ImmutableMultimap.Builder<String, String>().put("name", organization.getName()).build().asMap());
    });
    OrganizationEntity organization = new OrganizationEntity();
    BeanUtils.copyProperties(organizationDTO, organization);
    ApplicationEntity application = applicationRepository.findById(organizationDTO.getApplication().getId());
    organization.setApplication(application);
    organization.setActive(true);
    if (organizationDTO.getFile() != null) {
        ImageDTO imageDTO = ImageParser.parse(organizationDTO.getFile(), applicationProperties.getAws().getOrgsImageDirectory());
        String generatedURL = imageUploadService.uploadImage(imageDTO);
        organization.setLogoUrl(generatedURL);
    }
    return organizationMapper.entityToDto(organizationRepository.save(organization));
}
Also used : CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) ImageDTO(py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO)

Example 5 with ApplicationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class ApplicationServiceImpl method addApplication.

@Override
public ApplicationDTO addApplication(ApplicationDTO applicationDTO) {
    applicationRepository.findOneByName(applicationDTO.getName()).ifPresent(application -> {
        throw new CustomParameterizedException("Application already exists", new ImmutableMultimap.Builder<String, String>().put("name", application.getName()).build().asMap());
    });
    ApplicationEntity application = new ApplicationEntity();
    BeanUtils.copyProperties(applicationDTO, application);
    application.setHub(true);
    application.setActive(true);
    if (applicationDTO.getFile() != null) {
        ImageDTO imageDTO = ImageParser.parse(applicationDTO.getFile(), applicationProperties.getAws().getHubsImageDirectory());
        String generatedURL = imageUploadService.uploadImage(imageDTO);
        application.setLogoUrl(generatedURL);
    }
    return applicationMapper.entityToDto(applicationRepository.save(application));
}
Also used : CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) ImageDTO(py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO)

Aggregations

ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)7 ArrayList (java.util.ArrayList)2 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)2 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)2 OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)2 UserApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)2 ImageDTO (py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO)2 LocalDateTime (java.time.LocalDateTime)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Predicate (javax.persistence.criteria.Predicate)1 Root (javax.persistence.criteria.Root)1 PageRequest (org.springframework.data.domain.PageRequest)1 Specification (org.springframework.data.jpa.domain.Specification)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PaginableList (py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList)1 PspPageRequest (py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest)1 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)1 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)1 SurveyOrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.SurveyOrganizationDTO)1