Search in sources :

Example 1 with DHIS2ExternalSystem

use of net.geoprism.registry.graph.DHIS2ExternalSystem 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 DHIS2ExternalSystem

use of net.geoprism.registry.graph.DHIS2ExternalSystem in project geoprism-registry by terraframe.

the class ExternalSystemService method remove.

@Request(RequestType.SESSION)
public void remove(String sessionId, String oid) {
    ExternalSystem system = ExternalSystem.get(oid);
    Organization organization = system.getOrganization();
    ServiceFactory.getRolePermissionService().enforceRA(organization.getCode());
    if (system instanceof DHIS2ExternalSystem) {
        DHIS2ExternalSystem dhis2Sys = (DHIS2ExternalSystem) system;
        if (dhis2Sys.getOauthServer() != null) {
            OauthServer dbServer = dhis2Sys.getOauthServer();
            dbServer.delete();
        }
    }
    system.delete();
}
Also used : Organization(net.geoprism.registry.Organization) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) OauthExternalSystem(net.geoprism.registry.etl.OauthExternalSystem) OauthServer(net.geoprism.account.OauthServer) Request(com.runwaysdk.session.Request)

Example 3 with DHIS2ExternalSystem

use of net.geoprism.registry.graph.DHIS2ExternalSystem in project geoprism-registry by terraframe.

the class JsonSerializationTest method testSerializeExternalSystem.

// @Test
// @Request
// public void testDhis2Serialize() throws IOException
// {
// ServerGeoObjectType got = USATestData.DISTRICT.getServerObject();
// ServerHierarchyType ht = USATestData.HIER_ADMIN.getServerObject();
// 
// GeoObjectJsonExporter exporter = new GeoObjectJsonExporter(got, ht, null,
// true, GeoObjectExportFormat.JSON_DHIS2, system, -1, -1);
// exporter.setDHIS2Facade(this.dhis2);
// System.out.println(IOUtils.toString(exporter.export()));
// }
@Test
@Request
public void testSerializeExternalSystem() {
    DHIS2ExternalSystem dhis2Sys = (DHIS2ExternalSystem) system;
    JsonObject json = dhis2Sys.toJSON();
    DHIS2ExternalSystem dhis2Sys2 = (DHIS2ExternalSystem) ExternalSystem.desieralize(json);
    Assert.assertEquals(dhis2Sys.getUrl(), dhis2Sys2.getUrl());
    Assert.assertEquals(dhis2Sys.getUsername(), dhis2Sys2.getUsername());
    Assert.assertEquals(dhis2Sys.getPassword(), dhis2Sys2.getPassword());
}
Also used : DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 4 with DHIS2ExternalSystem

use of net.geoprism.registry.graph.DHIS2ExternalSystem in project geoprism-registry by terraframe.

the class RegistrySessionService method getActor.

@Transaction
private static synchronized SingleActorDAOIF getActor(OauthServer server, String username) throws JSONException {
    UsersQuery query = new UsersQuery(new QueryFactory());
    query.WHERE(query.getUsername().EQ(username));
    OIterator<? extends Users> it = query.getIterator();
    try {
        if (it.hasNext()) {
            UserDAO user = (UserDAO) BusinessFacade.getEntityDAO(it.next());
            try {
                GeoprismUser geoprismUser = GeoprismUser.getByUsername(user.getUsername());
                UserInfo userInfo = UserInfo.getByUser(geoprismUser);
                ExternalSystem system = ExternalSystem.get(userInfo.getExternalSystemOid());
                if (system instanceof DHIS2ExternalSystem) {
                    DHIS2ExternalSystem dhis2System = (DHIS2ExternalSystem) system;
                    if (dhis2System.getOauthServerOid().equals(server.getOid())) {
                        return user;
                    }
                }
            } catch (Throwable t) {
                logger.error("Encountered an unexpected error while logging user in.", t);
            }
            UserNotOuathEnabledException ex = new UserNotOuathEnabledException();
            ex.setUsername(user.getUsername());
            ex.setOauthServer(server.getDisplayLabel().getValue());
            throw ex;
        } else {
            UserNotFoundException ex = new UserNotFoundException();
            ex.setUsername(username);
            throw ex;
        }
    } finally {
        it.close();
    }
}
Also used : UserNotFoundException(net.geoprism.registry.session.UserNotFoundException) UserNotOuathEnabledException(net.geoprism.registry.session.UserNotOuathEnabledException) QueryFactory(com.runwaysdk.query.QueryFactory) UserDAO(com.runwaysdk.business.rbac.UserDAO) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) UsersQuery(com.runwaysdk.system.UsersQuery) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) GeoprismUser(net.geoprism.GeoprismUser) UserInfo(net.geoprism.registry.UserInfo) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 5 with DHIS2ExternalSystem

use of net.geoprism.registry.graph.DHIS2ExternalSystem in project geoprism-registry by terraframe.

the class SynchronizationConfigPatch method patchJobs.

@Transaction
private void patchJobs() {
    SynchronizationConfigQuery query = new SynchronizationConfigQuery(new QueryFactory());
    logger.info("Attempting to patch " + query.getCount() + " synchronization configs.");
    long count = 0;
    try (OIterator<? extends SynchronizationConfig> iterator = query.getIterator()) {
        while (iterator.hasNext()) {
            SynchronizationConfig config = iterator.next();
            ExternalSystem system = config.getExternalSystem();
            if (system instanceof DHIS2ExternalSystem) {
                JsonObject json = config.getConfigurationJson();
                ServerHierarchyType hierarchy = null;
                MdTermRelationship universalRelationship = config.getHierarchy();
                if (universalRelationship != null) {
                    hierarchy = ServerHierarchyType.get(universalRelationship);
                } else if (json.has("hierarchy")) {
                    hierarchy = ServerHierarchyType.get(json.get("hierarchy").getAsString());
                } else if (json.has("hierarchyCode")) {
                    hierarchy = ServerHierarchyType.get(json.get("hierarchyCode").getAsString());
                }
                if (hierarchy != null) {
                    json.remove("hierarchy");
                    json.addProperty(DHIS2SyncConfig.HIERARCHY, hierarchy.getCode());
                    config.appLock();
                    config.setConfiguration(json.toString());
                    config.apply();
                    count++;
                } else {
                    logger.error("Skipping " + config.getKey() + " because we couldn't resolve a hierarchy.");
                }
            }
        }
    }
    logger.info("Successfully patched " + count + " synchronization configs.");
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) SynchronizationConfigQuery(net.geoprism.registry.SynchronizationConfigQuery) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

DHIS2ExternalSystem (net.geoprism.registry.graph.DHIS2ExternalSystem)8 JsonObject (com.google.gson.JsonObject)6 Request (com.runwaysdk.session.Request)5 ExternalSystem (net.geoprism.registry.graph.ExternalSystem)5 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 DHIS2TransportServiceIF (net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF)3 FhirExternalSystem (net.geoprism.registry.graph.FhirExternalSystem)3 JsonArray (com.google.gson.JsonArray)2 QueryFactory (com.runwaysdk.query.QueryFactory)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 OauthExternalSystem (net.geoprism.registry.etl.OauthExternalSystem)2 HttpError (net.geoprism.registry.etl.export.HttpError)2 LoginException (net.geoprism.registry.etl.export.LoginException)2 UserDAO (com.runwaysdk.business.rbac.UserDAO)1 UsersQuery (com.runwaysdk.system.UsersQuery)1 MdTermRelationship (com.runwaysdk.system.metadata.MdTermRelationship)1 GeoprismUser (net.geoprism.GeoprismUser)1