-
1. Re: create POJO Model jar using REST API
bigcar Dec 4, 2012 11:28 AM (in response to richard916)Not sure if you can do that using REST api.
Here is what I did using WebDav:
Sardine sardine = SardineFactory.begin("", ""); byte[] jar = IOUtils.toByteArray(new FileInputStream("./workspace/my_model.jar")); sardine.put("http://localhost:38080/guvnor-5.3.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/webdav/packages/mypackage/my_model.jar", jar); System.out.println("Jar added ..."); -
2. Re: create POJO Model jar using REST API
richard916 Dec 4, 2012 9:52 PM (in response to bigcar)I finally firebug the post request when creating a pojo model with guvnor, and simulate that.
besides,your code seems to add the jar file attachment,not create a model asset.
-
3. Re: create POJO Model jar using REST API
bigcar Dec 5, 2012 9:34 AM (in response to richard916)Yes. from WebDav perspective, uploading a jar file is essentially creating a pojo model asset.
-
4. Re: create POJO Model jar using REST API
ravinandan Dec 25, 2012 11:06 PM (in response to bigcar)Hello Tao,
I'm able to upload my jar using sardine after which I'm able to see an entry in Model list in Guvnor.
But the facts are not getting reflected in the rules editor.
If I upload the same jar manually via Guvnor upload Model jar, I'm able to see the Facts.
Is there any way to trigger refresh or save functionality after I put the jar from sardine?
Thanks!
Edit:
I'm able to upload the JAR via REST using the below code
byte[] jar = Javac.getJar("FactUpload", classInfos);
WebClient client = WebClient.create("http://localhost:8080");
MultivaluedMap<String, String> map = new MetadataMap<String, String>();
List<String> slugHeader = new ArrayList<String>();
slugHeader.add("FactModel.jar");
List<String> authHeader = new ArrayList<String>();
authHeader.add("Basic " + new String(Base64.encodeBase64("admin:admin" .getBytes())));
List<String> contentTypeHeader = new ArrayList<String>();
contentTypeHeader.add("application/octet-stream");
map.put("slug", slugHeader);
map.put("Authorization", authHeader);
map.put("Content-Type", contentTypeHeader);
client.headers(map);
client.path("/drools-guvnor-webapp/rest/packages/PLATFORMS/assets/");
Response response = client.post(jar);
But still the same issue exists!
-
5. Re: create POJO Model jar using REST API
ravinandan Dec 26, 2012 5:28 AM (in response to ravinandan)Resolved the issue by adding the below block of code before repository save in createAssetFromBinary method from PackageResource class
ContentHandler handler = ContentManager.getHandler( ai.getFormat() );
if ( handler instanceof ICanHasAttachment ) {
((ICanHasAttachment) handler).onAttachmentAdded( ai );
}
Copied it from attachFileToAsset method from FileManagerService class.
-
6. Re: create POJO Model jar using REST API
neoner2002 Dec 29, 2012 4:05 AM (in response to ravinandan)Hi
I'm trying to create an automated way to assign a model to a created package, but I have the same problem.
The model is apparently assigned to the package via REST or WebDAV, but if a want to create a rule, it says that there is no model, (manually uploaded jar works)
Your solution seems to be to change the surce code of Guvnor and compile it, isn't it?. Is it difficult to do?, Are there other solutions?
Regards,
Felipe.