2

I am trying to create shortcut or link of a document in Alfresco using apache-chemistry. Using below code I am trying to create link or shortcut

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);

Now problem is that I am able to create link from above code but whenever I clicked on link it showing me

The item cannot be found. Either you do not have permissions to view the item, it has been removed or it never existed.

deen
  • 2,185
  • 7
  • 29
  • 53

1 Answers1

0

To modify the properties of an existing object, you first need to retrieve it, Then you can call the setProperty method on the object itself, passing in the ID and the new value for each property that you intend to change. At the end, simply call the updateProperties method as follows:

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();
}

in this method i am changing properties of a document, try to do something like that Hope that helped you

Yagami Light
  • 1,756
  • 4
  • 19
  • 39
  • thnx for reply, that's not what I want, I want to create link or shortcut. Can you please tell me how I can get nodeRef from document object. thnx – deen Jul 25 '16 at 13:26