Search in sources :

Example 1 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class CascadeUpdateAspect method markCascadeUpdate.

private void markCascadeUpdate(NodeRef nodeRef) {
    Status status = nodeService.getNodeStatus(nodeRef);
    nodeService.setProperty(status.getNodeRef(), ContentModel.PROP_CASCADE_CRC, solrTrackingComponent.getCRC(status.getDbId()));
    nodeService.setProperty(status.getNodeRef(), ContentModel.PROP_CASCADE_TX, status.getDbTxnId());
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status)

Example 2 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class DbNodeServiceImpl method getNodePairNotNull.

/**
 * Performs a null-safe get of the node
 *
 * @param nodeRef the node to retrieve
 * @return Returns the node entity (never null)
 * @throws InvalidNodeRefException if the referenced node could not be found
 */
private Pair<Long, NodeRef> getNodePairNotNull(NodeRef nodeRef) throws InvalidNodeRefException {
    ParameterCheck.mandatory("nodeRef", nodeRef);
    Pair<Long, NodeRef> unchecked = nodeDAO.getNodePair(nodeRef);
    if (unchecked == null) {
        Status nodeStatus = nodeDAO.getNodeRefStatus(nodeRef);
        throw new InvalidNodeRefException("Node does not exist: " + nodeRef + " (status:" + nodeStatus + ")", nodeRef);
    }
    return unchecked;
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 3 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class SOLRTrackingComponentImpl method convertVersionNodeRefToVersionedNodeRef.

@SuppressWarnings("deprecation")
protected NodeRef convertVersionNodeRefToVersionedNodeRef(NodeRef versionNodeRef) {
    Status status = nodeDAO.getNodeRefStatus(versionNodeRef);
    if (status == null) {
        return versionNodeRef;
    }
    Map<QName, Serializable> properties = nodeDAO.getNodeProperties(status.getDbId());
    NodeRef nodeRef = null;
    // Switch VersionStore depending on configured impl
    if (versionNodeRef.getStoreRef().getIdentifier().equals(Version2Model.STORE_ID)) {
        // V2 version store (eg. workspace://version2Store)
        nodeRef = (NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF);
    } else if (versionNodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) {
        // Deprecated V1 version store (eg. workspace://lightWeightVersionStore)
        nodeRef = new NodeRef((String) properties.get(VersionModel.PROP_QNAME_FROZEN_NODE_STORE_PROTOCOL), (String) properties.get(VersionModel.PROP_QNAME_FROZEN_NODE_STORE_ID), (String) properties.get(VersionModel.PROP_QNAME_FROZEN_NODE_ID));
    }
    return nodeRef;
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName)

Example 4 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class SOLRTrackingComponentImpl method getNodesMetadata.

/**
 * {@inheritDoc}
 */
public void getNodesMetadata(NodeMetaDataParameters nodeMetaDataParameters, MetaDataResultsFilter resultFilter, NodeMetaDataQueryCallback callback) {
    if (false == enabled) {
        return;
    }
    NodeMetaDataQueryRowHandler rowHandler = new NodeMetaDataQueryRowHandler(callback);
    boolean includeType = (resultFilter == null ? true : resultFilter.getIncludeType());
    boolean includeProperties = (resultFilter == null ? true : resultFilter.getIncludeProperties());
    boolean includeAspects = (resultFilter == null ? true : resultFilter.getIncludeAspects());
    boolean includePaths = (resultFilter == null ? true : resultFilter.getIncludePaths());
    boolean includeNodeRef = (resultFilter == null ? true : resultFilter.getIncludeNodeRef());
    boolean includeParentAssociations = (resultFilter == null ? true : resultFilter.getIncludeParentAssociations());
    boolean includeChildAssociations = (resultFilter == null ? true : resultFilter.getIncludeChildAssociations());
    boolean includeOwner = (resultFilter == null ? true : resultFilter.getIncludeOwner());
    boolean includeChildIds = (resultFilter == null ? true : resultFilter.getIncludeChildIds());
    boolean includeTxnId = (resultFilter == null ? true : resultFilter.getIncludeTxnId());
    List<Long> nodeIds = preCacheNodes(nodeMetaDataParameters);
    for (Long nodeId : nodeIds) {
        Status status = nodeDAO.getNodeIdStatus(nodeId);
        if (status == null) {
            // See org.alfresco.solr.tracker.CoreTracker.updateDescendantAuxDocs(NodeMetaData, boolean, SolrIndexSearcher)
            continue;
        }
        NodeRef nodeRef = status.getNodeRef();
        NodeRef unversionedNodeRef = null;
        if (isVersionNodeRef(nodeRef)) {
            unversionedNodeRef = convertVersionNodeRefToVersionedNodeRef(VersionUtil.convertNodeRef(nodeRef));
        }
        NodeMetaData nodeMetaData = new NodeMetaData();
        nodeMetaData.setNodeId(nodeId);
        if (includeNodeRef) {
            nodeMetaData.setNodeRef(tenantService.getBaseName(nodeRef, true));
        }
        if (includeTxnId) {
            nodeMetaData.setTxnId(status.getDbTxnId());
        }
        if (status.isDeleted()) {
            rowHandler.processResult(nodeMetaData);
            continue;
        }
        Map<QName, Serializable> props = null;
        Set<QName> aspects = null;
        Status unversionedStatus = null;
        if (unversionedNodeRef != null) {
            unversionedStatus = nodeDAO.getNodeRefStatus(unversionedNodeRef);
        }
        if (unversionedStatus != null) {
            nodeMetaData.setAclId(nodeDAO.getNodeAclId(unversionedStatus.getDbId()));
        } else {
            nodeMetaData.setAclId(nodeDAO.getNodeAclId(nodeId));
        }
        if (includeType) {
            QName nodeType = getNodeType(nodeId);
            if (nodeType != null) {
                nodeMetaData.setNodeType(nodeType);
            } else {
                QName typeQName = null;
                TypeDefinition typeDefinition = null;
                String errorMessage = "NodeId " + nodeId + " with nodeRef " + nodeRef;
                typeQName = nodeDAO.getNodeType(nodeId);
                if (typeQName != null) {
                    errorMessage += " has type " + typeQName + ", but this type is not registered in DictionaryService.";
                } else {
                    errorMessage += " has no type.";
                }
                throw new AlfrescoRuntimeException(errorMessage + " It will be ignored by SOLR.");
            }
        }
        if (includeProperties) {
            if (props == null) {
                props = getProperties(nodeId);
            }
            nodeMetaData.setProperties(props);
        } else {
            nodeMetaData.setProperties(Collections.<QName, Serializable>emptyMap());
        }
        if (includeAspects || includePaths || includeParentAssociations) {
            aspects = getNodeAspects(nodeId);
        }
        nodeMetaData.setAspects(aspects);
        boolean ignoreLargeMetadata = (typeIndexFilter.shouldBeIgnored(getNodeType(nodeId)) || aspectIndexFilter.shouldBeIgnored(getNodeAspects(nodeId)));
        CategoryPaths categoryPaths = new CategoryPaths(new ArrayList<Pair<Path, QName>>(), new ArrayList<ChildAssociationRef>());
        if (!ignoreLargeMetadata && (includePaths || includeParentAssociations)) {
            if (props == null) {
                props = getProperties(nodeId);
            }
            categoryPaths = getCategoryPaths(status.getNodeRef(), aspects, props);
        }
        if (!ignoreLargeMetadata && (typeIndexFilter.isIgnorePathsForSpecificTypes() || aspectIndexFilter.isIgnorePathsForSpecificAspects() || includeParentAssociations)) {
            // check if parent should be ignored
            final List<Long> parentIds = new LinkedList<Long>();
            final List<ChildAssociationRef> parentAssocs = new ArrayList<ChildAssociationRef>(100);
            nodeDAO.getParentAssocs(nodeId, null, null, true, new ChildAssocRefQueryCallback() {

                @Override
                public boolean preLoadNodes() {
                    return false;
                }

                @Override
                public boolean orderResults() {
                    return false;
                }

                @Override
                public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
                    parentIds.add(parentNodePair.getFirst());
                    parentAssocs.add(tenantService.getBaseName(childAssocPair.getSecond(), true));
                    return false;
                }

                @Override
                public void done() {
                }
            });
            if (!parentIds.isEmpty()) {
                Long parentId = parentIds.iterator().next();
                if (typeIndexFilter.isIgnorePathsForSpecificTypes()) {
                    QName parentType = getNodeType(parentId);
                    ignoreLargeMetadata = typeIndexFilter.shouldBeIgnored(parentType);
                }
                if (!ignoreLargeMetadata && aspectIndexFilter.isIgnorePathsForSpecificAspects()) {
                    ignoreLargeMetadata = aspectIndexFilter.shouldBeIgnored(getNodeAspects(parentId));
                }
            }
            if (includeParentAssociations) {
                for (ChildAssociationRef ref : categoryPaths.getCategoryParents()) {
                    parentAssocs.add(tenantService.getBaseName(ref, true));
                }
                CRC32 crc = new CRC32();
                for (ChildAssociationRef car : parentAssocs) {
                    try {
                        crc.update(car.toString().getBytes("UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException("UTF-8 encoding is not supported");
                    }
                }
                nodeMetaData.setParentAssocs(parentAssocs, crc.getValue());
            }
        }
        nodeMetaData.setTenantDomain(tenantService.getDomain(nodeRef.getStoreRef().getIdentifier()));
        if (includeChildAssociations || includeChildIds) {
            final List<ChildAssociationRef> childAssocs = new ArrayList<ChildAssociationRef>(100);
            final List<Long> childIds = new ArrayList<Long>(100);
            nodeDAO.getChildAssocs(nodeId, null, null, null, null, null, new ChildAssocRefQueryCallback() {

                @Override
                public boolean preLoadNodes() {
                    return false;
                }

                @Override
                public boolean orderResults() {
                    return false;
                }

                @Override
                public boolean handle(Pair<Long, ChildAssociationRef> childAssocPair, Pair<Long, NodeRef> parentNodePair, Pair<Long, NodeRef> childNodePair) {
                    QName nodeType = nodeDAO.getNodeType(childNodePair.getFirst());
                    if (includeChildAssociations) {
                        boolean addCurrentChildAssoc = true;
                        if (typeIndexFilter.isIgnorePathsForSpecificTypes()) {
                            addCurrentChildAssoc = !typeIndexFilter.shouldBeIgnored(nodeType);
                        }
                        if (!addCurrentChildAssoc && aspectIndexFilter.isIgnorePathsForSpecificAspects()) {
                            addCurrentChildAssoc = !aspectIndexFilter.shouldBeIgnored(getNodeAspects(childNodePair.getFirst()));
                        }
                        if (addCurrentChildAssoc) {
                            childAssocs.add(tenantService.getBaseName(childAssocPair.getSecond(), true));
                        }
                    }
                    if (includeChildIds) {
                        boolean addCurrentId = true;
                        if (typeIndexFilter.isIgnorePathsForSpecificTypes()) {
                            addCurrentId = !typeIndexFilter.shouldBeIgnored(nodeType);
                        }
                        if (!addCurrentId) {
                            addCurrentId = !aspectIndexFilter.shouldBeIgnored(getNodeAspects(childNodePair.getFirst()));
                        }
                        if (addCurrentId) {
                            childIds.add(childNodePair.getFirst());
                        }
                    }
                    return true;
                }

                @Override
                public void done() {
                }
            });
            nodeMetaData.setChildAssocs(childAssocs);
            nodeMetaData.setChildIds(childIds);
        }
        if (includePaths && !ignoreLargeMetadata) {
            List<Path> directPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(nodeId, status.getNodeRef()), false);
            Collection<Pair<Path, QName>> paths = new ArrayList<Pair<Path, QName>>(directPaths.size() + categoryPaths.getPaths().size());
            for (Path path : directPaths) {
                paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null));
            }
            for (Pair<Path, QName> catPair : categoryPaths.getPaths()) {
                paths.add(new Pair<Path, QName>(catPair.getFirst().getBaseNamePath(tenantService), catPair.getSecond()));
            }
            if (unversionedStatus != null) {
                List<Path> unversionedPaths = nodeDAO.getPaths(new Pair<Long, NodeRef>(unversionedStatus.getDbId(), unversionedStatus.getNodeRef()), false);
                for (Path path : unversionedPaths) {
                    paths.add(new Pair<Path, QName>(path.getBaseNamePath(tenantService), null));
                }
            }
            nodeMetaData.setPaths(paths);
            // Calculate name path
            Collection<Collection<String>> namePaths = new ArrayList<Collection<String>>(2);
            nodeMetaData.setNamePaths(namePaths);
            for (Pair<Path, QName> catPair : paths) {
                Path path = catPair.getFirst();
                boolean added = false;
                List<String> namePath = new ArrayList<String>(path.size());
                NEXT_ELEMENT: for (Path.Element pathElement : path) {
                    if (!(pathElement instanceof ChildAssocElement)) {
                        // This is some path element that is terminal to a cm:name path
                        break;
                    }
                    ChildAssocElement pathChildAssocElement = (ChildAssocElement) pathElement;
                    NodeRef childNodeRef = pathChildAssocElement.getRef().getChildRef();
                    Pair<Long, NodeRef> childNodePair = nodeDAO.getNodePair(childNodeRef);
                    if (childNodePair == null) {
                        // Gone
                        break;
                    }
                    Long childNodeId = childNodePair.getFirst();
                    String childNodeName = (String) nodeDAO.getNodeProperty(childNodeId, ContentModel.PROP_NAME);
                    if (childNodeName == null) {
                        // We have hit a non-name node, which acts as a root for cm:name
                        // DH: There is no particular constraint here.  This is just a decision made.
                        namePath.clear();
                        // We have to continue down the path as there could be a name path lower down
                        continue NEXT_ELEMENT;
                    }
                    // We can finally add the name to the path
                    namePath.add(childNodeName);
                    // Add the path if this is the first entry in the name path
                    if (!added) {
                        namePaths.add(namePath);
                        added = true;
                    }
                }
            }
        }
        if (includeOwner) {
            // cached in OwnableService
            nodeMetaData.setOwner(ownableService.getOwner(status.getNodeRef()));
        }
        rowHandler.processResult(nodeMetaData);
    }
}
Also used : Serializable(java.io.Serializable) CRC32(java.util.zip.CRC32) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) ArrayList(java.util.ArrayList) ChildAssocRefQueryCallback(org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Pair(org.alfresco.util.Pair) Status(org.alfresco.service.cmr.repository.NodeRef.Status) Path(org.alfresco.service.cmr.repository.Path) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) QName(org.alfresco.service.namespace.QName) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Collection(java.util.Collection)

