org.alfresco.service.cmr.repository.InvalidNodeRefException Java Examples

The following examples show how to use org.alfresco.service.cmr.repository.InvalidNodeRefException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUserComponentImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override public void deleteTestUser(final String userName)
{
    // And tear down afterwards.
    AuthenticationUtil.runAs(new RunAsWork<Void>()
    {
        @Override public Void doWork() throws Exception
        {
            try
            {
                if (personService.personExists(userName))
                {
                    log.debug("Deleting person " + userName + "...");
                    personService.deletePerson(userName);
                }
            } catch (InvalidNodeRefException ignoreIfThrown)
            {
                // It seems that in cloud code, asking if a person exists when the tenant they would be in also doesn't
                // exist, can give this exception.
            }
            return null;
        }
    }, AuthenticationUtil.getAdminUserName());
}
 
Example #2
Source File: LuceneCategoryServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Collection<ChildAssociationRef> resultSetToChildAssocCollection(ResultSet resultSet)
{
    List<ChildAssociationRef> collection = new LinkedList<ChildAssociationRef>();
    if (resultSet != null)
    {
        for (ResultSetRow row : resultSet)
        {
            try
            {
                ChildAssociationRef car = nodeService.getPrimaryParent(row.getNodeRef());
                collection.add(car);
            }
            catch(InvalidNodeRefException inre)
            {
                // keep going the node has gone beneath us just skip it
            }
        }
    }
    return collection;
    // The caller closes the result set
}
 
Example #3
Source File: AbstractPermissionsDaoComponentImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean getInheritParentPermissions(NodeRef nodeRef)
{
    Acl acl = null;
    try
    {
        acl = getAccessControlList(nodeRef);
    }
    catch (InvalidNodeRefException e)
    {
        return INHERIT_PERMISSIONS_DEFAULT;
    }
    if (acl == null)
    {
        return INHERIT_PERMISSIONS_DEFAULT;
    }
    else
    {
        return aclDaoComponent.getAccessControlListProperties(acl.getId()).getInherits();
    }
}
 
Example #4
Source File: CategoryPropertyDecorator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    Collection<NodeRef> collection = (Collection<NodeRef>)value;
    JSONArray array = new JSONArray();

    for (NodeRef obj : collection)
    {
        try
        {
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
            jsonObj.put("path", this.getPath(obj));
            jsonObj.put("nodeRef", obj.toString());
            array.add(jsonObj);
        }
        catch (InvalidNodeRefException e)
        {
            logger.warn("Category with nodeRef " + obj.toString() + " does not exist.");
        }
    }

    return array;
}
 
Example #5
Source File: FileFolderServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Helper method to convert node reference instances to file info
 * 
 * @param nodeRefs the node references
 * @return Return a list of file info
 * @throws InvalidTypeException if the node is not a valid type
 */
private List<FileInfo> toFileInfo(List<NodeRef> nodeRefs) throws InvalidTypeException
{
    List<FileInfo> results = new ArrayList<FileInfo>(nodeRefs.size());
    for (NodeRef nodeRef : nodeRefs)
    {
        try
        {
            FileInfo fileInfo = toFileInfo(nodeRef, true);
            results.add(fileInfo);
        }
        catch (InvalidNodeRefException inre)
        {
            logger.warn("toFileInfo: "+inre);
            // skip
        }
    }
    return results;
}
 
Example #6
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
        throws InvalidNodeRefException, AssociationExistsException
{
    // The node(s) involved may not be pending deletion
    checkPendingDelete(sourceRef);
    checkPendingDelete(targetRef);
    
    Pair<Long, NodeRef> sourceNodePair = getNodePairNotNull(sourceRef);
    long sourceNodeId = sourceNodePair.getFirst();
    Pair<Long, NodeRef> targetNodePair = getNodePairNotNull(targetRef);
    long targetNodeId = targetNodePair.getFirst();

    // we are sure that the association doesn't exist - make it
    Long assocId = nodeDAO.newNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName, -1);
    AssociationRef assocRef = new AssociationRef(assocId, sourceRef, assocTypeQName, targetRef);

    // Invoke policy behaviours
    invokeOnCreateAssociation(assocRef);
    
    // Add missing aspects
    addAspectsAndPropertiesAssoc(sourceNodePair, assocTypeQName, null, null, null, null, false);

    return assocRef;
}
 
