Search in sources :

Example 1 with DHIS2TransportServiceIF

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

the class DHIS2FeatureService method getSystemCapabilities.

@Request(RequestType.SESSION)
public JsonObject getSystemCapabilities(String sessionId, String systemJSON) {
    JsonObject capabilities = new JsonObject();
    JsonObject jo = JsonParser.parseString(systemJSON).getAsJsonObject();
    ExternalSystem system = ExternalSystem.desieralize(jo);
    if (system instanceof DHIS2ExternalSystem) {
        DHIS2ExternalSystem dhis2System = (DHIS2ExternalSystem) system;
        DHIS2TransportServiceIF dhis2 = getTransportService(dhis2System);
        String version = dhis2.getVersionRemoteServer();
        if (ArrayUtils.contains(DHIS2FeatureService.OAUTH_INCOMPATIBLE_VERSIONS, version)) {
            capabilities.addProperty("oauth", false);
        } else {
            capabilities.addProperty("oauth", true);
        }
    } else if (system instanceof FhirExternalSystem) {
        capabilities.addProperty("oauth", true);
    } else {
        capabilities.addProperty("oauth", false);
    }
    return capabilities;
}
Also used : DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) JsonObject(com.google.gson.JsonObject) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) Request(com.runwaysdk.session.Request)

Example 2 with DHIS2TransportServiceIF

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

the class DataExportJob method execute.

@Override
public void execute(ExecutionContext executionContext) throws Throwable {
    ExportHistory history = (ExportHistory) executionContext.getJobHistoryRecord().getChild();
    this.setStage(history, ExportStage.EXPORT);
    SynchronizationConfig c = this.getConfig();
    ExternalSystemSyncConfig config = c.buildConfiguration();
    if (config instanceof DHIS2SyncConfig) {
        DHIS2SyncConfig dhis2Config = (DHIS2SyncConfig) config;
        DHIS2TransportServiceIF dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(dhis2Config.getSystem());
        DHIS2FeatureService dhis2FeatureService = new DHIS2FeatureService();
        dhis2FeatureService.setExternalSystemDhis2Version(dhis2, dhis2Config.getSystem());
        new DHIS2SynchronizationManager(dhis2, dhis2Config, history).synchronize();
    } else if (config instanceof FhirSyncExportConfig) {
        FhirExportSynchronizationManager manager = new FhirExportSynchronizationManager((FhirSyncExportConfig) config, history);
        manager.synchronize();
    } else if (config instanceof FhirSyncImportConfig) {
        FhirImportSynchronizationManager manager = new FhirImportSynchronizationManager(c, (FhirSyncImportConfig) config, history);
        manager.synchronize();
    }
}
Also used : DHIS2SyncConfig(net.geoprism.registry.etl.DHIS2SyncConfig) FhirExportSynchronizationManager(net.geoprism.registry.etl.fhir.FhirExportSynchronizationManager) DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) FhirSyncImportConfig(net.geoprism.registry.etl.FhirSyncImportConfig) ExternalSystemSyncConfig(net.geoprism.registry.etl.ExternalSystemSyncConfig) DHIS2FeatureService(net.geoprism.registry.dhis2.DHIS2FeatureService) FhirSyncExportConfig(net.geoprism.registry.etl.FhirSyncExportConfig) FhirImportSynchronizationManager(net.geoprism.registry.etl.fhir.FhirImportSynchronizationManager) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) DHIS2SynchronizationManager(net.geoprism.registry.dhis2.DHIS2SynchronizationManager)

Example 3 with DHIS2TransportServiceIF

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

the class DHIS2FeatureService method getDHIS2AttributeConfiguration.

