use of net.geoprism.GeoprismUser 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;
}
use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.
the class ETLService method getCompletedImports.
@Request(RequestType.SESSION)
public JsonObject getCompletedImports(String sessionId, int pageSize, int pageNumber, String sortAttr, boolean isAscending) {
QueryFactory qf = new QueryFactory();
ImportHistoryQuery ihq = new ImportHistoryQuery(qf);
ihq.WHERE(ihq.getStatus().containsExactly(AllJobStatus.SUCCESS).OR(ihq.getStatus().containsExactly(AllJobStatus.FAILURE)).OR(ihq.getStatus().containsExactly(AllJobStatus.CANCELED)));
this.filterHistoryQueryBasedOnPermissions(ihq);
ihq.restrictRows(pageSize, pageNumber);
ihq.ORDER_BY(ihq.get(sortAttr), isAscending ? SortOrder.ASC : SortOrder.DESC);
try (OIterator<? extends ImportHistory> it = ihq.getIterator()) {
List<JsonWrapper> results = it.getAll().stream().map(hist -> {
DataImportJob job = (DataImportJob) hist.getAllJob().getAll().get(0);
GeoprismUser user = GeoprismUser.get(job.getRunAsUser().getOid());
return new JsonWrapper(serializeHistory(hist, user, job));
}).collect(Collectors.toList());
return new Page<JsonWrapper>(ihq.getCount(), ihq.getPageNumber(), ihq.getPageSize(), results).toJSON();
}
}
use of net.geoprism.GeoprismUser 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 net.geoprism.GeoprismUser 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);
}
}
use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.
the class RegistrySessionService method getActor.
@Transaction
private static synchronized SingleActorDAOIF getActor(OauthServer server, String username) throws JSONException {
UsersQuery query = new UsersQuery(new QueryFactory());
query.WHERE(query.getUsername().EQ(username));
OIterator<? extends Users> it = query.getIterator();
try {
if (it.hasNext()) {
UserDAO user = (UserDAO) BusinessFacade.getEntityDAO(it.next());
try {
GeoprismUser geoprismUser = GeoprismUser.getByUsername(user.getUsername());
UserInfo userInfo = UserInfo.getByUser(geoprismUser);
ExternalSystem system = ExternalSystem.get(userInfo.getExternalSystemOid());
if (system instanceof DHIS2ExternalSystem) {
DHIS2ExternalSystem dhis2System = (DHIS2ExternalSystem) system;
if (dhis2System.getOauthServerOid().equals(server.getOid())) {
return user;
}
}
} catch (Throwable t) {
logger.error("Encountered an unexpected error while logging user in.", t);
}
UserNotOuathEnabledException ex = new UserNotOuathEnabledException();
ex.setUsername(user.getUsername());
ex.setOauthServer(server.getDisplayLabel().getValue());
throw ex;
} else {
UserNotFoundException ex = new UserNotFoundException();
ex.setUsername(username);
throw ex;
}
} finally {
it.close();
}
}
Aggregations