Search in sources :

Example 21 with GlobalNotificationMessage

use of net.geoprism.registry.ws.GlobalNotificationMessage in project geoprism-registry by terraframe.

the class ListCurator method run.

public void run() {
    final ListType masterlist = version.getListType();
    final ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
    // final MdBusinessDAO mdBusiness =
    // MdBusinessDAO.get(version.getMdBusinessOid()).getBusinessDAO();
    BusinessQuery query = this.version.buildQuery(new JsonObject());
    query.ORDER_BY_DESC(query.aCharacter(DefaultAttribute.CODE.getName()));
    history.appLock();
    history.setWorkTotal(query.getCount());
    history.setWorkProgress(0L);
    history.apply();
    OIterator<Business> objects = query.getIterator();
    try {
        while (objects.hasNext()) {
            Business row = objects.next();
            final Geometry geom = row.getObjectValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
            final String code = row.getValue(DefaultAttribute.CODE.getName());
            if (geom == null) {
                GeoObjectProblem problem = new GeoObjectProblem();
                problem.setHistory(history);
                problem.setResolution(CurationResolution.UNRESOLVED.name());
                problem.setProblemType(GeoObjectProblemType.NO_GEOMETRY.name());
                problem.setTypeCode(type.getCode());
                problem.setGoCode(code);
                problem.setUid(row.getValue(DefaultAttribute.UID.getName()));
                problem.apply();
            }
            history.appLock();
            history.setWorkProgress(history.getWorkProgress() + 1);
            history.apply();
            if (history.getWorkProgress() % 100 == 0) {
                NotificationFacade.queue(new GlobalNotificationMessage(MessageType.CURATION_JOB_CHANGE, null));
            }
        }
    } finally {
        objects.close();
    }
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) Geometry(com.vividsolutions.jts.geom.Geometry) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ListType(net.geoprism.registry.ListType) JsonObject(com.google.gson.JsonObject) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Business(com.runwaysdk.business.Business)

Example 22 with GlobalNotificationMessage

use of net.geoprism.registry.ws.GlobalNotificationMessage in project geoprism-registry by terraframe.

the class DHIS2SynchronizationManager method synchronize.

