001/** 002 * Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/ 003 * 004 * This file is part of Dicoogle/dicoogle. 005 * 006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Dicoogle/dicoogle is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Dicoogle. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package pt.ua.dicoogle.rGUI.server.controllers; 020 021import java.rmi.RemoteException; 022import java.util.ArrayList; 023import java.util.concurrent.Semaphore; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028import pt.ua.dicoogle.core.ServerSettings; 029import pt.ua.dicoogle.rGUI.interfaces.controllers.IAccessList; 030 031/** 032 * Controller of Access List to DICOM services 033 * 034 * @author Samuel Campos <samuelcampos@ua.pt> 035 */ 036@Deprecated 037public class AccessList implements IAccessList { 038 private ServerSettings settings; 039 040 private String AETitle; 041 private ArrayList<String> list; 042 private boolean permitAllAETitles; 043 044 private static Semaphore sem = new Semaphore(1, true); 045 private static AccessList instance = null; 046 047 public static synchronized AccessList getInstance() 048 { 049 try { 050 sem.acquire(); 051 if (instance == null) { 052 instance = new AccessList(); 053 } 054 sem.release(); 055 } catch (InterruptedException ex) { 056 LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex); 057 } 058 return instance; 059 } 060 061 private AccessList(){ 062 settings = ServerSettings.getInstance(); 063 064 loadSettings(); 065 } 066 067 /** 068 * Load settings from ServerSettings 069 */ 070 public void loadSettings(){ 071 AETitle = settings.getAE(); 072 permitAllAETitles = settings.getPermitAllAETitles(); 073 074 list = new ArrayList<String>(); 075 076 String[] CAET = settings.getCAET(); 077 078 if(CAET != null) 079 for(String AET : CAET) 080 list.add(AET); 081 } 082 083 /** 084 * Save the settings related to Access List 085 * 086 * not write the settings in XML 087 */ 088 public void saveSettings(){ 089 settings.setAE(AETitle); 090 settings.setPermitAllAETitles(permitAllAETitles); 091 092 String[] CAET = new String[list.size()]; 093 CAET = list.toArray(CAET); 094 095 settings.setCAET(CAET); 096 } 097 098 /** 099 * 100 * @return true - if there are unsaved settings ( != ServerSettings) 101 * false - not 102 */ 103 public boolean unsavedSettings(){ 104 if(!AETitle.equals(settings.getAE()) || settings.getPermitAllAETitles() != permitAllAETitles) 105 return true; 106 else{ 107 ArrayList<String> tmp = new ArrayList<String>(); 108 109 String[] CAET = settings.getCAET(); 110 111 if(CAET != null) 112 for(String AET : CAET) 113 tmp.add(AET); 114 else if(list.size() != 0) 115 return true; 116 117 if (!tmp.equals(list)) 118 return true; 119 } 120 121 return false; 122 } 123 124 @Override 125 public String getAETitle() throws RemoteException { 126 return AETitle; 127 } 128 129 @Override 130 public void setAETitle(String AETitle) throws RemoteException { 131 if(AETitle == null) 132 this.AETitle = " "; 133 else 134 this.AETitle = AETitle; 135 } 136 137 @Override 138 public ArrayList<String> getAccessList() throws RemoteException { 139 140 list.trimToSize(); //trim size of ArrayList 141 142 return list; 143 } 144 145 @Override 146 public boolean addToAccessList(String AETitle) throws RemoteException { 147 if(!list.contains(AETitle)) 148 return list.add(AETitle); 149 else 150 return false; 151 } 152 153 @Override 154 public boolean removeFromAccessList(String AETitle) throws RemoteException { 155 156 return list.remove(AETitle); 157 } 158 159 @Override 160 public void setPermitAllAETitles(boolean value) throws RemoteException { 161 permitAllAETitles = value; 162 } 163 164 @Override 165 public boolean getPermitAllAETitles() throws RemoteException { 166 return permitAllAETitles; 167 } 168 169}