use of py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity 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.SurveyOrganizationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyOrganizationServiceImpl method addSurveyOrganization.
@Override
public SurveyOrganizationDTO addSurveyOrganization(SurveyOrganizationDTO surveyOrganization) {
SurveyOrganizationEntity entity = new SurveyOrganizationEntity();
entity.setSurvey(surveyRepo.findOne(surveyOrganization.getSurvey().getId()));
entity.setOrganization(organizationRepo.findOne(surveyOrganization.getOrganization().getId()));
return mapper.entityToDto(repo.save(entity));
}
use of py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyServiceImpl method addSurveyDefinition.
@Override
public SurveyDefinition addSurveyDefinition(NewSurveyDefinition surveyDefinition) {
ValidationResults results = validateSchemas(surveyDefinition);
if (!results.isValid()) {
throw new CustomParameterizedException("Invalid Survey Schema", results.asMap());
}
SurveyEntity entity = this.repo.save(SurveyEntity.of(surveyDefinition.getTitle(), surveyDefinition.getDescription(), new SurveyDefinition().surveySchema(surveyDefinition.getSurveySchema()).surveyUISchema(surveyDefinition.getSurveyUISchema())));
if (surveyDefinition.getOrganizations() != null && surveyDefinition.getOrganizations().size() > 0) {
for (OrganizationDTO organization : surveyDefinition.getOrganizations()) {
if (surveyOrganizationRepo.findBySurveyIdAndApplicationIdAndOrganizationId(entity.getId(), organization.getApplication().getId(), organization.getId()) == null) {
SurveyOrganizationEntity surveyOrganization = new SurveyOrganizationEntity();
surveyOrganization.setSurvey(entity);
surveyOrganization.setApplication(applicationRepo.findById(organization.getApplication().getId()));
surveyOrganization.setOrganization(organizationRepo.findById(organization.getId()));
surveyOrganizationRepo.save(surveyOrganization);
}
}
}
if (surveyDefinition.getApplications() != null) {
for (ApplicationDTO application : surveyDefinition.getApplications()) {
SurveyOrganizationEntity surveyOrganization = new SurveyOrganizationEntity();
surveyOrganization.setSurvey(entity);
surveyOrganization.setApplication(applicationRepo.findById(application.getId()));
surveyOrganizationRepo.save(surveyOrganization);
}
}
return new SurveyDefinition().id(entity.getId()).title(entity.getTitle()).description(entity.getDescription()).surveySchema(entity.getSurveyDefinition().getSurveySchema()).surveyUISchema(entity.getSurveyDefinition().getSurveyUISchema()).organizations(surveyDefinition.getOrganizations());
}
Aggregations