Search in sources :

Example 51 with ServerGeoObjectType

use of net.geoprism.registry.model.ServerGeoObjectType in project geoprism-registry by terraframe.

the class HierarchyService method addToHierarchy.

/**
 * Adds the {@link GeoObjectType} with the given child code to the parent
 * {@link GeoObjectType} with the given code for the given
 * {@link HierarchyType} code.
 *
 * @param sessionId
 * @param hierarchyTypeCode
 *          code of the {@link HierarchyType} the child is being added to.
 * @param parentGeoObjectTypeCode
 *          parent {@link GeoObjectType}.
 * @param childGeoObjectTypeCode
 *          child {@link GeoObjectType}.
 */
@Request(RequestType.SESSION)
public HierarchyType addToHierarchy(String sessionId, String hierarchyTypeCode, String parentGeoObjectTypeCode, String childGeoObjectTypeCode) {
    ServerHierarchyType type = ServerHierarchyType.get(hierarchyTypeCode);
    ServerGeoObjectType parentType = ServerGeoObjectType.get(parentGeoObjectTypeCode);
    ServerGeoObjectType childType = ServerGeoObjectType.get(childGeoObjectTypeCode);
    ServiceFactory.getGeoObjectTypeRelationshipPermissionService().enforceCanAddChild(type, parentType, childType);
    type.addToHierarchy(parentType, childType);
    return type.toHierarchyType();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request)

Example 52 with ServerGeoObjectType

use of net.geoprism.registry.model.ServerGeoObjectType in project geoprism-registry by terraframe.

the class HierarchyService method getHierarchiesForType.

@Request(RequestType.SESSION)
public JsonArray getHierarchiesForType(String sessionId, String code, Boolean includeTypes) {
    ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(code);
    List<ServerHierarchyType> hierarchyTypes = ServerHierarchyType.getAll();
    JsonArray hierarchies = new JsonArray();
    HierarchyTypePermissionServiceIF htpService = ServiceFactory.getHierarchyPermissionService();
    GeoObjectRelationshipPermissionServiceIF grpService = ServiceFactory.getGeoObjectRelationshipPermissionService();
    for (ServerHierarchyType sHT : hierarchyTypes) {
        if (htpService.canRead(sHT.getOrganizationCode())) {
            List<GeoObjectType> parents = geoObjectType.getTypeAncestors(sHT, true);
            if (parents.size() > 0 || geoObjectType.isRoot(sHT)) {
                JsonObject object = new JsonObject();
                object.addProperty("code", sHT.getCode());
                object.addProperty("label", sHT.getDisplayLabel().getValue());
                if (includeTypes) {
                    JsonArray pArray = new JsonArray();
                    for (GeoObjectType parent : parents) {
                        ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
                        if (!pType.getCode().equals(geoObjectType.getCode()) && grpService.canViewChild(sHT.getOrganizationCode(), null, pType)) {
                            JsonObject pObject = new JsonObject();
                            pObject.addProperty("code", pType.getCode());
                            pObject.addProperty("label", pType.getLabel().getValue());
                            pArray.add(pObject);
                        }
                    }
                    object.add("parents", pArray);
                }
                hierarchies.add(object);
            }
        }
    }
    if (hierarchies.size() == 0) {
        for (ServerHierarchyType sHT : hierarchyTypes) {
            if (htpService.canWrite(sHT.getOrganizationCode())) {
                if (geoObjectType.isRoot(sHT)) {
                    JsonObject object = new JsonObject();
                    object.addProperty("code", sHT.getCode());
                    object.addProperty("label", sHT.getDisplayLabel().getValue());
                    object.add("parents", new JsonArray());
                    hierarchies.add(object);
                }
            }
        }
    }
    return hierarchies;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) Request(com.runwaysdk.session.Request)

Example 53 with ServerGeoObjectType

use of net.geoprism.registry.model.ServerGeoObjectType in project geoprism-registry by terraframe.

the class GeoObjectImportConfiguration method fromJSON.

