如何使用Alfresco Java API查找nodeRef

时间:2015-02-20 14:56:05

标签: java api alfresco

我想在alfresco中获取存储节点的nodeRef。我用Alfresco java API创建了一个节点,并在一个方法中添加了一个数据对象作为节点的属性。现在我想在第二种方法中从该nodeRef中检索此数据对象。为此,我试图获取该存储节点的nodeRef,以便我可以获得该对象的属性。

我的代码段如下;

// Methos to set RegisterProperty dataobject in a node as a property of node 


public void registerProperty(RegisterProperty registerProperty) {

    registry.getAuthenticationService().authenticate("admin", "admin".toCharArray());

    /* Create Store */
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "myStoreProtocol" + GUID.generate());
    if (!nodeService.exists(storeRef)) {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    /* Get the root node from which to hang the next level of nodes */
    NodeRef rootNode = nodeService.getRootNode(storeRef);

    /*         Create child node              */
    ChildAssociationRef assocRef = nodeService.createNode(rootNode, ContentModel.ASSOC_CHILDREN, QName.createQName("vit-mrms", QName.createValidLocalName("myProperty-assocQName")), ContentModel.TYPE_CMOBJECT);
    NodeRef propertyRef = assocRef.getChildRef();

    /*  Store Serialized PropertyRegistration object as a node property  */
    QName myPropertyQname = QName.createQName("vit-mrms", registerProperty.getSurveyNo());
    nodeService.setProperty(propertyRef, myPropertyQname, registerProperty);
}


// Methos to get RegisterProperty dataobject from node.


public RegisterProperty getRegisterProperty(String surveyNo) {
    registry.getAuthenticationService().authenticate("admin", "admin".toCharArray());
    QName myPropertyQname = QName.createQName("vit-mrms", surveyNo);
    Serializable property = nodeService.getProperty(NodeRef, myPropertyQname);

// I want to retrieve this NodeRef 

    System.out.println("Store property in alfresco " + property.toString());
    return (RegisterProperty) property;
}

// Data object RegisterProperty is as follow,

public class RegisterProperty implements Serializable{

    private String ownerName;
    private String surveyNo;

    public String getOwnerName() {
        return ownerName;
    }

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;
    }

    public String getSurveyNo() {
        return surveyNo;
    }
}

请建议一种在getRegisterProperty()方法中获取NodeRef的方法,以便我可以从该节点检索属性作为数据对象。

我试过SearchService& nodeService来检索这个节点,但对我来说不起作用。


非常感谢Leonardo快速回复:)

我不了解属性名称作为Lucene搜索查询中的myprop。在我的情况下它应该是什么。将属性设置为节点时,我将Qname添加到nodeService.setProperty()方法。 myproperty与Qname相同吗?

// while creating node set ptoperty
nodeService.setProperty(rootNodeRef, myQname, registerPropertyDataobject);

// my search query
ResultSet rs = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "@mynamespace\:myprop:\"" + whateverValue + "\"");

另外,我没有获得licene搜索查询的语法。

  

“@ mynamespace:myprop:\”“+ whateverValue +”\“”

0 个答案:

没有答案