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.io.File;
022import java.rmi.RemoteException;
023import java.util.ArrayList;
024import java.util.Iterator;
025import java.util.concurrent.Semaphore;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028import org.slf4j.Logger;
029import org.slf4j.LoggerFactory;
030import pt.ua.dicoogle.sdk.datastructs.MoveDestination;
031import pt.ua.dicoogle.core.ServerSettings;
032import pt.ua.dicoogle.rGUI.interfaces.controllers.IDicomSend;
033import pt.ua.dicoogle.server.queryretrieve.CallDCMSend;
034
035/**
036 *
037 * @author Samuel Campos <samuelcampos@ua.pt>
038 */
039@Deprecated
040public class DicomSend implements IDicomSend {
041
042    private static Semaphore sem = new Semaphore(1, true);
043    private static DicomSend instance = null;
044
045    public static synchronized DicomSend getInstance() {
046        try {
047            sem.acquire();
048            if (instance == null) {
049                instance = new DicomSend();
050            }
051            sem.release();
052        } catch (InterruptedException ex) {
053            LoggerFactory.getLogger(DicomSend.class).error(ex.getMessage(), ex);
054        }
055        return instance;
056    }
057
058    private DicomSend() {
059    }
060
061    @Override
062    public ArrayList<MoveDestination> getDestinations() throws RemoteException {
063        return ServerSettings.getInstance().getMoves();
064    }
065
066    @Override
067    public boolean sendFiles(MoveDestination destination, ArrayList<String> FilePaths) throws RemoteException {
068        if(destination == null || FilePaths == null || FilePaths.isEmpty())
069            return false;
070
071        /**
072         * Convert all images to an array with File list
073         */
074        ArrayList<File> fileList = new ArrayList<File>();
075
076        Iterator<String> it  = FilePaths.iterator();
077        while (it.hasNext()) 
078            fileList.add(new File(it.next()));
079        
080
081         //DebugManager.getInstance().debug("Sending files to Destination");
082         
083        /**
084         * Call DICOM Storage SCU for each image
085         */
086        //DebugManager.getInstance().debug("AETITLE to DICOM STORAGE SCU: "
087          //      + destination.getAETitle());
088
089        try {
090            CallDCMSend s = new CallDCMSend(fileList, destination.getPort(), destination.getIpAddrs(), destination.getAETitle(), null);
091        } catch (Exception ex) {
092            return false;
093        }
094
095        return true;
096    }
097}