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.server.web.rest;
020
021import org.restlet.data.Status;
022import org.restlet.representation.OutputRepresentation;
023import org.restlet.resource.Get;
024import org.restlet.resource.ServerResource;
025import pt.ua.dicoogle.server.web.rest.elements.FileDownloadUtils;
026
027/**
028 *
029 * @author psytek
030 *
031 * WARNING: This will return *any* file on the host! The best way to correct
032 * this will be to change the generated XML in order to produce SOPInstanceUID,
033 * and let them act as a tag for the file. This will imply a new query every
034 * time we want to download a new file, but that's probably fine...
035 *
036 */
037public class RestWADOResource extends ServerResource {
038    
039    @Get
040    public OutputRepresentation represent() {
041        String studyUID = getRequest().getResourceRef().getQueryAsForm().getValues("studyUID");
042        String seriesUID = getRequest().getResourceRef().getQueryAsForm().getValues("seriesUID");
043        String objectUID = getRequest().getResourceRef().getQueryAsForm().getValues("objectUID");
044        String requestType = getRequest().getResourceRef().getQueryAsForm().getValues("requestType");
045        String contentType = getRequest().getResourceRef().getQueryAsForm().getValues("contentType");
046
047        
048
049        setStatus( Status.SUCCESS_OK );
050        //lets make sure that all the REQUIRED (all caps, according to standard :)) are here
051        if(objectUID==null || objectUID.isEmpty())
052        {
053            setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
054            //result = generateErrorRepresentation("Please enter a UID", "400");
055            //400 means bad request
056        }
057
058        //the standard also requires that the request type is present and == WADO
059        if(requestType == null || !requestType.equals("WADO")){
060                setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
061        }
062        
063        return FileDownloadUtils.gerFileRepresentation(objectUID);
064    }
065}