AttachmentResource.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.monitor.sdk.transaction;

  21. import org.openspcoop2.monitor.sdk.constants.ContentResourceNames;
  22. import org.openspcoop2.monitor.sdk.constants.MessageType;

  23. import java.util.ArrayList;
  24. import java.util.LinkedList;
  25. import java.util.List;

  26. /**
  27.  * AttachmentResource
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class AttachmentResource extends AbstractContentResource {

  34.     private LinkedList<Attachment> attachments = null;
  35.    
  36.     public AttachmentResource(MessageType messageType) {
  37.         super(messageType);
  38.         this.attachments = new LinkedList<Attachment>();
  39.     }
  40.    
  41.     public void addAttachment(Attachment attach) {
  42.         this.attachments.add(attach);
  43.     }
  44.    
  45.     public void addAttachment(Attachment attach, int position) {
  46.         this.attachments.add(position, attach);
  47.     }
  48.    
  49.     public void setValue(LinkedList<Attachment> attachs) {
  50.         this.attachments = attachs;
  51.     }
  52.    
  53.    

  54.     public List<Attachment> getAttachments() {
  55.         return this.attachments;
  56.     }
  57.    
  58.     public Attachment getAttachmentByPosition(int index) {
  59.         return this.attachments.get(index);
  60.     }
  61.    
  62.     public Attachment getAttachmentByContentId(String cid) {
  63.         for (int i=0; i<this.attachments.size(); i++) {
  64.             if (cid.equals(this.attachments.get(i).getContentID()))
  65.                     return this.attachments.get(i);
  66.         }
  67.         return null;
  68.     }
  69.    
  70.     @Override
  71.     public String getName() {
  72.         if (this.isRequest())
  73.             return ContentResourceNames.REQ_ATTACHMENT;
  74.         else
  75.             return ContentResourceNames.RES_ATTACHMENT;
  76.     }
  77.    
  78.     @Override
  79.     public LinkedList<Attachment> getValue() {
  80.         return this.attachments;
  81.     }
  82.    
  83.     public List<String> cids(){
  84.         List<String> list = new ArrayList<>();
  85.         for (int i=0; i<this.attachments.size(); i++) {
  86.             list.add(this.attachments.get(i).getContentID());
  87.         }
  88.         return list;
  89.     }
  90. }