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);
}
}
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);
}
}
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();
}
}
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);
}
}
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);
}
}
Aggregations