2

I like to creata package, POJO model asset with my java code ,using REST API. Creating package with Apache HttpClient is fine, but I have problems creating a model asset, now I create "other assets, documentation" by putting the following

<entry xml:base="http://localhost:9080/repository/packages/package1/assets">
<title>testAsset1</title>
<summary>desc1</summary>
</entry>"

how do i make it a model asset? I tried to add a format tag but failed.

thanks

Richard
  • 153
  • 1
  • 14

2 Answers2

0

I think you can use the REST API to upload content. Send PUT request to URL something like

http://{server}/guvnor/rest/packages/{package name}/assets/{asset name}/source

Where asset name is the name of model assets. Not sure about what the mime type should be, a quick google search gave 'application/java-archive'

See the Guvnor REST API docs for more information.

kaskelotti
  • 4,709
  • 9
  • 45
  • 72
  • thank you. Finally I made it to upload the jar file.but i find that the asset i create using rest api is not model ,it's "other assets,documentation".I put something like " testAsset1 desc1 " ,how do i make it a model? – Richard Nov 22 '12 at 02:11
  • What does the metadata part of that asset say? I just checked one of my models (uploaded via web UI) and it has format of jar. Rules have a format of 'brl'. Metadata should be available with the URL except for the '/source' at the end. According to the docs, you should be able to update the metadata with PUT request to the same URL. – kaskelotti Nov 22 '12 at 09:28
  • yes,model asset has metadata of jar,and the file I upload through java has format of txt.What version do you use? I use 5.3.0 and im not able to get metadata with url directly,I can get asset with url like "xxx/packages/package1/assets/myAsset",this shows binaryLink,metadata,refLink and so on. I wish I can update metadata with put request but I find the docs not clear with this and I don't know what to do . Thanks – Richard Nov 23 '12 at 01:39
  • The docs are not very clear on this. I assume that it means that you have to use multipart/form-data in order to PUT a file as an attachment in order to set the metadata. I noticed that there are Maven plugins and Ant tasks for mass upload to Guvnor. It might be worth checking those. I attempted earlier to upload a simple drl file via REST without success so far (it does upload, but it's not valid for Guvnor), so I left it for now. – kaskelotti Nov 23 '12 at 06:49
  • I have checked that the asset metadata is not in consistency with the attachment, which means if you create an document asset, uploading a jar file doesnot change the asset metadata to 'jar'. Maybe your invald drl file is due to this. Still working on this... -_- – Richard Nov 23 '12 at 07:10
0

You need to add below code to createAssetFromBinary method in PackageResource.java

ContentHandler handler = ContentManager.getHandler( ai.getFormat() );
   if ( handler instanceof ICanHasAttachment ) {
       ((ICanHasAttachment) handler).onAttachmentAdded( ai );
   }

You can also explore using standalone editor to create model & facts which will be stored directly in guvnor repository.