AttachmentsProcessingMode.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.message;

  21. import java.io.File;

  22. import org.openspcoop2.message.exception.MessageException;

  23. /**
  24.  * AttachmentsProcessingMode
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class AttachmentsProcessingMode {

  31.     public static AttachmentsProcessingMode getFileCacheProcessingMode(File fileRepository,String fileThreshold) throws MessageException{
  32.         return new AttachmentsProcessingMode(true,fileRepository,fileThreshold);
  33.     }
  34.     public static AttachmentsProcessingMode getFileCacheProcessingMode(String fileRepository,String fileThreshold) throws MessageException{
  35.         return new AttachmentsProcessingMode(true,new File(fileRepository),fileThreshold);
  36.     }
  37.     public static AttachmentsProcessingMode getMemoryCacheProcessingMode() {
  38.         return new AttachmentsProcessingMode(false);
  39.     }
  40.    
  41.     private boolean fileCacheEnable;
  42.     private File fileRepository;
  43.     private String fileThreshold;
  44.    
  45.     private AttachmentsProcessingMode(boolean fileCacheEnable) {
  46.         this.fileCacheEnable = fileCacheEnable;
  47.     }
  48.     private AttachmentsProcessingMode(boolean fileCacheEnable,File fileRepository,String fileThreshold) throws MessageException{
  49.         if(fileCacheEnable){
  50.             if(fileRepository==null){
  51.                 throw new MessageException("Repository directory for attachments undefined (required with fileCache enabled)");
  52.             }
  53.             if(fileRepository.exists()==false){
  54.                 throw new MessageException("Repository directory for attachments ["+fileRepository.getAbsolutePath()+"] not exists (required with fileCache enabled)");
  55.             }
  56.             if(fileRepository.canRead()==false){
  57.                 throw new MessageException("Repository directory for attachments ["+fileRepository.getAbsolutePath()+"] cannot read (required with fileCache enabled)");
  58.             }
  59.             if(fileRepository.canWrite()==false){
  60.                 throw new MessageException("Repository directory for attachments ["+fileRepository.getAbsolutePath()+"] cannot write (required with fileCache enabled)");
  61.             }
  62.             if(fileThreshold==null){
  63.                 throw new MessageException("Threshold for attachments undefined (required with fileCache enabled)");
  64.             }
  65.         }
  66.         this.fileCacheEnable = fileCacheEnable;
  67.         this.fileRepository = fileRepository;
  68.         this.fileThreshold = fileThreshold;
  69.     }
  70.    
  71.     public boolean isFileCacheEnable() {
  72.         return this.fileCacheEnable;
  73.     }
  74.     public void setFileCacheEnable(boolean fileCacheEnable) {
  75.         this.fileCacheEnable = fileCacheEnable;
  76.     }
  77.     public File getFileRepository() {
  78.         return this.fileRepository;
  79.     }
  80.     public void setFileRepository(File fileRepository) {
  81.         this.fileRepository = fileRepository;
  82.     }
  83.     public String getFileThreshold() {
  84.         return this.fileThreshold;
  85.     }
  86.     public void setFileThreshold(String fileThreshold) {
  87.         this.fileThreshold = fileThreshold;
  88.     }
  89.    
  90. }