Search in sources :

Example 16 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class IdentifiableObjectBundleHook method handleAttributeValues.

private void handleAttributeValues(IdentifiableObject identifiableObject, ObjectBundle bundle, Schema schema) {
    Session session = sessionFactory.getCurrentSession();
    if (!schema.havePersistedProperty("attributeValues"))
        return;
    Iterator<AttributeValue> iterator = identifiableObject.getAttributeValues().iterator();
    while (iterator.hasNext()) {
        AttributeValue attributeValue = iterator.next();
        // if value null or empty, just skip it
        if (StringUtils.isEmpty(attributeValue.getValue())) {
            iterator.remove();
            continue;
        }
        Attribute attribute = bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeValue.getAttribute());
        if (attribute == null) {
            iterator.remove();
            continue;
        }
        attributeValue.setAttribute(attribute);
        session.save(attributeValue);
        session.flush();
    }
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Session(org.hibernate.Session)

Aggregations

Attribute (org.hisp.dhis.attribute.Attribute)16 AttributeValue (org.hisp.dhis.attribute.AttributeValue)12 Test (org.junit.Test)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 DataElement (org.hisp.dhis.dataelement.DataElement)4 User (org.hisp.dhis.user.User)3 ArrayList (java.util.ArrayList)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 Option (org.hisp.dhis.option.Option)2 OptionSet (org.hisp.dhis.option.OptionSet)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Session (org.hibernate.Session)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)1 DataSet (org.hisp.dhis.dataset.DataSet)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1