Upload some javascript on the project area with api java or rest
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
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:
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.
2 other answers
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
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);
IProcessAttachment ipA = (IProcessAttachment)teamRepository.itemManager().fetchCompleteItem(ipAh, IItemManager.DEFAULT, null);
if(ipA.getName().contains(".js")){
[/code]
[/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.