Search in sources :

Example 11 with MdEdgeDAOIF

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

the class PatchHierarchicalRelationshipType method createHierarchicalRelationshipTypes.

public void createHierarchicalRelationshipTypes() {
    MdBusiness univMdBusiness = MdBusiness.getMdBusiness(Universal.CLASS);
    MdTermRelationshipQuery trq = new MdTermRelationshipQuery(new QueryFactory());
    trq.WHERE(trq.getParentMdBusiness().EQ(univMdBusiness).AND(trq.getChildMdBusiness().EQ(univMdBusiness)));
    try (OIterator<? extends MdTermRelationship> it = trq.getIterator()) {
        it.getAll().stream().filter(mdTermRel -> {
            if (!(mdTermRel.definesType().equals(IsARelationship.CLASS) || mdTermRel.getKey().equals(AllowedIn.CLASS) || mdTermRel.getKey().equals(LocatedIn.CLASS))) {
                return (HierarchicalRelationshipType.getByMdTermRelationship(mdTermRel) == null);
            }
            return false;
        }).forEach(mdTermRel -> {
            System.out.println("Creating HierarchicalRelationshipType for the MdTermRelationship [" + mdTermRel.definesType() + "]");
            String code = ServerHierarchyType.buildHierarchyKeyFromMdTermRelUniversal(mdTermRel.getKey());
            String geoEntityKey = ServerHierarchyType.buildMdTermRelGeoEntityKey(code);
            String mdEdgeKey = ServerHierarchyType.buildMdEdgeKey(code);
            MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(mdEdgeKey);
            String ownerActerOid = mdTermRel.getOwnerId();
            String organizationCode = Organization.getRootOrganizationCode(ownerActerOid);
            Organization organization = Organization.getByCode(organizationCode);
            HierarchicalRelationshipType hierarchicalRelationship = new HierarchicalRelationshipType();
            hierarchicalRelationship.setCode(code);
            hierarchicalRelationship.setOrganization(organization);
            hierarchicalRelationship.setMdTermRelationshipId(mdTermRel.getOid());
            hierarchicalRelationship.setMdEdgeId(mdEdge.getOid());
            try {
                MdTermRelationship entityRelationship = MdTermRelationship.getByKey(geoEntityKey);
                LocalizedValue displayLabel = AttributeTypeConverter.convert(entityRelationship.getDisplayLabel());
                LocalizedValue description = AttributeTypeConverter.convert(entityRelationship.getDescription());
                LocalizedValueConverter.populate(hierarchicalRelationship.getDisplayLabel(), displayLabel);
                LocalizedValueConverter.populate(hierarchicalRelationship.getDescription(), description);
                entityRelationship.delete();
            } catch (DataNotFoundException | AttributeDoesNotExistException e) {
                logger.debug("The entity geo relationship was not found defaulting to the mdTermRel displayLabel and description");
                LocalizedValue displayLabel = AttributeTypeConverter.convert(mdTermRel.getDisplayLabel());
                LocalizedValue description = AttributeTypeConverter.convert(mdTermRel.getDescription());
                LocalizedValueConverter.populate(hierarchicalRelationship.getDisplayLabel(), displayLabel);
                LocalizedValueConverter.populate(hierarchicalRelationship.getDescription(), description);
            }
            try {
                BusinessDAOIF metadata = BusinessDAO.get("net.geoprism.registry.HierarchyMetadata", mdTermRel.getOid());
                hierarchicalRelationship.setAbstractDescription(metadata.getValue("abstractDescription"));
                hierarchicalRelationship.setAcknowledgement(metadata.getValue("acknowledgement"));
                hierarchicalRelationship.setDisclaimer(metadata.getValue("disclaimer"));
                hierarchicalRelationship.setContact(metadata.getValue("contact"));
                hierarchicalRelationship.setPhoneNumber(metadata.getValue("phoneNumber"));
                hierarchicalRelationship.setEmail(metadata.getValue("email"));
                hierarchicalRelationship.setProgress(metadata.getValue("progress"));
                hierarchicalRelationship.setAccessConstraints(metadata.getValue("accessConstraints"));
                hierarchicalRelationship.setUseConstraints(metadata.getValue("useConstraints"));
            } catch (DataNotFoundException | AttributeDoesNotExistException e) {
            }
            hierarchicalRelationship.apply();
        });
    }
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) LoggerFactory(org.slf4j.LoggerFactory) AllowedIn(com.runwaysdk.system.gis.geo.AllowedIn) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Request(com.runwaysdk.session.Request) MdTermRelationshipQuery(com.runwaysdk.system.metadata.MdTermRelationshipQuery) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) HierarchyMetadata(net.geoprism.registry.HierarchyMetadata) Organization(net.geoprism.registry.Organization) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) QueryFactory(com.runwaysdk.query.QueryFactory) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) InheritedHierarchyAnnotationQuery(net.geoprism.registry.InheritedHierarchyAnnotationQuery) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Logger(org.slf4j.Logger) AttributeDoesNotExistException(com.runwaysdk.dataaccess.AttributeDoesNotExistException) MdEdgeDAO(com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO) AttributeTypeConverter(net.geoprism.registry.conversion.AttributeTypeConverter) OIterator(com.runwaysdk.query.OIterator) IsARelationship(com.runwaysdk.system.gis.geo.IsARelationship) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) LocatedIn(com.runwaysdk.system.gis.geo.LocatedIn) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) QueryFactory(com.runwaysdk.query.QueryFactory) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) Organization(net.geoprism.registry.Organization) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) AttributeDoesNotExistException(com.runwaysdk.dataaccess.AttributeDoesNotExistException) MdTermRelationshipQuery(com.runwaysdk.system.metadata.MdTermRelationshipQuery) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship)

