Search in sources :

Example 1 with SynchronizationConfigQuery

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

the class DeleteSyncConfigs method doIt.

@Transaction
private void doIt() {
    SynchronizationConfigQuery query = new SynchronizationConfigQuery(new QueryFactory());
    OIterator<? extends SynchronizationConfig> it = query.getIterator();
    it.forEach(config -> {
        config.delete();
    });
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) SynchronizationConfigQuery(net.geoprism.registry.SynchronizationConfigQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with SynchronizationConfigQuery

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

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 SynchronizationConfigQuery (net.geoprism.registry.SynchronizationConfigQuery)2 JsonObject (com.google.gson.JsonObject)1 MdTermRelationship (com.runwaysdk.system.metadata.MdTermRelationship)1 SynchronizationConfig (net.geoprism.registry.SynchronizationConfig)1 DHIS2ExternalSystem (net.geoprism.registry.graph.DHIS2ExternalSystem)1 ExternalSystem (net.geoprism.registry.graph.ExternalSystem)1 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)1