Search in sources :

Example 56 with MdVertexDAOIF

use of com.runwaysdk.dataaccess.MdVertexDAOIF in project geoprism-registry by terraframe.

the class VertexServerGeoObject method internalGetParentGeoObjects.

protected static ServerParentTreeNode internalGetParentGeoObjects(VertexServerGeoObject child, String[] parentTypes, boolean recursive, ServerHierarchyType htIn, Date date) {
    ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, htIn, date, null, null);
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", child.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND( inE(");
    if (htIn != null) {
        statement.append("'" + htIn.getMdEdge().getDBClassName() + "'");
    }
    statement.append(")");
    if (date != null || (parentTypes != null && parentTypes.length > 0)) {
        statement.append("[");
        if (date != null) {
            statement.append(" :date BETWEEN startDate AND endDate");
            parameters.put("date", date);
        }
        if (parentTypes != null && parentTypes.length > 0) {
            if (date != null) {
                statement.append(" AND");
            }
            statement.append("(");
            for (int i = 0; i < parentTypes.length; i++) {
                ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
                final String paramName = "p" + Integer.toString(i);
                if (i > 0) {
                    statement.append(" OR ");
                }
                statement.append("out.@class = :" + paramName);
                parameters.put(paramName, type.getMdVertex().getDBClassName());
            }
            statement.append(")");
        }
        statement.append("]");
    }
    statement.append(") FROM :rid");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        MdEdgeDAOIF mdEdge = (MdEdgeDAOIF) edge.getMdClass();
        if (HierarchicalRelationshipType.isEdgeAHierarchyType(mdEdge)) {
            final VertexObject parentVertex = edge.getParent();
            MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
            ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
            ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
            VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
            ServerParentTreeNode tnParent;
            if (recursive) {
                tnParent = internalGetParentGeoObjects(parent, parentTypes, recursive, ht, date);
            } else {
                tnParent = new ServerParentTreeNode(parent, ht, date, null, edge.getOid());
            }
            tnRoot.addParent(tnParent);
        }
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Point(com.vividsolutions.jts.geom.Point) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 57 with MdVertexDAOIF

use of com.runwaysdk.dataaccess.MdVertexDAOIF in project geoprism-registry by terraframe.

the class VertexServerGeoObject method toGeoObjectOverTime.

