Adding POJO property to DataObject

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding POJO property to DataObject

acichon89
Hi, I would like to add simple object retrieved from my DB to Component called "DataObject". Here is what I added. My DataObjectEditorModel class look like:

@Editor(template=CommonTemplate.class)
@ModelBinder(binder=DataObjectBinder.class)
public class DataObjectEditorModel extends DataEditorModel{
	
	@Widget(order=3,label="Is collection")
	private boolean collection;

	
	public boolean isCollection() {
		return collection;
	}

	public void setCollection(boolean collection) {
		this.collection = collection;
	}
	//MY POJO :
	@Widget(label="Document",order=20,instantiationHandler=DocumentOfficeInstatiationHandler.class)
	private DocumentOffice document;


	public DocumentOffice getDocument() {
		return document;
	}

	public void setDocument(DocumentOffice document) {
		this.document = document;
		setName(document.getName());
	}
	
	
	
}
My DataObjectBean is like:
public class DataObjectBean extends FlowElementBean implements IDataObjectBean{
	
	private boolean collection;
	private IItemDefinitionBean itemSubject;
	private String dataState;
	private DocumentOffice document;

	
	public DataObjectBean(){
		this(IdGenerator.createUniqueId());
	}
	
	public DataObjectBean(String id){
		super(id);
	}

	
	// just getters and setters below...

}

DocumentOfficeInstatiationHandler:
public class DocumentOfficeInstatiationHandler implements IWidgetInstantiationHandler<DocumentOfficeWidget>{

		
		
		@Override
		public DocumentOfficeWidget instantiate() {
			DocumentOfficeWidget documentOfficeWidget = new DocumentOfficeWidget();
			return documentOfficeWidget;
		}
		
		@Override
		public void setDataProvider(Object dataProvider) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void setEditorModel(IHasEditor model) {

		}

}

DocumentOfficeWidget I created in the same way like ExtensionWidget etc.
I can add my POJO (instance of OfficeDocument), bu after I save the project, a cannot load it. Every projectinstance with DataObject cannot be loaded. What did I do wrong, or what is to do more ?
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

Vincent Zurczak
Hi,

I must confess I am a little bit lost.
Which version of Petals ESB and which components are you using? Or are you working with Petals DSB?
« Petals M.D. »
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

acichon89
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

Vincent Zurczak
Thanks for the precision.
I am not working on this project, but I guess someone will reply soon after.
« Petals M.D. »
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

gcrosmarie
Hello,

Sorry for the delay, but the PetalsBPM team was on vacation last week.

Your classes seems right but you can ensure they are by using the maven gwt plugin.
When running mvn gwt:run, instantiate one of your enhanced DataObjects on the drawing panel. If you do not get any error in the third tab of the gwt console (the one named index FF), it means they are OK.

If the previous did not cause any error, the problem must come from the serialization/deserialization of the produced DataObjectBean. In this case you should get an error stack trace in your shell when saving/opening a project (while running gwt:run).
Please post the error stack trace if you succeed at getting one.

Maybe your .webeditor directory contains files with errors.
You should delete the {your.home.directory}/.webeditor directory before testing again in order to be sure no corrupted file is present.

NB : if you want to import/export your diagrams from/to BPMN 2.0 xml and not just save/open them, you will have some more work to do.
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

acichon89
I am sorry, but I cannot use gwt:run commend.

All I can paste is error:

com.ebmwebsourcing.petalsbpm.business.domain.bpmn2.to.standard.infrastructure.DefinitionsBean' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer. For security purposes, this type will not be deserialized.
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

gcrosmarie
What do you mean by "I cannot use gwt:run commend" ?
Does the GWT console start ? Do you succeed at getting PetalsBPM in your navigator ?


