View Javadoc

1   /*$Id: SiapImageFetchDescription.java,v 1.2 2004/11/29 20:00:56 clq2 Exp $
2    * Created on 15-Nov-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.applications.apps;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  
16  import java.io.IOException;
17  import java.io.InputStream;
18  import java.io.OutputStream;
19  import java.net.URISyntaxException;
20  import java.net.URL;
21  import java.sql.Timestamp;
22  import java.text.DateFormat;
23  import java.text.SimpleDateFormat;
24  import java.util.ArrayList;
25  import java.util.Date;
26  import java.util.Iterator;
27  import java.util.List;
28  
29  import org.astrogrid.applications.AbstractApplication;
30  import org.astrogrid.applications.Application;
31  import org.astrogrid.applications.CeaException;
32  import org.astrogrid.applications.DefaultIDs;
33  import org.astrogrid.applications.Status;
34  import org.astrogrid.applications.AbstractApplication.IDs;
35  import org.astrogrid.applications.apps.CatApplicationDescription.CatApplication;
36  import org.astrogrid.applications.apps.CatApplicationDescription.StreamParameterAdapter;
37  import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
38  import org.astrogrid.applications.beans.v1.parameters.types.ParameterTypes;
39  import org.astrogrid.applications.description.ApplicationInterface;
40  import org.astrogrid.applications.description.ParameterDescription;
41  import org.astrogrid.applications.description.base.AbstractApplicationDescription;
42  import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
43  import org.astrogrid.applications.description.base.BaseApplicationInterface;
44  import org.astrogrid.applications.description.base.BaseParameterDescription;
45  import org.astrogrid.applications.description.exception.ParameterDescriptionNotFoundException;
46  import org.astrogrid.applications.parameter.ParameterAdapter;
47  import org.astrogrid.applications.parameter.protocol.ExternalValue;
48  import org.astrogrid.applications.parameter.protocol.ProtocolLibrary;
49  import org.astrogrid.community.User;
50  import org.astrogrid.component.descriptor.ComponentDescriptor;
51  import org.astrogrid.io.Piper;
52  import org.astrogrid.store.Ivorn;
53  import org.astrogrid.store.VoSpaceClient;
54  import org.astrogrid.util.TimeStamp;
55  import org.astrogrid.workflow.beans.v1.Tool;
56  
57  import uk.ac.starlink.table.ColumnInfo;
58  import uk.ac.starlink.table.RowSequence;
59  import uk.ac.starlink.table.StarTable;
60  import uk.ac.starlink.table.StarTableFactory;
61  import uk.ac.starlink.util.DataSource;
62  
63  import junit.framework.Test;
64  
65  /*** @todo implementation is a bit tatty - could do with refactoring a bunch of these applications,
66   * improving the internal design, and extracting generally useful helper classes.
67   * for astrogrid 2 - this code is ugly, but works for now.
68   * @author Noel Winstanley nw@jb.man.ac.uk 15-Nov-2004
69   *
70   */
71  public class SiapImageFetchDescription extends AbstractApplicationDescription
72          implements ComponentDescriptor {
73      static final String URLS = "urls";
74      static final String IVORNS="ivorns";
75      static final String BASEIVORN = "baseIvorn";
76      static final String TABLE = "table";
77      /***
78       * Commons Logger for this class
79       */
80      private static final Log logger = LogFactory
81              .getLog(SiapImageFetchDescription.class);
82  
83      /*** Construct a new SiapImageFetchDescription
84       * @param env
85       */
86      public SiapImageFetchDescription(ApplicationDescriptionEnvironment env) {
87          super(env);
88          this.setMetaData();
89      }
90      
91      /*** set up metadata for this instance */
92      private final void setMetaData() {
93          setName("org.astrogrid.localhost/siap-image-fetch");
94          BaseParameterDescription src = new BaseParameterDescription();
95          src.setName(TABLE);
96          src.setDisplayName("Image List");
97          src.setDisplayDescription("VOTable containing URIs of images");
98          src.setType(ParameterTypes.VOTABLE);
99          this.addParameterDescription(src);
100         
101         BaseParameterDescription baseDir = new BaseParameterDescription();
102         baseDir.setName(BASEIVORN);
103         baseDir.setDisplayName("Save To");
104         baseDir.setDisplayDescription("Location of a directory in myspace in which to save fetched images");
105         baseDir.setType(ParameterTypes.ANYURI);
106         baseDir.setSubType("ivo://..");
107         this.addParameterDescription(baseDir);
108         
109         BaseParameterDescription urls = new BaseParameterDescription();
110         urls.setName(URLS);
111         urls.setDisplayName("URLs of files to fetch");
112         urls.setDisplayDescription("List of  the urls  of the fetched files");
113         urls.setType(ParameterTypes.TEXT);
114         this.addParameterDescription(urls);
115         
116         BaseParameterDescription ivorns = new BaseParameterDescription();
117         ivorns.setName(IVORNS);
118         ivorns.setDisplayName("Ivorns of fetched Files");
119         ivorns.setDisplayDescription("List of  the ivorns of the fetched files");
120         ivorns.setType(ParameterTypes.TEXT);
121         this.addParameterDescription(ivorns);
122         
123         BaseApplicationInterface intf = new BaseApplicationInterface("basic",this);
124         try {
125             intf.addInputParameter(src.getName());
126             intf.addInputParameter(baseDir.getName());
127             intf.addOutputParameter(urls.getName());
128             intf.addOutputParameter(ivorns.getName());
129         } catch (ParameterDescriptionNotFoundException e) {
130             logger.fatal("Programming error");
131             throw new RuntimeException("Programming Error",e);
132         }
133         this.addInterface(intf);
134     }
135 
136     /***
137      * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
138      */
139     public String getDescription() {
140         return "Application that parses results from a siap query and saves to myspace";
141     }
142 
143     /***
144      * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
145      */
146     public Test getInstallationTest() {
147         return null;
148     }
149 
150     /***
151      * @see org.astrogrid.applications.description.ApplicationDescription#initializeApplication(java.lang.String, org.astrogrid.community.User, org.astrogrid.workflow.beans.v1.Tool)
152      */
153     public Application initializeApplication(String callerAssignedID,
154             User user, Tool tool) throws Exception {
155         String newID = env.getIdGen().getNewID();
156         final DefaultIDs ids = new DefaultIDs(callerAssignedID,newID,user);
157         ApplicationInterface iface = this.getInterface(tool.getInterface());
158         return new SiapImageFetchApplication(ids,tool,iface,env.getProtocolLib());
159     }
160     
161     public static class ParameterAdapterDataSource extends DataSource {
162         public ParameterAdapterDataSource(CatApplicationDescription.StreamParameterAdapter p) {
163             this.p = p;
164         }
165         CatApplicationDescription.StreamParameterAdapter p;
166         protected InputStream getRawInputStream() throws IOException {
167             
168             try {
169                 return (InputStream)p.process();
170             } catch (CeaException e) {
171              throw new IOException(e.getMessage());
172             }
173         }
174     }
175     
176 
177 }
178 
179 
180 /* 
181 $Log: SiapImageFetchDescription.java,v $
182 Revision 1.2  2004/11/29 20:00:56  clq2
183 nww-itn07-684
184 
185 Revision 1.1.2.2  2004/11/24 00:14:58  nw
186 factored the application class out of the descripiton - makes for
187 more manageable code.
188 
189 Revision 1.1.2.1  2004/11/22 14:06:13  nw
190 start on implementing these.
191  
192 */