use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotServiceImpl method getIndicatorsValue.
private List<SurveyData> getIndicatorsValue(SnapshotEconomicEntity snapshotEconomic, SnapshotIndicators toRet) {
SurveyDefinition survey = surveyService.getSurveyDefinition(snapshotEconomic.getSurveyDefinition().getId());
List<String> indicatorGroup = survey.getSurveyUISchema().getGroupIndicators();
List<String> order = survey.getSurveyUISchema().getUiOrder().stream().filter(field -> indicatorGroup.contains(field)).collect(Collectors.toList());
SurveyData indicators = indicatorMapper.entityToDto(snapshotEconomic.getSnapshotIndicator());
List<SurveyData> indicatorsToRet = new ArrayList<>();
if (indicatorGroup != null && !indicatorGroup.isEmpty() && order != null && !order.isEmpty()) {
order.forEach(indicator -> {
if (indicators.containsKey(indicator)) {
SurveyData sd = new SurveyData();
sd.put(INDICATOR_NAME, getDescriptionOpt(survey, indicator).map(e -> e.get("es")).orElse(getNameFromCamelCase(indicator)));
sd.put(INDICATOR_VALUE, indicators.get(indicator));
countIndicators(toRet, sd.get(INDICATOR_VALUE));
indicatorsToRet.add(sd);
}
});
}
return indicatorsToRet;
}
use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition 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.SurveyDefinition in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyServiceImpl method validateSchemas.
private ValidationResults validateSchemas(NewSurveyDefinition surveyDefinition) {
ValidationResults results = ValidationSupport.validResults();
MultipleSchemaValidator schemaValidator = all(presentInSchema(), markedAsRequired());
propertyAttributeSupport.getPropertyAttributes().stream().filter(attr -> attr.getStoptLightType() == StopLightType.MANDATORY).forEach(attr -> {
results.addAll(schemaValidator.apply(surveyDefinition.getSurveySchema(), attr.getPropertySchemaName(), null));
});
return results;
}
use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyControllerTest method shouldPostToCreateSurvey.
@Test
public void shouldPostToCreateSurvey() throws Exception {
SurveyDefinition definition = getDefinition();
when(surveyService.addSurveyDefinition(anyObject())).thenReturn(definition);
String content = TestHelper.mapToJson(definition);
this.mockMvc.perform(post("/api/v1/surveys").content(content).contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(print()).andExpect(status().isCreated()).andDo(document("surveys-post", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), requestFields(survey)));
}
use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition 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