@Request
public GeoObjectImportConfiguration fromJSON(String json, boolean includeCoordinates) {
    super.fromJSON(json);
    SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    JSONObject config = new JSONObject(json);
    JSONObject type = config.getJSONObject(TYPE);
    JSONArray locations = config.has(LOCATIONS) ? config.getJSONArray(LOCATIONS) : new JSONArray();
    JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
    String code = type.getString(GeoObjectType.JSON_CODE);
    ServerGeoObjectType got = ServerGeoObjectType.get(code);
    this.setType(got);
    this.setIncludeCoordinates(includeCoordinates);
    this.setPostalCode(config.has(POSTAL_CODE) && config.getBoolean(POSTAL_CODE));
    if (config.has(REVEAL_GEOMETRY_COLUMN)) {
        this.setRevealGeometryColumn(config.getString(REVEAL_GEOMETRY_COLUMN));
    }
    try {
        if (config.has(GeoObjectImportConfiguration.START_DATE)) {
            this.setStartDate(format.parse(config.getString(GeoObjectImportConfiguration.START_DATE)));
        }
        if (config.has(GeoObjectImportConfiguration.END_DATE)) {
            this.setEndDate(format.parse(config.getString(GeoObjectImportConfiguration.END_DATE)));
        }
    } catch (ParseException e) {
        throw new ProgrammingErrorException(e);
    }
    if (config.has(HIERARCHY)) {
        String hCode = config.getString(HIERARCHY);
        if (hCode.length() > 0) {
            ServerHierarchyType hierarchyType = ServerHierarchyType.get(hCode);
            List<GeoObjectType> ancestors = got.getTypeAncestors(hierarchyType, true);
            this.setHierarchy(hierarchyType);
            if (ancestors.size() > 0) {
                this.setRoot(null);
            }
        }
    }
    if (config.has(EXCLUSIONS)) {
        JSONArray exclusions = config.getJSONArray(EXCLUSIONS);
        for (int i = 0; i < exclusions.length(); i++) {
            JSONObject exclusion = exclusions.getJSONObject(i);
            String attributeName = exclusion.getString(AttributeType.JSON_CODE);
            String value = exclusion.getString(VALUE);
            this.addExclusion(attributeName, value);
        }
    }
    for (int i = 0; i < attributes.length(); i++) {
        JSONObject attribute = attributes.getJSONObject(i);
        if (attribute.has(TARGET)) {
            String attributeName = attribute.getString(AttributeType.JSON_CODE);
            // In the case of a spreadsheet, this ends up being the column header
            String target = attribute.getString(TARGET);
            if (attribute.has("locale")) {
                String locale = attribute.getString("locale");
                if (this.getFunction(attributeName) == null) {
                    this.setFunction(attributeName, new LocalizedValueFunction());
                }
                LocalizedValueFunction function = (LocalizedValueFunction) this.getFunction(attributeName);
                function.add(locale, new BasicColumnFunction(target));
            } else {
                this.setFunction(attributeName, new BasicColumnFunction(target));
            }
        }
    }
    for (int i = 0; i < locations.length(); i++) {
        JSONObject location = locations.getJSONObject(i);
        if (location.has(TARGET) && location.getString(TARGET).length() > 0 && location.has(MATCH_STRATEGY) && location.getString(MATCH_STRATEGY).length() > 0) {
            String pCode = location.getString(AttributeType.JSON_CODE);
            ServerGeoObjectType pType = ServerGeoObjectType.get(pCode);
            ServerHierarchyType pHierarchy = got.findHierarchy(this.hierarchy, pType);
            String target = location.getString(TARGET);
            ParentMatchStrategy matchStrategy = ParentMatchStrategy.valueOf(location.getString(MATCH_STRATEGY));
            // coming in with use BasicColumnFunctions
            if (location.has("type") && location.getString("type").equals(ConstantShapefileFunction.class.getName())) {
                this.addParent(new Location(pType, pHierarchy, new ConstantShapefileFunction(target), matchStrategy));
            } else {
                this.addParent(new Location(pType, pHierarchy, new BasicColumnFunction(target), matchStrategy));
            }
        }
    }
    // If the hierarchy is inherited, we need to resolve the hierarchy
    // inheritance chain and set them properly on the Location objects
    // To do this, we must start from the bottom and resolve upwards
    ServerHierarchyType ht = this.hierarchy;
    for (int i = this.locations.size() - 1; i >= 0; --i) {
        Location loc = this.locations.get(i);
        ht = got.findHierarchy(ht, loc.getType());
        loc.setHierarchy(ht);
    }
    return this;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) JSONArray(org.json.JSONArray) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONObject(org.json.JSONObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Request(com.runwaysdk.session.Request)

Example 54 with ServerGeoObjectType

use of net.geoprism.registry.model.ServerGeoObjectType in project geoprism-registry by terraframe.

the class DirectedAcyclicGraphStrategy method getChildren.

@SuppressWarnings("unchecked")
@Override
public ServerChildGraphNode getChildren(VertexServerGeoObject parent, Boolean recursive, Date date) {
    ServerChildGraphNode tnRoot = new ServerChildGraphNode(parent, this.type, date, null, null);
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", parent.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND( outE(");
    statement.append("'" + this.type.getMdEdgeDAO().getDBClassName() + "'");
    statement.append(")");
    if (date != null) {
        statement.append("[:date BETWEEN startDate AND endDate]");
        parameters.put("date", date);
    }
    statement.append(") FROM :rid");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        final VertexObject childVertex = edge.getChild();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) childVertex.getMdClass();
        ServerGeoObjectType childType = ServerGeoObjectType.get(mdVertex);
        VertexServerGeoObject child = new VertexServerGeoObject(childType, childVertex, date);
        ServerChildGraphNode tnParent;
        if (recursive) {
            tnParent = this.getChildren(child, recursive, date);
            tnParent.setOid(edge.getOid());
        } else {
            tnParent = new ServerChildGraphNode(child, this.type, date, null, edge.getOid());
        }
        tnRoot.addChild(tnParent);
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ServerChildGraphNode(net.geoprism.registry.model.ServerChildGraphNode) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 55 with ServerGeoObjectType

