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 */ 019/* 020 * To change this template, choose Tools | Templates 021 * and open the template in the editor. 022 */ 023package pt.ua.dicoogle.server.web.rest; 024 025import java.io.*; 026import java.util.ArrayList; 027import java.util.List; 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030import org.slf4j.Logger; 031import org.slf4j.LoggerFactory; 032import java.util.zip.GZIPInputStream; 033import org.restlet.data.MediaType; 034import org.restlet.representation.OutputRepresentation; 035import org.restlet.representation.Representation; 036import org.restlet.resource.Get; 037import org.restlet.resource.ServerResource; 038 039/** 040 * 041 * @author Samuel Campos <samuelcampos@ua.pt> 042 */ 043public class RestImageResource extends ServerResource { 044 045 @Get 046 public Representation represent() {/* 047 String SOPInstanceUID = getRequest().getResourceRef().getQueryAsForm().getValues("uid"); 048 if (SOPInstanceUID == null) { 049 return null; 050 } 051 052 String heightString = getRequest().getResourceRef().getQueryAsForm().getValues("height"); 053 int height = 0; 054 055 if (heightString != null) { 056 try { 057 height = Integer.valueOf(heightString); 058 } catch (NumberFormatException ex) { 059 }; 060 } 061 062 IndexEngine core = IndexEngine.getInstance(); 063 ArrayList<String> extra = new ArrayList<String>(); 064 extra.add("SOPInstanceUID"); 065 String query = "SOPInstanceUID:" + SOPInstanceUID; 066 List<SearchResult> queryResultList = core.search(query, extra); 067 if (queryResultList.size() < 1) { 068 return null;//TODO:Throw exception 069 } 070 for (SearchResult r : queryResultList) { 071 LoggerFactory.getLogger(RestDimResource.class.getName()).error(r.getOrigin()); 072 } 073 File file = new File(queryResultList.get(0).getOrigin()); 074 075 return new DynamicFileRepresentation(MediaType.IMAGE_JPEG, file, height); 076 } 077 078 public class DynamicFileRepresentation extends OutputRepresentation { 079 080 private File dicomImage; 081 private int height; 082 083 public DynamicFileRepresentation(MediaType mediaType, File dicomImage, int height) { 084 super(mediaType); 085 086 this.dicomImage = dicomImage; 087 this.height = height; 088 089 090 091 if (dicomImage.getAbsolutePath().endsWith(".gz")) 092 { 093 File temp = null; 094 try { 095 temp = File.createTempFile(dicomImage.getName(), Platform.homePath() + ".dcm"); 096 } catch (IOException ex) { 097 LoggerFactory.getLogger(RestWADOResource.class).error(ex.getMessage(), ex); 098 } 099 temp.deleteOnExit(); 100 FileOutputStream fos; 101 try { 102 fos = new FileOutputStream(temp); 103 BufferedOutputStream bos = new BufferedOutputStream(fos, 256); 104 GZIPInputStream gz = new GZIPInputStream(new BufferedInputStream(new FileInputStream(dicomImage), 256)); 105 int byte_; 106 while ((byte_ = gz.read()) != -1) 107 bos.write(byte_); 108 bos.close(); 109 gz.close(); 110 } catch (Exception ex) { 111 LoggerFactory.getLogger(RestWADOResource.class).error(ex.getMessage(), ex); 112 } 113 dicomImage = temp; 114 }*/ 115 throw new UnsupportedOperationException(); 116 } 117 118 /*@Override 119 public void write(OutputStream outputStream) throws IOException { 120 Dicom2JPEG.convertDicom2Jpeg(dicomImage, outputStream, height); 121 }*/ 122 //} 123}