Search in sources :

Example 1 with ExportHistory

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

the class ETLService method serializeHistory.

protected JsonObject serializeHistory(JobHistory hist, GeoprismUser user, ExecutableJob job) {
    JsonObject jo = new JsonObject();
    jo.addProperty("jobType", job.getType());
    jo.addProperty("status", hist.getStatus().get(0).name());
    jo.addProperty("author", user.getUsername());
    jo.addProperty("createDate", formatDate(hist.getCreateDate()));
    jo.addProperty("lastUpdateDate", formatDate(hist.getLastUpdateDate()));
    jo.addProperty("workProgress", hist.getWorkProgress());
    jo.addProperty("workTotal", hist.getWorkTotal());
    jo.addProperty("historyId", hist.getOid());
    jo.addProperty("jobId", job.getOid());
    if (hist instanceof ImportHistory) {
        ImportHistory iHist = (ImportHistory) hist;
        jo.addProperty("importedRecords", iHist.getImportedRecords());
        jo.addProperty("stage", iHist.getStage().get(0).name());
        JsonObject config = JsonParser.parseString(iHist.getConfigJson()).getAsJsonObject();
        jo.addProperty("fileName", config.get(ImportConfiguration.FILE_NAME).getAsString());
        jo.add("configuration", JsonParser.parseString(config.toString()));
    } else if (hist instanceof ExportHistory) {
        ExportHistory eHist = (ExportHistory) hist;
        jo.addProperty("exportedRecords", eHist.getExportedRecords());
        jo.addProperty("stage", eHist.getStage().get(0).name());
    }
    if (job instanceof DataExportJob) {
        jo.addProperty("configuration", ((DataExportJob) job).getConfigOid());
    }
    if (hist.getStatus().get(0).equals(AllJobStatus.FAILURE) && hist.getErrorJson().length() > 0) {
        JsonObject exception = new JsonObject();
        exception.add("type", JsonParser.parseString(hist.getErrorJson()).getAsJsonObject().get("type"));
        exception.addProperty("message", hist.getLocalizedError(Session.getCurrentLocale()));
        jo.add("exception", exception);
    }
    return jo;
}
Also used : ExportHistory(net.geoprism.registry.etl.export.ExportHistory) JsonObject(com.google.gson.JsonObject) DataExportJob(net.geoprism.registry.etl.export.DataExportJob)

Example 2 with ExportHistory

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

the class SynchronizationConfigService method getJobs.

@Request(RequestType.SESSION)
public JsonObject getJobs(String sessionId, String configId, Integer pageSize, Integer pageNumber) {
    QueryFactory qf = new QueryFactory();
    DataExportJobQuery jQuery = new DataExportJobQuery(qf);
    jQuery.WHERE(jQuery.getConfig().EQ(configId));
    ExportHistoryQuery ihq = new ExportHistoryQuery(qf);
    ihq.WHERE(ihq.job(jQuery));
    ihq.restrictRows(pageSize, pageNumber);
    ihq.ORDER_BY_DESC(ihq.getCreateDate());
    try (OIterator<? extends ExportHistory> it = ihq.getIterator()) {
        LinkedList<JsonWrapper> results = new LinkedList<JsonWrapper>();
        while (it.hasNext()) {
            ExportHistory hist = it.next();
            DataExportJob job = (DataExportJob) hist.getAllJob().getAll().get(0);
            GeoprismUser user = GeoprismUser.get(job.getRunAsUser().getOid());
            results.add(new JsonWrapper(serializeHistory(hist, user, job)));
        }
        return new Page<JsonWrapper>(ihq.getCount(), pageNumber, pageSize, results).toJSON();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) JsonWrapper(net.geoprism.registry.view.JsonWrapper) ExportHistoryQuery(net.geoprism.registry.etl.export.ExportHistoryQuery) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) GeoprismUser(net.geoprism.GeoprismUser) DataExportJobQuery(net.geoprism.registry.etl.export.DataExportJobQuery) LinkedList(java.util.LinkedList) DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Request(com.runwaysdk.session.Request)

Example 3 with ExportHistory

use of net.geoprism.registry.etl.export.ExportHistory 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 4 with ExportHistory

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

the class ETLService method getExportDetails.

@Request(RequestType.SESSION)
public JsonObject getExportDetails(String sessionId, String historyId, int pageSize, int pageNumber) {
    ExportHistory hist = ExportHistory.get(historyId);
    DataExportJob job = (DataExportJob) hist.getAllJob().getAll().get(0);
    GeoprismUser user = GeoprismUser.get(job.getRunAsUser().getOid());
    JsonObject jo = this.serializeHistory(hist, user, job);
    jo.add("exportErrors", this.getExportErrors(sessionId, historyId, pageSize, pageNumber));
    return jo;
}
Also used : ExportHistory(net.geoprism.registry.etl.export.ExportHistory) JsonObject(com.google.gson.JsonObject) GeoprismUser(net.geoprism.GeoprismUser) DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Request(com.runwaysdk.session.Request)

Example 5 with ExportHistory

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

the class DHIS2ServiceTest method exportCustomAttribute.

