Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/19/08 23:47:49 (8 months ago)
Author:
bmckown
Message:

complex_obs branch: Added ability to override handlers via Spring. Added methods to update and purge ComplexData from the file system. Added support for multiple mime types in ImageHandler based on file name. Added temporary files complexObsList.jsp and complexObsForm.jsp

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/test/api/org/openmrs/test/api/ComplexObsTest.java

    r4239 r4265  
    1818import java.io.IOException; 
    1919import java.util.Date; 
     20import java.util.HashSet; 
    2021import java.util.List; 
     22import java.util.Set; 
    2123 
    2224import javax.imageio.ImageIO; 
     
    2729import org.openmrs.api.context.Context; 
    2830import org.openmrs.obs.ComplexData; 
     31import org.openmrs.obs.handler.ImageHandler; 
    2932import org.openmrs.test.BaseContextSensitiveTest; 
    3033 
     
    3538 
    3639        protected static final String INITIAL_OBS_XML = "org/openmrs/test/api/include/ObsServiceTest-initial.xml"; 
     40        private String MIME = "png"; 
    3741 
    3842        @Override 
     
    113117                 */ 
    114118                // ComplexData cobs = new ComplexData("McKowsayPost01.jpg", img); 
    115                 ComplexData cdat = new ComplexData("hoss-collab.jpg", img); 
     119                ComplexData cdat = new ComplexData("hoss-collab", img); 
    116120                obs.setComplexData(cdat); 
    117121                /* TODO: At this point the obs.isComplex() will return false. This is 
     
    147151                 */ 
    148152                Integer obsId = obs.getObsId(); 
    149                 Obs cobs = Context.getObsService().getComplexObs(obsId); 
     153                Obs cobs = Context.getObsService().getComplexObs(obsId, null); 
     154                 
     155                System.out.println(((ConceptComplex)cobs.getConcept()).getHandler()); 
    150156 
    151157                /* 
     
    153159                 * Assert that the ComplexData is not null. 
    154160                 */ 
     161                try { 
     162                        Set<String> mimes = new HashSet<String>(); 
     163                        for (String mt : ImageIO.getWriterFormatNames()) { 
     164                                mimes.add(mt); 
     165                        } 
     166                         
     167                         
     168                        File outputfile = new File("/home/bmckown/Desktop/test", 
     169                                                   cobs.getComplexData().getTitle()); 
     170                        String[] titles = cobs.getComplexData().getTitle().split("\\."); 
     171                        String mime = titles.length < 2 ? titles[0] : titles[titles.length-1]; 
     172                        String MIME = mimes.contains(mime) ? mime : ImageHandler.MIME; 
     173                                         
     174                        BufferedImage outImg = (BufferedImage)cobs.getComplexData().getData(); 
     175                        ImageIO.write(outImg, MIME, outputfile); 
     176                } catch (IOException e2) { 
     177                        System.out.println(e2); 
     178                } 
     179                assertNotNull(cobs.getComplexData()); 
     180 
     181                /* 
     182                 * Step 9. Print the valueComplex and the valueAsString 
     183                 */ 
     184                System.out.println("Obs.getValueComplex(): " + cobs.getValueComplex()); 
     185                System.out.println("Obs.getValueAsString(): " 
     186                        + cobs.getValueAsString(null)); 
     187 
     188                /* 
     189                 * Step 10. Print the list of registered ComplexObsHandlers. 
     190                 */ 
     191                List handlers = Context.getObsService().getComplexObsHandlers(); 
     192                for (int i=0; i<handlers.size(); i++)  { 
     193                        System.out.println(handlers.get(i).getClass()); 
     194                } 
     195 
     196        } 
     197 
     198        /** 
     199         * Test to get an existing complex obs. TODO: This should have an in memory 
     200         * database. 
     201         *         
     202         * @throws Exception 
     203         */ 
     204        public void disable_testGetExistingComplexObs() throws Exception { 
     205 
     206                Integer obsId = Integer.valueOf(28879); 
     207                Obs cobs = Context.getObsService().getComplexObs(obsId, null); 
     208                 
    155209                try { 
    156210                        File outputfile = new File("/home/bmckown/Desktop/test", 
    157211                                                   cobs.getComplexData().getTitle()); 
    158                         ImageIO.write(img, "jpg", outputfile); 
     212                        BufferedImage outImg = (BufferedImage)cobs.getComplexData().getData(); 
     213                        ImageIO.write(outImg, MIME, outputfile); 
    159214                } catch (IOException e2) { 
    160215                        System.out.println(e2); 
     
    162217                assertNotNull(cobs.getComplexData()); 
    163218 
    164                 /* 
    165                  * Step 9. Print the valueComplex and the valueAsString 
    166                  */ 
    167219                System.out.println("Obs.getValueComplex(): " + cobs.getValueComplex()); 
    168220                System.out.println("Obs.getValueAsString(): " 
    169221                        + cobs.getValueAsString(null)); 
    170222 
    171                 /* 
    172                  * Step 10. Print the list of registered ComplexObsHandlers. 
    173                  */ 
    174                 List handlers = Context.getObsService().getComplexObsHandlers(); 
    175                 for (int i=0; i<handlers.size(); i++)  { 
    176                         System.out.println(handlers.get(i).getClass()); 
    177                 } 
    178  
    179         } 
    180  
     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         
     236        /** 
     237         * Test to get an existing complex obs. TODO: This should have an in memory 
     238         * database. 
     239         *         
     240         * @throws Exception 
     241         */ 
     242        public void disabled_testPurgeExistingComplexObs() throws Exception { 
     243 
     244                Integer obsId = Integer.valueOf(28879); 
     245                Obs cobs = Context.getObsService().getComplexObs(obsId, null); 
     246 
     247                assertNotNull(cobs.getComplexData()); 
     248 
     249                System.out.println("Obs.getValueComplex(): " + cobs.getValueComplex()); 
     250                System.out.println("Obs.getValueAsString(): " 
     251                        + cobs.getValueAsString(null)); 
     252 
     253                 
     254                File file = org.openmrs.obs.handler.ImageHandler.getComplexDataFile(cobs); 
     255                assertTrue(file.exists()); 
     256                 
     257                Context.getObsService().deleteObs(cobs); 
     258                 
     259                assertFalse(file.exists()); 
     260                 
     261                 
     262        } 
     263         
     264         
    181265}