public void synchronize() {
    this.init();
    final ExternalSystem es = dhis2Config.getSystem();
    long rowIndex = 0;
    long total = 0;
    long exportCount = 0;
    SortedSet<DHIS2SyncLevel> levels = dhis2Config.getLevels();
    Boolean includeTranslations = LocalizationFacade.getInstalledLocales().size() > 0;
    // First calculate the total number of records
    HashMap<Integer, Long> countAtLevel = new HashMap<Integer, Long>();
    int expectedLevel = 0;
    for (DHIS2SyncLevel level : levels) {
        if (level.getLevel() != expectedLevel) {
            throw new ProgrammingErrorException("Unexpected level number [" + level.getLevel() + "].");
        }
        if (level.getSyncType() != null && !DHIS2SyncLevel.Type.NONE.equals(level.getSyncType())) {
            long count = this.getCount(level.getGeoObjectType());
            total += count;
            countAtLevel.put(level.getLevel(), count);
        }
        expectedLevel++;
    }
    history.appLock();
    history.setWorkTotal(total);
    history.apply();
    // Now do the work
    for (DHIS2SyncLevel level : levels) {
        if (level.getSyncType() != null && !DHIS2SyncLevel.Type.NONE.equals(level.getSyncType())) {
            long skip = 0;
            long pageSize = 1000;
            long count = countAtLevel.get(level.getLevel());
            while (skip < count) {
                List<VertexServerGeoObject> objects = this.query(level.getGeoObjectType(), skip, pageSize);
                for (VertexServerGeoObject go : objects) {
                    try {
                        this.exportGeoObject(dhis2Config, level, levels, rowIndex, go, includeTranslations);
                        exportCount++;
                        history.appLock();
                        history.setWorkProgress(rowIndex);
                        history.setExportedRecords(exportCount);
                        history.apply();
                        if (level.getOrgUnitGroupId() != null && level.getOrgUnitGroupId().length() > 0) {
                            final String externalId = go.getExternalId(es);
                            level.getOrCreateOrgUnitGroupIdSet(level.getOrgUnitGroupId()).add(externalId);
                        }
                    } catch (DHIS2SyncError ee) {
                        recordExportError(ee, history);
                    }
                    rowIndex++;
                }
                ;
                // Export OrgUnitGroup changes
                if (level.getOrgUnitGroupIdSet().size() > 0) {
                    try {
                        Map<String, Set<String>> orgUnitGroupIdSet = level.getOrgUnitGroupIdSet();
                        // Fetch and populate all the org unit groups with the ids of org units that we will be exporting
                        MetadataGetResponse<OrganisationUnitGroup> resp = dhis2.metadataGet(OrganisationUnitGroup.class);
                        this.service.validateDhis2Response(resp);
                        List<OrganisationUnitGroup> orgUnitGroups = resp.getObjects();
                        if (orgUnitGroups != null) {
                            Iterator<? extends OrganisationUnitGroup> it = orgUnitGroups.iterator();
                            while (it.hasNext()) {
                                OrganisationUnitGroup group = it.next();
                                if (orgUnitGroupIdSet.containsKey(group.getId())) {
                                    orgUnitGroupIdSet.get(group.getId()).addAll(group.getOrgUnitIds());
                                    group.setOrgUnitIds(orgUnitGroupIdSet.get(group.getId()));
                                    orgUnitGroupIdSet.remove(group.getId());
                                } else {
                                    it.remove();
                                }
                            }
                            if (orgUnitGroups.size() > 0) {
                                JsonObject payload = new JsonObject();
                                JsonArray jaOrgUnitGroups = new JsonArray();
                                for (OrganisationUnitGroup group : orgUnitGroups) {
                                    GsonBuilder builder = new GsonBuilder();
                                    JsonObject joOrgUnitGroup = builder.create().toJsonTree(group, group.getClass()).getAsJsonObject();
                                    joOrgUnitGroup.remove("created");
                                    joOrgUnitGroup.remove("lastUpdated");
                                    joOrgUnitGroup.remove("symbol");
                                    joOrgUnitGroup.remove("publicAccess");
                                    joOrgUnitGroup.remove("user");
                                    joOrgUnitGroup.remove("userGroupAccesses");
                                    joOrgUnitGroup.remove("attributeValues");
                                    joOrgUnitGroup.remove("translations");
                                    joOrgUnitGroup.remove("userAccesses");
                                    jaOrgUnitGroups.add(joOrgUnitGroup);
                                }
                                payload.add(DHIS2Objects.ORGANISATION_UNIT_GROUPS, jaOrgUnitGroups);
                                List<NameValuePair> params = new ArrayList<NameValuePair>();
                                MetadataImportResponse resp2 = dhis2.metadataPost(params, new StringEntity(payload.toString(), Charset.forName("UTF-8")));
                                this.service.validateDhis2Response(resp2);
                            }
                        }
                    } catch (InvalidLoginException e) {
                        LoginException cgrlogin = new LoginException(e);
                        throw cgrlogin;
                    } catch (HTTPException | BadServerUriException e) {
                        HttpError cgrhttp = new HttpError(e);
                        throw cgrhttp;
                    }
                }
                skip += pageSize;
                NotificationFacade.queue(new GlobalNotificationMessage(MessageType.DATA_EXPORT_JOB_CHANGE, null));
            }
        }
    }
    history.appLock();
    history.setWorkProgress(rowIndex);
    history.setExportedRecords(exportCount);
    history.clearStage();
    history.addStage(ExportStage.COMPLETE);
    history.apply();
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.DATA_EXPORT_JOB_CHANGE, null));
    handleExportErrors();
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) HashMap(java.util.HashMap) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) DHIS2SyncLevel(net.geoprism.registry.etl.DHIS2SyncLevel) ArrayList(java.util.ArrayList) MetadataImportResponse(net.geoprism.dhis2.dhis2adapter.response.MetadataImportResponse) JsonObject(com.google.gson.JsonObject) StringEntity(org.apache.http.entity.StringEntity) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) GsonBuilder(com.google.gson.GsonBuilder) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) DHIS2SyncError(net.geoprism.registry.dhis2.DHIS2FeatureService.DHIS2SyncError) OrganisationUnitGroup(net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup) JsonArray(com.google.gson.JsonArray) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) HttpError(net.geoprism.registry.etl.export.HttpError) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage)

Example 23 with GlobalNotificationMessage

use of net.geoprism.registry.ws.GlobalNotificationMessage in project geoprism-registry by terraframe.

the class FhirImportSynchronizationManager method synchronize.

