use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class ChangeRequest method execute.
@Transaction
public void execute(String maintainerNotes, String additionalNotes) {
if (this.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
List<AbstractAction> actions = this.getOrderedActions();
Set<AllGovernanceStatus> statuses = new TreeSet<AllGovernanceStatus>();
for (AbstractAction action : actions) {
if (action instanceof UpdateAttributeAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
throw new ActionExecuteException("Unable to execute an action with the pending status");
} else if (action instanceof CreateGeoObjectAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
action.appLock();
action.clearApprovalStatus();
action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
action.apply();
action.execute();
statuses.add(AllGovernanceStatus.ACCEPTED);
} else if (action.getApprovalStatus().contains(AllGovernanceStatus.ACCEPTED)) {
action.execute();
statuses.add(AllGovernanceStatus.ACCEPTED);
} else if (action.getApprovalStatus().contains(AllGovernanceStatus.REJECTED) || action.getApprovalStatus().contains(AllGovernanceStatus.INVALID)) {
statuses.add(AllGovernanceStatus.REJECTED);
}
}
AllGovernanceStatus status = AllGovernanceStatus.REJECTED;
if (statuses.size() > 0) {
status = statuses.size() == 1 ? statuses.iterator().next() : AllGovernanceStatus.PARTIAL;
}
this.appLock();
this.setMaintainerNotes(maintainerNotes);
this.setAdditionalNotes(additionalNotes);
this.clearApprovalStatus();
this.addApprovalStatus(status);
this.apply();
// Email the contributor
try {
SingleActor actor = this.getCreatedBy();
if (actor instanceof GeoprismUser) {
String email = ((GeoprismUser) actor).getEmail();
if (email != null && email.length() > 0 && !email.contains("@noreply")) {
final String statusLabel = status.getDisplayLabel().toLowerCase(Session.getCurrentLocale());
String subject = LocalizationFacade.getFromBundles("change.request.email.implement.subject");
subject = subject.replaceAll("\\{status\\}", StringUtils.capitalize(statusLabel));
String body = LocalizationFacade.getFromBundles("change.request.email.implement.body");
body = body.replaceAll("\\\\n", "\n");
body = body.replaceAll("\\{status\\}", statusLabel);
body = body.replaceAll("\\{geoobject\\}", this.getGeoObject().getDisplayLabel().getValue());
String link = GeoregistryProperties.getRemoteServerUrl() + "cgr/manage#/registry/change-requests/" + this.getOid();
body = body.replaceAll("\\{link\\}", link);
EmailSetting.sendEmail(subject, body, new String[] { email });
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class DataImportJob method startInTrans.
@Transaction
private JobHistoryRecord startInTrans(ImportConfiguration configuration) {
configuration.enforceCreatePermissions();
ImportHistory history = (ImportHistory) this.createNewHistory();
configuration.setHistoryId(history.getOid());
configuration.setJobId(this.getOid());
history.appLock();
history.setConfigJson(configuration.toJSON().toString());
history.setImportFileId(configuration.getVaultFileId());
configuration.populate(history);
history.apply();
JobHistoryRecord record = new JobHistoryRecord(this, history);
record.apply();
return record;
}
use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class DataImportJob method resumeInTrans.
@Transaction
private void resumeInTrans(JobHistoryRecord jhr) {
ImportHistory hist = (ImportHistory) jhr.getChild();
ImportStage stage = hist.getStage().get(0);
if (hist.getStatus().get(0).equals(AllJobStatus.RUNNING)) {
// This code block happens when the server restarts after a job was
// running when it died.
// Do nothing. Allow the job to resume as normal.
} else {
if (stage.equals(ImportStage.VALIDATION_RESOLVE)) {
DataImportJob.deleteValidationProblems(hist);
hist.appLock();
hist.clearStage();
hist.addStage(ImportStage.VALIDATE);
hist.setWorkProgress(0L);
hist.setImportedRecords(0L);
hist.apply();
} else // else if (stage.equals(ImportStage.IMPORT_RESOLVE))
// {
// hist.appLock();
// hist.clearStage();
// hist.setWorkProgress(0);
// hist.addStage(ImportStage.RESUME_IMPORT);
// hist.apply();
// }
{
logger.error("Resuming job with unexpected initial stage [" + stage + "].");
hist.appLock();
hist.clearStage();
hist.addStage(ImportStage.VALIDATE);
hist.apply();
}
}
NotificationFacade.queue(new GlobalNotificationMessage(MessageType.IMPORT_JOB_CHANGE, null));
}
use of com.runwaysdk.dataaccess.transaction.Transaction 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.transaction.Transaction in project geoprism-registry by terraframe.
the class ETLService method resolveImportInTrans.
@Transaction
private void resolveImportInTrans(String historyId, ImportHistory hist) {
hist.appLock();
ImportErrorQuery ieq = new ImportErrorQuery(new QueryFactory());
ieq.WHERE(ieq.getHistory().EQ(historyId));
OIterator<? extends ImportError> it = ieq.getIterator();
try {
ImportError err = it.next();
err.delete();
} finally {
it.close();
}
hist.clearStatus();
hist.addStatus(AllJobStatus.SUCCESS);
hist.clearStage();
hist.addStage(ImportStage.COMPLETE);
hist.apply();
VaultFile file = hist.getImportFile();
file.delete();
}
Aggregations