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();
}
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));
}
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;
}
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;
}
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);
}
Aggregations