Search in sources :

Example 41 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class DataImportJob method process.

// TODO : It might actually be faster to first convert into a shared temp
// table, assuming you're resolving the parent references into it.
private void process(ExecutionContext executionContext, ImportHistory history, ImportStage stage, ImportConfiguration config) throws MalformedURLException, InvocationTargetException {
    validate(config);
    // TODO : We should have a single transaction where we do all the history
    // configuration upfront, that way the job is either fully configured (and
    // resumable) or it isn't (no in-between)
    config.setHistoryId(history.getOid());
    config.setJobId(this.getOid());
    if (stage.equals(ImportStage.VALIDATE)) {
        // We can't do this because it prevents people from resuming the job where
        // it left off
        // history.appLock();
        // history.setWorkProgress(0L);
        // history.setImportedRecords(0L);
        // history.apply();
        ImportProgressListenerIF progressListener = runImport(history, stage, config);
        if (progressListener.hasValidationProblems()) {
            executionContext.setStatus(AllJobStatus.FEEDBACK);
            progressListener.applyValidationProblems();
            history.appLock();
            history.clearStage();
            history.addStage(ImportStage.VALIDATION_RESOLVE);
            history.setConfigJson(config.toJSON().toString());
            history.apply();
            NotificationFacade.queue(new GlobalNotificationMessage(MessageType.IMPORT_JOB_CHANGE, null));
        } else {
            history.appLock();
            history.clearStage();
            history.addStage(ImportStage.IMPORT);
            history.setConfigJson(config.toJSON().toString());
            history.setWorkProgress(0L);
            history.setImportedRecords(0L);
            history.apply();
            NotificationFacade.queue(new GlobalNotificationMessage(MessageType.IMPORT_JOB_CHANGE, null));
            this.process(executionContext, history, ImportStage.IMPORT, config);
        }
    } else if (stage.equals(ImportStage.IMPORT)) {
        deleteValidationProblems(history);
        // We can't do this because it prevents people from resuming the job where
        // it left off
        // history.appLock();
        // history.setWorkProgress(0L);
        // history.setImportedRecords(0L);
        // history.apply();
        runImport(history, stage, config);
        if (history.hasImportErrors()) {
            history.appLock();
            history.clearStage();
            history.addStage(ImportStage.IMPORT_RESOLVE);
            history.setConfigJson(config.toJSON().toString());
            history.apply();
            executionContext.setStatus(AllJobStatus.FEEDBACK);
        } else {
            history.appLock();
            history.clearStage();
            history.addStage(ImportStage.COMPLETE);
            history.setConfigJson(config.toJSON().toString());
            history.apply();
        }
        NotificationFacade.queue(new GlobalNotificationMessage(MessageType.IMPORT_JOB_CHANGE, null));
    } else if (// TODO : I'm not sure
    stage.equals(ImportStage.RESUME_IMPORT)) // this code block is ever
    // used
    {
        runImport(history, stage, config);
        if (history.hasImportErrors()) {
            history.appLock();
            history.clearStage();
            history.addStage(ImportStage.IMPORT_RESOLVE);
            history.setConfigJson(config.toJSON().toString());
            history.apply();
            executionContext.setStatus(AllJobStatus.FEEDBACK);
        } else {
            history.appLock();
            history.clearStage();
            history.addStage(ImportStage.COMPLETE);
            history.setConfigJson(config.toJSON().toString());
            history.apply();
        }
        NotificationFacade.queue(new GlobalNotificationMessage(MessageType.IMPORT_JOB_CHANGE, null));
    } else {
        String msg = "Invalid import stage [" + stage.getEnumName() + "].";
        logger.error(msg);
        throw new ProgrammingErrorException(msg);
    }
}
Also used : ImportProgressListenerIF(net.geoprism.registry.etl.upload.ImportProgressListenerIF) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 42 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class ETLService method filterHistoryQueryBasedOnPermissions.

