Search in sources :

Example 1 with DataExportJob

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

the class SynchronizationConfig method apply.

@Override
@Transaction
public void apply() {
    SessionIF session = Session.getCurrentSession();
    Organization organization = this.getOrganization();
    if (session != null && organization != null) {
        ServiceFactory.getRolePermissionService().enforceRA(organization.getCode());
    }
    super.apply();
    if (this.isNew()) {
        DataExportJob job = new DataExportJob();
        job.setConfig(this);
        job.apply();
    }
}
Also used : DataExportJob(net.geoprism.registry.etl.export.DataExportJob) SessionIF(com.runwaysdk.session.SessionIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with DataExportJob

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

the class SynchronizationConfig method delete.

@Override
@Transaction
public void delete() {
    List<? extends DataExportJob> jobs = getJobs();
    for (DataExportJob job : jobs) {
        job.delete();
    }
    super.delete();
}
Also used : DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with DataExportJob

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

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

use of net.geoprism.registry.etl.export.DataExportJob 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)

Aggregations

DataExportJob (net.geoprism.registry.etl.export.DataExportJob)6 ExportHistory (net.geoprism.registry.etl.export.ExportHistory)4 Request (com.runwaysdk.session.Request)3 GeoprismUser (net.geoprism.GeoprismUser)3 JsonObject (com.google.gson.JsonObject)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 QueryFactory (com.runwaysdk.query.QueryFactory)1 SessionIF (com.runwaysdk.session.SessionIF)1 LinkedList (java.util.LinkedList)1 SynchronizationConfig (net.geoprism.registry.SynchronizationConfig)1 DataExportJobQuery (net.geoprism.registry.etl.export.DataExportJobQuery)1 ExportHistoryQuery (net.geoprism.registry.etl.export.ExportHistoryQuery)1 JsonWrapper (net.geoprism.registry.view.JsonWrapper)1