Example #7
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Collection<NodeRef> getParents(NodeRef nodeRef) throws InvalidNodeRefException
{
    List<ChildAssociationRef> parentAssocs = getParentAssocs(
            nodeRef,
            RegexQNamePattern.MATCH_ALL,
            RegexQNamePattern.MATCH_ALL);
    
    // Copy into the set to avoid duplicates
    Set<NodeRef> parentNodeRefs = new HashSet<NodeRef>(parentAssocs.size());
    for (ChildAssociationRef parentAssoc : parentAssocs)
    {
        NodeRef parentNodeRef = parentAssoc.getParentRef();
        parentNodeRefs.add(parentNodeRef);
    }
    // Done
    return new ArrayList<NodeRef>(parentNodeRefs);
}
 
Example #8
Source File: VirtualStoreImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<ChildAssociationRef> getChildAssocs(Reference parentReference, QNamePattern typeQNamePattern,
            QNamePattern qnamePattern, int maxResults, boolean preload) throws InvalidNodeRefException
{
    if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS))
    {
        return parentReference.execute(new GetChildAssocsMethod(this,
                                                                environment,
                                                                preload,
                                                                maxResults,
                                                                qnamePattern,
                                                                typeQNamePattern));
    }
    else
    {
        return Collections.emptyList();
    }
}
 
Example #9
Source File: PersonServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public PersonInfo getPerson(NodeRef personRef) throws NoSuchPersonException
{
    Map<QName, Serializable> props = null;
    try
    {
        props = nodeService.getProperties(personRef);
    }
    catch (InvalidNodeRefException inre)
    {
        throw new NoSuchPersonException(personRef.toString());
    }
    
    String username  = (String)props.get(ContentModel.PROP_USERNAME);
    if (username == null)
    {
        throw new NoSuchPersonException(personRef.toString());
    }
    
    return new PersonInfo(personRef, 
                          username, 
                          (String)props.get(ContentModel.PROP_FIRSTNAME),
                          (String)props.get(ContentModel.PROP_LASTNAME));
}
 
Example #10
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the type definition of a node or <code>null</code> if no type
 * definition could be found.
 */
public TypeDefinitionWrapper getType(NodeRef nodeRef)
{
    try
    {
        QName typeQName = nodeService.getType(nodeRef);
        return getOpenCMISDictionaryService().findNodeType(typeQName);
    }
    catch(InvalidNodeRefException inre)
    {
        return null;
    }
}
 
Example #12
Source File: SearchServiceSubSystemDelegator.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param nodeRef NodeRef
 * @param propertyQName QName
 * @param sqlLikePattern String
 * @param includeFTS boolean
 * @return boolean
 * @throws InvalidNodeRefException
 * @see org.alfresco.service.cmr.search.SearchService#like(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.lang.String, boolean)
 */
public boolean like(NodeRef nodeRef, QName propertyQName, String sqlLikePattern, boolean includeFTS) throws InvalidNodeRefException
{
    if (propertyQName == null)
    {
        throw new IllegalArgumentException("Property QName is mandatory for the like expression");
    }

    if (includeFTS)
    {
        return subSystem.like(nodeRef, propertyQName, sqlLikePattern, includeFTS);
    }
    else
    {
        // convert the SQL-like pattern into a Lucene-compatible string
        String pattern = SearchLanguageConversion.convertXPathLikeToRegex(sqlLikePattern.toLowerCase());

        Serializable property = nodeService.getProperty(nodeRef, propertyQName);
        if (property == null)
        {
            return false;
        }
        else
        {
            String propertyString = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, propertyQName));
            return propertyString.toLowerCase().matches(pattern);
        }
    }
   
}
 
Example #13
Source File: SolrSearchService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<Serializable> selectProperties(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver,
        boolean followAllParentLinks) throws InvalidNodeRefException, XPathException
{
    return selectProperties(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, SearchService.LANGUAGE_XPATH);

}
 
Example #14
Source File: SolrSearchService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<NodeRef> selectNodes(NodeRef contextNodeRef, String xpath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver,
        boolean followAllParentLinks, String language) throws InvalidNodeRefException, XPathException
{
    NodeSearcher nodeSearcher = new NodeSearcher(nodeService, dictionaryService, this);
    return nodeSearcher.selectNodes(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, language);

}
 
