コード例 #1
0
  @Override
  public void process(ProcessletInputs in, ProcessletOutputs out, ProcessletExecutionInfo info)
      throws ProcessletException {

    try {

      WHSServiceVO vo = new WHSServiceVO();

      URL processDefinitionUrl =
          this.getClass().getResource("/" + this.getClass().getSimpleName() + ".xml");
      DataInputHandler dataInputHandler =
          new DataInputHandler(new File(processDefinitionUrl.toURI()));
      String srsName = dataInputHandler.getValidatedStringValue(in, "srsName");
      String x = String.valueOf(DataInputHandler.getDoubleInputValue(in, "x"));
      String y = String.valueOf(DataInputHandler.getDoubleInputValue(in, "y"));
      String z = String.valueOf(DataInputHandler.getDoubleInputValue(in, "z"));
      String tolerance = dataInputHandler.getValidatedStringValue(in, "tolerance");
      String filter = dataInputHandler.getValidatedStringValue(in, "filter");

      vo.setFromSRSCodeOne(srsName);
      vo.setFromSRSCode(srsName);
      // vo.setToSRSCodeOne(agea);
      // vo.setToSRSCode(agea);
      vo.setTolerance(tolerance);
      vo.setFilter(filter);

      if (vo.getFilter().toLowerCase().startsWith("filepath:")) {
        vo.setFilter(vo.getFilter().replaceAll("filePath:", ""));
      }

      LOG.debug("From SRS Code: {}", vo.getFromSRSCodeOne());
      LOG.debug("Filter: {}", vo.getFilter());

      // validate data inputs
      vo.setOriginalCoordinateX(x);
      vo.setOriginalCoordinateY(y);
      vo.setOriginalCoordinateZ(z);
      String transformedCoordinatesString = "";

      if (vo.getFromSRSCode().equalsIgnoreCase("image")) {
        vo.setTransformedCoordinateX(vo.getOriginalCoordinateX());
        vo.setTransformedCoordinateY(vo.getOriginalCoordinateY());
        vo.setTransformedCoordinateZ(vo.getOriginalCoordinateZ());
      } else if (vo.getFromSRSCode().equalsIgnoreCase(abaReference)) {
        vo.setTransformedCoordinateX(vo.getOriginalCoordinateX());
        vo.setTransformedCoordinateY(vo.getOriginalCoordinateY());
        vo.setTransformedCoordinateZ(vo.getOriginalCoordinateZ());
      } else {
        // Call getTransformationChain method here...
        // ABAVoxel
        vo.setOriginalCoordinateX(";x=" + vo.getOriginalCoordinateX());
        vo.setOriginalCoordinateY(";y=" + vo.getOriginalCoordinateY());
        vo.setOriginalCoordinateZ(";z=" + vo.getOriginalCoordinateZ());
        vo.setToSRSCode(abaReference);
        vo.setToSRSCodeOne(abaReference);

        // Construct GetTransformationChain URL
        // http://132.239.131.188:8080/atlas-ucsd?service=WPS&version=1.0.0&request=Execute&Identifier=GetTransformationChain&DataInputs=inputSrsName=Mouse_Paxinos_1.0;outputSrsName=Mouse_ABAreference_1.0;filter=Cerebellum

        // Start - FIXME - Uncomment below two lines and comment the
        // other three lines
        // String hostName = uri.getHost();
        // String portNumber = delimitor + uri.getPort();
        String delimitor = config.getValue("incf.deploy.port.delimitor");
        hostName = config.getValue("incf.deploy.host.name");
        portNumber = config.getValue("incf.aba.port.number");
        portNumber = delimitor + portNumber;
        // End - FIXME

        // central/atlas
        String servicePath =
            "/central/atlas?service=WPS&version=1.0.0&request=Execute&Identifier=GetTransformationChain&DataInputs=inputSrsName="
                + vo.getFromSRSCode()
                + ";outputSrsName="
                + vo.getToSRSCode()
                + ";filter=NONE";
        String transformationChainURL = "http://" + hostName + portNumber + servicePath;
        XMLUtilities xmlUtilities = new XMLUtilities();
        transformedCoordinatesString =
            xmlUtilities.coordinateTransformation(
                transformationChainURL,
                vo.getOriginalCoordinateX(),
                vo.getOriginalCoordinateY(),
                vo.getOriginalCoordinateZ());

        // Start - exception handling
        if (transformedCoordinatesString.startsWith("Error:")) {
          throw new OWSException("Transformed Coordinates Error: ", transformedCoordinatesString);
        }
        // End - exception handling
        WHSUtil util = new WHSUtil();
        String[] tempArray = util.getTabDelimNumbers(transformedCoordinatesString);
        vo.setTransformedCoordinateX(tempArray[0]);
        vo.setTransformedCoordinateY(tempArray[1]);
        vo.setTransformedCoordinateZ(tempArray[2]);
      }
      // End

      AnnotationResponseDocument document = completeResponse(vo);

      ArrayList errorList = new ArrayList();
      // opt.setErrorListener(errorList);
      // boolean isValid = document.validate(opt);

      // If the XML isn't valid, loop through the listener's contents,
      // printing contained messages.
      /*			if (!isValid) {
      				for (int i = 0; i < errorList.size(); i++) {
      					XmlError error = (XmlError) errorList.get(i);

      					LOG.debug("\n");
      					LOG.debug("Message: {}" , error.getMessage() + "\n");
      					LOG.debug("Location of invalid XML: {}"
      							, error.getCursorLocation().xmlText() + "\n");
      				}
      			}
      */

      ComplexOutput complexOutput = (ComplexOutput) out.getParameter("GetAnnotationsByPOIOutput");

      // get reader on document; reader --> writer
      XMLStreamReader reader = document.newXMLStreamReader();
      XMLStreamWriter writer = complexOutput.getXMLStreamWriter();
      XMLAdapter.writeElement(writer, reader);

    } catch (MissingParameterException e) {
      LOG.error(e.getMessage(), e);
      throw new ProcessletException(new OWSException(e));
    } catch (InvalidParameterValueException e) {
      LOG.error(e.getMessage(), e);
      throw new ProcessletException(new OWSException(e));
    } catch (Throwable e) {
      String message = "Unexpected exception occured";
      LOG.error(message, e);
      OWSException owsException =
          new OWSException(message, e, ControllerException.NO_APPLICABLE_CODE);
      throw new ProcessletException(owsException);
    }
  }
