Beispiel #1
0
  /**
   * Makes a request to the IRIS service for a particular station's channels.
   *
   * <p>The request will look something like this:
   * http://www.iris.edu/ws/station/query?net=S&station=AUDAR&level=chan
   *
   * @param serviceUrl The IRIS web service URL.
   * @param networkCode The network code that you're interested in.
   * @param stationCode The code of the station to interrogate.
   * @return a JSONResponseMAV containing the start and end dates of the site and a collection of
   *     channel codes.
   */
  @RequestMapping("/getStationChannels.do")
  public ModelAndView getStationChannels(
      @RequestParam("serviceUrl") String serviceUrl,
      @RequestParam("networkCode") String networkCode,
      @RequestParam("stationCode") String stationCode) {
    serviceUrl = ensureTrailingForwardslash(serviceUrl);
    try {
      Document irisDoc =
          getDocumentFromURL(
              serviceUrl
                  + "fdsnws/station/1/query?net="
                  + networkCode
                  + "&sta="
                  + stationCode
                  + "&level=chan");

      NodeList channels = irisDoc.getDocumentElement().getElementsByTagName("Channel");

      String[] channelCodes = new String[channels.getLength()];

      // For each station:
      for (int i = 0; i < channels.getLength(); i++) {
        Node channel = channels.item(i);
        channelCodes[i] = channel.getAttributes().getNamedItem("code").getTextContent();
      }

      NamespaceContext nc = getIrisNamespace();
      String startDate =
          DOMUtil.compileXPathExpr(
                  "//default:Station[@code='" + stationCode + "']/default:Channel/@startDate", nc)
              .evaluate(irisDoc, XPathConstants.STRING)
              .toString();
      String endDate =
          DOMUtil.compileXPathExpr(
                  "//default:Station[@code='" + stationCode + "']/default:Channel/@endDate", nc)
              .evaluate(irisDoc, XPathConstants.STRING)
              .toString();

      ModelMap channelInfo = new ModelMap();
      channelInfo.put("start_date", startDate);
      channelInfo.put("end_date", endDate);
      channelInfo.put("channel_codes", channelCodes);

      return generateJSONResponseMAV(true, channelInfo, "OK");
    } catch (Exception e) {
      return generateJSONResponseMAV(false, e.getMessage(), "Failed.");
    }
  }
Beispiel #2
0
  /**
   * Creates a new spatial domain
   *
   * @param envelope
   * @param rectifiedGrid
   * @throws XPathExpressionException
   */
  public SpatialDomain(Node node, WCSNamespaceContext nc) throws XPathExpressionException {
    NodeList envelopeNodes =
        (NodeList)
            DOMUtil.compileXPathExpr("wcs:Envelope | gml:Envelope | wcs:EnvelopeWithTimePeriod", nc)
                .evaluate(node, XPathConstants.NODESET);
    this.envelopes = new SimpleEnvelope[envelopeNodes.getLength()];
    for (int i = 0; i < envelopeNodes.getLength(); i++) {
      this.envelopes[i] = new SimpleEnvelope(envelopeNodes.item(i), nc);
    }

    Node gridNode =
        (Node)
            DOMUtil.compileXPathExpr("gml:RectifiedGrid", nc).evaluate(node, XPathConstants.NODE);
    if (gridNode != null) {
      this.rectifiedGrid = new RectifiedGrid(gridNode);
    }
  }
