Changeset 4289
- Timestamp:
- 05/21/08 01:41:31 (8 months ago)
- Files:
-
- openmrs/branches/complex-obs/src/api/org/openmrs/ConceptComplex.java (modified) (4 diffs)
- openmrs/branches/complex-obs/src/api/org/openmrs/obs/ComplexData.java (modified) (5 diffs)
- openmrs/branches/complex-obs/src/api/org/openmrs/obs/ComplexObsHandler.java (modified) (1 diff)
- openmrs/branches/complex-obs/src/api/org/openmrs/obs/handler/ImageHandler.java (modified) (8 diffs)
- openmrs/branches/complex-obs/src/api/org/openmrs/obs/handler/TextHandler.java (modified) (3 diffs)
- openmrs/branches/complex-obs/src/web/org/openmrs/web/controller/observation/handler/WebImageHandler.java (modified) (1 diff)
- openmrs/branches/complex-obs/test/api/org/openmrs/test/api/ComplexObsTest.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/complex-obs/src/api/org/openmrs/ConceptComplex.java
r4265 r4289 17 17 18 18 /** 19 * Child class of Concept that has a Co nceptComplexHandler associated with the19 * Child class of Concept that has a ComplexObsHandler associated with the 20 20 * Concept. 21 21 */ … … 34 34 } 35 35 36 /** 37 * Constructor from Concept. 38 * 39 * @param c 40 */ 36 41 public ConceptComplex(Concept c) { 37 42 this.setAnswers(c.getAnswers(true)); … … 80 85 81 86 /** 82 * Set the ConceptComplexHandler 87 * Set the ConceptComplexHandler. This should be the ComplexObsHandler key 83 88 * 84 89 * @param handler … … 89 94 90 95 /** 91 * Get the ConceptComplexHandler associated with this ConceptComlex96 * Get the key to the ComplexObsHandler associated with this ConceptComplex. 92 97 * 93 98 * @return openmrs/branches/complex-obs/src/api/org/openmrs/obs/ComplexData.java
r4166 r4289 14 14 package org.openmrs.obs; 15 15 16 import org.openmrs.ConceptComplex;17 import org.openmrs.Obs;18 16 19 17 /** 20 18 * ComplexObs is a transient Object that extends Obs but is not itself persisted 21 * in the database. It has a data Object and a title. 19 * in the database. It has a data Object and a title. Alternatively, it can have 20 * a byte array instead of an Object. 22 21 * 23 22 */ … … 27 26 28 27 private Object data; 28 private byte[] bytes; 29 29 private String title; 30 31 public static enum Type { 32 OBJECT, BYTE 33 } 34 35 private Type type; 30 36 31 37 /** … … 38 44 setTitle(title); 39 45 setData(data); 46 this.type = Type.OBJECT; 40 47 } 41 48 42 49 /** 43 * Set the data Object. 50 * Alternative constructor for using byte array. <br/>Example use: <br/>File 51 * file = new File("test.txt"); <br/>byte[] bytes = 52 * OpenmrsUtil.getFileAsBytes(file); <br/>ComplexData data = new 53 * ComplexData("test name", bytes); 44 54 * 45 * @param data 55 * @param title 56 * @param bytes 46 57 */ 47 public void setData(Object data) { 48 this.data = data; 49 } 50 51 /** 52 * Get the data Object 53 * 54 * @return 55 */ 56 public Object getData() { 57 return this.data; 58 public ComplexData(String title, byte[] bytes) { 59 setBytes(bytes); 60 setTitle(title); 61 this.type = Type.BYTE; 58 62 } 59 63 … … 63 67 * @param title 64 68 */ 65 p ublicvoid setTitle(String title) {69 private void setTitle(String title) { 66 70 this.title = title; 67 71 } … … 75 79 return this.title; 76 80 } 81 82 /** 83 * Set the data Object. 84 * 85 * @param data 86 */ 87 private void setData(Object data) { 88 if (this.type == Type.OBJECT) 89 this.data = data; 90 } 91 92 /** 93 * Get the data Object. If this was initialized with a byte array, the 94 * output may not be reliable. TODO: Should this even try to return the byte 95 * array? 96 * 97 * @return 98 */ 99 public Object getData() { 100 if (this.type != Type.OBJECT) { 101 return getBytes(); 102 } 103 return this.data; 104 } 105 106 /** 107 * Set the byte array. This is alternative to {@link #setData(Object)} 108 * 109 * @param bytes 110 */ 111 private void setBytes(byte[] bytes) { 112 this.bytes = bytes; 113 } 114 115 /** 116 * Get the byte array. If this was initialized with an Object, returns 117 * Object.toString.getBytes(). <br/>Example use: <br/> File file = new 118 * File("text"); <br/> FileOutputStream fout = new FileOutputStream(file); 119 * <br/> fout.write(complexData.getBytes()); <br/> 120 * 121 * @return 122 */ 123 public byte[] getBytes() { 124 if (this.type != Type.BYTE && null != data) { 125 return data.toString().getBytes(); 126 } 127 return this.bytes; 128 } 129 130 /** 131 * Returns the ComplexData.Type that this ComplexData was initialized. If 132 * initialized with a byte array, returns ComplexData.Type.BYTE. If 133 * initialized with an Object, returns ComplexData.Type.OBJECT. 134 * 135 * @return ComplexData.Type.OBJECT or ComplexData.Type.BYTE 136 */ 137 public ComplexData.Type getType() { 138 return this.type; 139 } 140 141 /** 142 * Convenience method for getting the className of the data. Same as 143 * this.getData().getClass().getName() except that it safely returns the 144 * String "null" if this.data is null. 145 * 146 * TODO: This method is not used anywhere. Should it be deleted? 147 * 148 * @return 149 */ 150 public String dataClass() { 151 if (null != data) { 152 return this.data.getClass().getName(); 153 } 154 return "null"; 155 } 77 156 } openmrs/branches/complex-obs/src/api/org/openmrs/obs/ComplexObsHandler.java
r4265 r4289 21 21 * Interface for handling complex obs. Implementing classes are responsible for 22 22 * the storage and retrieval of ComplexData associated with an Obs that is 23 * complex (where Obs.isComplex() returns true.23 * complex - where Obs.isComplex() returns true. 24 24 */ 25 25 public interface ComplexObsHandler { openmrs/branches/complex-obs/src/api/org/openmrs/obs/handler/ImageHandler.java
r4265 r4289 34 34 35 35 /** 36 * Handler for storing basic images for complex obs to the file system. 36 * Handler for storing basic images for complex obs to the file system. The 37 * image mime type used is taken from the image name. if the .* image name 38 * suffix matches {@link javax.imageio.ImageIO#getWriterFormatNames()} then that 39 * mime type will be used to save the image. Otherwise the default mime type is 40 * ImageHandler.MIME (currently "jpg"). 41 * 42 * Images are stored in the location specified by the global property: 43 * "obs.complex_obs_dir" 37 44 */ 38 45 public class ImageHandler implements ComplexObsHandler { … … 42 49 SimpleDateFormat longfmt; 43 50 // default mime type 44 public static final String MIME = " bmp";51 public static final String MIME = "jpg"; 45 52 private Set<String> mimes; 46 53 … … 87 94 String[] titles = t.split("\\."); 88 95 System.out.println(titles.length); 89 String mime = (titles.length < 2) ? titles[0] : titles[titles.length-1]; 96 String mime = (titles.length < 2) ? titles[0] 97 : titles[titles.length - 1]; 90 98 String MIME = mimes.contains(mime) ? mime : ImageHandler.MIME; 91 99 String title = obs.getComplexData().getTitle().replace("." + MIME, ""); … … 102 110 } else { 103 111 outputfile = new File(dir, title + "." + MIME); 104 // outputfile = new File(dir, title);112 // outputfile = new File(dir, title); 105 113 } 106 114 int i = 0; … … 112 120 // Remove the mime type from the filename. 113 121 tmp = new String(outputfile.getAbsolutePath() 114 .replace("." + MIME, ""));122 .replace("." + MIME, "")); 115 123 outputfile = null; 116 124 // Append two-digit count number to the filename. … … 120 128 nf.format(Integer.valueOf(++i))); 121 129 // Append the mime type to the filename. 122 // outputfile = new File(filename);130 // outputfile = new File(filename); 123 131 outputfile = new File(filename + "." + MIME); 124 132 } … … 164 172 File file = ImageHandler.getComplexDataFile(obs); 165 173 if (file.exists() && file.delete()) { 166 //obs.setComplexData(null);174 obs.setComplexData(null); 167 175 // obs.setValueComplex(null); 168 176 return true; … … 173 181 } 174 182 183 /** 184 * @see org.openmrs.obs.ComplexObsHandler#getComplexData(org.openmrs.Obs, java.lang.String) 185 */ 175 186 public ComplexData getComplexData(Obs obs, String view) { 176 187 return this.getObs(obs).getComplexData(); openmrs/branches/complex-obs/src/api/org/openmrs/obs/handler/TextHandler.java
r4265 r4289 14 14 package org.openmrs.obs.handler; 15 15 16 import java.awt.image.BufferedImage;17 16 import java.io.File; 17 import java.io.FileOutputStream; 18 18 import java.io.IOException; 19 import java.text.NumberFormat; 19 20 import java.text.SimpleDateFormat; 20 21 import java.util.Date; 21 22 import javax.imageio.ImageIO;23 22 24 23 import org.apache.commons.logging.Log; … … 31 30 32 31 /** 33 * TODO: This is not a text handler yet. It is a copy of the ImageHandler. 34 * Change it to handle text files. 32 * Handler for storing files for complex obs to the file system. 35 33 * 36 * Handler for storing basic images for complex obs to the file system. 34 * Files are stored in the location specified by the global property: 35 * "obs.complex_obs_dir" 37 36 */ 38 37 public class TextHandler implements ComplexObsHandler { 39 38 40 39 public Log log = LogFactory.getLog(this.getClass()); 41 40 private NumberFormat nf; 41 SimpleDateFormat longfmt; 42 43 /** 44 * Constructor initializes formats for alternative file names to protect 45 * from unintentionally overwriting existing files. 46 */ 47 public TextHandler() { 48 nf = NumberFormat.getInstance(); 49 nf.setMaximumFractionDigits(0); 50 nf.setMinimumIntegerDigits(2); 51 longfmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 52 } 53 54 /** 55 * Currently supports all views and is the same as {@link #getObs(Obs)} 56 * 57 * @see org.openmrs.obs.ComplexObsHandler#getObs(org.openmrs.Obs, 58 * java.lang.String) 59 */ 60 public Obs getObs(Obs obs, String view) { 61 return this.getObs(obs); 62 } 63 42 64 /** 43 65 * @see org.openmrs.obs.ComplexDataHandler#saveObs() 44 66 */ 45 67 public Obs saveObs(Obs obs) { 46 BufferedImage img = (BufferedImage) obs.getComplexData() 47 .getData(); 48 String title = obs.getComplexData().getTitle(); 49 SimpleDateFormat longfmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 50 String now = longfmt.format(new Date()); 51 52 53 File dir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(Context.getAdministrationService().getGlobalProperty("obs.complex_obs_dir")); 68 // Get the buffered file from the ComplexData. 69 ComplexData data = obs.getComplexData(); 70 if (data == null) { 71 log.error("Cannot save complex data where obsId=" + obs.getObsId() 72 + " because its ComplexData is null."); 73 return obs; 74 } 75 76 // Get the title and remove the mime type. 77 String t = obs.getComplexData().getTitle(); 78 String[] titles = t.split("\\."); 79 System.out.println(titles.length); 80 String mime = (titles.length < 2) ? titles[0] 81 : titles[titles.length - 1]; 82 String MIME = (null != mime && !"".equals(mime)) ? mime : "raw"; 83 String title = obs.getComplexData().getTitle().replace("." + MIME, ""); 84 85 File dir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(Context.getAdministrationService() 86 .getGlobalProperty("obs.complex_obs_dir")); 54 87 File outputfile = null; 55 88 56 // Write the imageto the file system.89 // Write the file to the file system. 57 90 try { 58 91 if (null == title) { 92 String now = longfmt.format(new Date()); 59 93 outputfile = new File(dir, now); 60 94 } else { 61 outputfile = new File(dir, title); 95 outputfile = new File(dir, title + "." + MIME); 96 // outputfile = new File(dir, title); 62 97 } 63 if (outputfile.exists()) { 64 File altfile = new File(outputfile.getAbsolutePath() + now); 65 ImageIO.write(img, "jpg", altfile); 98 int i = 0; 99 String tmp = null; 100 // If the Obs does not exist, but the File does, append a two-digit 101 // count number to the filename and save it. 102 while (obs.getObsId() == null && outputfile.exists() && i < 100) { 103 tmp = null; 104 // Remove the mime type from the filename. 105 tmp = new String(outputfile.getAbsolutePath() 106 .replace("." + MIME, "")); 107 outputfile = null; 108 // Append two-digit count number to the filename. 109 String filename = (i < 1) ? tmp + "_" 110 + nf.format(Integer.valueOf(++i)) 111 : tmp.replace(nf.format(Integer.valueOf(i)), 112 nf.format(Integer.valueOf(++i))); 113 // Append the mime type to the filename. 114 // outputfile = new File(filename); 115 outputfile = new File(filename + "." + MIME); 66 116 } 67 else {68 ImageIO.write(img, "jpg",outputfile);69 }117 // Write the file to the file system. 118 FileOutputStream fout = new FileOutputStream(outputfile); 119 fout.write(data.getBytes()); 70 120 } catch (IOException ioe) { 71 121 log.error("Trying to write complex obs to the file system. ", ioe); 72 122 } 73 123 74 124 // Set the Title and URI for the valueComplex 75 obs.setValueComplex( "JPG Image |" + outputfile.getAbsolutePath());125 obs.setValueComplex(MIME + " file |" + outputfile.getName()); 76 126 77 // TODO: Will the ComplexData instance remain in memory or be gc'd?127 // Remove the ComplexData from the Obs 78 128 obs.setComplexData(null); 79 129 … … 81 131 } 82 132 133 /** 134 * @see org.openmrs.obs.ComplexObsHandler#getObs(org.openmrs.Obs) 135 */ 83 136 public Obs getObs(Obs obs) { 84 File file = new File(obs.getValueComplex()); 85 BufferedImage img = null; 137 File file = TextHandler.getComplexDataFile(obs); 138 System.out.println("getObs: " + obs.getValueComplex()); 139 System.out.println("getObs: " + file.getAbsolutePath()); 140 ComplexData complexData = null; 86 141 try { 87 img = ImageIO.read(file); 142 complexData = new ComplexData(file.getName(), 143 OpenmrsUtil.getFileAsBytes(file)); 88 144 } catch (IOException e) { 89 // System.out.println(e); 145 System.out.println("Trying to read file: " + file.getAbsolutePath() 146 + " " + e); 90 147 } 91 148 92 ComplexData complexData = new ComplexData(file.getName(), img);93 94 149 obs.setComplexData(complexData); 95 150 96 151 return obs; 97 152 } 98 153 154 /** 155 * @see org.openmrs.obs.ComplexObsHandler#purgeComplexData(org.openmrs.Obs) 156 */ 99 157 public boolean purgeComplexData(Obs obs) { 158 File file = TextHandler.getComplexDataFile(obs); 159 if (file.exists() && file.delete()) { 160 obs.setComplexData(null); 161 // obs.setValueComplex(null); 162 return true; 163 } 164 log.debug("Could not delete complex data object for obsId=" 165 + obs.getObsId() + " located at " + file.getAbsolutePath()); 100 166 return false; 101 167 } 102 168 103 169 /** 104 * TODO: Implement for context 170 * @see org.openmrs.obs.ComplexObsHandler#getComplexData(org.openmrs.Obs, 171 * java.lang.String) 105 172 */ 106 public Obs saveObs(Obs obs, String context) { 107 return this.saveObs(obs); 108 } 109 110 /** 111 * TODO: IMplement for context. 112 * @see org.openmrs.obs.ComplexObsHandler#getObs(org.openmrs.Obs, java.lang.String) 113 */ 114 public Obs getObs(Obs obs, String context) { 115 return this.getObs(obs); 173 public ComplexData getComplexData(Obs obs, String view) { 174 return this.getObs(obs).getComplexData(); 116 175 } 117 176 118 177 /** 119 * @see org.openmrs.obs.ComplexObsHandler#getComplexData(org.openmrs.Obs, java.lang.String) 120 */ 121 public ComplexData getComplexData(Obs obs, String view) { 122 // TODO Auto-generated method stub 123 return null; 124 } 125 178 * Convenience method to create and return a file for the stored 179 * ComplexData.data Object 180 * 181 * @param obs 182 * @return 183 */ 184 public static File getComplexDataFile(Obs obs) { 185 String[] names = obs.getValueComplex().split("\\|"); 186 String filename = names.length < 2 ? names[0] : names[names.length - 1]; 187 File dir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(Context.getAdministrationService() 188 .getGlobalProperty("obs.complex_obs_dir")); 189 return new File(dir, filename); 190 } 191 126 192 } openmrs/branches/complex-obs/src/web/org/openmrs/web/controller/observation/handler/WebImageHandler.java
r4265 r4289 16 16 import org.openmrs.Obs; 17 17 import org.openmrs.obs.ComplexData; 18 import org.openmrs.obs.ComplexObsHandler;19 18 import org.openmrs.obs.handler.ImageHandler; 20 19 import org.openmrs.web.WebConstants; 21 20 22 21 /** 23 * 22 * Extends functionality of ImageHandler for web specific views. 24 23 */ 25 public class WebImageHandler extends ImageHandler { //implements ComplexObsHandler {24 public class WebImageHandler extends ImageHandler { 26 25 27 26 /** 28 * 27 * Default Constructor 29 28 */ 30 public WebImageHandler() { 31 29 public WebImageHandler() { 32 30 } 33 31 34 public Obs getObs(Obs obs, String view) { 35 Obs wobs = super.getObs(obs); 36 // TODO: Do something here... 37 return wobs; 32 /** 33 * Returns the ComplexData for an Obs depending on the view. Currently 34 * supported views are listed in WebConstants.*_VIEW. Currently the only 35 * implemented view is WebConstants.HYPERLINK_VIEW, which is a lightweight 36 * alternative to returning the ComplexData from the parent class since this 37 * does not require access to the service layer. 38 * 39 * @see org.openmrs.obs.handler.ImageHandler#getComplexData(org.openmrs.Obs, 40 * java.lang.String) 41 */ 42 public ComplexData getComplexData(Obs obs, String view) { 43 44 if (WebConstants.HYPERLINK_VIEW.equals(view)) { 45 String hyperlink = "/complexObsServlet?obsId=" + obs.getObsId(); 46 return new ComplexData(obs.getValueAsString(null), hyperlink); 47 } else if (WebConstants.HTML_VIEW.equals(view)) { 48 // TODO: Do something for html view. 49 } else if (WebConstants.HTML_THUMNAIL_VIEW.equals(view)) { 50 // TODO: Probably return a hyperlink view with extra parameters for 51 // width & height. 52 } 53 return super.getObs(obs, view).getComplexData(); 38 54 } 39 40 public ComplexData getComplexData(Obs obs, String view) {41 Obs cobs = super.getObs(obs, view);42 ComplexData data = cobs.getComplexData();43 if (WebConstants.HTML_VIEW.equals(view)) {44 //TODO: Do something for html view.45 }46 else if (WebConstants.HYPERLINK_VIEW.equals(view)) {47 data.setData(this.getHyperlink(obs));48 }49 return data;50 }51 52 private String getHyperlink(Obs obs) {53 String[] valComplex = obs.getValueComplex().split("\\|");54 String path = (valComplex.length < 2) ? valComplex[0] : valComplex[valComplex.length-1];55 56 //TODO: return a 'real' hyperlink57 return path;58 }59 60 55 61 62 56 } openmrs/branches/complex-obs/test/api/org/openmrs/test/api/ComplexObsTest.java
r4265 r4289 16 16 import java.awt.image.BufferedImage; 17 17 import java.io.File; 18 import java.io.FileOutputStream; 18 19 import java.io.IOException; 20 import java.nio.Buffer; 21 import java.nio.ByteBuffer; 19 22 import java.util.Date; 20 23 import java.util.HashSet; … … 31 34 import org.openmrs.obs.handler.ImageHandler; 32 35 import org.openmrs.test.BaseContextSensitiveTest; 36 import org.openmrs.util.OpenmrsUtil; 33 37 34 38 /** … … 49 53 return false; 50 54 } 51 52 public void testGetRegisteredHandlers( ) throws Exception {53 /* 54 * Step 10.Print the list of registered ComplexObsHandlers.55 56 public void testGetRegisteredHandlers() throws Exception { 57 /* 58 * Print the list of registered ComplexObsHandlers. 55 59 */ 56 60 List handlers = Context.getObsService().getComplexObsHandlers(); 57 for (int i =0; i<handlers.size(); i++){61 for (int i = 0; i < handlers.size(); i++) { 58 62 System.out.println(handlers.get(i).getClass()); 59 63 } … … 72 76 * @throws Exception 73 77 */ 74 public void testSaveGetComplexObs() throws Exception {78 public void disable_testSaveGetImageComplexObs() throws Exception { 75 79 76 80 /* … … 119 123 ComplexData cdat = new ComplexData("hoss-collab", img); 120 124 obs.setComplexData(cdat); 121 /* TODO: At this point the obs.isComplex() will return false. This is 125 /* 126 * TODO: At this point the obs.isComplex() will return false. This is 122 127 * because we do not want the Obs pojo to know anyting of the 123 128 * ComplexObsHandler, and it is the responsibility of the … … 125 130 * considered complex if obs.getValueComplex() != null. 126 131 */ 127 128 /* 129 * Step 4. Persist the Complex Obs. 132 133 /* 134 * Step 4. Persist the Complex Obs. 130 135 */ 131 136 Context.getObsService().createObs((Obs) obs); 132 /*TODO: Starting here the obs.isComplex() will return true. 137 /* 138 * TODO: Starting here the obs.isComplex() will return true. 133 139 */ 134 140 // Save a complex obs to the database for testing. 135 //setComplete(); 136 141 // setComplete(); 137 142 /* 138 143 * Step 5. Assert that the Complex Obs now has an obsId. … … 145 150 */ 146 151 System.out.println(obs.getValueComplex()); 147 // assertNotNull(obs.getValueComplex());152 // assertNotNull(obs.getValueComplex()); 148 153 149 154 /* … … 152 157 Integer obsId = obs.getObsId(); 153 158 Obs cobs = Context.getObsService().getComplexObs(obsId, null); 154 155 System.out.println(((ConceptComplex) cobs.getConcept()).getHandler());156 157 /* 158 * Step 8. Save the ComplexData to the file system. 159 * Assert that theComplexData is not null.159 160 System.out.println(((ConceptComplex) cobs.getConcept()).getHandler()); 161 162 /* 163 * Step 8. Save the ComplexData to the file system. Assert that the 164 * ComplexData is not null. 160 165 */ 161 166 try { … … 164 169 mimes.add(mt); 165 170 } 166 167 171 168 172 File outputfile = new File("/home/bmckown/Desktop/test", 169 173 cobs.getComplexData().getTitle()); 170 174 String[] titles = cobs.getComplexData().getTitle().split("\\."); 171 String mime = titles.length < 2 ? titles[0] : titles[titles.length-1]; 175 String mime = titles.length < 2 ? titles[0] 176 : titles[titles.length - 1]; 172 177 String MIME = mimes.contains(mime) ? mime : ImageHandler.MIME; 173 174 BufferedImage outImg = (BufferedImage)cobs.getComplexData().getData(); 178 179 BufferedImage outImg = (BufferedImage) cobs.getComplexData() 180 .getData(); 181 System.out.println("Class.getCanononicalName(): " 182 + outImg.getClass().getCanonicalName()); 183 System.out.println("Class.getName(): " 184 + outImg.getClass().getName()); 175 185 ImageIO.write(outImg, MIME, outputfile); 176 186 } catch (IOException e2) { … … 190 200 */ 191 201 List handlers = Context.getObsService().getComplexObsHandlers(); 192 for (int i =0; i<handlers.size(); i++){202 for (int i = 0; i < handlers.size(); i++) { 193 203 System.out.println(handlers.get(i).getClass()); 194 204 } … … 199 209 * Test to get an existing complex obs. TODO: This should have an in memory 200 210 * database. 201 * 211 * 202 212 * @throws Exception 203 213 */ 204 public void disable_testGetExistingComplexObs() throws Exception { 205 214 public void disable_testGetExistingImageComplexObs() throws Exception { 215 216 // Set obsId to the obsId of an existing complex obs. 206 217 Integer obsId = Integer.valueOf(28879); 218 207 219 Obs cobs = Context.getObsService().getComplexObs(obsId, null); 208 220 // Make sure the obs exists. 221 assertNotNull(cobs); 222 assertNotNull(cobs.getObsId()); 223 // If this is not a complex obs, then fail. 224 assertTrue(cobs.isComplex()); 225 209 226 try { 210 227 File outputfile = new File("/home/bmckown/Desktop/test", 211 228 cobs.getComplexData().getTitle()); 212 BufferedImage outImg = (BufferedImage)cobs.getComplexData().getData(); 213 ImageIO.write(outImg, MIME, outputfile); 229 BufferedImage outImg = (BufferedImage) cobs.getComplexData() 230 .getData(); 231 ImageIO.write(outImg, this.MIME, outputfile); 214 232 } catch (IOException e2) { 215 233 System.out.println(e2); 216 234 } 235 assertNotNull(cobs.getComplexData().getData()); 236 } 237 238 /** 239 * Test to purge an existing complex obs. Warning: This will indeed remove 240 * an existing file from the file system. 241 * 242 * @throws Exception 243 */ 244 public void disabled_testPurgeExistingComplexObs() throws Exception { 245 246 // Set obsId to the obsId of an existing complex obs. 247 Integer obsId = Integer.valueOf(28879); 248 249 Obs cobs = Context.getObsService().getComplexObs(obsId, null); 250 // Make sure the obs exists. 251 assertNotNull(cobs); 252 assertNotNull(cobs.getObsId()); 253 // If this is not a complex obs, then fail. 254 assertTrue(cobs.isComplex()); 255 217 256 assertNotNull(cobs.getComplexData()); 218 257 … … 221 260 + cobs.getValueAsString(null)); 222 261 223 /* 224 String[] mimetypes = ImageIO.getWriterMIMETypes(); 225 for (int i=0; i<mimetypes.length; i++) { 226 System.out.println(mimetypes[i]); 227 } 228 System.out.println(); 229 String[] readtypes = ImageIO.getWriterFormatNames(); 230 for (int i=0; i<readtypes.length; i++) { 231 System.out.println(readtypes[i]); 232 } 233 */ 234 } 235 262 // Cheat to find out if the file exists. 263 // TODO: Should ObsService provide a convenience method for this? 264 File file = org.openmrs.obs.handler.ImageHandler.getComplexDataFile(cobs); 265 assertTrue(file.exists()); 266 267 // Delete the file. 268 Context.getObsService().deleteObs(cobs); 269 270 // Assert that the file was deleted. 271 assertFalse(file.exists()); 272 } 273 236 274 /** 237 * Test to get an existingcomplex obs. TODO: This should have an in memory275 * Test to save and get a complex obs. TODO: This should have an in memory 238 276 * database.