Search in sources :

Example 1 with OrganizationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity 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 OrganizationEntity

use of py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity 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 3 with OrganizationEntity

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

the class OrganizationServiceImpl method listOrganizations.

@Override
public PaginableList<OrganizationDTO> listOrganizations(Long applicationId, Long organizationId, int page, int perPage, String orderBy, String sortBy) {
    PaginableList<OrganizationDTO> response;
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
    Page<OrganizationEntity> pageResponse = organizationRepository.findAll(where(byFilter(applicationId, organizationId)), pageRequest);
    if (pageResponse == null) {
        return new PaginableList<>(Collections.emptyList());
    } else {
        Page<OrganizationDTO> organizationPage = pageResponse.map(new Converter<OrganizationEntity, OrganizationDTO>() {

            @Override
            public OrganizationDTO convert(OrganizationEntity source) {
                return organizationMapper.entityToDto(source);
            }
        });
        response = new PaginableList<OrganizationDTO>(organizationPage, organizationPage.getContent());
    }
    return response;
}
Also used : PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PaginableList(py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)

Example 4 with OrganizationEntity

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

the class FamilyServiceImpl method createOrReturnFamilyFromSnapshot.

@Override
public FamilyEntity createOrReturnFamilyFromSnapshot(UserDetailsDTO details, NewSnapshot snapshot, String code, PersonEntity person) {
    if (familyRepository.findByCode(code).isPresent()) {
        return familyRepository.findByCode(code).get();
    }
    FamilyEntity newFamily = new FamilyEntity();
    newFamily.setPerson(person);
    newFamily.setCode(code);
    newFamily.setName(person.getFirstName().concat(SPACE).concat(person.getLastName()));
    newFamily.setLocationPositionGps(snapshot.getEconomicSurveyData().getAsString("familyUbication"));
    if (details.getApplication() != null) {
        newFamily.setApplication(applicationMapper.dtoToEntity(details.getApplication()));
    }
    newFamily.setActive(true);
    Optional<CountryEntity> country = countryRepository.findByCountry(snapshot.getEconomicSurveyData().getAsString("familyCountry"));
    newFamily.setCountry(country.orElse(null));
    Optional<CityEntity> city = cityRepository.findByCity(snapshot.getEconomicSurveyData().getAsString("familyCity"));
    newFamily.setCity(city.orElse(null));
    if (snapshot.getOrganizationId() != null) {
        OrganizationEntity organization = organizationRepository.findOne(snapshot.getOrganizationId());
        newFamily.setOrganization(organization);
        newFamily.setApplication(organization.getApplication());
    }
    newFamily = familyRepository.save(newFamily);
    return newFamily;
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) CityEntity(py.org.fundacionparaguaya.pspserver.system.entities.CityEntity) CountryEntity(py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity)

Example 5 with OrganizationEntity

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

the class UserServiceImpl method createUserOrganization.

private UserApplicationEntity createUserOrganization(UserEntity user, UserRoleApplicationDTO userRoleApplicationDTO) {
    UserApplicationEntity userApplicationEntity = new UserApplicationEntity();
    userApplicationEntity.setUser(user);
    OrganizationEntity organization = organizationRepository.findById(userRoleApplicationDTO.getOrganizationId());
    userApplicationEntity.setOrganization(organization);
    userApplicationEntity.setApplication(organization.getApplication());
    return userApplicationRepository.save(userApplicationEntity);
}
Also used : OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Aggregations

OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)6 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)2 ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)2 UserApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1 Direction (org.springframework.data.domain.Sort.Direction)1 Specification (org.springframework.data.jpa.domain.Specification)1 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 Service (org.springframework.stereotype.Service)1 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1 PaginableList (py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList)1 PspPageRequest (py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest)1 StringConverter (py.org.fundacionparaguaya.pspserver.common.utils.StringConverter)1