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();
});
}
}
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);
}
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;
}
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;
}
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();
}
}
Aggregations