Setting user id of an attachment

Discuss problems installing or using TrackStudio.

Setting user id of an attachment

Postby grahamb » Mon Sep 21, 2015 4:54 pm

We have a script that generates a task of a new category from an existing task, and it moves file attachments from the original task to the new task, however since the upgrade from 4.0.19 to 5.0.5, the user associated with the task seems to randomly change. The random user is then added to the participants list of the new task and gets mailouts for each attachment and any future changes on the new task,

We are still using the older .bsh scripts, this is an excerpt fro the script that handles the moving of the attachments:

Code: Select all
/* Move any attachments */
if (task.hasAttachments()) {
  int notCopied = 0;
  Map ma = task.getAttachsTaskOrMessage();
  Set s=ma.entrySet();
  Iterator it=s.iterator();
  while (it.hasNext()) {
    Map.Entry m = (Map.Entry)it.next();
    SecuredTaskAttachmentBean key = (SecuredTaskAttachmentBean)m.getKey();
    boolean value = (boolean)m.getValue(); // True for Task attachment, False for Message attachment
    int maxSize = Integer.parseInt(UDFManager.getTaskUDFValue(sc, configTaskId, "maxAttachmentCopySize"));
    if (key.getSize() < maxSize*1024*1024) {

      ByteArrayInputStream data = new ByteArrayInputStream(AttachmentManager.getAttachment(sc, key.getId()));
      AttachmentManager.createAttachment( sc,
                                          newTaskId,
                                          null,
                                          key.getUserId(),
                                          key.getName(),
                                          key.getDescription(),
                                          data);
      AttachmentManager.deleteAttachment( sc, key.getId());
    } else {
      notCopied++;
    }
  }

  if (notCopied > 0) {
    newMsgDesc = "There is one large file";
    if (notCopied > 1) {
      newMsgDesc = "There are " + Integer.toString(notCopied) + " large files";
    }
    newMsgDesc = newMsgDesc + " attached to the original report (#" + MyTaskNumber + ").";
    MessageManager.createMessage(sc, newTaskId, newNoteId, newMsgDesc,
                               null, null, null, null, null, null, null, false);
  }
}


Even if the attachment user isn't randomly set, it seems to default to the user running the script, I'd like it to be the original user that uploaded the attachment. How can I do that?
Regards,

Graham
grahamb
 
Posts: 14
Joined: Wed Jan 28, 2009 7:16 pm

Re: Setting user id of an attachment

Postby dpochtarev » Wed Sep 23, 2015 1:05 pm

You should create attachments for every user, who uploaded files.
Code: Select all
TriggerManager.getAttachment().createAttachment(
                taskId,  /* task id*/
                null,      /*message id*/
                att.getUserId(),    /* attachment owner id*/
                atts
);

You can get attachment owner id from SecuredAttachmentBean.
dpochtarev
 
Posts: 282
Joined: Wed Aug 22, 2012 4:35 pm

Re: Setting user id of an attachment

Postby grahamb » Thu Sep 24, 2015 3:23 pm

We are using the user id from the attachment though. key is the SecuredTaskAttachmentBean instance, and we're passing key.getUserId() into createAttachment().

Your example uses TriggerManager to create the attachment, whereas we're using an instance of SecuredAttachmentAdapterManager (AttachmentManager). Are we doing that wrong?
Regards,

Graham
grahamb
 
Posts: 14
Joined: Wed Jan 28, 2009 7:16 pm

Re: Setting user id of an attachment

Postby Petr » Thu Sep 24, 2015 9:06 pm

Hello. The user is taken from SessionContext sc in your scripts, for this reason you have such problem.
So you can create the SessionContext for each user who upload the file or you need to upload the file directly through kernel by AttachmentManager how the Dmitry shows you.
Thanks.
Стань Java программистом с www.job4j.ru
Petr
 
Posts: 2929
Joined: Wed Aug 12, 2009 4:38 pm

Re: Setting user id of an attachment

Postby grahamb » Thu Jan 28, 2016 7:19 pm

Thank you for the info, I've now got this working, belatedly.
Regards,

Graham
grahamb
 
Posts: 14
Joined: Wed Jan 28, 2009 7:16 pm


Return to TrackStudio Support

Who is online

Users browsing this forum: No registered users and 10 guests

cron