コード例 #2
0
  public AnnotationResponseDocument completeResponse(WHSServiceVO vo) {

    LOG.debug("X1: " + vo.getTransformedCoordinateX());
    LOG.debug("Y1: " + vo.getTransformedCoordinateY());
    LOG.debug("Z1: " + vo.getTransformedCoordinateZ());

    String x1 = vo.getTransformedCoordinateX();
    String x2 =
        String.valueOf(
            Double.parseDouble(vo.getTransformedCoordinateX())
                + Double.parseDouble(vo.getTolerance()));
    String x3 =
        String.valueOf(
            Double.parseDouble(vo.getTransformedCoordinateX())
                + Double.parseDouble(vo.getTolerance()));
    String x4 = vo.getTransformedCoordinateX();
    String y1 = vo.getTransformedCoordinateY();
    String y2 = vo.getTransformedCoordinateY();
    String y3 =
        String.valueOf(
            Double.parseDouble(vo.getTransformedCoordinateY())
                - Double.parseDouble(vo.getTolerance()));
    String y4 =
        String.valueOf(
            Double.parseDouble(vo.getTransformedCoordinateY())
                - Double.parseDouble(vo.getTolerance()));

    AnnotationResponseDocument doc = AnnotationResponseDocument.Factory.newInstance();
    AnnotationResponse annResp = doc.addNewAnnotationResponse();
    String polygonString =
        x1 + " " + y1 + "," + x2 + " " + y2 + "," + x3 + " " + y3 + "," + x4 + " " + y4 + "," + x1
            + " " + y1;
    LOG.debug("Artibrary polygon string - {}", polygonString);

    ArrayList annotationDataList = new ArrayList();
    WHSServiceDAOImpl daoImpl = new WHSServiceDAOImpl();

    LOG.debug("*********************************SRSName outside: " + vo.getFromSRSCode());
    LOG.debug("*********************************filter outside: " + vo.getFilter());
    if (!vo.getFromSRSCode().equalsIgnoreCase("image")) {
      LOG.debug("*********************************SRSName inside Image: " + vo.getSrsName());
      annotationDataList = daoImpl.getAnnotationData(vo, polygonString);
    } else if (vo.getFromSRSCode().equalsIgnoreCase("image")) {
      LOG.debug(
          "*********************************SRSName inside Not Actual SRSName: "
              + vo.getFromSRSCode());
      annotationDataList = daoImpl.getAnnotationData(vo);
    } else {
      // FIXME - Put some exception code here to throw an exception
      LOG.debug("SRS TYPE NOT SUPPORTED");
    }

    Iterator iterator0 = annotationDataList.iterator();
    String id = "";
    String path = "";
    HashMap map = new HashMap();
    while (iterator0.hasNext()) {
      vo = (WHSServiceVO) iterator0.next();
      id = vo.getUniqueID();
      path = vo.getOntoFilePath();
      map.put(id, path);
    }
    LOG.debug("Map Size: " + map.size());

    Iterator annotationsIterator = map.keySet().iterator();
    String key = "";
    while (annotationsIterator.hasNext()) {

      key = annotationsIterator.next().toString();

      LOG.debug("*****************New Annotation*****************");
      AnnotationType ann = annResp.addNewAnnotation();

      Iterator dataIterator = annotationDataList.iterator();
      GEOMETRYTYPE geom1 = null;
      AnnPolygonType polygon1 = null;
      GEOMETRIES geometries = null;

      geometries = ann.addNewGEOMETRIES();
      geom1 = geometries.addNewGEOMETRY();
      // Resource and Geometries should be only one time
      RESOURCE res = ann.addNewRESOURCE();

      /*		CentralServiceVO vo1 = null;
      		while (dataIterator.hasNext()) {

      			vo1 = (CentralServiceVO)dataIterator.next();

      			LOG.debug("**Key from Hash Map:**" + key );
      			LOG.debug("**Key from Collection:**" + vo1.getUniqueID() );

      		if (key.equals(vo1.getUniqueID())){
      */
      LOG.debug("*****************New Data Inside Annotation*****************");
      // Loop here - New Annotation

      Iterator iterator1 = annotationDataList.iterator();
      WHSServiceVO vo2 = null;

      // Delete this loop
      while (iterator1.hasNext()) {

        vo2 = (WHSServiceVO) iterator1.next();

        LOG.debug("##Original Key MAP INSIDEPOLYGON:##" + key);
        LOG.debug("##Key from Collection INSIDE POLYGON:##" + vo2.getUniqueID());

        if (vo2.getUniqueID().equals(key)) {

          polygon1 = geom1.addNewPOLYGON();
          LOG.debug("##Inside POLYGON:##");
          /*			LOG.debug("Date is: " + date );
          			LOG.debug("Time is: " + date.getTime() );
          			LOG.debug("Day is: " + date.getDate() );
          */

          // FIXME - update the unique url below from the db
          res.setFilepath(vo2.getOntoFilePath());

          geom1.setUserName(vo2.getUserName());

          if (vo2.getSrsName() == null || vo2.getSrsName().equals("")) {
            polygon1.setSrsName("Undefined");
          } else {
            polygon1.setSrsName(vo2.getSrsName());
          }
          polygon1.setId(gmlId(vo2.getPolygonID()));

          // date = vo.getUpdatedTime();

          // FIXME
          Calendar cal = Calendar.getInstance();
          cal.setTime(vo.getUpdatedTime());

          ann.setMODIFIEDDATE(cal);

          // FIXME - modifiedTime
          // long modifiedTime = Long.parseLong(vo1.getUpdatedTime());
          Date date = null;

          // FIXME
          geom1.setModifiedTime(vo.getUpdatedTime().getTime());

          AbstractRingPropertyType poly1exterior = polygon1.addNewExterior();
          XmlObject ring = poly1exterior.addNewAbstractRing();
          XmlObject linearRing =
              ring.substitute(
                  new QName("http://www.opengis.net/gml/3.2", "LinearRing"), LinearRingType.type);

          DirectPositionType pos1 = ((LinearRingType) linearRing).addNewPos();

          pos1.setStringValue(vo2.getTransformedCoordinates().replaceAll(",", " "));
        }
      }

      GENERALONTOMODEL model1 = ann.addNewGENERALONTOMODEL();
      RELATIONSTYPE relations = model1.addNewRELATIONS();

      Iterator iterator2 = annotationDataList.iterator();

      WHSServiceVO vo3 = null;
      while (iterator2.hasNext()) {

        vo3 = (WHSServiceVO) iterator2.next();

        if (vo3.getUniqueID().equals(key)) {

          ONTOPROPERTYTYPE prop2 = relations.addNewONTOPROPERTY();
          prop2.setTitle("has_geometry");
          // Below URL never changes
          prop2.setHref(
              "http://ontology.neuinfo.org/NIF/Backend/NIFSTD_Datatype_properties.owl#hasGeometry");
          prop2.setUserName(vo3.getUserName());
          // FIXME - modifiedTime
          prop2.setModifiedTime(vo.getUpdatedTime().getTime());

          SUBJECTTYPE subj2 = prop2.addNewSUBJECT();
          ONTOTERMTYPE term2_1 = subj2.addNewONTOTERM();
          term2_1.setTitle(vo3.getOntoName());
          term2_1.setHref(vo3.getOntoURI());
          term2_1.setId(gmlId(vo3.getPolygonID()));
          // term2_1.newCursor().insertComment(" title = onto_name, href = onto_url gml:id=
          // instance_id");

          OBJECTTYPE obj2 = prop2.addNewOBJECT();
          GEOMETRYTYPE term2_2 = obj2.addNewGEOMETRY();
          term2_2.setHref(gmlIdInteralReference(gmlId(vo3.getPolygonID())));
        }
      }

      ONTOTERMS terms = ann.addNewONTOTERMS();

      Iterator iterator3 = annotationDataList.iterator();

      WHSServiceVO vo4 = null;

      while (iterator3.hasNext()) {

        vo4 = (WHSServiceVO) iterator3.next();

        if (vo4.getUniqueID().equals(key)) {

          ONTOTERMTYPE term2 = terms.addNewONTOTERM();
          term2.setId(gmlId(vo4.getPolygonID()));
          term2.setHref(vo4.getOntoURI());
          term2.setTitle(vo4.getOntoName());
        }
      }
      // }
      // }
    }
    return doc;
  }