use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyServiceImpl method getSurveyDefinition.
@Override
public SurveyDefinition getSurveyDefinition(Long surveyId) {
checkNotNull(surveyId);
checkArgument(surveyId > 0, "Argument was %s but expected nonnegative", surveyId);
return Optional.ofNullable(repo.findOne(surveyId)).map(entity -> new SurveyDefinition().id(entity.getId()).description(entity.getDescription()).title(entity.getTitle()).surveySchema(entity.getSurveyDefinition().getSurveySchema()).surveyUiSchema(entity.getSurveyDefinition().getSurveyUISchema()).organizations(organizationMapper.entityListToDtoList(surveyOrganizationRepo.findBySurveyId(entity.getId()).stream().map(o -> o.getOrganization()).collect(Collectors.toList()))).applications(applicationMapper.entityListToDtoList(surveyOrganizationRepo.findBySurveyId(entity.getId()).stream().map(o -> o.getApplication()).collect(Collectors.toList())))).orElseThrow(() -> new UnknownResourceException("Survey definition does not exist"));
}
use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyServiceImpl method checkSchemaCompliance.
@Override
public ValidationResults checkSchemaCompliance(NewSnapshot snapshot) {
SurveyDefinition surveyDefinition = this.getSurveyDefinition(snapshot.getSurveyId());
SurveySchema schema = surveyDefinition.getSurveySchema();
ValidationResults results = ValidationSupport.validResults();
schema.getProperties().entrySet().stream().forEach(propertyEntry -> {
Property property = propertyEntry.getValue();
Object propertyValue = snapshot.getAllSurveyData().get(propertyEntry.getKey());
results.add(propertyValue != null ? validType().apply(property, propertyEntry.getKey(), propertyValue) : ValidationResult.valid());
results.add(requiredValue().apply(schema, propertyEntry.getKey(), propertyValue));
});
snapshot.getAllSurveyData().entrySet().stream().forEach(surveyData -> {
results.add(presentInSchema().apply(schema, surveyData.getKey(), surveyData.getValue()));
});
return results;
}
Aggregations