2016-07-25 39 views
2

我正嘗試使用apache-chemistry在Alfresco中創建文檔的快捷方式或鏈接。使用下面的代碼,我想創建鏈接或快捷方式Alfresco:創建鏈接後無法找到該項目

properties = new HashMap<String, Object>(); 
properties.put(PropertyIds.BASE_TYPE_ID, BaseTypeId.CMIS_ITEM.value()); 

// define a name and a description for the link 
properties.put(PropertyIds.NAME, "Name_for_the.link"); 
properties.put("cmis:description", "test create link");    
properties.put(PropertyIds.OBJECT_TYPE_ID, "I:app:filelink"); 

//define the destination node reference 
properties.put("cm:destination", "workspace://SpacesStore/41f43936-31c1-432e-bb33-438c05bcb26c");  

// choose a folder where the link is to be create 
Folder destinationFolder = (Folder) session.getObjectByPath("/path/to/the/destination/folder"); 

session.createItem(properties, destinationFolder); 

現在的問題是,我能夠從上面的代碼創建鏈接,但每當我點擊鏈接它顯示我

該項目不能找到。您沒有權限查看該項目,該項目已被刪除或從未存在。

+1

你想獲得一個'文件「或」文件夾「? –

+0

就像一個建議,你可以激勵人們幫助你投票它只是一個暗示 –

+0

thanx的迴應,我使用文件 – deen

回答

0

要修改現有對象的屬性,首先需要找回它,然後你就可以調用setProperty方法 對象本身,傳遞ID,併爲您 打算每個屬性的新值改變。最後,只需調用updateProperties方法如下:

public static void main(String args[]) { 
String serverUrl = args[0]; 
String username = args[1]; 
String password = args[2]; 
Session session = getSession(serverUrl, username, password); 
Folder root = session.getRootFolder(); 
Map<String, Object> properties = new HashMap<String, Object>(); 
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT. 
value()); 
String name = "New Document (" + System.currentTimeMillis() + 
").txt"; 
properties.put(PropertyIds.NAME, name); 
List<Ace> addAces = new LinkedList<Ace>(); 
List<Ace> removeAces = new LinkedList<Ace>(); 
List<Policy> policies = new LinkedList<Policy>(); 
String content = "The quick brown fox jumps over the lazy dog."; 
ContentStream contentStream = new ContentStreamImpl("text.txt", 
BigInteger.valueOf(content.length()), 
"text/plain", new ByteArrayInputStream(content.getBytes())); 
Document newDocument = root.createDocument(properties, 
contentStream, VersioningState.MAJOR, policies, addAces, removeAces, 
session.getDefaultContext()); 
newDocument.setProperty(PropertyIds.NAME, "Modified document (" + 
System.currentTimeMillis() + ").txt"); 
newDocument.updateProperties(); 
session.save(); 
} 

在這個方法中,我改變一個文件的屬性,嘗試做類似的東西。希望幫你

+0

thnx回覆,這不是我想要的,我想創建鏈接或快捷方式。你能告訴我如何從文檔對象中獲取nodeRef嗎?日Thnx – deen