Search in sources :

Example 6 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class ETLService method submitValidationProblemResolutionInTrans.

@Transaction
private JsonObject submitValidationProblemResolutionInTrans(String sessionId, String json) {
    JsonObject response = new JsonObject();
    JsonObject config = JsonParser.parseString(json).getAsJsonObject();
    ValidationProblem problem = ValidationProblem.get(config.get("validationProblemId").getAsString());
    ImportHistory hist = problem.getHistory();
    hist.getConfig().enforceExecutePermissions();
    String resolution = config.get("resolution").getAsString();
    if (resolution.equals(ValidationResolution.SYNONYM.name())) {
        if (problem instanceof TermReferenceProblem) {
            String classifierId = config.get("classifierId").getAsString();
            String label = config.get("label").getAsString();
            response = JsonParser.parseString(DataUploader.createClassifierSynonym(classifierId, label)).getAsJsonObject();
        } else if (problem instanceof ParentReferenceProblem) {
            String code = config.get("code").getAsString();
            String typeCode = config.get("typeCode").getAsString();
            String label = config.get("label").getAsString();
            ServerGeoObjectIF go = new ServerGeoObjectService().getGeoObjectByCode(code, typeCode);
            response = JsonParser.parseString(new GeoSynonymService().createGeoEntitySynonym(sessionId, typeCode, go.getCode(), label).toString()).getAsJsonObject();
        }
        problem.appLock();
        problem.setResolution(resolution);
        problem.apply();
    // hist.appLock();
    // hist.setErrorResolvedCount(hist.getErrorResolvedCount() + 1);
    // hist.apply();
    } else if (resolution.equals(ValidationResolution.IGNORE.name())) {
        problem.appLock();
        problem.setResolution(resolution);
        problem.apply();
    } else if (resolution.equals(ValidationResolution.CREATE.name())) {
        if (problem instanceof TermReferenceProblem) {
            String parentTermCode = config.get("parentTermCode").getAsString();
            String termJSON = config.get("termJSON").toString();
            response = RegistryService.getInstance().createTerm(sessionId, parentTermCode, termJSON).toJSON();
        } else if (problem instanceof ParentReferenceProblem) {
        // TODO
        }
        problem.appLock();
        problem.setResolution(resolution);
        problem.apply();
    } else {
        throw new UnsupportedOperationException("Invalid import resolution [" + resolution + "].");
    }
    return response;
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) JsonObject(com.google.gson.JsonObject) GeoSynonymService(net.geoprism.registry.service.GeoSynonymService) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 7 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class GeoObjectEditorControllerNoOverTime method applyInTransaction.

