use of org.hisp.dhis.textpattern.TextPattern in project dhis2-core by dhis2.
the class ReservedValueServiceTest method createTrackedEntityAttribute.
private static TrackedEntityAttribute createTrackedEntityAttribute(Objects objects, String uid, String pattern) throws TextPatternParser.TextPatternParsingException {
TextPattern textPattern = TextPatternParser.parse(pattern);
textPattern.setOwnerObject(objects);
textPattern.setOwnerUid(uid);
TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
trackedEntityAttribute.setTextPattern(textPattern);
trackedEntityAttribute.setGenerated(true);
return trackedEntityAttribute;
}
use of org.hisp.dhis.textpattern.TextPattern in project dhis2-core by dhis2.
the class HibernateReservedValueStoreTest method getAvailableValuesWhenAlreadyUsed.
@Test
void getAvailableValuesWhenAlreadyUsed() throws TextPatternParser.TextPatternParsingException, IllegalAccessException {
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
TrackedEntityInstance tei = createTrackedEntityInstance(ou);
trackedEntityInstanceStore.save(tei);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
TextPattern textPattern = TextPatternParser.parse(key);
textPattern.setOwnerObject(Objects.fromClass(tea.getClass()));
textPattern.setOwnerUid(tea.getUid());
tea.setTextPattern(textPattern);
tea.setUid(teaUid);
trackedEntityAttributeStore.save(tea);
TrackedEntityAttributeValue teav = createTrackedEntityAttributeValue('Z', tei, tea);
teav.setValue(prog001);
trackedEntityAttributeValueStore.save(teav);
ReservedValue rv = reservedValue.value(prog001).build();
rv.setTrackedEntityAttributeId(teav.getAttribute().getId());
assertEquals(1, trackedEntityAttributeValueStore.getAll().size());
assertEquals(0, reservedValueStore.getAll().size());
List<ReservedValue> res = reservedValueStore.getAvailableValues(rv, Lists.newArrayList(prog001, prog002), rv.getOwnerObject());
assertFalse(res.stream().anyMatch(r -> r.getValue().equals(prog001)));
assertTrue(res.stream().anyMatch(r -> r.getValue().equals(prog002)));
assertEquals(1, res.size());
}
use of org.hisp.dhis.textpattern.TextPattern in project dhis2-core by dhis2.
the class TrackedEntityAttributeObjectBundleHook method updateTextPattern.
private void updateTextPattern(TrackedEntityAttribute attr) {
if (attr.isGenerated()) {
try {
TextPattern textPattern = TextPatternParser.parse(attr.getPattern());
textPattern.setOwnerObject(Objects.TRACKEDENTITYATTRIBUTE);
textPattern.setOwnerUid(attr.getUid());
attr.setTextPattern(textPattern);
} catch (TextPatternParser.TextPatternParsingException e) {
e.printStackTrace();
}
}
}
Aggregations