@Override public void serialize(InventoryStructure<?> inventoryStructure, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { Object blueprint = inventoryStructure.getRoot(); InventoryStructure.EntityType blueprintType = InventoryStructure.EntityType.ofBlueprint(blueprint.getClass()); if (blueprintType == null) { throw new IllegalArgumentException("Unsupported type of root element: " + blueprint); } jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("type", blueprintType.name()); jsonGenerator.writeObjectField("data", inventoryStructure.getRoot()); jsonGenerator.writeFieldName("children"); jsonGenerator.writeStartObject(); serializeLevel(inventoryStructure, RelativePath.empty(), jsonGenerator); jsonGenerator.writeEndObject(); jsonGenerator.writeEndObject(); }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
@Override public List<OperationType.Blueprint> getOperationTypes(ResourceType.Blueprint rt) { RelativePath p = rt.equals(structure.getRoot()) ? RelativePath.empty().get() : RelativePath.to().resourceType(rt.getId()).get(); try (Stream<OperationType.Blueprint> s = structure.getChildren(p, OperationType.class)) { return s.collect(toList()); } }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
R root = other.getRoot();
R root = other.getRoot();
@Override public DataEntity.Blueprint<?> getConfigurationSchema(ResourceType.Blueprint rt) { RelativePath.Extender p = rt.equals(structure.getRoot()) ? RelativePath.empty() : RelativePath.empty().extend(SegmentType.rt, rt.getId()); return getData(p, configurationSchema); }
@Override public DataEntity.Blueprint<?> getConnectionConfigurationSchema(ResourceType.Blueprint rt) { RelativePath.Extender p = rt.equals(structure.getRoot()) ? RelativePath.empty() : RelativePath.empty().extend(SegmentType.rt, rt.getId()); return getData(p, connectionConfigurationSchema); }
static Hashes of(InventoryStructure<?> inventory, CanonicalPath rootPath, boolean computeIdentity, boolean computeContent, boolean computeSync) { ComputeHash.HashConstructor ctor = new ComputeHash.HashConstructor(new ComputeHash.DigestComputingWriter( ComputeHash.newDigest())); IntermediateHashResult res = ComputeHash.computeHash(rootPath, inventory.getRoot(), ComputeHash.HashableView.of(inventory), ctor, computeIdentity, computeContent, computeSync, rp -> null, rp -> null); return new Hashes(res.identityHash, res.contentHash, res.syncHash); }
public static String of(Iterator<? extends Entity<? extends Entity.Blueprint, ?>> entities, Inventory inventory) { SortedSet<Entity<? extends Entity.Blueprint, ?>> sortedEntities = new TreeSet<>(ComputeHash.ENTITY_COMPARATOR); entities.forEachRemaining(sortedEntities::add); ComputeHash.HashConstructor ctor = new ComputeHash.HashConstructor(new ComputeHash.DigestComputingWriter( ComputeHash.newDigest())); StringBuilder resultHash = new StringBuilder(); sortedEntities.forEach((e) -> { InventoryStructure<?> structure = InventoryStructure.of(e, inventory); ComputeHash.HashableView v = ComputeHash.HashableView.of(structure); ComputeHash.IntermediateHashResult res = ComputeHash .computeHash(e.getPath(), structure.getRoot(), v, ctor, true, false, false, rp -> null, rp -> null); resultHash.append(res.identityHash); }); ctor.getDigestor().reset(); ctor.getDigestor().append(resultHash); ctor.getDigestor().close(); return ctor.getDigestor().digest(); }
static IntermediateHashResult treeOf(InventoryStructure<?> inventory, CanonicalPath rootPath, boolean computeIdentity, boolean computeContent, boolean computeSync, Consumer<IntermediateHashContext> onStartChild, BiConsumer<IntermediateHashContext, IntermediateHashResult> onEndChild, Function<RelativePath, Hashes> hashLoader) { ComputeHash.DigestComputingWriter wrt = new ComputeHash.DigestComputingWriter(ComputeHash.newDigest()); ComputeHash.HashConstructor ctor = new ComputeHash.HashConstructor(wrt) { @Override public void startChild(ComputeHash.IntermediateHashContext context) { super.startChild(context); onStartChild.accept(context); } @Override public void endChild(ComputeHash.IntermediateHashContext ctx, ComputeHash.IntermediateHashResult result) { super.endChild(ctx, result); onEndChild.accept(ctx, result); } }; return computeHash(rootPath, inventory.getRoot(), ComputeHash.HashableView.of(inventory), ctor, computeIdentity, computeContent, computeSync, //we don't want the root element in the relative paths of the children so that they are easily //appendable to the root. (rp) -> rp.slide(1, 0), hashLoader ); }
Mutator<BE, E, B, U, String> mutator = createMutator(tx); EntityAndPendingNotifications<BE, E> res = mutator.doCreate(syncRequest.getInventoryStructure().getRoot(), tx); root = res.getEntityRepresentation(); entity = res.getEntity();