public void filterHistoryQueryBasedOnPermissions(ImportHistoryQuery ihq) {
    List<String> raOrgs = new ArrayList<String>();
    List<String> rmGeoObjects = new ArrayList<String>();
    Condition cond = null;
    SingleActorDAOIF actor = Session.getCurrentSession().getUser();
    for (RoleDAOIF role : actor.authorizedRoles()) {
        String roleName = role.getRoleName();
        if (RegistryRole.Type.isOrgRole(roleName) && !RegistryRole.Type.isRootOrgRole(roleName)) {
            if (RegistryRole.Type.isRA_Role(roleName)) {
                String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
                raOrgs.add(roleOrgCode);
            } else if (RegistryRole.Type.isRM_Role(roleName)) {
                rmGeoObjects.add(roleName);
            }
        }
    }
    if (!new RolePermissionService().isSRA() && raOrgs.size() == 0 && rmGeoObjects.size() == 0) {
        throw new ProgrammingErrorException("This endpoint must be invoked by an RA or RM");
    }
    for (String orgCode : raOrgs) {
        Organization org = Organization.getByCode(orgCode);
        Condition loopCond = ihq.getOrganization().EQ(org);
        if (cond == null) {
            cond = loopCond;
        } else {
            cond = cond.OR(loopCond);
        }
    }
    for (String roleName : rmGeoObjects) {
        String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
        Organization org = Organization.getByCode(roleOrgCode);
        String gotCode = RegistryRole.Type.parseGotCode(roleName);
        Condition loopCond = ihq.getGeoObjectTypeCode().EQ(gotCode).AND(ihq.getOrganization().EQ(org));
        if (cond == null) {
            cond = loopCond;
        } else {
            cond = cond.OR(loopCond);
        }
        // If they have permission to an abstract parent type, then they also have
        // permission to all its children.
        Optional<ServerGeoObjectType> op = ServiceFactory.getMetadataCache().getGeoObjectType(gotCode);
        if (op.isPresent() && op.get().getIsAbstract()) {
            List<ServerGeoObjectType> subTypes = op.get().getSubtypes();
            for (ServerGeoObjectType subType : subTypes) {
                Condition superCond = ihq.getGeoObjectTypeCode().EQ(subType.getCode()).AND(ihq.getOrganization().EQ(subType.getOrganization()));
                cond = cond.OR(superCond);
            }
        }
    }
    if (cond != null) {
        ihq.AND(cond);
    }
}
Also used : Condition(com.runwaysdk.query.Condition) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ArrayList(java.util.ArrayList) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 43 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class ETLService method cancelImportInTrans.

