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;
}
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();
}
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());
}
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();
}
}
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.");
}
Aggregations