@Transaction
private GeoObject applyInTransaction(String sessionId, String sPtn, String sGo, Boolean isNew, String masterListId) {
    final Date startDate = new Date();
    final Date endDate = ValueOverTime.INFINITY_END_DATE;
    GeoObject go;
    Map<String, String> roles = Session.getCurrentSession().getUserRoles();
    if (roles.keySet().contains(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE)) {
        Instant base = Instant.now();
        int sequence = 0;
        ChangeRequest request = new ChangeRequest();
        request.addApprovalStatus(AllGovernanceStatus.PENDING);
        request.apply();
        if (!isNew) {
            UpdateGeoObjectAction action = new UpdateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        } else {
            CreateGeoObjectAction action = new CreateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyChangeRequest(sessionId, request, ptn, isNew, base, sequence, startDate, endDate);
    } else {
        if (!isNew) {
            go = RegistryService.getInstance().updateGeoObject(sessionId, sGo.toString(), startDate, endDate);
        } else {
            go = RegistryService.getInstance().createGeoObject(sessionId, sGo.toString(), startDate, endDate);
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyPtn(sessionId, ptn, startDate, endDate);
        // Update the master list record
        if (masterListId != null) {
            ServerGeoObjectService service = new ServerGeoObjectService();
            ServerGeoObjectIF geoObject = service.getGeoObject(go);
            if (!isNew) {
                ListTypeVersion.get(masterListId).updateRecord(geoObject);
            } else {
                ListTypeVersion.get(masterListId).publishRecord(geoObject);
            }
        }
        return go;
    }
    return null;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Instant(java.time.Instant) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 8 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class EdgeJsonImporter method importData.

public void importData() throws JsonSyntaxException, IOException {
    ServerGeoObjectService service = new ServerGeoObjectService();
    JsonObject data = JsonParser.parseString(IOUtils.toString(stream, "UTF-8")).getAsJsonObject();
    JsonArray edges = data.get("edges").getAsJsonArray();
    logger.info("About to import [" + edges.size() + "] edges as MdEdge [" + this.graphType.getCode() + "].");
    for (int i = 0; i < edges.size(); ++i) {
        JsonObject joEdge = edges.get(i).getAsJsonObject();
        String sourceCode = joEdge.get("source").getAsString();
        String sourceTypeCode = joEdge.get("sourceType").getAsString();
        String targetCode = joEdge.get("target").getAsString();
        String targetTypeCode = joEdge.get("targetType").getAsString();
        ServerGeoObjectIF source = service.getGeoObjectByCode(sourceCode, sourceTypeCode);
        ServerGeoObjectIF target = service.getGeoObjectByCode(targetCode, targetTypeCode);
        source.addGraphChild(target, this.graphType, this.startDate, this.endDate);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) JsonObject(com.google.gson.JsonObject)

Example 9 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class AbstractFhirResourceProcessor method configure.

public void configure(FhirExternalSystem system) {
    this.system = system;
    this.service = new ServerGeoObjectService();
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService)

Example 10 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class BusinessObjectImporter method getGeoObject.

/**
 * Returns the entity as defined by the 'parent' and 'parentType' attributes
 * of the given feature. If an entity is not found then Earth is returned by
 * default. The 'parent' value of the feature must define an entity name or a
 * geo oid. The 'parentType' value of the feature must define the localized
 * display label of the universal.
 *
 * This algorithm resolves parent contexts starting at the top of the
 * hierarchy and traversing downward, resolving hierarchy inheritance as
 * needed. If at any point a location cannot be found, a SmartException will
 * be thrown which varies depending on the ParentMatchStrategy.
 *
 * @param feature
 *          Shapefile feature used to determine the parent
 * @return Parent entity
 */
private ServerGeoObjectIF getGeoObject(FeatureRow feature) {
    List<Location> locations = this.configuration.getLocations();
    ServerGeoObjectIF parent = null;
    JSONArray context = new JSONArray();
    ArrayList<String> parentKeyBuilder = new ArrayList<String>();
    for (Location location : locations) {
        Object label = getParentCode(feature, location);
        if (label != null) {
            String key = parent != null ? parent.getCode() + "-" + label : label.toString();
            parentKeyBuilder.add(label.toString());
            if (this.configuration.isExclusion(GeoObjectImportConfiguration.PARENT_EXCLUSION, key)) {
                throw new IgnoreRowException();
            }
            // Check the parent cache
            String parentChainKey = StringUtils.join(parentKeyBuilder, parentConcatToken);
            if (this.cache.containsKey(parentChainKey)) {
                parent = this.cache.get(parentChainKey);
                JSONObject element = new JSONObject();
                element.put("label", label.toString());
                element.put("type", location.getType().getLabel().getValue());
                context.put(element);
                continue;
            }
            final ParentMatchStrategy ms = location.getMatchStrategy();
            // Search
            ServerGeoObjectQuery query = new ServerGeoObjectService().createQuery(location.getType(), this.configuration.getDate());
            query.setLimit(20);
            if (ms.equals(ParentMatchStrategy.CODE)) {
                query.setRestriction(new ServerCodeRestriction(label.toString()));
            } else if (ms.equals(ParentMatchStrategy.EXTERNAL)) {
                query.setRestriction(new ServerExternalIdRestriction(this.getConfiguration().getExternalSystem(), label.toString()));
            } else if (ms.equals(ParentMatchStrategy.DHIS2_PATH)) {
                String path = label.toString();
                String dhis2Parent;
                try {
                    if (path.startsWith("/")) {
                        path = path.substring(1);
                    }
                    String[] pathArr = path.split("/");
                    dhis2Parent = pathArr[pathArr.length - 2];
                } catch (Throwable t) {
                    InvalidDhis2PathException ex = new InvalidDhis2PathException(t);
                    ex.setDhis2Path(path);
                    throw ex;
                }
                query.setRestriction(new ServerExternalIdRestriction(this.getConfiguration().getExternalSystem(), dhis2Parent));
            } else {
                query.setRestriction(new ServerSynonymRestriction(label.toString(), this.configuration.getDate(), parent, location.getHierarchy()));
            }
            List<ServerGeoObjectIF> results = query.getResults();
            if (results != null && results.size() > 0) {
                ServerGeoObjectIF result = null;
                // into the query SQL.
                for (ServerGeoObjectIF loop : results) {
                    if (result != null && !result.getCode().equals(loop.getCode())) {
                        AmbiguousParentException ex = new AmbiguousParentException();
                        ex.setParentLabel(label.toString());
                        ex.setContext(context.toString());
                        throw ex;
                    }
                    result = loop;
                }
                parent = result;
                JSONObject element = new JSONObject();
                element.put("label", label.toString());
                element.put("type", location.getType().getLabel().getValue());
                context.put(element);
                this.cache.put(parentChainKey, parent);
            } else {
                if (ms.equals(ParentMatchStrategy.CODE)) {
                    final ParentCodeException ex = new ParentCodeException();
                    ex.setParentCode(label.toString());
                    ex.setParentType(location.getType().getLabel().getValue());
                    ex.setContext(context.toString());
                    throw ex;
                } else if (ms.equals(ParentMatchStrategy.EXTERNAL)) {
                    final ExternalParentReferenceException ex = new ExternalParentReferenceException();
                    ex.setExternalId(label.toString());
                    ex.setParentType(location.getType().getLabel().getValue());
                    ex.setContext(context.toString());
                    throw ex;
                } else {
                    String parentCode = (parent == null) ? null : parent.getCode();
                    ParentReferenceProblem prp = new ParentReferenceProblem(location.getType().getCode(), label.toString(), parentCode, context.toString());
                    prp.addAffectedRowNumber(this.progressListener.getWorkProgress() + 1);
                    prp.setHistoryId(this.configuration.historyId);
                    this.progressListener.addReferenceProblem(prp);
                }
                return null;
            }
        }
    }
    return parent;
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ServerSynonymRestriction(net.geoprism.registry.query.ServerSynonymRestriction) IgnoreRowException(net.geoprism.registry.io.IgnoreRowException) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) JSONObject(org.json.JSONObject) AmbiguousParentException(net.geoprism.registry.io.AmbiguousParentException) ParentCodeException(net.geoprism.registry.io.ParentCodeException) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) BusinessObject(net.geoprism.registry.model.BusinessObject) VertexObject(com.runwaysdk.business.graph.VertexObject) ParentMatchStrategy(net.geoprism.registry.io.ParentMatchStrategy) ParentReferenceProblem(net.geoprism.registry.etl.ParentReferenceProblem) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) ServerExternalIdRestriction(net.geoprism.registry.query.ServerExternalIdRestriction) Location(net.geoprism.registry.io.Location)

Aggregations

ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)33 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)23 Request (com.runwaysdk.session.Request)10 JsonObject (com.google.gson.JsonObject)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)7 AllowAllGeoObjectPermissionService (net.geoprism.registry.permission.AllowAllGeoObjectPermissionService)7 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)7 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)6 Date (java.util.Date)5 JsonArray (com.google.gson.JsonArray)4 Location (net.geoprism.registry.io.Location)4 GraphType (net.geoprism.registry.model.GraphType)4 ServerCodeRestriction (net.geoprism.registry.query.ServerCodeRestriction)4 ServerGeoObjectQuery (net.geoprism.registry.query.ServerGeoObjectQuery)4 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)4 ArrayList (java.util.ArrayList)3 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)3 ServerGraphNode (net.geoprism.registry.model.ServerGraphNode)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2