use of models.Version in project civiform by seattle-uat.
the class VersionRepositoryTest method updatePredicateNode.
@Test
public void updatePredicateNode() {
Version draft = versionRepository.getDraftVersion();
Version active = versionRepository.getActiveVersion();
// Old versions of questions
Question oldOne = resourceCreator.insertQuestion("one");
oldOne.addVersion(active);
oldOne.save();
Question oldTwo = resourceCreator.insertQuestion("two");
oldTwo.addVersion(active);
oldTwo.save();
// New versions of questions
Question newOne = resourceCreator.insertQuestion("one");
newOne.addVersion(draft);
newOne.save();
Question newTwo = resourceCreator.insertQuestion("two");
newTwo.addVersion(draft);
newTwo.save();
// Build a predicate tree that covers all node types:
// AND
// / \
// LEAF1 OR
// / \
// LEAF2 LEAF3
PredicateExpressionNode leafOne = PredicateExpressionNode.create(LeafOperationExpressionNode.create(oldOne.id, Scalar.TEXT, Operator.EQUAL_TO, PredicateValue.of("")));
PredicateExpressionNode leafTwo = PredicateExpressionNode.create(LeafOperationExpressionNode.create(oldTwo.id, Scalar.TEXT, Operator.EQUAL_TO, PredicateValue.of("")));
PredicateExpressionNode leafThree = PredicateExpressionNode.create(LeafOperationExpressionNode.create(oldOne.id, Scalar.NUMBER, Operator.LESS_THAN, PredicateValue.of(12)));
PredicateExpressionNode or = PredicateExpressionNode.create(OrNode.create(ImmutableSet.of(leafTwo, leafThree)));
PredicateExpressionNode and = PredicateExpressionNode.create(AndNode.create(ImmutableSet.of(leafOne, or)));
PredicateExpressionNode updated = versionRepository.updatePredicateNode(and);
// The tree should have the same structure, just with question IDs for the draft version.
PredicateExpressionNode expectedLeafOne = PredicateExpressionNode.create(leafOne.getLeafNode().toBuilder().setQuestionId(newOne.id).build());
PredicateExpressionNode expectedLeafTwo = PredicateExpressionNode.create(leafTwo.getLeafNode().toBuilder().setQuestionId(newTwo.id).build());
PredicateExpressionNode expectedLeafThree = PredicateExpressionNode.create(leafThree.getLeafNode().toBuilder().setQuestionId(newOne.id).build());
PredicateExpressionNode expectedOr = PredicateExpressionNode.create(OrNode.create(ImmutableSet.of(expectedLeafTwo, expectedLeafThree)));
PredicateExpressionNode expectedAnd = PredicateExpressionNode.create(AndNode.create(ImmutableSet.of(expectedLeafOne, expectedOr)));
assertThat(updated.getType()).isEqualTo(PredicateExpressionNodeType.AND);
assertThat(updated).isEqualTo(expectedAnd);
}
use of models.Version in project civiform by seattle-uat.
the class VersionRepositoryTest method testPublish.
@Test
public void testPublish() {
resourceCreator.insertActiveProgram("foo");
resourceCreator.insertActiveProgram("bar");
resourceCreator.insertDraftProgram("bar");
assertThat(this.versionRepository.getActiveVersion().getPrograms()).hasSize(2);
assertThat(this.versionRepository.getDraftVersion().getPrograms()).hasSize(1);
Version oldDraft = this.versionRepository.getDraftVersion();
this.versionRepository.publishNewSynchronizedVersion();
assertThat(this.versionRepository.getActiveVersion().getPrograms()).hasSize(2);
assertThat(this.versionRepository.getDraftVersion().getPrograms()).hasSize(0);
oldDraft.refresh();
assertThat(oldDraft.getLifecycleStage()).isEqualTo(LifecycleStage.ACTIVE);
}
use of models.Version in project civiform by seattle-uat.
the class ReadOnlyCurrentQuestionServiceImplTest method getEnumeratorQuestions.
@Test
public void getEnumeratorQuestions() {
QuestionDefinition enumeratorQuestion = testQuestionBank.applicantHouseholdMembers().getQuestionDefinition();
service = new ReadOnlyCurrentQuestionServiceImpl(new Version(LifecycleStage.ACTIVE) {
@Override
public ImmutableList<Question> getQuestions() {
return ImmutableList.<QuestionDefinition>builder().addAll(questions).add(enumeratorQuestion).build().stream().map(q -> new Question(q)).collect(ImmutableList.toImmutableList());
}
}, new Version(LifecycleStage.DRAFT));
assertThat(service.getAllEnumeratorQuestions().size()).isEqualTo(1);
assertThat(service.getAllEnumeratorQuestions().get(0)).isEqualTo(enumeratorQuestion);
assertThat(service.getUpToDateEnumeratorQuestions().size()).isEqualTo(1);
assertThat(service.getUpToDateEnumeratorQuestions().get(0)).isEqualTo(enumeratorQuestion);
}
use of models.Version in project civiform by seattle-uat.
the class ReadOnlyVersionedQuestionServiceImplTest method getEnumeratorQuestions.
@Test
public void getEnumeratorQuestions() {
QuestionDefinition enumeratorQuestion = testQuestionBank.applicantHouseholdMembers().getQuestionDefinition();
service = new ReadOnlyVersionedQuestionServiceImpl(new Version(LifecycleStage.OBSOLETE) {
@Override
public ImmutableList<Question> getQuestions() {
return ImmutableList.<QuestionDefinition>builder().addAll(questions).add(enumeratorQuestion).build().stream().map(q -> new Question(q)).collect(ImmutableList.toImmutableList());
}
});
assertThat(service.getAllEnumeratorQuestions().size()).isEqualTo(1);
assertThat(service.getAllEnumeratorQuestions().get(0)).isEqualTo(enumeratorQuestion);
}
use of models.Version in project civiform by seattle-uat.
the class ProgramServiceImpl method syncProgramAssociations.
private CompletionStage<ProgramDefinition> syncProgramAssociations(Program program) {
if (isActiveOrDraftProgram(program)) {
return syncProgramDefinitionQuestions(program.getProgramDefinition()).thenApply(programDefinition -> programDefinition.orderBlockDefinitions());
}
// Any version that the program is in has all the questions the program has.
Version version = program.getVersions().stream().findAny().get();
ProgramDefinition programDefinition = syncProgramDefinitionQuestions(program.getProgramDefinition(), version);
return CompletableFuture.completedStage(programDefinition.orderBlockDefinitions());
}
Aggregations