Search in sources :

Example 1 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class SynchronizationConfigService method remove.

@Request(RequestType.SESSION)
public void remove(String sessionId, String oid) {
    SynchronizationConfig config = SynchronizationConfig.get(oid);
    Organization organization = config.getOrganization();
    ServiceFactory.getRolePermissionService().enforceRA(organization.getCode());
    config.delete();
}
Also used : Organization(net.geoprism.registry.Organization) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

Example 2 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class SynchronizationConfigService method run.

@Request(RequestType.SESSION)
public JsonObject run(String sessionId, String oid) {
    SynchronizationConfig config = SynchronizationConfig.get(oid);
    ServiceFactory.getRolePermissionService().enforceRA(config.getOrganization().getCode());
    List<? extends DataExportJob> jobs = config.getJobs();
    DataExportJob job = jobs.get(0);
    job.appLock();
    job.setRunAsUserId(Session.getCurrentSession().getUser().getOid());
    job.apply();
    ExportHistory hist = job.start(config);
    GeoprismUser user = GeoprismUser.get(job.getRunAsUser().getOid());
    return serializeHistory(hist, user, job);
}
Also used : ExportHistory(net.geoprism.registry.etl.export.ExportHistory) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) GeoprismUser(net.geoprism.GeoprismUser) DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Request(com.runwaysdk.session.Request)

Example 3 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class SynchronizationConfigService method edit.

@Request(RequestType.SESSION)
public JsonObject edit(String sessionId, String oid) {
    JsonObject response = new JsonObject();
    if (oid != null && oid.length() > 0) {
        SynchronizationConfig config = SynchronizationConfig.lock(oid);
        response.add("config", config.toJSON());
    }
    JsonArray orgs = new JsonArray();
    List<Organization> organizations = Organization.getUserAdminOrganizations();
    for (Organization organization : organizations) {
        JsonArray hierarchies = new JsonArray();
        List<ServerHierarchyType> sHierachies = ServerHierarchyType.getForOrganization(organization);
        for (ServerHierarchyType hierarchy : sHierachies) {
            JsonObject object = new JsonObject();
            object.addProperty("label", hierarchy.getDisplayLabel().getValue());
            object.addProperty("code", hierarchy.getCode());
            hierarchies.add(object);
        }
        JsonArray systems = new JsonArray();
        List<ExternalSystem> esystems = ExternalSystem.getForOrganization(organization);
        for (ExternalSystem system : esystems) {
            if (system.isExportSupported()) {
                LocalizedValue label = LocalizedValueConverter.convert(system.getEmbeddedComponent(ExternalSystem.LABEL));
                JsonObject object = new JsonObject();
                object.addProperty("label", label.getValue());
                object.addProperty("oid", system.getOid());
                object.addProperty("type", system.getMdClass().getTypeName());
                systems.add(object);
            }
        }
        JsonObject object = new JsonObject();
        object.addProperty("label", organization.getDisplayLabel().getValue());
        object.addProperty("code", organization.getCode());
        object.add("hierarchies", hierarchies);
        object.add("systems", systems);
        orgs.add(object);
    }
    response.add("orgs", orgs);
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

Example 4 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class FhirImportTest method testBasicImport.

@Request
@Test
public void testBasicImport() throws InterruptedException {
    try {
        FhirExternalSystem system = createExternalSystem();
        SynchronizationConfig config = createSyncConfig(system);
        FhirSyncImportConfig iConfig = (FhirSyncImportConfig) config.buildConfiguration();
        FhirResourceProcessor processor = FhirFactory.getProcessor(iConfig.getImplementation());
        IParser parser = FhirContext.forR4().newJsonParser();
        Bundle bundle = new Bundle();
        bundle.addEntry(new BundleEntryComponent().setResource((Resource) parser.parseResource(this.getClass().getResourceAsStream("/fhir/organization.json"))));
        bundle.addEntry(new BundleEntryComponent().setResource((Resource) parser.parseResource(this.getClass().getResourceAsStream("/fhir/location.json"))));
        FhirResourceImporter importer = new FhirResourceImporter(new BasicFhirConnection(system), processor, null, null);
        importer.synchronize(bundle);
        ServerGeoObjectIF geoobject = new ServerGeoObjectService().getGeoObjectByCode("USATestDataHsTwo", "USATestDataHealthStop");
        geoobject.setDate(new Date());
        LocalizedValue displayLabel = geoobject.getDisplayLabel();
        Assert.assertEquals("USATestDataHsTwo ZZZZZZZ", displayLabel.getValue());
    } finally {
        TestDataSet.deleteExternalSystems("FHIRImportTest");
    }
}
Also used : FhirResourceImporter(net.geoprism.registry.etl.fhir.FhirResourceImporter) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) BasicFhirResourceProcessor(net.geoprism.registry.etl.fhir.BasicFhirResourceProcessor) FhirResourceProcessor(net.geoprism.registry.etl.fhir.FhirResourceProcessor) BasicFhirConnection(net.geoprism.registry.etl.fhir.BasicFhirConnection) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) IParser(ca.uhn.fhir.parser.IParser) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 5 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class DHIS2ServiceTest method createSyncConfig.