@Transaction
private void cancelImportInTrans(String sessionId, String json) {
    ImportConfiguration config = ImportConfiguration.build(json);
    String id = config.getVaultFileId();
    VaultFile.get(id).delete();
    if (config.getHistoryId() != null && config.getHistoryId().length() > 0) {
        String historyId = config.getHistoryId();
        ImportHistory hist = ImportHistory.get(historyId);
        hist.getConfig().enforceExecutePermissions();
        if (!hist.getStage().get(0).equals(ImportStage.VALIDATION_RESOLVE)) {
            throw new ProgrammingErrorException("Import jobs can only be canceled if they are in " + ImportStage.VALIDATION_RESOLVE.name() + " stage.");
        }
        ValidationProblemQuery vpq = new ValidationProblemQuery(new QueryFactory());
        vpq.WHERE(vpq.getHistory().EQ(historyId));
        OIterator<? extends ValidationProblem> it = vpq.getIterator();
        try {
            while (it.hasNext()) {
                it.next().delete();
            }
        } finally {
            it.close();
        }
        hist = ImportHistory.lock(historyId);
        hist.clearStage();
        hist.addStage(ImportStage.COMPLETE);
        hist.clearStatus();
        hist.addStatus(AllJobStatus.CANCELED);
        hist.setImportedRecords(0L);
        hist.apply();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 44 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class PublishMasterListJob method toJson.

public JsonObject toJson() {
    SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final MasterList masterlist = this.getMasterList();
    final ServerGeoObjectType type = masterlist.getGeoObjectType();
    List<? extends JobHistory> allHist = this.getAllJobHistory().getAll();
    final GeoprismUser user = GeoprismUser.get(this.getRunAsUser().getOid());
    try {
        final JsonObject object = new JsonObject();
        object.addProperty(PublishMasterListJob.OID, this.getOid());
        object.addProperty(PublishMasterListJob.MASTERLIST, this.getMasterListOid());
        object.addProperty(PublishMasterListJob.TYPE, type.getLabel().getValue());
        if (allHist.size() > 0) {
            final JobHistory history = allHist.get(0);
            object.addProperty(JobHistory.STATUS, history.getStatus().get(0).getDisplayLabel());
            object.addProperty("author", user.getUsername());
            object.addProperty("createDate", format.format(history.getCreateDate()));
            object.addProperty("lastUpdateDate", format.format(history.getLastUpdateDate()));
            object.addProperty("workProgress", history.getWorkProgress());
            object.addProperty("workTotal", history.getWorkTotal());
            object.addProperty("historyoryId", history.getOid());
            if (history.getStatus().get(0).equals(AllJobStatus.FAILURE) && history.getErrorJson().length() > 0) {
                String errorJson = history.getErrorJson();
                JsonObject error = JsonParser.parseString(errorJson).getAsJsonObject();
                JsonObject exception = new JsonObject();
                exception.addProperty("type", error.get("type").getAsString());
                exception.addProperty("message", history.getLocalizedError(Session.getCurrentLocale()));
                object.add("exception", exception);
            }
        }
        return object;
    } catch (JSONException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : MasterList(net.geoprism.registry.MasterList) JobHistory(com.runwaysdk.system.scheduler.JobHistory) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) JSONException(org.json.JSONException) GeoprismUser(net.geoprism.GeoprismUser) SimpleDateFormat(java.text.SimpleDateFormat) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 45 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class PublishShapefileJob method toJson.

public JsonObject toJson() {
    SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final MasterListVersion version = this.getVersion();
    final MasterList masterlist = version.getMasterlist();
    final ServerGeoObjectType type = masterlist.getGeoObjectType();
    final JobHistory history = this.getAllJobHistory().getAll().get(0);
    final GeoprismUser user = GeoprismUser.get(this.getRunAsUser().getOid());
    try {
        final JsonObject object = new JsonObject();
        object.addProperty(PublishShapefileJob.OID, this.getOid());
        object.add(PublishShapefileJob.VERSION, this.getVersion().toJSON(false));
        object.addProperty(PublishShapefileJob.TYPE, type.getLabel().getValue());
        object.addProperty(JobHistory.STATUS, history.getStatus().get(0).getDisplayLabel());
        object.addProperty("date", format.format(version.getPublishDate()));
        object.addProperty("author", user.getUsername());
        object.addProperty("createDate", format.format(history.getCreateDate()));
        object.addProperty("lastUpdateDate", format.format(history.getLastUpdateDate()));
        object.addProperty("workProgress", history.getWorkProgress());
        object.addProperty("workTotal", history.getWorkTotal());
        object.addProperty("historyoryId", history.getOid());
        return object;
    } catch (JSONException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : MasterList(net.geoprism.registry.MasterList) JobHistory(com.runwaysdk.system.scheduler.JobHistory) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) JSONException(org.json.JSONException) MasterListVersion(net.geoprism.registry.MasterListVersion) GeoprismUser(net.geoprism.GeoprismUser) SimpleDateFormat(java.text.SimpleDateFormat) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Aggregations

ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)67 IOException (java.io.IOException)34 SimpleDateFormat (java.text.SimpleDateFormat)21 JsonObject (com.google.gson.JsonObject)18 File (java.io.File)16 ParseException (java.text.ParseException)16 InputStream (java.io.InputStream)13 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)13 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)12 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)11 JSONException (org.json.JSONException)11 JsonArray (com.google.gson.JsonArray)10 List (java.util.List)10 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)8