use of net.geoprism.registry.model.ServerGeoObjectType in project geoprism-registry by terraframe.

the class DirectedAcyclicGraphStrategy method getParentCollection.

private Set<ValueOverTime> getParentCollection(VertexServerGeoObject geoObject) {
    Set<ValueOverTime> set = new TreeSet<ValueOverTime>(new Comparator<ValueOverTime>() {

        @Override
        public int compare(ValueOverTime o1, ValueOverTime o2) {
            return o1.getOid().compareTo(o2.getOid());
        }
    });
    SortedSet<EdgeObject> edges = this.getParentEdges(geoObject);
    for (EdgeObject edge : edges) {
        final Date startDate = edge.getObjectValue(GeoVertex.START_DATE);
        final Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
        VertexObject parentVertex = edge.getParent();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
        ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
        VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, startDate);
        set.add(new ValueOverTime(edge.getOid(), startDate, endDate, parent));
    }
    return set;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) VertexObject(com.runwaysdk.business.graph.VertexObject) TreeSet(java.util.TreeSet) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date)

Aggregations

ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)201 Request (com.runwaysdk.session.Request)69 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)57 JsonObject (com.google.gson.JsonObject)48 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)32 JsonArray (com.google.gson.JsonArray)30 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)30 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)27 LinkedList (java.util.LinkedList)27 Test (org.junit.Test)27 VertexObject (com.runwaysdk.business.graph.VertexObject)26 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)26 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)23 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)23 Date (java.util.Date)21 GraphQuery (com.runwaysdk.business.graph.GraphQuery)19 List (java.util.List)18 EdgeObject (com.runwaysdk.business.graph.EdgeObject)17 SimpleDateFormat (java.text.SimpleDateFormat)17 Locale (java.util.Locale)17