@Request
public static SynchronizationConfig createSyncConfig(ExternalSystem system, DHIS2SyncLevel additionalLevel, boolean apply) {
    // Define reusable objects
    final ServerHierarchyType ht = AllAttributesDataset.HIER.getServerObject();
    final Organization org = AllAttributesDataset.ORG.getServerObject();
    // Create DHIS2 Sync Config
    DHIS2SyncConfig dhis2Config = new DHIS2SyncConfig();
    dhis2Config.setHierarchy(ht);
    dhis2Config.setHierarchyCode(ht.getCode());
    dhis2Config.setLabel(new LocalizedValue("DHIS2 Export Test Data"));
    dhis2Config.setOrganization(org);
    // Populate Levels
    SortedSet<DHIS2SyncLevel> levels = new TreeSet<DHIS2SyncLevel>();
    DHIS2SyncLevel level = new DHIS2SyncLevel();
    level.setGeoObjectType(AllAttributesDataset.GOT_ALL.getServerObject().getCode());
    level.setSyncType(DHIS2SyncLevel.Type.ALL);
    level.setMappings(getDefaultMappings());
    level.setLevel(0);
    levels.add(level);
    // Populate Attribute Mappings
    if (additionalLevel != null) {
        levels.add(additionalLevel);
    }
    dhis2Config.setLevels(levels);
    // Serialize the DHIS2 Config
    GsonBuilder builder = new GsonBuilder();
    String dhis2JsonConfig = builder.create().toJson(dhis2Config);
    // Create a SynchronizationConfig
    SynchronizationConfig config = new SynchronizationConfig();
    config.setConfiguration(dhis2JsonConfig);
    config.setOrganization(org);
    config.setHierarchy(ht.getMdTermRelationship());
    config.setSystem(system.getOid());
    config.getLabel().setValue("DHIS2 Export Test");
    if (apply) {
        config.apply();
    }
    return config;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) GsonBuilder(com.google.gson.GsonBuilder) TreeSet(java.util.TreeSet) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

Aggregations

SynchronizationConfig (net.geoprism.registry.SynchronizationConfig)14 Request (com.runwaysdk.session.Request)10 JsonObject (com.google.gson.JsonObject)5 Organization (net.geoprism.registry.Organization)4 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 JsonArray (com.google.gson.JsonArray)3 ExportHistory (net.geoprism.registry.etl.export.ExportHistory)3 Test (org.junit.Test)3 GsonBuilder (com.google.gson.GsonBuilder)2 Dhis2Payload (net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload)2 ExternalSystemSyncConfig (net.geoprism.registry.etl.ExternalSystemSyncConfig)2 FhirSyncExportConfig (net.geoprism.registry.etl.FhirSyncExportConfig)2 BasicFhirResourceProcessor (net.geoprism.registry.etl.fhir.BasicFhirResourceProcessor)2 FhirExportSynchronizationManager (net.geoprism.registry.etl.fhir.FhirExportSynchronizationManager)2 DHIS2ExternalSystem (net.geoprism.registry.graph.DHIS2ExternalSystem)2 ExternalSystem (net.geoprism.registry.graph.ExternalSystem)2 SynchronizationConfigService (net.geoprism.registry.service.SynchronizationConfigService)2 IParser (ca.uhn.fhir.parser.IParser)1 JsonElement (com.google.gson.JsonElement)1