Search in sources :

Example 1 with SurveyDefinition

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;
}
Also used : SnapshotEconomicMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotEconomicMapper) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) LoggerFactory(org.slf4j.LoggerFactory) FamilyService(py.org.fundacionparaguaya.pspserver.families.services.FamilyService) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) I18n(py.org.fundacionparaguaya.pspserver.config.I18n) StringUtils(org.apache.commons.lang3.StringUtils) UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO) SnapshotEconomicSpecification.byApplication(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.byApplication) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) PersonMapper(py.org.fundacionparaguaya.pspserver.families.mapper.PersonMapper) Map(java.util.Map) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) SnapshotService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotService) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicSpecification.createdAtLess2Months(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.createdAtLess2Months) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO) OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) HashMap(java.util.HashMap) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorPriorityService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotIndicatorPriorityService) Logger(org.slf4j.Logger) Snapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.Snapshot) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) PropertyTitle(py.org.fundacionparaguaya.pspserver.surveys.dtos.PropertyTitle) SurveyStoplightEnum(py.org.fundacionparaguaya.pspserver.surveys.enums.SurveyStoplightEnum) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken) DateTimeFormatter(java.time.format.DateTimeFormatter) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) Transactional(org.springframework.transaction.annotation.Transactional) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) ArrayList(java.util.ArrayList) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 2 with SurveyDefinition

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"));
}
Also used : OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SurveyMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SurveyMapper) LocalDateTime(java.time.LocalDateTime) SchemaValidator.requiredValue(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.requiredValue) ArrayList(java.util.ArrayList) SurveySchema(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) MultipleSchemaValidator(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator) ApplicationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.ApplicationRepository) Service(org.springframework.stereotype.Service) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity) SurveyOrganizationService(py.org.fundacionparaguaya.pspserver.network.services.SurveyOrganizationService) PropertyValidator.validType(py.org.fundacionparaguaya.pspserver.surveys.validation.PropertyValidator.validType) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) Property(py.org.fundacionparaguaya.pspserver.surveys.dtos.Property) PropertyAttributeSupport(py.org.fundacionparaguaya.pspserver.surveys.mapper.PropertyAttributeSupport) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SurveyOrganizationSpecification.lastModifiedGt(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.lastModifiedGt) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) MultipleSchemaValidator.all(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator.all) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SurveyRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SurveyRepository) ValidationResult(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResult) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SurveyOrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.SurveyOrganizationRepository) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) ApplicationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.ApplicationMapper) List(java.util.List) StopLightType(py.org.fundacionparaguaya.pspserver.surveys.entities.StopLightType) ValidationSupport(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationSupport) SurveyOrganizationSpecification.byOrganization(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byOrganization) SchemaValidator.presentInSchema(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.presentInSchema) Optional(java.util.Optional) SurveyOrganizationSpecification.byApplication(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byApplication) SchemaValidator.markedAsRequired(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.markedAsRequired) Transactional(org.springframework.transaction.annotation.Transactional) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 3 with SurveyDefinition

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;
}
Also used : OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SurveyMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SurveyMapper) LocalDateTime(java.time.LocalDateTime) SchemaValidator.requiredValue(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.requiredValue) ArrayList(java.util.ArrayList) SurveySchema(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) MultipleSchemaValidator(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator) ApplicationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.ApplicationRepository) Service(org.springframework.stereotype.Service) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity) SurveyOrganizationService(py.org.fundacionparaguaya.pspserver.network.services.SurveyOrganizationService) PropertyValidator.validType(py.org.fundacionparaguaya.pspserver.surveys.validation.PropertyValidator.validType) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) Property(py.org.fundacionparaguaya.pspserver.surveys.dtos.Property) PropertyAttributeSupport(py.org.fundacionparaguaya.pspserver.surveys.mapper.PropertyAttributeSupport) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SurveyOrganizationSpecification.lastModifiedGt(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.lastModifiedGt) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) MultipleSchemaValidator.all(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator.all) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SurveyRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SurveyRepository) ValidationResult(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResult) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SurveyOrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.SurveyOrganizationRepository) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) ApplicationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.ApplicationMapper) List(java.util.List) StopLightType(py.org.fundacionparaguaya.pspserver.surveys.entities.StopLightType) ValidationSupport(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationSupport) SurveyOrganizationSpecification.byOrganization(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byOrganization) SchemaValidator.presentInSchema(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.presentInSchema) Optional(java.util.Optional) SurveyOrganizationSpecification.byApplication(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byApplication) SchemaValidator.markedAsRequired(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.markedAsRequired) Transactional(org.springframework.transaction.annotation.Transactional) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) MultipleSchemaValidator(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator)

Example 4 with SurveyDefinition

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)));
}
Also used : SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 5 with SurveyDefinition

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;
}
Also used : ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SurveySchema(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) Property(py.org.fundacionparaguaya.pspserver.surveys.dtos.Property)

Aggregations

SurveyDefinition (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition)8 NewSurveyDefinition (py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition)6 ValidationResults (py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults)6 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)4 Service (org.springframework.stereotype.Service)4 Transactional (org.springframework.transaction.annotation.Transactional)4 UnknownResourceException (py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)4 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)4 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)4 SurveyOrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)4 OrganizationMapper (py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper)4 OrganizationRepository (py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository)4 Role (py.org.fundacionparaguaya.pspserver.security.constants.Role)4 UserDetailsDTO (py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO)4