Search in sources :

Example 16 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class SetPublishInfoCommand method execute.

public void execute() {
    final NodeIds nodeIdsToUpdate = findNodesWithoutPublishFirstAndFrom(nodeIds);
    if (nodeIdsToUpdate.getSize() == 0) {
        return;
    }
    final Instant now = Instant.now();
    final Instant publishFrom = contentPublishInfo.getFrom() == null ? now : contentPublishInfo.getFrom();
    final Instant publishTo = contentPublishInfo.getTo();
    for (final NodeId id : nodeIdsToUpdate) {
        this.nodeService.update(UpdateNodeParams.create().editor(toBeEdited -> {
            PropertySet publishInfo = toBeEdited.data.getSet(ContentPropertyNames.PUBLISH_INFO);
            if (publishInfo == null) {
                publishInfo = toBeEdited.data.addSet(ContentPropertyNames.PUBLISH_INFO);
            }
            if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FIRST) == null) {
                final Instant publishFromPropertyValue = publishInfo.getInstant(ContentPropertyNames.PUBLISH_FROM);
                if (publishFromPropertyValue == null) {
                    publishInfo.setInstant(ContentPropertyNames.PUBLISH_FIRST, publishFrom);
                } else {
                    // TODO Special case for Enonic XP 6.7 and 6.8 contents. Remove after 7.0
                    publishInfo.setInstant(ContentPropertyNames.PUBLISH_FIRST, publishFromPropertyValue);
                }
            }
            if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FROM) == null) {
                publishInfo.setInstant(ContentPropertyNames.PUBLISH_FROM, publishFrom);
                if (publishTo == null) {
                    if (publishInfo.hasProperty(ContentPropertyNames.PUBLISH_TO)) {
                        publishInfo.removeProperty(ContentPropertyNames.PUBLISH_TO);
                    }
                } else {
                    publishInfo.setInstant(ContentPropertyNames.PUBLISH_TO, publishTo);
                }
            }
        }).id(id).build());
        if (publishContentListener != null) {
            publishContentListener.contentPushed(1);
        }
    }
    this.nodeService.refresh(RefreshMode.ALL);
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) IdFilter(com.enonic.xp.query.filter.IdFilter) ContentIndexPath(com.enonic.xp.content.ContentIndexPath) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) PropertySet(com.enonic.xp.data.PropertySet) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) PushContentListener(com.enonic.xp.content.PushContentListener) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeIds(com.enonic.xp.node.NodeIds) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) PropertySet(com.enonic.xp.data.PropertySet)

Example 17 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class CreateContentCommandTest method mockNodeServiceCreate.

private Node mockNodeServiceCreate(final InvocationOnMock invocation) throws Throwable {
    CreateNodeParams params = (CreateNodeParams) invocation.getArguments()[0];
    final AccessControlList permissions = AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(PrincipalKey.ofAnonymous()).build()).build();
    return Node.create().id(params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).timestamp(Instant.now()).build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 18 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class InputValidatorTest method validate_correct_input_types.

@Test
public void validate_correct_input_types() {
    // Creates a property set
    final PropertySet propertySet = new PropertySet();
    propertySet.addString("setString", "ost");
    propertySet.addDouble("setDouble", 123d);
    // Creates the correct data to validate
    final PropertyTree data = new PropertyTree();
    data.addString("textLine", "textLine");
    data.addString("color", "#12345");
    data.addString("comboBox", "value2");
    data.addBoolean("checkbox", true);
    data.addString("phone", "+4797773223");
    data.addString("tag", "myTag");
    data.addReference("contentSelector", new Reference(new NodeId()));
    data.addString("contentTypeFilter", "article");
    data.addString("siteConfigurator", "my config here");
    data.addDouble("double", 1.1d);
    data.addLong("long", 12345678910L);
    data.addStrings("stringArray", "a", "b", "c");
    data.addLocalDateTime("localDateTime", LocalDateTime.parse("2015-01-14T10:00:00"));
    data.addInstant("dateTime", DateTimeFormatter.ISO_DATE_TIME.parse("2015-01-15T10:15:00+02:00", Instant::from));
    data.addLocalDate("date", LocalDate.parse("2015-01-15"));
    data.addLocalTime("time", LocalTime.parse("10:00:32.123"));
    data.addGeoPoint("geoPoint", GeoPoint.from("-45,34"));
    data.addString("htmlArea", "<stuff>staff</stuff>");
    // Validates the correct data
    inputValidator.validate(data);
}
Also used : Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 19 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class BranchServiceImpl method delete.