@Request(RequestType.SESSION)
public JsonArray getDHIS2AttributeConfiguration(String sessionId, String dhis2SystemOid, String geoObjectTypeCode) {
    DHIS2ExternalSystem system = DHIS2ExternalSystem.get(dhis2SystemOid);
    JsonArray response = new JsonArray();
    ServerGeoObjectType got = ServerGeoObjectType.get(geoObjectTypeCode);
    Map<String, AttributeType> cgrAttrs = got.getAttributeMap();
    DHIS2TransportServiceIF dhis2;
    try {
        dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | UnexpectedResponseException | BadServerUriException | IllegalArgumentException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
    final DHIS2OptionCache optionCache = new DHIS2OptionCache(dhis2);
    List<Attribute> dhis2Attrs = getDHIS2Attributes(dhis2);
    final String[] skipAttrs = new String[] { DefaultAttribute.GEOMETRY.getName(), DefaultAttribute.SEQUENCE.getName(), DefaultAttribute.TYPE.getName() };
    for (AttributeType cgrAttr : cgrAttrs.values()) {
        if (!ArrayUtils.contains(skipAttrs, cgrAttr.getName())) {
            JsonObject joAttr = new JsonObject();
            JsonObject joCgrAttr = new JsonObject();
            joCgrAttr.addProperty("name", cgrAttr.getName());
            joCgrAttr.addProperty("label", cgrAttr.getLabel().getValue());
            joCgrAttr.addProperty("type", cgrAttr.getType());
            joCgrAttr.addProperty("typeLabel", AttributeTypeMetadata.get().getTypeEnumDisplayLabel(cgrAttr.getType()));
            joAttr.add("cgrAttr", joCgrAttr);
            JsonArray jaStrategies = new JsonArray();
            List<DHIS2AttributeMapping> strategies = this.getMappingStrategies(cgrAttr);
            for (DHIS2AttributeMapping strategy : strategies) {
                jaStrategies.add(strategy.getClass().getName());
            }
            joAttr.add("attributeMappingStrategies", jaStrategies);
            JsonArray jaDhis2Attrs = new JsonArray();
            for (Attribute dhis2Attr : dhis2Attrs) {
                if (!dhis2Attr.getOrganisationUnitAttribute()) {
                    continue;
                }
                boolean valid = false;
                JsonObject jo = new JsonObject();
                if (cgrAttr instanceof AttributeBooleanType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.BOOLEAN) || dhis2Attr.getValueType().equals(ValueType.TRUE_ONLY))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeIntegerType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.INTEGER) || dhis2Attr.getValueType().equals(ValueType.INTEGER_POSITIVE) || dhis2Attr.getValueType().equals(ValueType.INTEGER_NEGATIVE) || dhis2Attr.getValueType().equals(ValueType.INTEGER_ZERO_OR_POSITIVE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeFloatType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.NUMBER) || dhis2Attr.getValueType().equals(ValueType.UNIT_INTERVAL) || dhis2Attr.getValueType().equals(ValueType.PERCENTAGE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeDateType && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.DATE) || dhis2Attr.getValueType().equals(ValueType.DATETIME) || dhis2Attr.getValueType().equals(ValueType.TIME) || dhis2Attr.getValueType().equals(ValueType.AGE))) {
                    valid = true;
                } else if (cgrAttr instanceof AttributeTermType && dhis2Attr.getOptionSetId() != null) {
                    valid = true;
                    JsonArray jaDhis2Options = new JsonArray();
                    IntegratedOptionSet set = optionCache.getOptionSet(dhis2Attr.getOptionSetId());
                    SortedSet<Option> options = set.getOptions();
                    for (Option option : options) {
                        JsonObject joDhis2Option = new JsonObject();
                        joDhis2Option.addProperty("code", option.getCode());
                        joDhis2Option.addProperty("name", option.getName());
                        joDhis2Option.addProperty("id", option.getName());
                        jaDhis2Options.add(joDhis2Option);
                    }
                    jo.add("options", jaDhis2Options);
                } else if ((cgrAttr instanceof AttributeCharacterType || cgrAttr instanceof AttributeLocalType) && dhis2Attr.getOptionSetId() == null && (dhis2Attr.getValueType().equals(ValueType.TEXT) || dhis2Attr.getValueType().equals(ValueType.LONG_TEXT) || dhis2Attr.getValueType().equals(ValueType.LETTER) || dhis2Attr.getValueType().equals(ValueType.PHONE_NUMBER) || dhis2Attr.getValueType().equals(ValueType.EMAIL) || dhis2Attr.getValueType().equals(ValueType.USERNAME) || dhis2Attr.getValueType().equals(ValueType.URL))) {
                    valid = true;
                }
                if (valid) {
                    jo.addProperty("dhis2Id", dhis2Attr.getId());
                    jo.addProperty("code", dhis2Attr.getCode());
                    jo.addProperty("name", dhis2Attr.getName());
                    jaDhis2Attrs.add(jo);
                }
            }
            joAttr.add("dhis2Attrs", jaDhis2Attrs);
            if (cgrAttr instanceof AttributeTermType) {
                JsonArray terms = new JsonArray();
                List<Term> children = ((AttributeTermType) cgrAttr).getTerms();
                for (Term child : children) {
                    JsonObject joTerm = new JsonObject();
                    joTerm.addProperty("label", child.getLabel().getValue());
                    joTerm.addProperty("code", child.getCode());
                    terms.add(joTerm);
                }
                joAttr.add("terms", terms);
            }
            response.add(joAttr);
        }
    }
    return response;
}
Also used : HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) Attribute(net.geoprism.dhis2.dhis2adapter.response.model.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) JsonObject(com.google.gson.JsonObject) DHIS2AttributeMapping(net.geoprism.registry.etl.DHIS2AttributeMapping) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Term(org.commongeoregistry.adapter.Term) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) IntegratedOptionSet(net.geoprism.registry.etl.export.dhis2.DHIS2OptionCache.IntegratedOptionSet) JsonArray(com.google.gson.JsonArray) DHIS2OptionCache(net.geoprism.registry.etl.export.dhis2.DHIS2OptionCache) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) Option(net.geoprism.dhis2.dhis2adapter.response.model.Option) HttpError(net.geoprism.registry.etl.export.HttpError) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Request(com.runwaysdk.session.Request)

