1 package jalview.ws.dbsources.das.datamodel;
3 import java.text.ParseException;
4 import java.util.ArrayList;
8 import org.biodas.jdas.dassources.Capabilities;
9 import org.biodas.jdas.dassources.utils.DasTimeFormat;
10 import org.biodas.jdas.dassources.utils.RegistrySourceAdapter;
11 import org.biodas.jdas.schema.sources.CAPABILITY;
12 import org.biodas.jdas.schema.sources.COORDINATES;
13 import org.biodas.jdas.schema.sources.MAINTAINER;
14 import org.biodas.jdas.schema.sources.PROP;
15 import org.biodas.jdas.schema.sources.SOURCE;
16 import org.biodas.jdas.schema.sources.VERSION;
18 import jalview.ws.dbsources.das.api.jalviewSourceI;
19 import jalview.ws.seqfetcher.DbSourceProxy;
21 public class JalviewSource implements jalviewSourceI
25 public JalviewSource(SOURCE local2, boolean local)
32 public String getTitle()
34 return source.getTitle();
38 public VERSION getVersion()
41 return getVersionFor(source);
45 public String getDocHref()
47 return source.getDocHref();
51 public String getDescription()
53 return source.getDescription();
57 public String getUri()
59 return source.getUri();
63 public MAINTAINER getMAINTAINER()
65 return source.getMAINTAINER();
69 public String getEmail()
71 return (local) ? null: source.getMAINTAINER().getEmail();
74 boolean local = false;
77 public boolean isLocal()
83 public boolean isSequenceSource()
85 String seqcap = "das1:" + Capabilities.SEQUENCE.getName();
86 for (String cp : getCapabilityList(getVersionFor(source)))
88 if (cp.equals(seqcap))
97 public boolean isFeatureSource()
99 String seqcap = "das1:" + Capabilities.FEATURES.getName();
100 for (String cp : getCapabilityList(getVersionFor(source)))
102 if (cp.equals(seqcap))
111 private VERSION getVersionFor(SOURCE ds)
113 VERSION latest = null;
114 for (VERSION v : ds.getVERSION())
117 || isLaterThan(latest.getCreated(), v.getCreated()))
119 // TODO: das 1.6 - should just get the first version - ignore other
120 // versions since not specified how to construct URL from version's URI
128 private boolean isLaterThan(String ref, String newer)
130 Date refdate = null, newdate = null;
133 refdate = DasTimeFormat.fromDASString(ref);
135 } catch (ParseException x)
141 newdate = DasTimeFormat.fromDASString(newer);
142 } catch (ParseException e)
144 // TODO: handle exception
150 return refdate.before(newdate);
158 // assume first instance of source is newest in list. - TODO: check if
159 // natural ordering of source versions is newest first or oldest first
163 public String[] getLabelsFor(VERSION v)
165 ArrayList<String> labels = new ArrayList<String>();
166 for (PROP p : v.getPROP())
168 if (p.getName().equalsIgnoreCase("LABEL"))
170 labels.add(p.getValue());
173 return labels.toArray(new String[0]);
176 private CAPABILITY getCapability(Capabilities capability) {
177 for (CAPABILITY p: getVersion().getCAPABILITY()) {
178 if (p.getType().equalsIgnoreCase(capability.getName()) || p.getType().equalsIgnoreCase("das1:"+capability.getName()))
185 public String[] getCapabilityList(VERSION v)
188 ArrayList<String> labels = new ArrayList<String>();
189 for (CAPABILITY p : v.getCAPABILITY())
191 // TODO: work out what to do with namespace prefix
192 // does SEQUENCE == das1:SEQUENCE and das2:SEQUENCE ?
193 // for moment, just show all capabilities...
194 if (p.getType().startsWith("das1:"))
196 labels.add(p.getType());
199 return labels.toArray(new String[0]);
203 public List<DbSourceProxy> getSequenceSourceProxies()
205 if (!isSequenceSource())
209 ArrayList<DbSourceProxy> seqsources = new ArrayList<DbSourceProxy>();
212 VERSION v = getVersion();
213 for (COORDINATES cs : v.getCOORDINATES())
217 * if (css == null || css.length == 0) { // TODO: query das source
218 * directly to identify coordinate system... or // have to make up a
219 * coordinate system css = new DasCoordinateSystem[] { new
220 * DasCoordinateSystem() }; css[0].setName(d1s.getNickname());
221 * css[0].setUniqueId(d1s.getNickname()); } for (int c = 0; c <
226 seqsources.add(new DasSequenceSource("das:" + getTitle() + " ("
227 + cs.getAuthority()+" "+cs.getSource() + ")", cs.getAuthority(), source, v, cs));
228 } catch (Exception e)
230 System.err.println("Ignoring sequence coord system " + cs + " ("
231 + cs.getContent() + ") for source " + getTitle()
232 + "- threw exception when constructing fetcher.\n");
239 seqsources.add(new DasSequenceSource("das:"+getTitle(), getTitle(), source, getVersion(), null));
240 } catch (Exception e)
242 // TODO Auto-generated catch block
250 public String getSourceURL()
253 String url = new RegistrySourceAdapter(source).getOriginalDataSourceUri();
258 System.err.println("Serious: Couldn't get the URL for source "+source.getTitle());