@Override
public void delete(final NodeIds nodeIds, final InternalContext context) {
    final NodeBranchEntries nodeBranchEntries = getIgnoreOrder(nodeIds, context);
    nodeBranchEntries.forEach(entry -> pathCache.evict(createPath(entry.getNodePath(), context)));
    storageDao.delete(DeleteRequests.create().forceRefresh(false).ids(nodeIds.stream().map(nodeId -> new BranchDocumentId(nodeId, context.getBranch()).toString()).collect(Collectors.toList())).settings(createStorageSettings(context)).build());
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) NodePaths(com.enonic.xp.node.NodePaths) StoreStorageName(com.enonic.xp.repo.impl.storage.StoreStorageName) SearchRequest(com.enonic.xp.repo.impl.search.SearchRequest) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Supplier(java.util.function.Supplier) StorageDao(com.enonic.xp.repo.impl.storage.StorageDao) BranchPath(com.enonic.xp.repo.impl.cache.BranchPath) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) Component(org.osgi.service.component.annotations.Component) BranchService(com.enonic.xp.repo.impl.branch.BranchService) BranchCachePath(com.enonic.xp.repo.impl.cache.BranchCachePath) SingleRepoStorageSource(com.enonic.xp.repo.impl.SingleRepoStorageSource) SearchDao(com.enonic.xp.repo.impl.search.SearchDao) IdFilter(com.enonic.xp.query.filter.IdFilter) ReturnFields(com.enonic.xp.repo.impl.ReturnFields) Striped(com.google.common.util.concurrent.Striped) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) StaticStorageType(com.enonic.xp.repo.impl.storage.StaticStorageType) InternalContext(com.enonic.xp.repo.impl.InternalContext) StoreRequest(com.enonic.xp.repo.impl.storage.StoreRequest) NodePath(com.enonic.xp.node.NodePath) NodeBranchQueryResult(com.enonic.xp.repo.impl.branch.search.NodeBranchQueryResult) ValueFactory(com.enonic.xp.data.ValueFactory) GetResult(com.enonic.xp.repo.impl.storage.GetResult) Collectors(java.util.stream.Collectors) NodeId(com.enonic.xp.node.NodeId) Objects(java.util.Objects) List(java.util.List) Lock(java.util.concurrent.locks.Lock) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) StorageSource(com.enonic.xp.repo.impl.StorageSource) NodeBranchQueryResultFactory(com.enonic.xp.repo.impl.branch.search.NodeBranchQueryResultFactory) Reference(org.osgi.service.component.annotations.Reference) NodeIds(com.enonic.xp.node.NodeIds) GetByIdRequest(com.enonic.xp.repo.impl.storage.GetByIdRequest) DeleteRequests(com.enonic.xp.repo.impl.storage.DeleteRequests) NodeBranchQuery(com.enonic.xp.repo.impl.branch.search.NodeBranchQuery)

Example 20 with NodeId

use of com.enonic.xp.node.NodeId in project xp by enonic.

the class RepoDumper method dumpBranch.

private void dumpBranch(final BranchDumpResult.Builder dumpResult, Consumer<NodeId> nodeIdsAccumulator) {
    final Node rootNode = this.nodeService.getRoot();
    final FindNodesByParentResult children = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(rootNode.id()).recursive(true).childOrder(ChildOrder.from("_path asc")).build());
    final Branch branch = ContextAccessor.current().getBranch();
    this.listener.dumpingBranch(repository.getId(), branch, children.getTotalHits() + 1);
    LOG.info("Dumping repository [{}], branch [{}]", repository.getId(), branch);
    doDumpNode(rootNode.id(), dumpResult);
    nodeIdsAccumulator.accept(rootNode.id());
    for (final NodeId child : children.getNodeIds()) {
        doDumpNode(child, dumpResult);
        nodeIdsAccumulator.accept(child);
    }
}
Also used : Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Aggregations

NodeId (com.enonic.xp.node.NodeId)91 Node (com.enonic.xp.node.Node)44 Test (org.junit.jupiter.api.Test)36 NodePath (com.enonic.xp.node.NodePath)23 InternalContext (com.enonic.xp.repo.impl.InternalContext)18 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)15 NodeIds (com.enonic.xp.node.NodeIds)14 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)11 Context (com.enonic.xp.context.Context)10 PropertyTree (com.enonic.xp.data.PropertyTree)10 Branch (com.enonic.xp.branch.Branch)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)9 NodeVersionId (com.enonic.xp.node.NodeVersionId)9 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)8 RefreshMode (com.enonic.xp.node.RefreshMode)8 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 Event (com.enonic.xp.event.Event)6 RenameNodeParams (com.enonic.xp.node.RenameNodeParams)6