public GeoObjectOverTime toGeoObjectOverTime(boolean generateUid) {
    Map<String, ValueOverTimeCollectionDTO> votAttributeMap = GeoObjectOverTime.buildVotAttributeMap(type.getType());
    Map<String, Attribute> attributeMap = GeoObjectOverTime.buildAttributeMap(type.getType());
    GeoObjectOverTime geoObj = new GeoObjectOverTime(type.getType(), votAttributeMap, attributeMap);
    Map<String, AttributeType> attributes = type.getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
            ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
            for (ValueOverTime vot : votc) {
                Object value = this.getDisplayLabel(vot.getStartDate());
                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                votDTO.setValue(value);
                votcDTO.add(votDTO);
            }
            geoObj.setValueCollection(attributeName, votcDTO);
        } else // }
        if (vertex.hasAttribute(attributeName)) {
            if (attribute.isChangeOverTime()) {
                ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
                ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
                for (ValueOverTime vot : votc) {
                    // if (attributeName.equals(DefaultAttribute.STATUS.getName()))
                    // {
                    // Term statusTerm =
                    // ServiceFactory.getConversionService().geoObjectStatusToTerm(this.getStatus(vot.getStartDate()));
                    // 
                    // ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(),
                    // vot.getStartDate(), vot.getEndDate(), votcDTO);
                    // votDTO.setValue(statusTerm.getCode());
                    // votcDTO.add(votDTO);
                    // }
                    // else
                    // {
                    Object value = vot.getValue();
                    if (value != null) {
                        if (attribute instanceof AttributeTermType) {
                            Classifier classifier = Classifier.get((String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classifier.getClassifierId());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else if (attribute instanceof AttributeClassificationType) {
                            String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
                            ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                            Classification classification = Classification.getByOid(classificationType, (String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classification.toTerm());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else {
                            ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                            votDTO.setValue(value);
                            votcDTO.add(votDTO);
                        }
                    }
                // }
                }
                geoObj.setValueCollection(attributeName, votcDTO);
            } else {
                Object value = this.getValue(attributeName);
                if (value != null) {
                    if (attribute instanceof AttributeTermType) {
                        Classifier classifier = Classifier.get((String) value);
                        try {
                            geoObj.setValue(attributeName, classifier.getClassifierId());
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else if (attribute instanceof AttributeClassificationType) {
                        String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
                        MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
                        MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
                        VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
                        try {
                            geoObj.setValue(attributeName, classification.getObjectValue(AbstractClassification.CODE));
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else {
                        geoObj.setValue(attributeName, value);
                    }
                }
            }
        }
    });
    if (// && !vertex.isAppliedToDB())
    generateUid && vertex.isNew()) {
        geoObj.setUid(RegistryIdService.getInstance().next());
    // geoObj.setStatus(ServiceFactory.getAdapter().getMetadataCache().getTerm(DefaultTerms.GeoObjectStatusTerm.NEW.code).get(),
    // this.date, this.date);
    } else {
        geoObj.setUid(vertex.getObjectValue(RegistryConstants.UUID));
    }
    ValueOverTimeCollection votc = this.getValuesOverTime(this.getGeometryAttributeName());
    ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(geoObj.getGeometryAttributeType());
    for (ValueOverTime vot : votc) {
        Object value = vot.getValue();
        ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
        votDTO.setValue(value);
        votcDTO.add(votDTO);
    }
    geoObj.setValueCollection(DefaultAttribute.GEOMETRY.getName(), votcDTO);
    geoObj.setCode(vertex.getObjectValue(DefaultAttribute.CODE.getName()));
    return geoObj;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) Attribute(org.commongeoregistry.adapter.dataaccess.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) VertexObject(com.runwaysdk.business.graph.VertexObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) TermValueException(net.geoprism.registry.io.TermValueException) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Example 58 with MdVertexDAOIF

use of com.runwaysdk.dataaccess.MdVertexDAOIF in project geoprism-registry by terraframe.

the class VertexServerGeoObject method setParentCollection.

public SortedSet<EdgeObject> setParentCollection(ServerHierarchyType hierarchyType, ValueOverTimeCollection votc) {
    SortedSet<EdgeObject> newEdges = new TreeSet<EdgeObject>(new EdgeComparator());
    SortedSet<EdgeObject> edges = this.getEdges(hierarchyType);
    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);
        final VertexServerGeoObject edgeGo = new VertexServerGeoObject(parentType, parentVertex, startDate);
        ValueOverTime inVot = null;
        for (ValueOverTime vot : votc) {
            if (vot.getOid() == edge.getOid()) {
                inVot = vot;
                break;
            }
        }
        if (inVot == null) {
            edge.delete();
        } else {
            VertexServerGeoObject inGo = (VertexServerGeoObject) inVot.getValue();
            boolean hasValueChange = false;
            if ((inGo == null && edgeGo != null) || (inGo != null && edgeGo == null)) {
                hasValueChange = true;
            } else if ((inGo != null && edgeGo != null) && !inGo.equals(edgeGo)) {
                hasValueChange = true;
            }
            if (hasValueChange) {
                edge.delete();
                EdgeObject newEdge = this.getVertex().addParent(inGo.getVertex(), hierarchyType.getMdEdge());
                newEdge.setValue(GeoVertex.START_DATE, startDate);
                newEdge.setValue(GeoVertex.END_DATE, endDate);
                newEdge.apply();
                newEdges.add(newEdge);
            } else {
                boolean hasChanges = false;
                if (startDate != inVot.getStartDate()) {
                    hasChanges = true;
                    edge.setValue(GeoVertex.START_DATE, startDate);
                }
                if (endDate != inVot.getEndDate()) {
                    hasChanges = true;
                    edge.setValue(GeoVertex.END_DATE, endDate);
                }
                if (hasChanges) {
                    edge.apply();
                }
            }
        }
    }
    for (ValueOverTime vot : votc) {
        boolean isNew = true;
        for (EdgeObject edge : edges) {
            if (vot.getOid() == edge.getOid()) {
                isNew = false;
            }
        }
        if (isNew) {
            EdgeObject newEdge = this.getVertex().addParent(((VertexServerGeoObject) vot.getValue()).getVertex(), hierarchyType.getMdEdge());
            newEdge.setValue(GeoVertex.START_DATE, vot.getStartDate());
            newEdge.setValue(GeoVertex.END_DATE, vot.getEndDate());
            newEdge.apply();
            newEdges.add(newEdge);
        }
    }
    return newEdges;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) TreeSet(java.util.TreeSet) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 59 with MdVertexDAOIF

use of com.runwaysdk.dataaccess.MdVertexDAOIF in project geoprism-registry by terraframe.

the class SearchService method search.

public List<ServerGeoObjectIF> search(String text, Date date, Long limit) {
    String suffix = this.getSuffix();
    RolePermissionService service = new RolePermissionService();
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
    MdAttributeDAOIF code = mdVertex.definesAttribute(CODE);
    MdAttributeDAOIF startDate = mdVertex.definesAttribute(START_DATE);
    MdAttributeDAOIF endDate = mdVertex.definesAttribute(END_DATE);
    MdAttributeDAOIF label = mdVertex.definesAttribute(LABEL);
    MdAttributeDAOIF vertexType = mdVertex.definesAttribute(VERTEX_TYPE);
    MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(PACKAGE + "." + EDGE_PREFIX + suffix);
    String attributeName = label.getValue(MdAttributeTextInfo.NAME);
    String className = mdVertex.getDBClassName();
    String indexName = className + "." + attributeName;
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND(out('" + mdEdge.getDBClassName() + "'))");
    statement.append(" FROM " + mdVertex.getDBClassName());
    if (text != null) {
        String regex = "([+\\-!\\(\\){}\\[\\]^\"~*?:\\\\]|[&\\|]{2})";
        String escapedText = text.replaceAll(regex, "\\\\\\\\$1").trim();
        statement.append(" WHERE (SEARCH_INDEX(\"" + indexName + "\", \"+" + label.getColumnName() + ":" + escapedText + "*\") = true");
        statement.append(" OR :code = " + code.getColumnName() + ")");
    } else {
        statement.append(" WHERE " + code.getColumnName() + " IS NOT NULL");
    }
    if (date != null) {
        statement.append(" AND :date BETWEEN " + startDate.getColumnName() + " AND " + endDate.getColumnName());
    }
    if (!service.isSRA() && service.hasSessionUser()) {
        statement.append(" AND " + vertexType.getColumnName() + " IN ( :vertexTypes )");
    }
    statement.append(" ORDER BY " + label.getColumnName() + " DESC");
    if (limit != null) {
        statement.append(" LIMIT " + limit);
    }
    List<ServerGeoObjectIF> list = new LinkedList<ServerGeoObjectIF>();
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    if (text != null) {
        query.setParameter("code", text);
    }
    if (date != null) {
        query.setParameter("date", date);
    }
    if (!service.isSRA() && service.hasSessionUser()) {
        List<String> vertexTypes = new GeoObjectPermissionService().getMandateTypes(service.getOrganization());
        query.setParameter("vertexTypes", vertexTypes);
    }
    List<VertexObject> results = query.getResults();
    for (VertexObject result : results) {
        MdVertexDAOIF mdVertexType = (MdVertexDAOIF) result.getMdClass();
        ServerGeoObjectType type = ServerGeoObjectType.get(mdVertexType);
        list.add(new VertexServerGeoObject(type, result, date));
    }
    return list;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) LinkedList(java.util.LinkedList) GeoObjectPermissionService(net.geoprism.registry.permission.GeoObjectPermissionService) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 60 with MdVertexDAOIF

use of com.runwaysdk.dataaccess.MdVertexDAOIF in project geoprism-registry by terraframe.

the class HistoricalRow method getCount.

public static Long getCount(ServerGeoObjectType type, Date startDate, Date endDate) {
    MdVertexDAOIF transitionVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
    MdAttributeDAOIF eventAttribute = transitionVertex.definesAttribute(Transition.EVENT);
    MdVertexDAOIF eventVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
    MdAttributeDAOIF beforeTypeCode = eventVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
    MdAttributeDAOIF afterTypeCode = eventVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
    MdAttributeDAOIF eventDate = eventVertex.definesAttribute(TransitionEvent.EVENTDATE);
    List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
    types.add(type);
    types.addAll(type.getSubtypes());
    List<String> codes = types.stream().map(t -> t.getCode()).distinct().collect(Collectors.toList());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT COUNT(*)");
    statement.append(" FROM " + transitionVertex.getDBClassName());
    statement.append(" WHERE ( " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " IN :typeCode");
    statement.append(" OR " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " IN :typeCode )");
    statement.append(" AND " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " BETWEEN :startDate AND :endDate");
    GraphQuery<Long> query = new GraphQuery<Long>(statement.toString());
    query.setParameter("typeCode", codes);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    return query.getSingleResult();
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList)

Aggregations

MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)62 GraphQuery (com.runwaysdk.business.graph.GraphQuery)34 VertexObject (com.runwaysdk.business.graph.VertexObject)30 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)26 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)24 EdgeObject (com.runwaysdk.business.graph.EdgeObject)16 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)11 Date (java.util.Date)10 LinkedList (java.util.LinkedList)9 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)8 JsonObject (com.google.gson.JsonObject)7 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)7 HashedMap (org.apache.commons.collections4.map.HashedMap)7 HashMap (java.util.HashMap)5 TreeSet (java.util.TreeSet)5 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)5 GraphObject (com.runwaysdk.business.graph.GraphObject)4 MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)4 LineString (com.vividsolutions.jts.geom.LineString)4