private void exportCustomAttribute(TestGeoObjectTypeInfo got, TestGeoObjectInfo go, TestAttributeTypeInfo attr) throws InterruptedException {
    DHIS2SyncLevel level2 = new DHIS2SyncLevel();
    level2.setGeoObjectType(got.getServerObject().getCode());
    level2.setSyncType(DHIS2SyncLevel.Type.ALL);
    level2.setLevel(1);
    Collection<DHIS2AttributeMapping> mappings = getDefaultMappings();
    DHIS2AttributeMapping mapping;
    if (attr.getType().equals(AttributeTermType.TYPE)) {
        mapping = new DHIS2TermAttributeMapping();
        mapping.setAttributeMappingStrategy(DHIS2TermAttributeMapping.class.getName());
        Map<String, String> terms = new HashMap<String, String>();
        terms.put(AllAttributesDataset.AT_GO_TERM.fetchRootAsClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        terms.put(AllAttributesDataset.TERM_TERM_VAL1.fetchClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        terms.put(AllAttributesDataset.TERM_TERM_VAL2.fetchClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        ((DHIS2TermAttributeMapping) mapping).setTerms(terms);
    } else {
        mapping = new DHIS2AttributeMapping();
        mapping.setAttributeMappingStrategy(DHIS2AttributeMapping.class.getName());
    }
    mapping.setCgrAttrName(attr.getAttributeName());
    mapping.setDhis2AttrName(attr.getAttributeName());
    mapping.setExternalId("TEST_EXTERNAL_ID");
    mappings.add(mapping);
    level2.setMappings(mappings);
    SynchronizationConfig config = createSyncConfig(this.system, level2);
    JsonObject jo = syncService.run(testData.clientSession.getSessionId(), config.getOid());
    ExportHistory hist = ExportHistory.get(jo.get("historyId").getAsString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    LinkedList<Dhis2Payload> payloads = this.dhis2.getPayloads();
    Assert.assertEquals(2, payloads.size());
    for (int level = 0; level < payloads.size(); ++level) {
        Dhis2Payload payload = payloads.get(level);
        JsonObject joPayload = JsonParser.parseString(payload.getData()).getAsJsonObject();
        JsonArray orgUnits = joPayload.get("organisationUnits").getAsJsonArray();
        Assert.assertEquals(1, orgUnits.size());
        JsonObject orgUnit = orgUnits.get(0).getAsJsonObject();
        Assert.assertEquals(level, orgUnit.get("level").getAsInt());
        Assert.assertEquals("MULTI_POLYGON", orgUnit.get("featureType").getAsString());
        if (level == 0) {
            Assert.assertEquals(AllAttributesDataset.GO_ALL.getCode(), orgUnit.get("code").getAsString());
        } else {
            Assert.assertEquals(go.getCode(), orgUnit.get("code").getAsString());
            Assert.assertTrue(orgUnit.has("attributeValues"));
            JsonArray attributeValues = orgUnit.get("attributeValues").getAsJsonArray();
            Assert.assertEquals(1, attributeValues.size());
            JsonObject attributeValue = attributeValues.get(0).getAsJsonObject();
            Assert.assertNotNull(attributeValue.get("lastUpdated").getAsString());
            Assert.assertNotNull(attributeValue.get("created").getAsString());
            AttributeType attrDto = attr.fetchDTO();
            if (attrDto instanceof AttributeIntegerType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsLong());
            } else if (attrDto instanceof AttributeFloatType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsDouble());
            } else if (attrDto instanceof AttributeDateType) {
                // TODO : If we fetch the object from the database in this manner the
                // miliseconds aren't included on the date. But if we fetch the object
                // via a query (as in DataExportJob) then the miliseconds ARE
                // included...
                // String expected =
                // DHIS2GeoObjectJsonAdapters.DHIS2Serializer.formatDate((Date)
                // go.getServerObject().getValue(attr.getAttributeName()));
                String expected = DHIS2GeoObjectJsonAdapters.DHIS2Serializer.formatDate(AllAttributesDataset.GO_DATE_VALUE);
                String actual = attributeValue.get("value").getAsString();
                Assert.assertEquals(expected, actual);
            } else if (attrDto instanceof AttributeBooleanType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsBoolean());
            } else if (attrDto instanceof AttributeTermType) {
                String dhis2Id = attributeValue.get("value").getAsString();
                // Term term = (Term)
                // go.getServerObject().getValue(attr.getAttributeName());
                Assert.assertEquals("TEST_EXTERNAL_ID", dhis2Id);
            } else {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsString());
            }
            Assert.assertEquals("TEST_EXTERNAL_ID", attributeValue.get("attribute").getAsJsonObject().get("id").getAsString());
        }
    }
}
Also used : AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Dhis2Payload(net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) JsonArray(com.google.gson.JsonArray) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Aggregations

ExportHistory (net.geoprism.registry.etl.export.ExportHistory)6 JsonObject (com.google.gson.JsonObject)4 Request (com.runwaysdk.session.Request)4 DataExportJob (net.geoprism.registry.etl.export.DataExportJob)4 GeoprismUser (net.geoprism.GeoprismUser)3 SynchronizationConfig (net.geoprism.registry.SynchronizationConfig)3 JsonArray (com.google.gson.JsonArray)2 Dhis2Payload (net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload)2 QueryFactory (com.runwaysdk.query.QueryFactory)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 DataExportJobQuery (net.geoprism.registry.etl.export.DataExportJobQuery)1 ExportHistoryQuery (net.geoprism.registry.etl.export.ExportHistoryQuery)1 SynchronizationConfigService (net.geoprism.registry.service.SynchronizationConfigService)1 JsonWrapper (net.geoprism.registry.view.JsonWrapper)1 AttributeBooleanType (org.commongeoregistry.adapter.metadata.AttributeBooleanType)1 AttributeDateType (org.commongeoregistry.adapter.metadata.AttributeDateType)1 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)1 AttributeIntegerType (org.commongeoregistry.adapter.metadata.AttributeIntegerType)1 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)1