cancel
Showing results for 
Search instead for 
Did you mean: 

Creating links

hunterbit
Champ in-the-making
Champ in-the-making
Hello everyone,
I wanted to know whether code, through WebService, I can insert a Item (any binary document) and then create always code a link to this file in other folders without replicate the file again.
Thank you.

Rocco.
4 REPLIES 4

lascaux
Champ on-the-rise
Champ on-the-rise
Hi,

here is a method to create a link of a node in another destination,

It assumes you have the object you want to link and the destination as Alfresco Node Type …


public boolean addLink(Node object, Node destination)
   {
      boolean result = false;
      try
      {
         ParentReference to = new ParentReference(
               Constant.STORE,
               destination.getReference().getUuid(),
               destination.getReference().getPath(),
               Constants.ASSOC_CONTAINS,
               Constants.ASSOC_CONTAINS);

         Predicate where = new Predicate( new Reference[] { object.getReference() }, null, null );

         CMLAddChild addChild = new CMLAddChild();
         addChild.setTo(to);
         addChild.setWhere(where);

         CML cml = new CML();
         cml.setAddChild(new CMLAddChild[] {addChild});

         UpdateResult[] updateResult = repositoryService.update(cml);

         result = (updateResult != null);
      }
      catch(RepositoryFault e)
      {
         System.out.println("RepositoryFault: " + e.getMessage() + "\n" + e.getStackTrace());
      }
      catch(RemoteException e)
      {
         System.out.println("RemoteException: " + e.getMessage());
      }
      return result;
   }

Hope it helps Smiley Happy
Sylvain

hunterbit
Champ in-the-making
Champ in-the-making
Thank you for suggestion,
tomorrow I make a test and do you know if everything ok
Thank you.

hunterbit
Champ in-the-making
Champ in-the-making
Hello,
I wanted to ask how you can create the node destination,
The crux origin so recovery through a search XPATH and the step to your method, but I would not know how to create the node destination.
The manufacturer requires the parameters that I do not know what they are.
For example this is the code that I use but I do not know whether it is right to create the Reference as I have done and also do not know how to create the node dest to send then the method that I have recommended.

Reference reference = new Reference(STORE, null, "/app:company_home/cm:categoria/cm:links");
Node dest=new Node(reference,"prova",null,null);
addLink(sourse,dest);

Thank you.

hunterbit
Champ in-the-making
Champ in-the-making
Hello everyone,
I did the tests and it was solving the problem I had initially with knots.
Now I have another problem. If a link gate of what I created him I erase all that can be found in other folders plus links to real, in practice a link gate and I delete everything.
how can I do to him only delete the link that refers to the object in the repository and not everything?
Thank you.