Search in sources :

Example 6 with TextPattern

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;
}
Also used : TextPattern(org.hisp.dhis.textpattern.TextPattern) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 7 with TextPattern

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());
}
Also used : Date(java.util.Date) TextPattern(org.hisp.dhis.textpattern.TextPattern) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ReservedValue(org.hisp.dhis.reservedvalue.ReservedValue) Autowired(org.springframework.beans.factory.annotation.Autowired) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstanceStore(org.hisp.dhis.trackedentity.TrackedEntityInstanceStore) ArrayList(java.util.ArrayList) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) ReservedValueStore(org.hisp.dhis.reservedvalue.ReservedValueStore) TextPatternParser(org.hisp.dhis.textpattern.TextPatternParser) Calendar(java.util.Calendar) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Objects(org.hisp.dhis.common.Objects) OrganisationUnitStore(org.hisp.dhis.organisationunit.OrganisationUnitStore) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeStore(org.hisp.dhis.trackedentity.TrackedEntityAttributeStore) TrackedEntityAttributeValueStore(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueStore) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TextPattern(org.hisp.dhis.textpattern.TextPattern) ReservedValue(org.hisp.dhis.reservedvalue.ReservedValue) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with TextPattern

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();
        }
    }
}
Also used : TextPattern(org.hisp.dhis.textpattern.TextPattern) TextPatternParser(org.hisp.dhis.textpattern.TextPatternParser)

Aggregations

TextPattern (org.hisp.dhis.textpattern.TextPattern)8 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 Date (java.util.Date)3 TextPatternParser (org.hisp.dhis.textpattern.TextPatternParser)3 TextPatternSegment (org.hisp.dhis.textpattern.TextPatternSegment)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects (org.hisp.dhis.common.Objects)2 TextPatternValidationUtils (org.hisp.dhis.textpattern.TextPatternValidationUtils)2 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)2 Test (org.junit.jupiter.api.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1