Search in sources :

Example 1 with MissingDHIS2TermOrgUnitGroupMapping

use of net.geoprism.registry.etl.export.dhis2.MissingDHIS2TermOrgUnitGroupMapping in project geoprism-registry by terraframe.

the class DHIS2TermAttributeMapping method writeCustomAttributes.

@Override
public void writeCustomAttributes(JsonArray attributeValues, VertexServerGeoObject serverGo, DHIS2SyncConfig dhis2Config, DHIS2SyncLevel syncLevel, String lastUpdateDate, String createDate) {
    ServerGeoObjectType got = syncLevel.getGeoObjectType();
    AttributeType attr = got.getAttribute(this.getCgrAttrName()).get();
    Object value = serverGo.getValue(attr.getName());
    if (value == null || (value instanceof String && ((String) value).length() == 0)) {
        return;
    }
    if (this.isOrgUnitGroup()) {
        if (attr instanceof AttributeTermType) {
            String termId = this.getTermId(value);
            String orgUnitGroupId = this.getTermMapping(termId);
            if (orgUnitGroupId == null) {
                MissingDHIS2TermOrgUnitGroupMapping ex = new MissingDHIS2TermOrgUnitGroupMapping();
                ex.setTermCode(termId);
                throw ex;
            }
            Set<String> orgUnitGroupIdSet = syncLevel.getOrgUnitGroupIdSet(orgUnitGroupId);
            if (orgUnitGroupIdSet == null) {
                orgUnitGroupIdSet = syncLevel.newOrgUnitGroupIdSet(orgUnitGroupId);
            }
            orgUnitGroupIdSet.add(serverGo.getExternalId(dhis2Config.getSystem()));
        } else {
            logger.error("Unsupported attribute type [" + attr.getClass().getName() + "] with name [" + attr.getName() + "] when matched to OrgUnitGroup.");
            return;
        }
    } else {
        super.writeCustomAttributes(attributeValues, serverGo, dhis2Config, syncLevel, lastUpdateDate, createDate);
    }
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MissingDHIS2TermOrgUnitGroupMapping(net.geoprism.registry.etl.export.dhis2.MissingDHIS2TermOrgUnitGroupMapping) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Aggregations

JsonObject (com.google.gson.JsonObject)1 MissingDHIS2TermOrgUnitGroupMapping (net.geoprism.registry.etl.export.dhis2.MissingDHIS2TermOrgUnitGroupMapping)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)1 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)1 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)1