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;
}
Reference reference1 = new Reference(STORE, null, "/app:company_home/cm:ArchivoOrigen.txt");
Node object=new Node(reference1,"prueba",null,null);
Reference reference2 = new Reference(STORE, null, "/app:company_home");
Node destination=new Node(reference2,"prueba",null,null);
public void wsCrearLink(String sourceNode,
String destinationNode)
{
String storeSchema = Constants.WORKSPACE_STORE;
String storeAddress = "SpacesStore";
final Store STORE = new Store(storeSchema, storeAddress);
try
{
//node to link
Reference ref = new Reference();
ref.setStore(STORE);
ref.setUuid(sourceNode);
//node destination 14c29a12-7be0-11db-83b6-f5ef9685f99e
ParentReference destinationFolder = new ParentReference();
destinationFolder.setStore(STORE);
destinationFolder.setUuid(destinationNode);
destinationFolder.setAssociationType(Constants.ASSOC_CONTAINS);
destinationFolder.setChildName("poppi");
Predicate pred = new Predicate();
pred.setStore(STORE);
pred.setNodes(new Reference[]{ref});
NamedValue[] prop = new NamedValue[4];
prop[0] = new NamedValue();
prop[0].setName(Constants.PROP_NAME);
prop[0].setValue("Name");
prop[0].setIsMultiValue(false);
prop[1] = new NamedValue();
prop[1].setName(Constants.PROP_TITLE);
prop[1].setValue("Title");
prop[1].setIsMultiValue(false);
prop[2] = new NamedValue();
prop[2].setName(Constants.PROP_DESCRIPTION);
prop[2].setValue("Description");
prop[2].setIsMultiValue(false);
prop[3] = new NamedValue();
prop[3].setName("{http://www.alfresco.org/model/content/1.0}destination");
prop[2].setName(Constants.PROP_DESCRIPTION);
prop[2].setValue("Descrizione");
prop[2].setIsMultiValue(false);
prop[3].setValue("workspace://SpacesStore/75710e09-83a4-11db-a5ec-7f23e300cdcd");
prop[3].setIsMultiValue(false);
CMLCreate create = new CMLCreate();
create.setParent(destinationFolder);
create.setAssociationType(Constants.ASSOC_CONTAINS);
create.setType("{http://www.alfresco.org/model/application/1.0}filelink");
create.setProperty(prop);
create.setChildName("Childname");
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] result = repositoryService.update(cml);
}
catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Para que en el cliente web aparezcan con el icono de un enlace, su nombre debe tener extensión ".lnk", es decir:prop[0].setValue("miEnlace.lnk");
Espero que te resulte útil UpdateResult[] result = repositoryService.update(cml);
por:UpdateResult[] updateResult = WebServiceFactory.getRepositoryService().update(cml);
Además, me sale el siguiente error al ejecutarlo:Creando link del documento…
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString:
faultActor:
faultNode:
faultDetail:
{http://www.alfresco.org/ws/service/repository/1.0}RepositoryFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>java.lang.IllegalArgumentException: A uuid or a path must be supplied to resolve to a NodeRef</ns1:message>
{http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.repository.RepositoryFault
{http://xml.apache.org/axis/}stackTrace:
at org.alfresco.repo.webservice.repository.RepositoryWebService.update(RepositoryWebService.java:341)
at sun.reflect.GeneratedMethodAccessor658.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)
{http://xml.apache.org/axis/}hostname:RPINEDA
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
at org.alfresco.webservice.repository.RepositoryFault.getDeserializer(RepositoryFault.java:146)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub.update(RepositoryServiceSoapBindingStub.java:986)
at es.sadesi.alfresco.test.TestWebServicesPrueba.crearReferenciaDocumento(TestWebServicesPrueba.java:211)
at es.sadesi.alfresco.test.TestWebServicesPrueba.main(TestWebServicesPrueba.java:472)
//la referencia1 sería el documento origen que tengo en mi alfresco
Reference reference1 = new Reference(STORE, null, "/app:company_home/cm:PruebaContenido.html");
String sourceNode = reference1.getUuid();
//la referencia2 seria la ubicación donde quiero crear el link
Reference reference2 = new Reference(STORE, null, "/app:company_home");
String destinationNode = reference2.getUuid();
CMLAddChild addChild = new CMLAddChild();
addChild.setTo(new ParentReference(STORE, espacio.getUUID(), espacio.getPath(), Constants.ASSOC_CONTAINS, UtilidadesNamespace.getQNameContentModel(espacio.getNombre()))); //ESPACIO DESTINO
addChild.setWhere(new Predicate(new Reference[]{new Reference(STORE, documento.getUUID(), documento.getPath())}, STORE, null)); //DOCUMENTO ORIGEN
CML cml = new CML();
cml.setAddChild(new CMLAddChild[] {addChild});
UpdateResult[] ur = WebServiceFactory.getRepositoryService().update(cml); //ACTUALIZAMOS
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.