Example #15
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * When searching for <code>primaryOnly == true</code>, checks that there is exactly
 * one path.
 */
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public List<Path> getPaths(NodeRef nodeRef, boolean primaryOnly) throws InvalidNodeRefException
{
    // get the starting node
    Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
    
    return nodeDAO.getPaths(nodePair, primaryOnly);
}
 
Example #16
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void removeAspect(NodeRef nodeRef, QName aspectTypeQName)
            throws InvalidNodeRefException, InvalidAspectException
{
    getTrait().removeAspect(materializeIfPossible(nodeRef),
                            aspectTypeQName);
}
 
Example #17
Source File: AbstractNodeDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<Path> getPaths(Pair<Long, NodeRef> nodePair, boolean primaryOnly) throws InvalidNodeRefException
{
    // create storage for the paths - only need 1 bucket if we are looking for the primary path
    List<Path> paths = new ArrayList<Path>(primaryOnly ? 1 : 10);
    // create an empty current path to start from
    Path currentPath = new Path();
    // create storage for touched associations
    Stack<Long> assocIdStack = new Stack<Long>();
    
    // call recursive method to sort it out
    prependPaths(nodePair, null, currentPath, paths, assocIdStack, primaryOnly);
    
    // check that for the primary only case we have exactly one path
    if (primaryOnly && paths.size() != 1)
    {
        throw new RuntimeException("Node has " + paths.size() + " primary paths: " + nodePair);
    }
    
    // done
    if (loggerPaths.isDebugEnabled())
    {
        StringBuilder sb = new StringBuilder(256);
        if (primaryOnly)
        {
            sb.append("Primary paths");
        }
        else
        {
            sb.append("Paths");
        }
        sb.append(" for node ").append(nodePair);
        for (Path path : paths)
        {
            sb.append("\n").append("   ").append(path);
        }
        loggerPaths.debug(sb);
    }
    return paths;
}
 
Example #18
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ChildAssociationRef addChild(NodeRef parentRef, NodeRef childRef, QName assocTypeQName, QName qname)
            throws InvalidNodeRefException
{
    return getTrait().addChild(materializeIfPossible(parentRef),
                               materializeIfPossible(childRef),
                               assocTypeQName,
                               qname);
}
 
Example #19
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ChildAssociationRef> addChild(Collection<NodeRef> parentRefs, NodeRef childRef, QName assocTypeQName,
            QName qname) throws InvalidNodeRefException
{
    return getTrait().addChild(materializeIfPossible(parentRefs),
                               materializeIfPossible(childRef),
                               assocTypeQName,
                               qname);
}
 
Example #20
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
{
    Long nodeId = getNodePairNotNull(nodeRef).getFirst();
    // Spoof referencable properties
    if (qname.equals(ContentModel.PROP_STORE_PROTOCOL))
    {
        return nodeRef.getStoreRef().getProtocol();
    }
    else if (qname.equals(ContentModel.PROP_STORE_IDENTIFIER))
    {
        return nodeRef.getStoreRef().getIdentifier();
    }
    else if (qname.equals(ContentModel.PROP_NODE_UUID))
    {
        return nodeRef.getId();
    }
    else if (qname.equals(ContentModel.PROP_NODE_DBID))
    {
        return nodeId;
    }
    
    Serializable property = nodeDAO.getNodeProperty(nodeId, qname);
    
    // check if we need to provide a spoofed name
    if (property == null && qname.equals(ContentModel.PROP_NAME))
    {
        return nodeRef.getId();
    }
    
    // done
    return property;
}
 
Example #21
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addAspect(NodeRef nodeRef, QName aspectTypeQName, Map<QName, Serializable> aspectProperties)
            throws InvalidNodeRefException, InvalidAspectException
{
    getTrait().addAspect(materializeIfPossible(nodeRef),
                         aspectTypeQName,
                         aspectProperties);
}
 
Example #22
Source File: NodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @throws UnsupportedOperationException always
 */
public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException
{
    ChildAssociationRef childAssocRef = getPrimaryParent(nodeRef);
    Path path = new Path();
    path.append(new Path.ChildAssocElement(childAssocRef));
    return path;
}
 
Example #23
Source File: NodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQName, QNamePattern qname, int maxResults,
        boolean preload) throws InvalidNodeRefException
{
    List<ChildAssociationRef> result = getChildAssocs(nodeRef, typeQName, qname);
    if (result.size() > maxResults)
    {
        return result.subList(0, maxResults);
    }
    return result;
}
 
