Search in sources :

Example 6 with Reference

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);
        }
    }
}
Also used : Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node)

Example 7 with Reference

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]));
}
Also used : PublishRequestItem(com.enonic.xp.issue.PublishRequestItem) Reference(com.enonic.xp.util.Reference) ArrayList(java.util.ArrayList) PropertySet(com.enonic.xp.data.PropertySet)

Example 8 with Reference

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);
    }
}
Also used : Reference(com.enonic.xp.util.Reference) PropertySet(com.enonic.xp.data.PropertySet)

Example 9 with Reference

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);
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) Property(com.enonic.xp.data.Property) Nodes(com.enonic.xp.node.Nodes) Logger(org.slf4j.Logger) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) Node(com.enonic.xp.node.Node) LoggerFactory(org.slf4j.LoggerFactory) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) AttachedBinary(com.enonic.xp.node.AttachedBinary) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) InsertManualStrategy(com.enonic.xp.node.InsertManualStrategy) RepositoryId(com.enonic.xp.repository.RepositoryId) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) Reference(com.enonic.xp.util.Reference) ContextAccessor(com.enonic.xp.context.ContextAccessor) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) ValueTypes(com.enonic.xp.data.ValueTypes) Preconditions(com.google.common.base.Preconditions) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Property(com.enonic.xp.data.Property)

Example 10 with Reference

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());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) BinaryReference(com.enonic.xp.util.BinaryReference) Reference(com.enonic.xp.util.Reference) Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Aggregations

Reference (com.enonic.xp.util.Reference)12 PropertyTree (com.enonic.xp.data.PropertyTree)7 Test (org.junit.jupiter.api.Test)5 PropertySet (com.enonic.xp.data.PropertySet)4 Node (com.enonic.xp.node.Node)4 BinaryReference (com.enonic.xp.util.BinaryReference)3 Property (com.enonic.xp.data.Property)2 Content (com.enonic.xp.content.Content)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ValueTypes (com.enonic.xp.data.ValueTypes)1 DumpUpgradeStepResult (com.enonic.xp.dump.DumpUpgradeStepResult)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 PublishRequestItem (com.enonic.xp.issue.PublishRequestItem)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1