Concerning the error you get about DefinitionsBean :
We use GWT RPC for the client/server communication. This imply that all the GWT objects used by these services must implement either java.io.Serializable or com.google.gwt.user.client.rpc.IsSerializable.
(https://developers.google.com/web-toolkit/doc/1.6/DevGuideServerCommunication#DevGuideSerializableTypes)

On the trunk version of PetalsBPM DefintionsBean does implement Serializable. Maybe you have modified its type hierarchy.
I tried to remove this inheritance and I got a pop up window with an error when I launched the site from the GWT console.
(the error was : Deffered bindign failed for IProjectService...)
So maybe it is the error you encounter ?
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

acichon89
I cannot use gwt:run, because the Jetty server are in conflict with my tomcat server.


Forget about that previous error. I added some changes to DefinitionBean:

[code]
public class DefinitionsBean implements Serializable, IDefinitionsBean {
   
    public static final String DEFAULT_TNS = "http://com.ebmwebsourcing.petalsbpm/model";
    public static final String DEFAUTL_ExpressionLanguage = "http://www.w3.org/1999/XPath";
    public static final String DEFAULT_TypeLanguage = "http://www.w3.org/2001/XMLSchema";

        private String targetNamespace;
        private String expressionLanguage;
        private String typeLanguage;
        private String id;
        private String exporter;
        private String exporterVersion;
       
       
        private List<IImportBean> imports;
        (...)
        private List<AttributeExtension> attributeExtensions;
       
        //MY POJO ADDED:
        private DocumentOffice documentOffice;

        private String name;
        private HashMap<String,INamespaceDeclaration> importNsDeclarations;
       
        protected DefinitionsBean(){
               
                imports = new ArrayList<IImportBean>();
                (...)
                eventDefinitions = new ArrayList<IEventDefinitionBean>();
               
                //MY POJO ADDED:
                documentOffice = new DocumentOffice();
               
                (...)
        }

        (...) //JUST GETTERS, SETTERS :

        @Override
        public DocumentOffice getDocumentOffice() {
                return documentOffice;
        }

        @Override
        public void setDocumentOffice(DocumentOffice documentOffice) {
                this.documentOffice = documentOffice;
        }

        @Override
        public void addDocumentOffice(DocumentOffice documentOffice) {
                this.documentOffice = documentOffice;
               
        }

        @Override
        public void removeDocumentOffice(DocumentOffice documentOffice) {
                this.documentOffice = new DocumentOffice();
        }


       
       

}
[/code]

but after that every try to load projectinstance causes endless loading bar...
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

gcrosmarie
I tested something similar to your use case : I added a dummy POJO in the DefinitionsBean the way you did.

[code]

//the POJO
public class Pojo implements Serializable {

        private String name;
       
        public Pojo() {
                super();
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }
       
}

*******************************************

//I add the POJO in the constructor
protected DefinitionsBean(){
                imports = new ArrayList<IImportBean>();
                (...)
               
               pojo = new Pojo();
                pojo.setName("pojoName");
               
                (...)
}

[code]

I was able to save and open the project without any error. Perhaps it is because my POJO is very simple. But theorically, the save/open feature should work for any GWT serializable object.

Could you please check that a file is correclty generated when you save your project ?
It should be stored in {your.home}/.webeditor/data/projects and be named int@XX.xml

If it contains all the info from your DocumentOffice object, then the error might come from a loading problem.

Did you modify the DefaultParticipantEditorModel to add a widget for your POJO ?
If you did, you should try to comment your changes and test to save/open again. If commenting this code solves the problem, then error must come from the EditorModel or one of the associated classes (Template, Binder...)

If you did not modify the EditorModel, the error might have many different explainations and I need more info to solve your problem. If you cannot use the GWT development mode, maybe you can find some stack traces in the tomcat logs or use Firebug to determine if the fail is due to an incorrect service call.
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

acichon89
yes, int@XX.xml is generated correctly.

Did your POJO's name also was saved and you could read them after project was loaded?
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

gcrosmarie
My POJO could be instantiated, transferred to the server, serialized, deserialized and transferred back to the client with no errors : the 2 POJOs were semantically equivalent (same class and same content).

But I did not add any code for display or to use this POJO.

Moreover if your int@XX.xml file contains the info from your DocumentOffice, then there is no serialization/deserialization problem.

That is why I think the error you have might come from some code you added outside of your POJO and outside of DefinitionsBean.
Probably an EditorModel or any class you might have written which reads the content of your POJO.
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

acichon89
"
Moreover if your int@XX.xml file contains the info from your DocumentOffice, then there is no serialization/deserialization problem."

I think this is a problem, because i don't have any info about my pojo in these file.
What to do?
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

gcrosmarie
I made a little test with the serialization library we use (xstream) and I found that if an Object field of a class is null, this field is not serialized at all.
So maybe you add a null POJO in your DefinitionsBean at some point of the process.
You can check it by debugging your application (how-to).

But if your POJO is not null it might be a bug in the Xstream library.
You can test it directly by doing somethnig like this :

[code]

...
import com.thoughtworks.xstream.XStream;

public class PlopTest {

        @Test
        public void test() {
                XStream xstream = new XStream();
                String  s = xstream.toXML(new DocumentOffice());
                System.out.println(s);

                System.out.println();

                DefinitionsBean defs = new DefinitionsBean("id");
                s = xstream.toXML(new DocumentOffice());
                System.out.println(s);
        }
       
}

[code]
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

acichon89
In reply to this post by acichon89
Hi,
I'm still getting weird error... I changed my strategy - I want to added List reference to DataObjectBean. I did everything in the same way as if List<AttributeExtension> in BaseElementBean (super-super class of DataObjectBean).

After compilation I create simple process and after adding dataObject to my process, it goes to top-left corner and I cannot move it.

screen.png

I can save this weird project and in the xml file I got:
<dataObjects>
<com.ebmwebsourcing.petalsbpm.business.domain.bpmn2.to.standard.process.data.DataObjectBean>
                  <documentation></documentation>
                  <id>_1349174525672id59</id>
                  <objectExtensions/>
                  <attributeExtensions/>
                  <name></name>
                  <process class="com.ebmwebsourcing.petalsbpm.business.domain.bpmn2.to.standard.process.ProcessBean" reference="../../.."/>
                  <collection>false</collection>
                  <documentOffices/>
</com.ebmwebsourcing.petalsbpm.business.domain.bpmn2.to.standard.process.data.DataObjectBean>
</dataObjects>

but I cannot load this project anymore...
Here are my java classes:
bpmn_java.zip
Reply | Threaded
Open this post in threaded view
|

Re: Adding POJO property to DataObject

gcrosmarie
Hello,

The error shown in your screen shot mean sthat you got a runtime exception at the instantiation of the DataObject.
I took a good look in the classes you sent me and they seem ok.

I must confess I do not see where the error come from. Maybe you could use gwt:debug or gwt:run with a different port (How to change port) in order not to conflict with your other server(s) and provide me with some more info about the exception that was thrown.

The xml file you get is interesting. It means that the DataObjectBean is instantiated correctly : it simply has no DocumentOffice object in its list. This means that the error most likely comes from the widget or the instantiationHandler.

I think you cannot load the project because you encounter the same error that you get at the instantiation of the data object.