Example #24
Source File: AbstractNodeImporter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected final void importImportableItemMetadata(NodeRef nodeRef, Path parentFile, MetadataLoader.Metadata metadata)
{
    // Attach aspects
    if (metadata.getAspects() != null)
    {
        for (final QName aspect : metadata.getAspects())
        {
            if (logger.isDebugEnabled()) logger.debug("Attaching aspect '" + aspect.toString() + "' to node '" + nodeRef.toString() + "'.");

            nodeService.addAspect(nodeRef, aspect, null);  // Note: we set the aspect's properties separately, hence null for the third parameter
        }
    }

    // Set property values for both the type and any aspect(s)
    if (metadata.getProperties() != null)
    {
        if (logger.isDebugEnabled()) logger.debug("Adding properties to node '" + nodeRef.toString() + "':\n" + mapToString(metadata.getProperties()));

        try
        {
            nodeService.addProperties(nodeRef, metadata.getProperties());
        }
        catch (final InvalidNodeRefException inre)
        {
            if (!nodeRef.equals(inre.getNodeRef()))
            {
                // Caused by an invalid NodeRef in the metadata (e.g. in an association)
                throw new IllegalStateException("Invalid nodeRef found in metadata for '" + getFileName(parentFile) + "'.  " +
                        "Probable cause: an association is being populated via metadata, but the " +
                        "NodeRef for the target of that association ('" + inre.getNodeRef() + "') is invalid.  " +
                        "Please double check your metadata file and try again.", inre);
            }
            else
            {
                // Logic bug in the BFSIT.  :-(
                throw inre;
            }
        }
    }
}
 
Example #25
Source File: NodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Simulates the node begin attached ot the root node of the version store.
 */
public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) throws InvalidNodeRefException
{
    return new ChildAssociationRef(
            ContentModel.ASSOC_CHILDREN,
            dbNodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, STORE_ID)),
            rootAssocName,
            nodeRef);
}
 
Example #26
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public int countChildAssocs(NodeRef nodeRef, boolean isPrimary) throws InvalidNodeRefException
{    
    final Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
    final Long nodeId = nodePair.getFirst();
    return nodeDAO.countChildAssocsByParent(nodeId, isPrimary);
}
 
Example #27
Source File: AbstractUsageDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private long getNodeIdNotNull(NodeRef nodeRef)
{
    ParameterCheck.mandatory("nodeRef", nodeRef);
    
    Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(nodeRef);
    if (nodePair == null)
    {
        throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef);
    }
    return nodePair.getFirst();
}
 
Example #28
Source File: NodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @throws UnsupportedOperationException always
 */
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
        throws InvalidNodeRefException, AssociationExistsException
{
    // This operation is not supported for a version store
    throw new UnsupportedOperationException(MSG_UNSUPPORTED);
}
 
Example #29
Source File: ADMAccessControlListDAO.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Long getNodeIdNotNull(NodeRef nodeRef)
{
    Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(nodeRef);
    if (nodePair == null)
    {
        throw new InvalidNodeRefException(nodeRef);
    }
    return nodePair.getFirst();
}
 
Example #30
Source File: DbNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.repository.NodeService#setType(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
 */
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public void setType(NodeRef nodeRef, QName typeQName) throws InvalidNodeRefException
{
    // The node(s) involved may not be pending deletion
    checkPendingDelete(nodeRef);
    
    // check the node type
    TypeDefinition nodeTypeDef = dictionaryService.getType(typeQName);
    if (nodeTypeDef == null)
    {
        throw new InvalidTypeException(typeQName);
    }
    Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
    
    // Invoke policies
    invokeBeforeUpdateNode(nodeRef);
    QName oldType = nodeDAO.getNodeType(nodePair.getFirst());
    invokeBeforeSetType(nodeRef, oldType, typeQName);
    
    // Set the type
    boolean updatedNode = nodeDAO.updateNode(nodePair.getFirst(), typeQName, null);
    
    // Add the default aspects and properties required for the given type. Existing values will not be overridden.
    boolean updatedProps = addAspectsAndProperties(nodePair, typeQName, null, null, null, null, false);
    
    // Invoke policies
    if (updatedNode || updatedProps)
    {
        // Invoke policies
        invokeOnUpdateNode(nodeRef);
        invokeOnSetType(nodeRef, oldType, typeQName);
    }
}