Example 4 with DHIS2TransportServiceIF

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

the class DHIS2ServiceFactory method instanceGetDhis2Service.

public synchronized DHIS2TransportServiceIF instanceGetDhis2Service(DHIS2ExternalSystem system) throws UnexpectedResponseException, InvalidLoginException, HTTPException, BadServerUriException {
    if (this.dhis2 == null) {
        HTTPConnector connector = new HTTPConnector();
        connector.setServerUrl(system.getUrl());
        connector.setCredentials(system.getUsername(), system.getPassword());
        DHIS2TransportService dhis2 = new DHIS2TransportService(connector);
        try {
            dhis2.initialize();
            if (dhis2.getVersionRemoteServerApi() > DHIS2FeatureService.LAST_TESTED_DHIS2_API_VERSION) {
                Integer compatLayerVersion = dhis2.getVersionRemoteServerApi() - 2;
                if (compatLayerVersion < DHIS2FeatureService.LAST_TESTED_DHIS2_API_VERSION) {
                    compatLayerVersion = DHIS2FeatureService.LAST_TESTED_DHIS2_API_VERSION;
                }
                dhis2.setVersionApiCompat(compatLayerVersion);
            }
        } catch (IncompatibleServerVersionException e) {
            throw new ProgrammingErrorException(e);
        }
        return dhis2;
    }
    return this.dhis2;
}
Also used : IncompatibleServerVersionException(net.geoprism.dhis2.dhis2adapter.exception.IncompatibleServerVersionException) HTTPConnector(net.geoprism.dhis2.dhis2adapter.HTTPConnector) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) DHIS2TransportService(net.geoprism.registry.etl.export.dhis2.DHIS2TransportService)

Example 5 with DHIS2TransportServiceIF

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

the class SynchronizationConfigService method getConfigForExternalSystem.

@Request(RequestType.SESSION)
public JsonObject getConfigForExternalSystem(String sessionId, String externalSystemId, String hierarchyTypeCode) {
    JsonObject ret = new JsonObject();
    // Add GeoObjectTypes
    GeoObjectType[] gots = ServiceFactory.getRegistryService().getGeoObjectTypes(sessionId, null, new String[] { hierarchyTypeCode }, PermissionContext.WRITE);
    CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(sessionId);
    JsonArray jarray = new JsonArray();
    for (int i = 0; i < gots.length; ++i) {
        jarray.add(gots[i].toJSON(serializer));
    }
    ret.add("types", jarray);
    // Add DHIS2 OrgUnitGroups
    DHIS2ExternalSystem system = DHIS2ExternalSystem.get(externalSystemId);
    try {
        DHIS2TransportServiceIF dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
        JsonArray jaGroups = new JsonArray();
        MetadataGetResponse<OrganisationUnitGroup> resp = dhis2.<OrganisationUnitGroup>metadataGet(OrganisationUnitGroup.class);
        List<OrganisationUnitGroup> groups = resp.getObjects();
        for (OrganisationUnitGroup group : groups) {
            JsonObject joGroup = new JsonObject();
            joGroup.addProperty("id", group.getId());
            joGroup.addProperty("name", group.getName());
            jaGroups.add(joGroup);
        }
        ret.add("orgUnitGroups", jaGroups);
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | UnexpectedResponseException | IllegalArgumentException | BadServerUriException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
    return ret;
}
Also used : DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) JsonArray(com.google.gson.JsonArray) OrganisationUnitGroup(net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) HttpError(net.geoprism.registry.etl.export.HttpError) Request(com.runwaysdk.session.Request)

Aggregations

DHIS2TransportServiceIF (net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF)4 JsonObject (com.google.gson.JsonObject)3 Request (com.runwaysdk.session.Request)3 DHIS2ExternalSystem (net.geoprism.registry.graph.DHIS2ExternalSystem)3 JsonArray (com.google.gson.JsonArray)2 BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)2 HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)2 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)2 UnexpectedResponseException (net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException)2 HttpError (net.geoprism.registry.etl.export.HttpError)2 LoginException (net.geoprism.registry.etl.export.LoginException)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 HTTPConnector (net.geoprism.dhis2.dhis2adapter.HTTPConnector)1 IncompatibleServerVersionException (net.geoprism.dhis2.dhis2adapter.exception.IncompatibleServerVersionException)1 Attribute (net.geoprism.dhis2.dhis2adapter.response.model.Attribute)1 Option (net.geoprism.dhis2.dhis2adapter.response.model.Option)1 OrganisationUnitGroup (net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup)1 SynchronizationConfig (net.geoprism.registry.SynchronizationConfig)1 DHIS2FeatureService (net.geoprism.registry.dhis2.DHIS2FeatureService)1 DHIS2SynchronizationManager (net.geoprism.registry.dhis2.DHIS2SynchronizationManager)1