Search in sources :

Example 1 with SurveySchema

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"));
}
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 2 with SurveySchema

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;
}
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

NewSurveyDefinition (py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition)2 Property (py.org.fundacionparaguaya.pspserver.surveys.dtos.Property)2 SurveyDefinition (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition)2 SurveySchema (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1 UnknownResourceException (py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)1 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)1 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)1 SurveyOrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)1 ApplicationMapper (py.org.fundacionparaguaya.pspserver.network.mapper.ApplicationMapper)1