private void parseCustomNodeTypes(ModelNode model, EditableDocument configDoc, List<String> additionalClasspathEntries) { if (model.hasDefined(ModelKeys.NODE_TYPES)) { EditableArray nodeTypesArray = configDoc.getOrCreateArray(FieldName.NODE_TYPES); for (ModelNode nodeType : model.get(ModelKeys.NODE_TYPES).asList()) { nodeTypesArray.add(nodeType.asString()); } } }
protected void removeFederatedSegments( EditableDocument federatedDocument, Set<String> externalNodeKeys ) { if (!federatedDocument.containsField(FEDERATED_SEGMENTS)) { return; } EditableArray federatedSegments = federatedDocument.getArray(FEDERATED_SEGMENTS); for (int i = 0; i < federatedSegments.size(); i++) { Object federatedSegment = federatedSegments.get(i); assert federatedSegment instanceof Document; String segmentKey = getKey((Document)federatedSegment); if (externalNodeKeys.contains(segmentKey)) { federatedSegments.remove(i); } } if (federatedSegments.isEmpty()) { federatedDocument.remove(FEDERATED_SEGMENTS); } }
@Override public DocumentWriter addChild( String id, String name ) { EditableArray children = federatedDocument.getArray(DocumentTranslator.CHILDREN); if (children == null) { children = DocumentFactory.newArray(); federatedDocument.setArray(DocumentTranslator.CHILDREN, children); } children.addDocument(DocumentFactory.newDocument(DocumentTranslator.KEY, id, DocumentTranslator.NAME, name)); return this; }
@Override public DocumentWriter removeChild( String id ) { EditableArray children = federatedDocument.getArray(DocumentTranslator.CHILDREN); if (children != null) { for (int i = 0; i != children.size(); ++i) { Object val = children.get(i); if (val instanceof Document) { Document child = (Document)val; if (child.getString(DocumentTranslator.KEY).equals(id)) { children.remove(i); return this; } } } } return this; }
if (value instanceof List<?>) { for (Object val : (List<?>)value) { provider.getOrCreateArray(keyStr).addValue(val); for (int i = 0; i < providers.size(); i++) { providerPosition = i; Document document = (Document)providers.get(i); String className = document.getString(FieldName.CLASSNAME); boolean isBuiltinProvider = !StringUtil.isBlank(className) && providers.add(providerPosition, provider);
} else { EditableArray parents = Schematic.newArray(additionalParents.additionCount() + 1); parents.add(parent.toString()); for (NodeKey added : additionalParents.getAdditions()) { parents.add(added.toString()); EditableArray parents = Schematic.newArray(additionalParents.additionCount()); for (NodeKey added : additionalParents.getAdditions()) { parents.add(added.toString()); parents.addStringIfAbsent(parent.toString()); if (oldParent != null) { parents.remove((Object)oldParent.toString()); parents.remove((Object)removedParent.toString()); // remove by value (not by name) parents.addStringIfAbsent(added.toString()); parents.add(existing); parents.add(parent.toString()); document.set(PARENT, parents); EditableArray parents = Schematic.newArray(totalNumber); if (parent != null && !existingParent.equals(parent.toString())) { parents.add(parent.toString()); } else { parents.add(existingParent); parents.remove((Object)removed.toString());
EditableArray array = Schematic.newArray(numValues); for (Object value : values) { array.addValue(valueToDocument(value, unusedBinaryKeys, usedBinaryKeys)); for (Object value : values) { value = valueToDocument(value, unusedBinaryKeys, usedBinaryKeys); array.addValueIfAbsent(value); value = valueToDocument(value, unusedBinaryKeys, usedBinaryKeys); if (!value.equals(propValue)) { array.addValue(value); assert !array.isEmpty(); urlProps.setArray(localName, array);
assert tolerance < targetCountPerBlock; int total = children.size(); int numFullBlocks = total / targetCountPerBlock; EditableArray blockChildren = Schematic.newArray(children.subList(startIndex, endIndex)); EditableDocument blockDoc = Schematic.newDocument(); EditableDocument childInfo = blockDoc.setDocument(CHILDREN_INFO); childInfo.setNumber(BLOCK_SIZE, blockChildren.size()); if (nextBlockKey != null) { childInfo.setString(NEXT_BLOCK, nextBlockKey); EditableArray newChildren = Schematic.newArray(children.subList(0, targetCountPerBlock)); document.setArray(CHILDREN, newChildren); EditableDocument childInfo = document.getDocument(CHILDREN_INFO); childInfo = document.setDocument(CHILDREN_INFO); childInfo.setNumber(BLOCK_SIZE, newChildren.size()); childInfo.setString(NEXT_BLOCK, firstNewBlockKey);
if (selfContained) { int total = children.size(); if (total < targetCountPerBlock + tolerance) { String nextKey = docInfo != null ? docInfo.getString(NEXT_BLOCK) : null; children = doc.getArray(CHILDREN); int count = children.size(); boolean isFirst = doc == document; if (count > (targetCountPerBlock + tolerance)) {
if (value instanceof List<?>) { for (Object val : (List<?>)value) { externalSource.getOrCreateArray(keyStr).addValue(val);
protected void persistBucketRemovalChanges( NodeKey parentKey, Map<BucketId, Set<NodeKey>> removalsPerBucket ) { EditableDocument parentDoc = documentStore.edit(parentKey.toString(), false); // for each bucket, get the corresponding document (locking it) and make the children changes for (Map.Entry<BucketId, Set<NodeKey>> entry : removalsPerBucket.entrySet()) { BucketId bucketId = entry.getKey(); Set<NodeKey> removalsFromBucket = entry.getValue(); String bucketIdString = bucketId.toString(); String bucketKey = bucketKey(parentKey.toString(), bucketIdString); // we don't worry about locking the bucket keys because the parent key should've already been locked, acting therefore // as a monitor for all the buckets EditableDocument bucketDoc = documentStore.edit(bucketKey, false); assert bucketDoc != null; for (NodeKey toRemove : removalsFromBucket) { // keys are stored directly in the bucket bucketDoc.remove(toRemove.toString()); } if (bucketDoc.isEmpty()) { documentStore.remove(bucketKey); parentDoc.getArray(BUCKETS).remove((Object)bucketIdString); } } }
/** * Make sure that a workspace with the supplied name exists. * * @param workspaceName the name of the workspace; may not be null */ protected void predefineWorkspace( RepositoryConfiguration configuration, String workspaceName ) { assertThat(workspaceName, is(notNullValue())); // Edit the configuration ... Editor editor = configuration.edit(); EditableDocument workspaces = editor.getOrCreateDocument("workspaces"); EditableArray predefined = workspaces.getOrCreateArray("predefined"); predefined.addStringIfAbsent(workspaceName); // And apply the changes ... Changes changes = editor.getChanges(); if (changes.isEmpty()) return; try { repository.apply(changes); } catch (Exception e) { e.printStackTrace(); throw new AssertionFailedError("Unexpected error while predefining the \"" + workspaceName + "\" workspace:" + e.getMessage()); } }
protected void removeAllBucketsFromUnorderedCollection( NodeKey parentDocKey ) { // should already have been loaded into the cache and the parent locked EditableDocument parentDoc = documentStore.edit(parentDocKey.toString(), false); assert parentDoc != null; EditableArray bucketsIds = parentDoc.getArray(BUCKETS); if (bucketsIds == null || bucketsIds.isEmpty()) { return; } for (Object bucketId : bucketsIds) { String bucketKey = bucketKey(parentDocKey.toString(), bucketId.toString()); documentStore.remove(bucketKey); } }
@Override public DocumentWriter removeChild( String id ) { EditableArray children = federatedDocument.getArray(DocumentTranslator.CHILDREN); if (children != null) { for (int i = 0; i != children.size(); ++i) { Object val = children.get(i); if (val instanceof Document) { Document child = (Document)val; if (child.getString(DocumentTranslator.KEY).equals(id)) { children.remove(i); return this; } } } } return this; }
} else { EditableArray parents = Schematic.newArray(additionalParents.additionCount() + 1); parents.add(parent.toString()); for (NodeKey added : additionalParents.getAdditions()) { parents.add(added.toString()); EditableArray parents = Schematic.newArray(additionalParents.additionCount()); for (NodeKey added : additionalParents.getAdditions()) { parents.add(added.toString()); parents.addStringIfAbsent(parent.toString()); if (oldParent != null) { parents.remove((Object)oldParent.toString()); parents.remove((Object)removedParent.toString()); // remove by value (not by name) parents.addStringIfAbsent(added.toString()); parents.add(existing); parents.add(parent.toString()); document.set(PARENT, parents); EditableArray parents = Schematic.newArray(totalNumber); if (parent != null && !existingParent.equals(parent.toString())) { parents.add(parent.toString()); } else { parents.add(existingParent); parents.remove((Object)removed.toString());