Beispiel #3
0
  /**
   * Makes a request to the IRIS service specified, for all the stations on the network code
   * provided.
   *
   * <p>The response is converted to some KML points to be rendered on the map.
   *
   * <p>The request will look something like this:
   * http://service.iris.edu/fdsnws/station/1/query?net=S
   *
   * @param serviceUrl The IRIS web service URL.
   * @param networkCode The network code that you're interested in.
   * @return a JSONResponseMAV containing KML points of each station.
   */
  @RequestMapping("/getIRISStations.do")
  public ModelAndView getIRISStations(
      @RequestParam("serviceUrl") String serviceUrl,
      @RequestParam("networkCode") String networkCode) {
    serviceUrl = ensureTrailingForwardslash(serviceUrl);

    try {
      Document irisDoc =
          getDocumentFromURL(serviceUrl + "fdsnws/station/1/query?net=" + networkCode);

      // TODO VT: As part of the review for AGOS-15 , we should be following the same architecture
      // as the rest of portal and
      // create a xslt file to do the transformation from xml to kml
      NodeList stations = irisDoc.getDocumentElement().getElementsByTagName("Station");
      NamespaceContext nc = getIrisNamespace();
      XPathExpression nameExpression =
          DOMUtil.compileXPathExpr("default:Site/default:Name/text()", nc);
      XPathExpression latExpression = DOMUtil.compileXPathExpr("default:Latitude/text()", nc);
      XPathExpression lonExpression = DOMUtil.compileXPathExpr("default:Longitude/text()", nc);

      StringBuilder kml =
          new StringBuilder(
              "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><name>GML Links to KML</name><description><![CDATA[GeoSciML data converted to KML]]></description>");

      // For each station:
      for (int i = 0; i < stations.getLength(); i++) {
        Node station = stations.item(i);
        Node staCode = station.getAttributes().getNamedItem("code");
        kml.append(
            String.format(
                "<Placemark><name>%s</name><description><![CDATA[GENERIC_PARSER:%s]]></description>"
                    + "<MultiGeometry><Point><coordinates>%s,%s,0</coordinates></Point></MultiGeometry></Placemark>",
                nameExpression.evaluate(station, XPathConstants.STRING),
                staCode.getTextContent(),
                lonExpression.evaluate(station, XPathConstants.STRING),
                latExpression.evaluate(station, XPathConstants.STRING)));
      }

      kml.append("</Document></kml>");

      return generateJSONResponseMAV(true, "gml", kml.toString(), null);
    } catch (Exception e) {
      return generateJSONResponseMAV(false, e.getMessage(), "Failed.");
    }
  }
  /**
   * This is a legacy test for the older vocabularyServiceResponse.xml
   *
   * <p>It tests our concepts still return EVEN if we don't define top level concepts
   */
  @Test
  public void testGetConcepts() throws Exception {
    String responseXml =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/sissvoc/vocabularyServiceResponse.xml");
    Document responseDoc = DOMUtil.buildDomFromString(responseXml);
    Node rdfNode =
        (Node)
            DOMUtil.compileXPathExpr("rdf:RDF", new VocabNamespaceContext())
                .evaluate(responseDoc, XPathConstants.NODE);

    ConceptFactory cf = new ConceptFactory();
    Concept[] actualConcepts = cf.parseFromRDF(rdfNode);

    Assert.assertEquals("There are 27 concepts", 27, actualConcepts.length);

    // Must contain: Siltstone - concrete aggregate
    boolean found = false;
    for (Concept concept : actualConcepts) {
      if (concept.getPreferredLabel().equals("Siltstone - concrete aggregate")) {
        found = true;
        break;
      }
    }
    Assert.assertTrue("Must contain: Siltstone - concrete aggregate", found);

    // Must contain: Gneiss - crusher dust
    found = false;
    for (Concept concept : actualConcepts) {
      if (concept.getPreferredLabel().equals("Gneiss - crusher dust")) {
        found = true;
        break;
      }
    }
    Assert.assertTrue("Must contain: Gneiss - crusher dust", found);
  }