Example 5 with Status

use of org.alfresco.service.cmr.repository.NodeRef.Status in project alfresco-repository by Alfresco.

the class AbstractEventsService method getNodeInfo.

protected NodeInfo getNodeInfo(final NodeRef nodeRef, final String eventType) {
    NodeInfo nodeInfo = AuthenticationUtil.runAsSystem(new RunAsWork<NodeInfo>() {

        public NodeInfo doWork() throws Exception {
            NodeInfo nodeInfo = null;
            String txnId = AlfrescoTransactionSupport.getTransactionId();
            if (!includeEventType(eventType)) {
                nodeInfo = new NodeInfo(eventType, null, null, nodeRef, null, null, null, null, null, null, null, null, false, null, null);
            } else if (nodeRef == null || !nodeService.exists(nodeRef)) {
                nodeInfo = new NodeInfo(eventType, txnId, null, nodeRef, null, null, null, null, null, null, null, false, true, false, null);
            } else {
                FileFilterMode.Client filterclient = FileFilterMode.getClient();
                Visibility visibility = hiddenAspect.getVisibility(filterclient, nodeRef);
                QName type = nodeService.getType(nodeRef);
                if (!typeMatches(type)) {
                    nodeInfo = new NodeInfo(eventType, txnId, null, nodeRef, null, null, null, null, null, null, null, true, true, false, false);
                } else if (!visibility.equals(Visibility.Visible)) {
                    nodeInfo = new NodeInfo(eventType, txnId, null, nodeRef, null, null, null, null, null, null, null, true, true, true, true);
                } else {
                    SiteInfo siteInfo = siteService.getSite(nodeRef);
                    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
                    Set<QName> aspects = nodeService.getAspects(nodeRef);
                    final String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
                    List<Path> nodePaths = Collections.singletonList(nodeService.getPath(nodeRef));
                    Date modifiedTime = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
                    Long modificationTimestamp = (modifiedTime != null ? modifiedTime.getTime() : null);
                    Status status = nodeService.getNodeStatus(nodeRef);
                    Client client = ClientUtil.from(filterclient);
                    nodeInfo = new NodeInfo(eventType, txnId, name, nodeRef, status, nodePaths, modificationTimestamp, type, aspects, siteId, client, true, true, true, true);
                }
            }
            return nodeInfo;
        }
    });
    return nodeInfo;
}
Also used : Status(org.alfresco.service.cmr.repository.NodeRef.Status) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Set(java.util.Set) HashSet(java.util.HashSet) QName(org.alfresco.service.namespace.QName) MessagingException(org.gytheio.messaging.MessagingException) Date(java.util.Date) Visibility(org.alfresco.repo.model.filefolder.HiddenAspect.Visibility) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) FileFilterMode(org.alfresco.util.FileFilterMode) Client(org.alfresco.sync.repo.Client)

Aggregations

Status (org.alfresco.service.cmr.repository.NodeRef.Status)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 QName (org.alfresco.service.namespace.QName)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 CannedQueryDAOTest (org.alfresco.repo.domain.query.CannedQueryDAOTest)2 Test (org.junit.Test)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CRC32 (java.util.zip.CRC32)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ChildAssocRefQueryCallback (org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback)1 Visibility (org.alfresco.repo.model.filefolder.HiddenAspect.Visibility)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1