public void synchronize() {
    final FhirExternalSystem system = (FhirExternalSystem) this.details.getSystem();
    try (FhirConnection connection = FhirConnectionFactory.get(system)) {
        FhirResourceProcessor processor = FhirFactory.getProcessor(this.details.getImplementation());
        FhirResourceImporter importer = new FhirResourceImporter(connection, processor, this.history, this.config.getLastSynchDate());
        importer.synchronize();
        history.appLock();
        history.clearStage();
        history.addStage(ExportStage.COMPLETE);
        history.apply();
        config.appLock();
        config.setLastSynchDate(new Date());
        config.apply();
        NotificationFacade.queue(new GlobalNotificationMessage(MessageType.DATA_EXPORT_JOB_CHANGE, null));
        handleExportErrors();
    } catch (ExportJobHasErrors e) {
        throw e;
    } catch (Exception e) {
        throw new HttpError(e);
    }
}
Also used : HttpError(net.geoprism.registry.etl.export.HttpError) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) ExportJobHasErrors(net.geoprism.registry.etl.ExportJobHasErrors) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) Date(java.util.Date) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 24 with GlobalNotificationMessage

use of net.geoprism.registry.ws.GlobalNotificationMessage in project geoprism-registry by terraframe.

the class ListTypeService method publishVersion.

@Request(RequestType.SESSION)
public JsonObject publishVersion(String sessionId, String oid) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    // Only a working version can be republished.
    if (!version.getWorking()) {
        throw new UnsupportedOperationException();
    }
    this.enforceReadPermissions(version.getListType());
    QueryFactory factory = new QueryFactory();
    PublishListTypeVersionJobQuery query = new PublishListTypeVersionJobQuery(factory);
    query.WHERE(query.getVersion().EQ(version));
    JobHistoryQuery q = new JobHistoryQuery(factory);
    q.WHERE(q.getStatus().containsAny(AllJobStatus.NEW, AllJobStatus.QUEUED, AllJobStatus.RUNNING));
    q.AND(q.job(query));
    if (q.getCount() > 0) {
        throw new DuplicateJobException("This version has already been queued for publishing");
    }
    PublishListTypeVersionJob job = new PublishListTypeVersionJob();
    job.setRunAsUserId(Session.getCurrentSession().getUser().getOid());
    job.setVersion(version);
    job.setListType(version.getListType());
    job.apply();
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.PUBLISH_JOB_CHANGE, null));
    final JobHistory history = job.start();
    JsonObject resp = new JsonObject();
    resp.addProperty("jobOid", history.getOid());
    return resp;
}
Also used : PublishListTypeVersionJob(net.geoprism.registry.etl.PublishListTypeVersionJob) QueryFactory(com.runwaysdk.query.QueryFactory) JobHistoryQuery(com.runwaysdk.system.scheduler.JobHistoryQuery) DuplicateJobException(net.geoprism.registry.etl.DuplicateJobException) JobHistory(com.runwaysdk.system.scheduler.JobHistory) PublishListTypeVersionJobQuery(net.geoprism.registry.etl.PublishListTypeVersionJobQuery) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Request(com.runwaysdk.session.Request)

Example 25 with GlobalNotificationMessage

use of net.geoprism.registry.ws.GlobalNotificationMessage in project geoprism-registry by terraframe.

the class RegistryService method updateGeoObjectType.

/**
 * Updates the given {@link GeoObjectType} represented as JSON.
 *
 * @pre given {@link GeoObjectType} must already exist.
 *
 * @param sessionId
 * @param gtJSON
 *          JSON of the {@link GeoObjectType} to be updated.
 * @return updated {@link GeoObjectType}
 */
@Request(RequestType.SESSION)
public GeoObjectType updateGeoObjectType(String sessionId, String gtJSON) {
    GeoObjectType geoObjectType = GeoObjectType.fromJSON(gtJSON, adapter);
    ServerGeoObjectType serverGeoObjectType = ServerGeoObjectType.get(geoObjectType.getCode());
    ServiceFactory.getGeoObjectTypePermissionService().enforceCanWrite(geoObjectType.getOrganizationCode(), serverGeoObjectType, geoObjectType.getIsPrivate());
    serverGeoObjectType.update(geoObjectType);
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.TYPE_CACHE_CHANGE, null));
    return serverGeoObjectType.getType();
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Aggregations

GlobalNotificationMessage (net.geoprism.registry.ws.GlobalNotificationMessage)25 Date (java.util.Date)5 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)4 Request (com.runwaysdk.session.Request)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 JsonObject (com.google.gson.JsonObject)3 Session (com.runwaysdk.session.Session)3 HttpError (net.geoprism.registry.etl.export.HttpError)3 FhirExternalSystem (net.geoprism.registry.graph.FhirExternalSystem)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 ListTypeVersion (net.geoprism.registry.ListTypeVersion)2 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)2 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 Business (com.runwaysdk.business.Business)1 BusinessQuery (com.runwaysdk.business.BusinessQuery)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 JobHistory (com.runwaysdk.system.scheduler.JobHistory)1 JobHistoryQuery (com.runwaysdk.system.scheduler.JobHistoryQuery)1