It's all about the answers!

Ask a question

Upload some javascript on the project area with api java or rest


Emiliano Iannetti (385) | asked Aug 24, 5:41 a.m.
edited Aug 24, 5:42 a.m.

Hi everyone I'm back here, I've been around forums and internet in general for days but I'm not finding ideas for what I need.

In short we would like to load some javascript for some condition or setValue, in the projectArea, so not on the tickets as attachments. I hypothesized two ways, the first was to modify the process configuration source, I saw that there is the possibility of doing so but I'm having some difficulties and then I still haven't been able to understand where the js that should be modified are "physically" located . The other solution is to simulate an upload of the resource instead of another, as in the screen: https://ibb.co/9TMbXXf
As you can see from the highlighting, I would like to perform this uplaod from a certain path, but I have not found any ideas to be able to do it. Actually, this operation can only be done on the "client" side and not on the web so I doubt whether it can be done, but it seems impossible to me that it is not provided through any api, whether it is java or rest. Thanks a lot in advance to everyone and sorry for the many questions.

Accepted answer


permanent link
Emiliano Iannetti (385) | answered Aug 26, 1:41 p.m.
edited Aug 26, 1:44 p.m.

I always found on this forum, a user who created them completely from 0 and encountered problems, but taking advantage of what he had posted here:

I managed to understand that I was doing everything right but I was missing saving the IProcessAttachment for that one failed to see the "loaded" changes.
Thanks so much everyone.
Here is the source if it can be useful to someone else:
FileOutputStream file = om.saveJSSource(projectAreaParent, a, icm, ipA.getName(), monitor);
InputStream inputstream = new FileInputStream("Path"+ ipA.getName());
IContent contenuto = icm.storeContent("application/octet-stream", IContent.ENCODING_UTF_8, LineDelimiter.LINE_DELIMITER_NONE, 
                          inputstream, null, monitor); 
ipA = (IProcessAttachment) processItemService.getMutableCopy(ipA);
ipA.setContent(contenuto);
processItemService.save(ipA, monitor);
projectAreaParent.addAttachment(ipA);
processItemService.save(projectAreaParent, monitor);
    
As you can see I execute the outputStream only because to do the tests I made the modification manually.

Ralph Schoon selected this answer as the correct answer

2 other answers



permanent link
Ralph Schoon (59.0k23642) | answered Aug 24, 7:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 The upload is stored in the database:



As far as i am aware the Plain Java Client Libraries provide access to the Content manager: ITeamRepository.contentManager(). You can use that to upload information you can also use it to access the process XML that you could theoretically manipulate. I am sure this is not a supported mode of operation.


Comments
Emiliano Iannetti commented Aug 24, 8:49 a.m.

Yes I had read something about ITeamRepository.contentManager() and I had also read that it was not supported and that the modification is not always effective anyway, because it leads to further modifications often. I have to study what you are talking about well, but do you have any examples? I could not find much unfortunately. Anyway thanks, I will update the post if I find something.


Ralph Schoon commented Aug 24, 10:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Emiliano Iannetti commented Aug 26, 12:52 p.m.
Good evening Ralph sorry I'm late.
So I'll update you, I read the post after I answer.

As for the "download" of the files I found the solution. The problem, however, now I have it for loading it, if I look for a method to load something I understand that you have to use the "storeContent" method, only this has various signatures, some of which are "deprecated" and others not deprecated there is not a shred of description on what it wants, for example there is one that wants String, String and more, the others have come to replace them, but the two strings I have no idea what they can represent, I don't know if you have any ideas or other .... I still continue to try to understand to find a solution. 


permanent link
Emiliano Iannetti (385) | answered Aug 26, 1:00 p.m.
I have found a solution.
The method that does what we need is in the IProjectArea class and is called getAttachments ()
Practically this method returns everything that is present on the DB as an attachment then the js the gif and so on. Then, of course, by returning a list you can "manage" as you wish, in fact, by only serving those with the .js extension, I did the following management:

[code]
IProcessAttachmentHandle[] listJs = projectAreaParent.getAttachments();

for (IProcessAttachmentHandle ipAh : listJs) {
  IProcessAttachment ipA = (IProcessAttachment)teamRepository.itemManager().fetchCompleteItem(ipAh, IItemManager.DEFAULT, null);
  if(ipA.getName().contains(".js")){
[/code]
Then of course it is only an example to give the idea, but for those who run into the same "problem" it can be useful.
Now the problem I have, however, in the upload of the same modified file, at the moment I am modifying it by hand, but then it will be modified on the code side with everything necessary, but I cannot show the attachment changes that I set :( I am going crazy....
I will update you if I find a solution to this too, in the meantime thanks to everyone.

Your answer


Register or to post your answer.