Search in sources :

Example 16 with GeoprismUser

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;
}
Also used : ExportHistory(net.geoprism.registry.etl.export.ExportHistory) JsonObject(com.google.gson.JsonObject) GeoprismUser(net.geoprism.GeoprismUser) DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Request(com.runwaysdk.session.Request)

Example 17 with GeoprismUser

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();
    }
}
Also used : JsonObject(com.google.gson.JsonObject) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) Date(java.util.Date) ErrorResolution(net.geoprism.registry.etl.ImportError.ErrorResolution) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request) Condition(com.runwaysdk.query.Condition) DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Organization(net.geoprism.registry.Organization) JsonWrapper(net.geoprism.registry.view.JsonWrapper) Optional(org.commongeoregistry.adapter.Optional) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) JobHistory(com.runwaysdk.system.scheduler.JobHistory) Collectors(java.util.stream.Collectors) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) Page(net.geoprism.registry.view.Page) List(java.util.List) JsonArray(com.google.gson.JsonArray) GraphType(net.geoprism.registry.model.GraphType) AllJobStatus(com.runwaysdk.system.scheduler.AllJobStatus) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RegistryIdService(net.geoprism.registry.service.RegistryIdService) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) JobHistoryRecord(com.runwaysdk.system.scheduler.JobHistoryRecord) RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) GeoSynonymService(net.geoprism.registry.service.GeoSynonymService) RequestType(com.runwaysdk.session.RequestType) SimpleDateFormat(java.text.SimpleDateFormat) ExecutableJob(com.runwaysdk.system.scheduler.ExecutableJob) JsonParser(com.google.gson.JsonParser) RegistryService(net.geoprism.registry.service.RegistryService) ServiceFactory(net.geoprism.registry.service.ServiceFactory) ArrayList(java.util.ArrayList) QueryFactory(com.runwaysdk.query.QueryFactory) LinkedList(java.util.LinkedList) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) JsonSyntaxException(com.google.gson.JsonSyntaxException) ExportError(net.geoprism.registry.etl.export.ExportError) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) IOException(java.io.IOException) ValidationResolution(net.geoprism.registry.etl.ValidationProblem.ValidationResolution) MultipartFileParameter(com.runwaysdk.controller.MultipartFileParameter) ExportErrorQuery(net.geoprism.registry.etl.export.ExportErrorQuery) OIterator(com.runwaysdk.query.OIterator) VaultFile(com.runwaysdk.system.VaultFile) GeoprismUser(net.geoprism.GeoprismUser) Session(com.runwaysdk.session.Session) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) InputStream(java.io.InputStream) DataUploader(net.geoprism.DataUploader) QueryFactory(com.runwaysdk.query.QueryFactory) JsonWrapper(net.geoprism.registry.view.JsonWrapper) GeoprismUser(net.geoprism.GeoprismUser) Request(com.runwaysdk.session.Request)

Example 18 with GeoprismUser

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);
    }
}
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 19 with GeoprismUser

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

Example 20 with GeoprismUser

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();
    }
}
Also used : UserNotFoundException(net.geoprism.registry.session.UserNotFoundException) UserNotOuathEnabledException(net.geoprism.registry.session.UserNotOuathEnabledException) QueryFactory(com.runwaysdk.query.QueryFactory) UserDAO(com.runwaysdk.business.rbac.UserDAO) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) UsersQuery(com.runwaysdk.system.UsersQuery) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) GeoprismUser(net.geoprism.GeoprismUser) UserInfo(net.geoprism.registry.UserInfo) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

GeoprismUser (net.geoprism.GeoprismUser)22 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)9 JsonObject (com.google.gson.JsonObject)8 Request (com.runwaysdk.session.Request)8 QueryFactory (com.runwaysdk.query.QueryFactory)7 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)6 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)5 JobHistory (com.runwaysdk.system.scheduler.JobHistory)5 SimpleDateFormat (java.text.SimpleDateFormat)5 LinkedList (java.util.LinkedList)5 DataExportJob (net.geoprism.registry.etl.export.DataExportJob)5 ExportHistory (net.geoprism.registry.etl.export.ExportHistory)5 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)4 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)3 ArrayList (java.util.ArrayList)3 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 MultipartFileParameter (com.runwaysdk.controller.MultipartFileParameter)2