CMDBuild Forum

Re: Workflow, delete existing Relations

Hi,

I have a workflow which creates a card. Like this:

cmdb.newCard("ServerPhysical")
.with("Customer", Customer)
.with("Article", Article)
[...]
.create();

Customer and Article are reference fields and there are domains from the process (NewServerPhysical) to Customer and from the process to Article. Naturally there are now two relations on the card Customer and Article one to the new created card ServerPhysical and another to the process which has created the card.

I tried to delete the relation after the creation of the card in the workflow with a code like this:

customerId= cmdb.cardFrom(Customer).getId();

cmdb.existingRelation("NewAssetCustomer")
.withCard1("Customer", customerId)
.withCard2("NewAsset", ProcessId)
.delete();

I had a look in the table Map, IdObj1 and IdObj2 are identical to customerId and ProcessId.

The process throws following error:

Error: org.cmdbuild.workflow.CMWorkflowException: org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException: Sourced file: eval stream : Error in method invocation: Method withCard1( java.lang.String, java.lang.Long ) not found in class'org.cmdbuild.api.fluent.ExistingRelation'
	at org.cmdbuild.workflow.service.AbstractSharkService.advanceActivityInstance(AbstractSharkService.java:435)
	at org.cmdbuild.workflow.service.TransactedSharkService.access$1301(TransactedSharkService.java:16)
	at org.cmdbuild.workflow.service.TransactedSharkService$13.command(TransactedSharkService.java:225)
	at org.cmdbuild.workflow.service.TransactedSharkService$13.command(TransactedSharkService.java:222)
	at org.cmdbuild.workflow.service.TransactedSharkService$TransactedExecutor.execute(TransactedSharkService.java:24)
	at org.cmdbuild.workflow.service.TransactedSharkService.advanceActivityInstance(TransactedSharkService.java:222)
	at org.cmdbuild.workflow.DefaultWorkflowEngine.advanceActivity(DefaultWorkflowEngine.java:462)
	at org.cmdbuild.logic.workflow.DefaultWorkflowLogic.updateActivity(DefaultWorkflowLogic.java:594)
	at org.cmdbuild.logic.workflow.DefaultWorkflowLogic.updateProcess(DefaultWorkflowLogic.java:563)
	at org.cmdbuild.logic.workflow.DefaultWorkflowLogic.updateProcess(DefaultWorkflowLogic.java:546)
	at org.cmdbuild.servlets.json.Workflow.saveActivity(Workflow.java:194)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.cmdbuild.servlets.JSONDispatcher.dispatch(JSONDispatcher.java:101)
	at org.cmdbuild.servlets.JSONDispatcher.doPost(JSONDispatcher.java:61)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.cmdbuild.filters.AuthFilter.doFilter(AuthFilter.java:158)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.cmdbuild.filters.PatchManagerFilter.doFilter(PatchManagerFilter.java:48)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.cmdbuild.filters.ConfCheckFilter.doFilter(ConfCheckFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.cmdbuild.filters.TranslationFilter.doFilter(TranslationFilter.java:52)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.cmdbuild.filters.LocalizationFilter.doFilter(LocalizationFilter.java:127)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException: Sourced file: eval stream : Error in method invocation: Method withCard1( java.lang.String, java.lang.Long ) not found in class'org.cmdbuild.api.fluent.ExistingRelation'
	at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
	at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
	at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
	at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(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.enhydra.shark.ejb.client.ws.WAPIEJBEndpointPortSoapBindingStub.changeActivityInstanceState(Unknown Source)
	at org.cmdbuild.workflow.service.AbstractSharkService.advanceActivityInstance(AbstractSharkService.java:431)
	... 58 more

 

Is there a possibility to delete the relation automatically with the workflow, because it is a bit confusing for the viewer in this case if there are two relations on the card? The manually deletion works well, but it creates too many work.

Thanks for your quick response.

Best regards.

I solved the problem with the error. With casting the ProcessId
Int processId = (int) ProcessId;
Now it works without error.

But there is still a relation between Customer and the process (NewServerPhysical).

Did you have any idea to solve this problem.

Best regards.

Hi Roger, 
you are seeing the relations between the process and the Customer class and between the process and the Article class because of the two reference attributes of the process (Customer and Article). For getting rid of those relations I suggest you to simply write 
Customer = null;
Article = null; 
in the point of the process where you do not need those values anymore, for instance after the piece of code that creates the Physical server. Resetting the references will automatically delete the relations.
 
Hope this helps!
Best regards.
CMDBuild Team
 
 
 
 
 
Previously Roger wrote:
I solved the problem with the error. With casting the ProcessId Int processId = (int) ProcessId; Now it works without error.

But there is still a relation between Customer and the process (NewServerPhysical).

Did you have any idea to solve this problem.

Best regards.

 

Hi,
Perfect, it works well.
I thought a bit too complicated.
thank you.
Best regards