Beispiel #5
0
  /**
   * Makes a DescribeCoverage request, returns the response as an array of DescribeCoverageRecords
   *
   * @param serviceUrl The WCS endpoint to query
   * @param coverageName The coverage name to describe
   * @throws URISyntaxException
   */
  public DescribeCoverageRecord[] describeCoverage(String serviceUrl, String coverageName)
      throws PortalServiceException {

    HttpRequestBase method = null;
    try {
      method = methodMaker.describeCoverageMethod(serviceUrl, coverageName);
      try (InputStream response = serviceCaller.getMethodResponseAsStream(method)) {

        Document responseDoc = DOMUtil.buildDomFromStream(response);
        OWSExceptionParser.checkForExceptionResponse(responseDoc);

        return DescribeCoverageRecord.parseRecords(responseDoc);
      }
    } catch (Exception ex) {
      throw new PortalServiceException(method, "Error while making GetCoverage request", ex);
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
  }
  /** Runs the factory through a standard SISSVoc response XML */
  @Test
  public void testSISSVocRDF() throws Exception {
    // Build our expectation
    Concept concept1 = new Concept("urn:concept:1");
    Concept concept2 = new Concept("urn:concept:2");
    Concept concept3 = new Concept("urn:concept:3");
    Concept concept4 = new Concept("urn:concept:4");
    NamedIndividual ni1 = new NamedIndividual("urn:ni:1");
    NamedIndividual ni2 = new NamedIndividual("urn:ni:2");
    NamedIndividual ni3 = new NamedIndividual("urn:ni:3");

    concept1.setNarrower(new Concept[] {concept2, concept3, ni2});
    concept1.setLabel("LabelConcept1");
    concept1.setPreferredLabel("PrefLabelConcept1");

    concept2.setBroader(new Concept[] {concept1});
    concept2.setRelated(new Concept[] {concept3});
    concept2.setLabel("LabelConcept2");
    concept2.setPreferredLabel("PrefLabelConcept2");
    concept2.setDefinition("DefinitionConcept2");

    concept3.setBroader(new Concept[] {concept1});
    concept3.setRelated(new Concept[] {concept2});
    concept3.setNarrower(new Concept[] {ni1});
    concept3.setLabel("LabelConcept3");
    concept3.setPreferredLabel("PrefLabelConcept3");

    concept4.setNarrower(new Concept[] {ni3});
    concept4.setLabel("LabelConcept4");
    concept4.setPreferredLabel("PrefLabelConcept4");
    concept4.setDefinition("DefinitionConcept4");

    ni1.setBroader(new Concept[] {concept3});
    ni1.setLabel("LabelNamedIndividual1");
    ni1.setPreferredLabel("PrefLabelNamedIndividual1");

    ni2.setBroader(new Concept[] {concept1});
    ni2.setLabel("LabelNamedIndividual2");
    ni2.setPreferredLabel("PrefLabelNamedIndividual2");

    ni3.setBroader(new Concept[] {concept4});
    ni3.setLabel("LabelNamedIndividual3");
    ni3.setPreferredLabel("PrefLabelNamedIndividual3");

    Concept[] expectation = new Concept[] {concept1, concept4};

    // Build our actual list
    String responseXml =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/sissvoc/SISSVocResponse.xml");
    Document responseDoc = DOMUtil.buildDomFromString(responseXml);
    Node rdfNode =
        (Node)
            DOMUtil.compileXPathExpr("rdf:RDF", new VocabNamespaceContext())
                .evaluate(responseDoc, XPathConstants.NODE);
    ConceptFactory cf = new ConceptFactory();
    Concept[] actualConcepts = cf.parseFromRDF(rdfNode);

    Assert.assertNotNull(actualConcepts);
    assertSameConcept(expectation, actualConcepts, new ArrayList<String>());
  }
Beispiel #7
0
 /**
  * Downloads a resource from a URL and returns it as Document object.
  *
  * @param queryUrl The URL of the resource you require.
  * @return The resource at the URL requested, converted to a Document object.
  * @throws IOException
  * @throws ParserConfigurationException
  * @throws SAXException
  */
 private Document getDocumentFromURL(String queryUrl)
     throws IOException, ParserConfigurationException, SAXException {
   String irisResponse = getIrisResponseFromQuery(queryUrl);
   return DOMUtil.buildDomFromString(irisResponse);
 }