public DataEntity(CanonicalPath path, StructuredData value, String identityHash, String contentHash, String syncHash, Map<String, Object> properties) { this(path.up(), DataRole.valueOf(path.getSegment().getElementId()), value, identityHash, contentHash, syncHash, properties); }
public Relationship(String id, String name, CanonicalPath source, CanonicalPath target, Map<String, Object> properties) { super(CanonicalPath.of().relationship(id).get(), properties); this.id = id; this.name = name; this.source = source; this.target = target; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AbstractElement<?, ?> entity = (AbstractElement<?, ?>) o; return path.equals(entity.path); }
/** * @return the id of the element. */ public String getId() { return path.getSegment().getElementId(); }
CanonicalPath resourceTypePath = null; try { CanonicalPath tenant = CanonicalPath.of().tenant(parentPath.ids().getTenantId()).get(); resourceTypePath = Util.canonicalize(blueprint.getResourceTypePath(), tenant, parentPath, ResourceType.SEGMENT_TYPE); throw new IllegalArgumentException("Resource type '" + blueprint.getResourceTypePath() + "' not found" + " when resolved to '" + resourceTypePath + "' while trying to wire up a new resource on path '" + parentPath.extend(SegmentType.r, blueprint.getId()).get() + "'."); Resource ret = new Resource(blueprint.getName(), parentPath.extend(Resource.SEGMENT_TYPE, tx.extractId(entity)).get(), null, null, null, resourceType, blueprint.getProperties());
@Override public Element find(CanonicalPath path) throws ElementNotFoundException { Iterator<? extends Element> it; if (SegmentType.rl.equals(path.getSegment().getElementType())) { //__eid is globally unique for relationships it = context.getGraph().traversal().E().has(__eid.name(), path.getSegment().getElementId()); } else { it = context.getGraph().traversal().V() .hasLabel(Constants.Type.of(path.getSegment().getElementType()).name()) .has(__cp.name(), path.toString()); } if (!it.hasNext()) { throw new ElementNotFoundException(); } return it.next(); }
public DataEntity(CanonicalPath owner, DataRole role, StructuredData value, String identityHash, String contentHash, String syncHash) { super(null, owner.extend(DataEntity.SEGMENT_TYPE, role.name()).get(), identityHash, contentHash, syncHash); this.value = value; }
@Override public Element relate(Element sourceEntity, Element targetEntity, String name, Map<String, Object> properties) { if (name == null) { throw new IllegalArgumentException("name == null"); } if (!(sourceEntity instanceof Vertex)) { throw new IllegalArgumentException("Source not a vertex."); } if (!(targetEntity instanceof Vertex)) { throw new IllegalArgumentException("Target not a vertex."); } Map<String, Object> props = properties == null ? Collections.emptyMap() : properties; Object[] keyValues = asKeyValues(props, __sourceType.name(), sourceEntity.property(__type.name()).value(), __targetType.name(), targetEntity.property(__type.name()).orElse(null), __sourceCp.name(), sourceEntity.property(__cp.name()).orElse(null), __targetCp.name(), targetEntity.property(__cp.name()).orElse(null), __sourceEid.name(), sourceEntity.property(__eid.name()).orElse(null), __targetEid.name(), targetEntity.property(__eid.name()).orElse(null)); Edge e = ((Vertex) sourceEntity).addEdge(name, (Vertex) targetEntity, keyValues); //these need the ID of the edge, so we need to set the props after the edge has been created e.property(__eid.name(), e.id().toString()); e.property(__cp.name(), CanonicalPath.of().relationship(e.id().toString()).get().toString()); return e; }
@Override public Single visitData(Void parameter) { String rt = ids.getResourceTypeId(); String ot = ids.getOperationTypeId(); if (rt != null && ot == null) { ResourceTypes.Single rts = inspect(path.up(), ResourceTypes.Single.class); DataRole.ResourceType role = DataRole.ResourceType.valueOf(ids.getDataRole()); return accessInterface.cast(rts.data().get(role)); } else if (ot != null) { OperationTypes.Single ots = inspect(path.up(), OperationTypes.Single.class); DataRole.OperationType role = DataRole.OperationType.valueOf(ids.getDataRole()); return accessInterface.cast(ots.data().get(role)); } else { Resources.Single res = inspect(path.up(), Resources.Single.class); DataRole.Resource role = DataRole.Resource.valueOf(ids.getDataRole()); return accessInterface.cast(res.data().get(role)); } }
if (parent == null) { if (context.entityClass == Tenant.class) { entityPath = CanonicalPath.of().tenant(id).get(); } else { throw new IllegalStateException("Could not find the parent of the entity to be created," + entityPath = parentCanonicalPath.extend(AbstractElement.segmentTypeFromType(context.entityClass), id) .get();
@Override public <EE extends Entity<? extends BB, ?>, BB extends Entity.Blueprint> Stream<FullNode> getChildNodes(RelativePath parent, Class<EE> childType) { CanonicalPath absoluteParent = rootEntity.getPath().modified().extend(parent.getPath()).get(); SegmentType parentType = absoluteParent.getSegment().getElementType();
Entity<?, ?> oldEntity = (Entity<?, ?>) oldChild.getAttachment(); CanonicalPath childCp = oldEntity.getPath(); SyncHash.Tree newChild = newTree.getChild(childCp.getSegment()); try { BE child = tx.find(childCp); syncTrees(tx, root, childCp.relativeTo(root), child, update, newStructure, persistedStructure); } catch (ElementNotFoundException ex) { Log.LOGGER.debug("Failed to find entity on " + childCp + " that we thought was there. Never mind " +
@Override public int hashCode() { int result = entityPath != null ? entityPath.hashCode() : 0; result = 31 * result + (relationshipName != null ? relationshipName.hashCode() : 0); result = 31 * result + (relationshipId != null ? relationshipId.hashCode() : 0); result = 31 * result + (entityRole != null ? entityRole.hashCode() : 0); return result; } }
@Override public MetadataPacks.Single create(MetadataPack.Blueprint blueprint, boolean cache) throws EntityAlreadyExistsException { blueprint.getMembers().forEach(p -> { if (p.ids().getFeedId() != null) { throw new IllegalArgumentException("Only global types can be part of a metadata pack. No " + "feed-local types are allowed but '" + p + "' encountered."); } }); return new Single<>(context.toCreatedEntity(doCreate(blueprint), cache)); } }
@Override public AbstractElement<?, ?> getElement(CanonicalPath path) { try { E element = getBackend().find(path); Class<?> type = getBackend().extractType(element); return (AbstractElement<?, ?>) getBackend().convert(element, type); } catch (ElementNotFoundException e) { throw new EntityNotFoundException("No element found on path: " + path.toString()); } }
/** * @return the id of the element. */ public String getId() { return path.getSegment().getElementId(); }
CanonicalPath tenant = CanonicalPath.of().tenant(parentPath.ids().getTenantId()).get(); CanonicalPath metricTypePath = Util.canonicalize(blueprint.getMetricTypePath(), tenant, parentPath, MetricType.SEGMENT_TYPE); Metric ret = new Metric(blueprint.getName(), parentPath.extend(Metric.SEGMENT_TYPE, tx.extractId(entity)).get(), null, null, null, metricType, blueprint.getCollectionInterval(), blueprint.getProperties());
@SuppressWarnings("unchecked") public void visit(GraphTraversal<?, ?> query, With.CanonicalPaths filter, QueryTranslationState state) { String prop = chooseBasedOnDirection(__cp, __targetCp, __sourceCp, state.getComingFrom()).name(); String typeName = null; String[] typeNames = null; if (filter.getPaths().length == 1) { typeName = Constants.Type.of(filter.getPaths()[0].getSegment().getElementType()).name(); query.has(prop, filter.getPaths()[0].toString()); } else { typeNames = Stream.of(filter.getPaths()).map(p -> p.getSegment().getElementType()) .toArray(String[]::new); String[] paths = Stream.of(filter.getPaths()).map(Object::toString).toArray(String[]::new); query.has(prop, P.within(paths)); } goBackFromEdges(query, state); if (typeNames == null) { query.hasLabel(typeName); } else { query.hasLabel(P.within(typeNames)); } }