Example 12 with MdEdgeDAOIF

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

the class ClassificationType method assignPermissions.

public void assignPermissions() {
    MdVertexDAOIF mdVertex = this.mdClassification.getReferenceMdVertexDAO();
    MdEdgeDAOIF mdEdge = this.mdClassification.getReferenceMdEdgeDAO();
    Roles sraRole = Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
    this.assignPermissions(mdVertex, sraRole, true);
    this.assignPermissions(mdEdge, sraRole, true);
    Roles raRole = Roles.findRoleByName(RegistryConstants.REGISTRY_ADMIN_ROLE);
    this.assignPermissions(mdVertex, raRole, false);
    this.assignPermissions(mdEdge, raRole, false);
    Roles rmRole = Roles.findRoleByName(RegistryConstants.REGISTRY_MAINTAINER_ROLE);
    this.assignPermissions(mdVertex, rmRole, false);
    this.assignPermissions(mdEdge, rmRole, false);
    Roles rcRole = Roles.findRoleByName(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE);
    this.assignPermissions(mdVertex, rcRole, false);
    this.assignPermissions(mdEdge, rcRole, false);
    Roles acRole = Roles.findRoleByName(RegistryConstants.API_CONSUMER_ROLE);
    this.assignPermissions(mdVertex, acRole, false);
    this.assignPermissions(mdEdge, acRole, false);
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) Roles(com.runwaysdk.system.Roles)

Example 13 with MdEdgeDAOIF

use of com.runwaysdk.dataaccess.MdEdgeDAOIF 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 14 with MdEdgeDAOIF

use of com.runwaysdk.dataaccess.MdEdgeDAOIF 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 15 with MdEdgeDAOIF

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

the class DHIS2ServiceTest method deleteExternalIds.

@Request
private void deleteExternalIds() {
    final MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(GeoVertex.EXTERNAL_ID);
    StringBuilder builder = new StringBuilder();
    builder.append("SELECT FROM " + mdEdge.getDBClassName());
    builder.append(" WHERE out = :system");
    final GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(builder.toString());
    query.setParameter("system", this.system.getRID());
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        edge.delete();
    }
}
Also used : MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) EdgeObject(com.runwaysdk.business.graph.EdgeObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Request(com.runwaysdk.session.Request)

Aggregations

MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)15 GraphQuery (com.runwaysdk.business.graph.GraphQuery)7 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)7 EdgeObject (com.runwaysdk.business.graph.EdgeObject)5 VertexObject (com.runwaysdk.business.graph.VertexObject)5 LineString (com.vividsolutions.jts.geom.LineString)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)4 GraphObject (com.runwaysdk.business.graph.GraphObject)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 Point (com.vividsolutions.jts.geom.Point)3 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)2 MdClassificationDAOIF (com.runwaysdk.dataaccess.MdClassificationDAOIF)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 Request (com.runwaysdk.session.Request)2 Date (java.util.Date)2 AbstractServerGeoObject (net.geoprism.registry.model.AbstractServerGeoObject)2 HashedMap (org.apache.commons.collections4.map.HashedMap)2 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)2