1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.apps;
12
13 import org.astrogrid.applications.Application;
14 import org.astrogrid.applications.CeaException;
15 import org.astrogrid.applications.DefaultIDs;
16 import org.astrogrid.applications.beans.v1.parameters.types.ParameterTypes;
17 import org.astrogrid.applications.description.ApplicationInterface;
18 import org.astrogrid.applications.description.base.AbstractApplicationDescription;
19 import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
20 import org.astrogrid.applications.description.base.BaseApplicationInterface;
21 import org.astrogrid.applications.description.base.BaseParameterDescription;
22 import org.astrogrid.applications.description.exception.ParameterDescriptionNotFoundException;
23 import org.astrogrid.community.User;
24 import org.astrogrid.component.descriptor.ComponentDescriptor;
25 import org.astrogrid.workflow.beans.v1.Tool;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import uk.ac.starlink.util.DataSource;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34
35 import junit.framework.Test;
36
37 /*** @todo implementation is a bit tatty - could do with refactoring a bunch of these applications,
38 * improving the internal design, and extracting generally useful helper classes.
39 * for astrogrid 2 - this code is ugly, but works for now.
40 * @author Noel Winstanley nw@jb.man.ac.uk 15-Nov-2004
41 *
42 */
43 public class SiapImageFetchDescription extends AbstractApplicationDescription
44 implements ComponentDescriptor {
45 static final String URLS = "urls";
46 static final String IVORNS="ivorns";
47 static final String BASEIVORN = "baseIvorn";
48 static final String TABLE = "table";
49 /***
50 * Commons Logger for this class
51 */
52 private static final Log logger = LogFactory
53 .getLog(SiapImageFetchDescription.class);
54
55 /*** Construct a new SiapImageFetchDescription
56 * @param env
57 */
58 public SiapImageFetchDescription(ApplicationDescriptionEnvironment env) {
59 super(env);
60 this.setMetaData();
61 }
62
63 /*** set up metadata for this instance */
64 private final void setMetaData() {
65 StringBuffer thename = new StringBuffer(env.getAuthIDResolver().getAuthorityID());
66 thename.append("/siap-image-fetch");
67 setName(thename.toString());
68 BaseParameterDescription src = new BaseParameterDescription();
69 src.setName(TABLE);
70 src.setDisplayName("Image List");
71 src.setDisplayDescription("VOTable containing URIs of images");
72 src.setType(ParameterTypes.VOTABLE);
73 this.addParameterDescription(src);
74
75 BaseParameterDescription baseDir = new BaseParameterDescription();
76 baseDir.setName(BASEIVORN);
77 baseDir.setDisplayName("Save To");
78 baseDir.setDisplayDescription("Location of a directory in myspace in which to save fetched images");
79 baseDir.setType(ParameterTypes.ANYURI);
80 baseDir.setSubType("ivo://..");
81 this.addParameterDescription(baseDir);
82
83 BaseParameterDescription urls = new BaseParameterDescription();
84 urls.setName(URLS);
85 urls.setDisplayName("URLs of files to fetch");
86 urls.setDisplayDescription("List of the urls of the fetched files");
87 urls.setType(ParameterTypes.TEXT);
88 this.addParameterDescription(urls);
89
90 BaseParameterDescription ivorns = new BaseParameterDescription();
91 ivorns.setName(IVORNS);
92 ivorns.setDisplayName("Ivorns of fetched Files");
93 ivorns.setDisplayDescription("List of the ivorns of the fetched files");
94 ivorns.setType(ParameterTypes.TEXT);
95 this.addParameterDescription(ivorns);
96
97 BaseApplicationInterface intf = new BaseApplicationInterface("basic",this);
98 try {
99 intf.addInputParameter(src.getName());
100 intf.addInputParameter(baseDir.getName());
101 intf.addOutputParameter(urls.getName());
102 intf.addOutputParameter(ivorns.getName());
103 } catch (ParameterDescriptionNotFoundException e) {
104 logger.fatal("Programming error");
105 throw new RuntimeException("Programming Error",e);
106 }
107 this.addInterface(intf);
108 }
109
110 /***
111 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
112 */
113 public String getDescription() {
114 return "Application that parses results from a siap query and saves to myspace";
115 }
116
117 /***
118 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
119 */
120 public Test getInstallationTest() {
121 return null;
122 }
123
124 /***
125 * @see org.astrogrid.applications.description.ApplicationDescription#initializeApplication(java.lang.String, org.astrogrid.community.User, org.astrogrid.workflow.beans.v1.Tool)
126 */
127 public Application initializeApplication(String callerAssignedID,
128 User user, Tool tool) throws Exception {
129 String newID = env.getIdGen().getNewID();
130 final DefaultIDs ids = new DefaultIDs(callerAssignedID,newID,user);
131 ApplicationInterface iface = this.getInterface(tool.getInterface());
132 return new SiapImageFetchApplication(ids,tool,iface,env.getProtocolLib());
133 }
134
135 public static class ParameterAdapterDataSource extends DataSource {
136 public ParameterAdapterDataSource(CatApplicationDescription.StreamParameterAdapter p) {
137 this.p = p;
138 }
139 CatApplicationDescription.StreamParameterAdapter p;
140 protected InputStream getRawInputStream() throws IOException {
141
142 try {
143 return (InputStream)p.process();
144 } catch (CeaException e) {
145 throw new IOException(e.getMessage());
146 }
147 }
148 }
149
150
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175