use of com.enonic.xp.util.Reference in project xp by enonic.
the class AbstractNodeTest method createNodes.
protected final void createNodes(final Node parent, final int numberOfNodes, final int maxLevels, final int level) {
for (int i = 0; i < numberOfNodes; i++) {
final PropertyTree data = new PropertyTree();
data.addReference("myRef", new Reference(parent.id()));
final Node node = createNode(CreateNodeParams.create().name("nodeName_" + level + "-" + i).parent(parent.path()).data(data).build(), false);
if (level < maxLevels) {
createNodes(node, numberOfNodes, maxLevels, level + 1);
}
}
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class IssueDataSerializer method addPublishRequest.
private void addPublishRequest(final PropertySet issueProperties, final PublishRequest publishRequest) {
final PropertySet publishRequestSet = issueProperties.addSet(PUBLISH_REQUEST);
publishRequestSet.addStrings(PublishRequestPropertyNames.EXCLUDE_IDS, publishRequest.getExcludeIds().asStrings());
final Collection<PropertySet> itemSets = new ArrayList<>();
for (final PublishRequestItem item : publishRequest.getItems()) {
final PropertySet itemSet = new PropertySet();
itemSet.setReference(PublishRequestPropertyNames.ITEM_ID, new Reference(NodeId.from(item.getId())));
itemSet.setBoolean(PublishRequestPropertyNames.ITEM_RECURSIVE, item.getIncludeChildren());
itemSets.add(itemSet);
}
publishRequestSet.addSets(PublishRequestPropertyNames.ITEMS, itemSets.toArray(new PropertySet[0]));
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class FlattenedPageDataUpgrader method addPageComponentData.
private void addPageComponentData(final PropertyTree nodeData, final PropertySet pageComponentSet) {
final PropertySet pageComponentDataSet = pageComponentSet.addSet(TGT_TYPE_VALUE.PAGE);
final PropertySet sourcePageSet = nodeData.getSet(SRC_PAGE_KEY);
String descriptorKey = sourcePageSet.getString(SRC_CONTROLLER_KEY);
final Reference sourceTemplateKey = sourcePageSet.getReference(SRC_TEMPLATE_KEY);
if (sourceTemplateKey != null && descriptorKey == null) {
if (!sourcePageSet.getSets(SRC_REGION_KEY).iterator().hasNext()) {
pageComponentDataSet.setReference(TGT_TEMPLATE_KEY, sourceTemplateKey);
} else {
descriptorKey = templateControllerMap.get(sourceTemplateKey.toString());
LOG.info("Page with both template reference and components. Replacing template reference [" + sourceTemplateKey + "] by descriptor key [" + descriptorKey + "]");
}
}
if (descriptorKey != null) {
pageComponentDataSet.setString(TGT_DESCRIPTOR_KEY, descriptorKey);
pageComponentDataSet.setBoolean(TGT_CUSTOMIZED_KEY, true);
final PropertySet sourceConfigSet = sourcePageSet.getSet(SRC_CONFIG_KEY);
if (sourceConfigSet != null) {
final PropertySet configSet = pageComponentDataSet.addSet(TGT_CONFIG_KEY);
final String applicationKey = getSanitizedApplicationKey(descriptorKey);
final PropertySet applicationConfigSet = configSet.addSet(applicationKey);
final String componentName = getSanitizedComponentName(descriptorKey);
applicationConfigSet.setSet(componentName, sourceConfigSet);
}
} else {
pageComponentDataSet.setBoolean(TGT_CUSTOMIZED_KEY, false);
}
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class DuplicateNodeCommand method updateNodeReferences.
private void updateNodeReferences(final Node node, final NodeReferenceUpdatesHolder nodeReferenceUpdatesHolder) {
final PropertyTree data = node.data();
boolean changes = false;
for (final Property property : node.data().getProperties(ValueTypes.REFERENCE)) {
final Reference reference = property.getReference();
if (reference != null && nodeReferenceUpdatesHolder.mustUpdate(reference)) {
changes = true;
data.setReference(property.getPath(), nodeReferenceUpdatesHolder.getNewReference(reference));
}
}
if (changes) {
UpdateNodeCommand.create(this).params(UpdateNodeParams.create().id(node.id()).editor(toBeEdited -> toBeEdited.data = data).build()).binaryService(this.binaryService).build().execute();
}
nodeReferencesUpdated(1);
}
use of com.enonic.xp.util.Reference in project xp by enonic.
the class CreateNodeCommandTest method node_with_reference.
@Test
public void node_with_reference() {
final Node referredNode = createNode(CreateNodeParams.create().name("test2").parent(NodePath.ROOT).build());
PropertyTree data = new PropertyTree();
data.setReference("myCar", new Reference(referredNode.id()));
createNode(CreateNodeParams.create().name("test").parent(NodePath.ROOT).data(data).build());
final FindNodesByQueryResult result = FindNodesByQueryCommand.create().storageService(this.storageService).searchService(this.searchService).indexServiceInternal(this.indexServiceInternal).query(NodeQuery.create().addQueryFilter(ValueFilter.create().fieldName(NodeIndexPath.REFERENCE.getPath()).addValue(ValueFactory.newReference(Reference.from(referredNode.id().toString()))).build()).build()).build().execute();
assertEquals(1, result.getHits());
}
Aggregations