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