001/* 002 * Copyright (c) 2003-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2012-09-20 22:42:39 +0000 (Thu, 20 Sep 2012) $' 007 * '$Revision: 30726 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.geon; 031 032import java.io.BufferedWriter; 033import java.io.File; 034import java.io.FileWriter; 035import java.io.IOException; 036import java.io.PrintWriter; 037import java.net.URL; 038import java.util.Iterator; 039import java.util.Map; 040import java.util.TreeMap; 041import java.util.Vector; 042 043import org.w3c.dom.Element; 044import org.w3c.dom.Node; 045import org.w3c.dom.NodeList; 046 047import ptolemy.actor.CompositeActor; 048import ptolemy.actor.Manager; 049import ptolemy.data.ArrayToken; 050import ptolemy.data.BooleanMatrixToken; 051import ptolemy.data.DoubleMatrixToken; 052import ptolemy.data.DoubleToken; 053import ptolemy.data.IntMatrixToken; 054import ptolemy.data.IntToken; 055import ptolemy.data.LongMatrixToken; 056import ptolemy.data.LongToken; 057import ptolemy.data.RecordToken; 058import ptolemy.data.StringToken; 059import ptolemy.data.Token; 060import ptolemy.data.UnsignedByteToken; 061import ptolemy.data.expr.Variable; 062import ptolemy.data.type.BaseType; 063import ptolemy.kernel.ComponentEntity; 064import ptolemy.kernel.ComponentPort; 065import ptolemy.kernel.ComponentRelation; 066import ptolemy.kernel.CompositeEntity; 067import ptolemy.kernel.util.Attribute; 068import ptolemy.kernel.util.IllegalActionException; 069import ptolemy.kernel.util.NamedObj; 070import ptolemy.moml.MoMLChangeRequest; 071import ptolemy.moml.MoMLParser; 072 073////////////////////////////////////////////////////////////////////////// 074////LidarWorkflowExecute 075/** 076 * Creates and Invokes the lidar workflow on the fly from portlet inputs. 077 * 078 * @author Efrat Jaeger 079 */ 080public class LidarWorkflowExecute { 081 public LidarWorkflowExecute() { 082 083 } 084 085 public synchronized String executeQuery(String modelURL, Map inputs) 086 throws Exception { 087 088 URL url = new URL(modelURL); 089 if (url != null) { 090 MoMLParser parser = new MoMLParser(); 091 NamedObj model; 092 try { 093 System.out.println("before parsing query template"); 094 model = parser.parse(null, url); 095 System.out.println("after parsing query template"); 096 boolean in = setInputs(model, inputs); 097 if (!in) 098 return null; 099 // TEMPORARY HERE TO SAVE THE GENERATED FILLED QUERY TEMPLATE... 100 try { 101 String uniqueId = (String) inputs.get("uniqueId"); 102 String appPath = (String) inputs.get("appPath"); 103 String filePath = appPath + "data/tmp/queryFilled" 104 + uniqueId + ".xml"; 105 File queryFilled = new File(filePath); 106 String queryFilledURL = queryFilled.getAbsolutePath(); 107 BufferedWriter out = new BufferedWriter(new FileWriter( 108 queryFilledURL, false)); 109 110 out.write(model.exportMoML()); 111 out.close(); 112 } catch (Exception ex1) { 113 System.out 114 .println("unable to create query template file queryFilled" 115 + uniqueId + ".xml: " + ex1.getMessage()); 116 _log("unable to create query template file queryFilled" 117 + uniqueId + ".xml: " + ex1.getMessage()); 118 } 119 120 } catch (Exception ex) { 121 ex.printStackTrace(); 122 try { 123 PrintWriter pw = new PrintWriter(new FileWriter(logURL, 124 true)); 125 ex.printStackTrace(pw); 126 pw.close(); 127 } catch (Exception e) { 128 } 129 return null; 130 } 131 if (model instanceof CompositeActor) { 132 return executeModel((CompositeActor) model); 133 } else { 134 return null; 135 } 136 } else { 137 return null; 138 } 139 } 140 141 public synchronized String executeProcess(String modelURL, Map inputs) 142 throws Exception { 143 144 uniqueId = (String) inputs.get("id"); 145 appPath = (String) inputs.get("appPath"); 146 String host = (String) inputs.get("host"); 147 String port = (String) inputs.get("port"); 148 149 // create workflow 150 Map workflowInputs = new TreeMap(); 151 workflowInputs.put("uniqueId", uniqueId); 152 workflowInputs.put("appPath", appPath); 153 workflowInputs.put("host", host); 154 workflowInputs.put("port", port); 155 String email = (String) inputs.get("email"); 156 if (email != null && !email.equals("")) { 157 workflowInputs.put("email", email); 158 } 159 160 // System.out.println(System.getProperty("user.dir")); 161 URL url = new URL(modelURL); 162 if (url != null) { 163 MoMLParser parser = new MoMLParser(); 164 NamedObj model; 165 try { 166 System.out.println("before parsing process template"); 167 model = parser.parse(null, url); 168 System.out.println("after parsing process template"); 169 boolean in = setInputs(model, workflowInputs); 170 if (!in) 171 return null; 172 updateWorkflow(model, inputs); 173 } catch (Exception ex) { 174 ex.printStackTrace(); 175 try { 176 PrintWriter pw = new PrintWriter(new FileWriter(logURL, 177 true)); 178 ex.printStackTrace(pw); 179 pw.close(); 180 } catch (Exception e) { 181 } 182 183 return null; 184 } 185 if (model instanceof CompositeActor) { 186 187 /* 188 * ComponentEntity CA = ((CompositeEntity) 189 * model).getEntity("EmailNotification"); CA = 190 * ((CompositeEntity) CA).getEntity("Expression"); String exp = 191 * ((Expression) CA).expression.getExpression(); 192 * System.out.println("Email content:\n" + exp); 193 */ 194 System.out.println("after updating model"); 195 return executeModel((CompositeActor) model); 196 } else { 197 return null; 198 } 199 } else { 200 return null; 201 } 202 203 } 204 205 /** 206 * This method takes a url specifying the model to be execute. The 207 * <i>args<i> argument is a record token that will be used to set 208 * corresponding attributes of the spedified model by naming match, (see 209 * _setAttribute() method). The results of executing the model is returned 210 * back by setting the value of some Attributes. In particular, only 211 * Attributes that have name matches the <i>resultLabels<i> are returned. 212 * The return result is a RecordToken which has the resultLabels as its 213 * feild. 214 * 215 * @param url 216 * The Model url. 217 * @param args 218 * A set of attributes of the specified model. 219 * @param resultLabels 220 * Labels of the returned result. 221 * @return The execution result. 222 * @exception IllegalActionException 223 * If can not parse the url or failed to execute the model. 224 */ 225 public synchronized String execute(String modelURL, Map inputs) 226 throws Exception { 227 228 uniqueId = (String) inputs.get("id"); 229 appPath = (String) inputs.get("appPath"); 230 231 String queryFile = createQueryFile(inputs); 232 System.out.println("query file ==> " + queryFile); 233 234 String paramsFile = createParamsFile(inputs); 235 System.out.println("params file ==> " + paramsFile); 236 237 inputs.put("download", download); 238 239 // create workflow 240 Map workflowInputs = new TreeMap(); 241 workflowInputs.put("uniqueId", uniqueId); 242 String email = (String) inputs.get("email"); 243 if (email != null && !email.equals("")) { 244 workflowInputs.put("email", email); 245 } 246 247 // System.out.println(System.getProperty("user.dir")); 248 URL url = new URL(modelURL); 249 if (url != null) { 250 MoMLParser parser = new MoMLParser(); 251 NamedObj model; 252 try { 253 System.out.println("before parsing query template"); 254 model = parser.parse(null, url); 255 System.out.println("after parsing query template"); 256 boolean in = setInputs(model, workflowInputs); 257 if (!in) 258 return null; 259 updateWorkflow(model, inputs); 260 } catch (Exception ex) { 261 ex.printStackTrace(); 262 return null; 263 } 264 if (model instanceof CompositeActor) { 265 System.out.println("after parsing model"); 266 // return "done"; ///////////// 267 return executeModel((CompositeActor) model); 268 } else { 269 return null; 270 } 271 } else { 272 return null; 273 } 274 275 // remove params file and query file 276 277 } 278 279 /** 280 * This method takes model argument which is type of CompositeActor. The 281 * <i>args<i> argument is a record token that will be used to set 282 * corresponding attributes of the spedified model by naming match, (see 283 * _setAttribute() method). The results of executing the model is returned 284 * back by setting the value of some Attributes. In particular, only 285 * Attributes that have name matches the <i>resultLabels<i> are returned. 286 * The return result is a RecordToken which has the resultLabels as its 287 * feild. 288 * 289 * @param model 290 * The Model. 291 * @param args 292 * A set of attributes of the specified model. 293 * @param resultLabels 294 * Labels of the returned result. 295 * @return The execution result. 296 * @exception IllegalActionException 297 * If failed to execute the model. 298 */ 299 public String executeModel(CompositeActor model) throws Exception { 300 Manager manager = model.getManager(); 301 if (manager == null) { 302 // System.out.println("create manager for the model"); 303 manager = new Manager(model.workspace(), "Manager"); 304 model.setManager(manager); 305 } 306 // _setAttribute(model, args); 307 308 manager.execute(); 309 310 return _getResult(model); 311 } 312 313 // ///////////////////////////////////////////////////////////////// 314 // // private methods //// 315 316 /** 317 * Get the output from the parameter (assuming that there is a single output 318 * variable name <i>output</i> 319 * 320 * @param model 321 * The model executed. 322 * @param resultLabels 323 * Labels of the returned result. 324 * @return The execution result. 325 * @exception IllegalActionException 326 * If reading the ports or setting the parameters causes it. 327 */ 328 private String _getResult(CompositeActor model) 329 throws IllegalActionException { 330 331 String val = ""; 332 Iterator atts = model.attributeList().iterator(); 333 while (atts.hasNext()) { 334 Attribute att = (Attribute) atts.next(); 335 if (att instanceof Variable) { 336 String attName = att.getName(); 337 if (attName.trim().toLowerCase().equals("output")) { 338 Variable var = (Variable) att; 339 System.out.println(var.getType().toString()); 340 if (var.getType().equals(BaseType.UNKNOWN)) { 341 var.setTypeEquals(BaseType.GENERAL); 342 } 343 344 val = processToken(var.getToken()); 345 System.out.println("after process token"); 346 break; 347 } 348 } 349 } 350 return val; 351 } 352 353 private boolean setInputs(NamedObj model, Map inputs) { 354 Iterator atts = model.attributeList().iterator(); 355 while (atts.hasNext()) { 356 Attribute att = (Attribute) atts.next(); 357 if (att instanceof Variable) { 358 String attName = att.getName(); 359 if (inputs.containsKey(attName)) { 360 try { 361 Variable var = (Variable) att; 362 var.setToken((String) inputs.get(attName)); 363 System.out.println(attName + ":" + var.getExpression()); 364 } catch (Exception ex) { 365 ex.printStackTrace(); 366 return false; 367 } 368 } 369 370 } 371 } 372 return true; 373 } 374 375 private Token process(Element tag) throws IllegalActionException { // elem = 376 // channel.. 377 String tagName = tag.getTagName(); 378 379 if (tagName.equals("unsignedbyte")) { 380 String val = tag.getFirstChild().getNodeValue().trim(); 381 UnsignedByteToken t = new UnsignedByteToken(val); 382 return t; 383 } 384 385 if (tagName.equals("int")) { 386 String val = tag.getFirstChild().getNodeValue().trim(); 387 IntToken t = new IntToken(val); 388 return t; 389 } 390 391 if (tagName.equals("double")) { 392 String val = tag.getFirstChild().getNodeValue().trim(); 393 DoubleToken t = new DoubleToken(val); 394 return t; 395 } 396 397 if (tagName.equals("long")) { 398 String val = tag.getFirstChild().getNodeValue().trim(); 399 LongToken t = new LongToken(val); 400 return t; 401 } 402 403 if (tagName.equals("intmatrix")) { 404 NodeList rows = tag.getElementsByTagName("row"); 405 int rowNum = rows.getLength(); 406 if (rowNum > 0) { 407 NodeList tempCols = ((Element) rows.item(0)) 408 .getElementsByTagName("value"); 409 int colNum = tempCols.getLength(); 410 int[][] Mat = new int[rowNum][colNum]; 411 for (int j = 0; j < rowNum; j++) { 412 NodeList Cols = ((Element) rows.item(j)) 413 .getElementsByTagName("value"); 414 for (int k = 0; k < colNum; k++) { 415 String val = Cols.item(k).getFirstChild() 416 .getNodeValue().trim(); 417 Mat[j][k] = Integer.parseInt(val); 418 } 419 } 420 IntMatrixToken t = new IntMatrixToken(Mat); 421 return t; 422 } else 423 return new IntMatrixToken(); 424 } 425 426 if (tagName.equals("doublematrix")) { 427 NodeList rows = tag.getElementsByTagName("row"); 428 int rowNum = rows.getLength(); 429 if (rowNum > 0) { 430 NodeList tempCols = ((Element) rows.item(0)) 431 .getElementsByTagName("value"); 432 int colNum = tempCols.getLength(); 433 double[][] Mat = new double[rowNum][colNum]; 434 for (int j = 0; j < rowNum; j++) { 435 NodeList Cols = ((Element) rows.item(j)) 436 .getElementsByTagName("value"); 437 for (int k = 0; k < colNum; k++) { 438 String val = Cols.item(k).getFirstChild() 439 .getNodeValue().trim(); 440 Mat[j][k] = Double.parseDouble(val); 441 } 442 } 443 DoubleMatrixToken t = new DoubleMatrixToken(Mat); 444 return t; 445 } else 446 return new DoubleMatrixToken(); 447 } 448 449 if (tagName.equals("longmatrix")) { 450 NodeList rows = tag.getElementsByTagName("row"); 451 int rowNum = rows.getLength(); 452 if (rowNum > 0) { 453 NodeList tempCols = ((Element) rows.item(0)) 454 .getElementsByTagName("value"); 455 int colNum = tempCols.getLength(); 456 long[][] Mat = new long[rowNum][colNum]; 457 for (int j = 0; j < rowNum; j++) { 458 NodeList Cols = ((Element) rows.item(j)) 459 .getElementsByTagName("value"); 460 for (int k = 0; k < colNum; k++) { 461 String val = Cols.item(k).getFirstChild() 462 .getNodeValue().trim(); 463 Mat[j][k] = Long.parseLong(val); 464 } 465 } 466 LongMatrixToken t = new LongMatrixToken(Mat); 467 return t; 468 } else 469 return new LongMatrixToken(); 470 } 471 472 if (tagName.equals("booleanmatrix")) { 473 NodeList rows = tag.getElementsByTagName("row"); 474 int rowNum = rows.getLength(); 475 if (rowNum > 0) { 476 NodeList tempCols = ((Element) rows.item(0)) 477 .getElementsByTagName("value"); 478 int colNum = tempCols.getLength(); 479 boolean[][] Mat = new boolean[rowNum][colNum]; 480 for (int j = 0; j < rowNum; j++) { 481 NodeList Cols = ((Element) rows.item(j)) 482 .getElementsByTagName("value"); 483 for (int k = 0; k < colNum; k++) { 484 String val = Cols.item(k).getFirstChild() 485 .getNodeValue().trim(); 486 Mat[j][k] = Boolean.getBoolean(val); 487 } 488 } 489 BooleanMatrixToken t = new BooleanMatrixToken(Mat); 490 return t; 491 } else 492 return new BooleanMatrixToken(); 493 } 494 495 if (tagName.equals("string")) { 496 String val = tag.getFirstChild().getNodeValue().trim(); 497 StringToken t = new StringToken(val); 498 return t; 499 } 500 501 if (tagName.equals("array")) { 502 Vector tVec = new Vector(); 503 NodeList arrChilds = tag.getChildNodes(); 504 505 // find only the element children 506 for (int j = 0; j < arrChilds.getLength(); j++) { 507 if (arrChilds.item(j) instanceof Element) { 508 509 Token token = process((Element) arrChilds.item(j)); 510 tVec.add(token); 511 } 512 } 513 Token tArr[] = new Token[tVec.size()]; 514 tVec.toArray(tArr); 515 ArrayToken t = new ArrayToken(tArr); 516 return t; 517 } 518 519 if (tagName.equals("record")) { 520 NodeList labelNodes = tag.getElementsByTagName("label"); 521 NodeList valueNodes = tag.getElementsByTagName("value"); 522 int recLen = labelNodes.getLength(); 523 String[] labels = new String[recLen]; 524 Token[] tokens = new Token[recLen]; 525 for (int j = 0; j < recLen; j++) { 526 labels[j] = labelNodes.item(j).getFirstChild().getNodeValue() 527 .trim(); 528 } 529 int k = 0; 530 for (int j = 0; j < valueNodes.getLength(); j++) { 531 Element value = (Element) valueNodes.item(j); 532 NodeList childs = value.getChildNodes(); 533 for (int l = 0; l < childs.getLength(); l++) { 534 Node node = childs.item(l); 535 if (node instanceof Element) { 536 tokens[k++] = process((Element) node); 537 } 538 } 539 } 540 RecordToken t = new RecordToken(labels, tokens); 541 return t; 542 } 543 544 Token t = new Token(); 545 return t; 546 } 547 548 private String processToken(Token token) { 549 550 String val = ""; 551 if (token instanceof UnsignedByteToken) { 552 val = ((UnsignedByteToken) token).unitsString(); 553 return val; 554 555 } else if (token instanceof IntToken) { 556 val = ((IntToken) token).toString(); 557 return val; 558 559 } else if (token instanceof DoubleToken) { 560 val = ((DoubleToken) token).toString(); 561 return val; 562 563 } else if (token instanceof LongToken) { 564 val = ((LongToken) token).toString(); 565 return val; 566 567 } else if (token instanceof IntMatrixToken) { 568 val = "["; 569 int[][] Mat = ((IntMatrixToken) token).intMatrix(); 570 for (int i = 0; i < Mat.length; i++) { 571 for (int j = 0; j < Mat[0].length; j++) { 572 val += Mat[i][j] + ","; 573 } 574 val += ":"; 575 } 576 val += "]"; 577 return val; 578 579 } else if (token instanceof DoubleMatrixToken) { 580 val = "["; 581 double[][] Mat = ((DoubleMatrixToken) token).doubleMatrix(); 582 for (int i = 0; i < Mat.length; i++) { 583 for (int j = 0; j < Mat[0].length; j++) { 584 val += Mat[i][j] + ","; 585 } 586 val += ":"; 587 } 588 val += "]"; 589 return val; 590 591 } else if (token instanceof LongMatrixToken) { 592 val = "["; 593 long[][] Mat = ((LongMatrixToken) token).longMatrix(); 594 for (int i = 0; i < Mat.length; i++) { 595 for (int j = 0; j < Mat[0].length; j++) { 596 val += Mat[i][j] + ","; 597 } 598 val += ":"; 599 } 600 val += "]"; 601 return val; 602 603 } else if (token instanceof BooleanMatrixToken) { 604 val = "["; 605 boolean Mat[][] = ((BooleanMatrixToken) token).booleanMatrix(); 606 for (int i = 0; i < Mat.length; i++) { 607 for (int j = 0; j < Mat[0].length; j++) { 608 val += Mat[i][j] + ","; 609 } 610 val += ":"; 611 } 612 val += "]"; 613 return val; 614 615 } else if (token instanceof StringToken) { 616 val = ((StringToken) token).stringValue(); 617 return val; 618 619 } else if (token instanceof ArrayToken) { 620 val = "{"; 621 ArrayToken at = (ArrayToken) token; 622 Token[] tArr = at.arrayValue(); 623 for (int i = 0; i < tArr.length; i++) { 624 val += processToken(tArr[i]) + ","; 625 } 626 val += "}"; 627 return val; 628 629 } else if (token instanceof RecordToken) { 630 val = "{"; 631 RecordToken rt = (RecordToken) token; 632 Object[] labelObjects = rt.labelSet().toArray(); 633 for (int i = 0; i < labelObjects.length; i++) { 634 String label = (String) labelObjects[i]; 635 val += label + "="; 636 Token value = rt.get(label); 637 val += processToken(value); 638 val += ","; 639 } 640 val += "}"; 641 return val; 642 } 643 return val; 644 } 645 646 private String createParamsFile(Map inputs) { 647 try { 648 String filePath = appPath + "data/tmp/params" + uniqueId + ".txt"; 649 // //String filePath = appPath + "params" + uniqueId + ".txt"; 650 File paramsFile = new File(filePath); 651 String paramsFileURL = paramsFile.getAbsolutePath(); 652 BufferedWriter out = new BufferedWriter(new FileWriter( 653 paramsFileURL, false)); 654 655 String algs[] = { "elev", "slope", "aspect", "pcurv" }; 656 String formats[] = { "view", "arc", "ascii", "tiff" }; 657 download = "0"; 658 659 for (int i = 0; i < 4; i++) { 660 for (int j = 0; j < 4; j++) { 661 String type = algs[i] + formats[j]; 662 String typeVal = (String) inputs.get(type); 663 System.out.println(type + "=" + typeVal); 664 if (typeVal != null && !typeVal.equals("")) 665 out.write(type + "=" + typeVal + "\n"); 666 if (typeVal != null && typeVal.equals("1") && j > 0) { 667 download = "1"; 668 } 669 } 670 } 671 672 String res = (String) inputs.get("res"); 673 if (res != null && !res.equals("")) 674 out.write("res=" + res + "\n"); 675 676 String dmin = (String) inputs.get("dmin"); 677 String tension = (String) inputs.get("tension"); 678 String smooth = (String) inputs.get("smooth"); 679 680 if (dmin != null && !dmin.equals("")) 681 out.write("dmin=" + dmin + "\n"); 682 if (tension != null && !tension.equals("")) 683 out.write("tension=" + tension + "\n"); 684 if (smooth != null && !smooth.equals("")) 685 out.write("smooth=" + smooth + "\n"); 686 687 out.close(); 688 689 return paramsFileURL; 690 691 } catch (Exception ex) { 692 System.out.println("unable to create parameters file params" 693 + uniqueId + ": " + ex.getMessage()); 694 _log("unable to create parameters file params" + uniqueId + ": " 695 + ex.getMessage()); 696 } 697 return ""; 698 } 699 700 private String createQueryFile(Map inputs) { 701 try { 702 String filePath = appPath + "data/tmp/" + uniqueId + ".sql"; 703 // //String filePath = appPath + uniqueId + ".sql"; 704 File queryFile = new File(filePath); 705 String queryFileURL = queryFile.getAbsolutePath(); 706 BufferedWriter out = new BufferedWriter(new FileWriter( 707 queryFileURL, false)); 708 709 String MinX = (String) inputs.get("MinX"); 710 String MaxX = (String) inputs.get("MaxX"); 711 String MinY = (String) inputs.get("MinY"); 712 String MaxY = (String) inputs.get("MaxY"); 713 714 out.write("CONNECT TO LIDAR;\n"); 715 out.write("EXPORT TO db2temp/" + uniqueId + " OF DEL\n"); 716 out.write("MODIFIED by decplusblank striplzeros\n"); 717 out.write("select dec(X,10,2) , dec(Y,10,2), dec(Z,10,2)\n"); 718 out.write("from NSAF.Q39123C73\n"); // the table name will be 719 // variable!!! 720 out.write("WHERE db2gse.EnvelopesIntersect ( geometry, "); 721 out.write(MinX + ", " + MinY + ", " + MaxX + ", " + MaxY 722 + ", 1005 ) = 1;\n"); 723 // 1005 will be variable as well!!! 724 out.write("DISCONNECT LIDAR;"); 725 726 out.close(); 727 728 return queryFileURL; 729 730 } catch (Exception ex) { 731 System.out.println("unable to create query file " + uniqueId 732 + ".sql: " + ex.getMessage()); 733 _log("unable to create query file " + uniqueId + ".sql: " 734 + ex.getMessage()); 735 } 736 return ""; 737 } 738 739 private void updateWorkflow(NamedObj model, Map inputs) { 740 741 String elevview = (String) inputs.get("elevview"); 742 String slopeview = (String) inputs.get("slopeview"); 743 String aspectview = (String) inputs.get("aspectview"); 744 String pcurvview = (String) inputs.get("pcurvview"); 745 String queryCount = (String) inputs.get("queryCount"); 746 747 StringBuffer imageSrcs = new StringBuffer(); 748 749 if (queryCount != null) { 750 if (!queryCount.equals("-1")) { 751 imageSrcs.append("<TABLE cellpadding=2> "); 752 imageSrcs.append("<TR><TD>"); 753 imageSrcs.append("Processing of " + queryCount 754 + " points in Lidar point cloud."); 755 imageSrcs.append("</TD></TR> "); 756 imageSrcs.append("</TABLE><BR> "); 757 } 758 } 759 760 if (elevview != null && elevview.equals("1")) { 761 addEntityAndLinks(model, "Spline"); 762 imageSrcs.append(createImageSrc("Elevation (spline)", "Spline")); 763 } 764 if (slopeview != null && slopeview.equals("1")) { 765 addEntityAndLinks(model, "Slope"); 766 imageSrcs.append(createImageSrc("Slope", "Slope")); 767 } 768 if (aspectview != null && aspectview.equals("1")) { 769 addEntityAndLinks(model, "Aspect"); 770 imageSrcs.append(createImageSrc("Aspect", "Aspect")); 771 } 772 if (pcurvview != null && pcurvview.equals("1")) { 773 addEntityAndLinks(model, "Pcurv"); 774 imageSrcs.append(createImageSrc("Pcurv", "Pcurv")); 775 } 776 777 // Connect TGZ entity (component to pass the tgz url) to Transmitter's 778 // output. 779 addRelationAndLinks(model, "TGZ", "filePath", "Transmitter", "output"); 780 781 String dl = (String) inputs.get("download"); 782 if (dl.equals("1")) { 783 // Connect TGZ output to CreateHTML input 784 addRelationAndLinks(model, "CreateHTML", "tgz", "TGZ", "output"); 785 786 // /add download to imageSrc!!!! 787 imageSrcs.append("<HR><BR> "); 788 imageSrcs 789 .append("<p>Below you can download an archive file (tgz format) with the results of your job"); 790 imageSrcs.append("</P> "); 791 imageSrcs 792 .append("<A href=\\"" + tgz + "\\">Results</A> "); 793 } 794 795 String rawdata = (String) inputs.get("rawdata"); 796 if (rawdata.equals("1")) { 797 String MinX = (String) inputs.get("MinX"); 798 String MinY = (String) inputs.get("MinY"); 799 String MaxX = (String) inputs.get("MaxX"); 800 String MaxY = (String) inputs.get("MaxY"); 801 String cStr = (String) inputs.get("classification"); 802 String rawdataURL = (String) inputs.get("rawdataURL"); 803 804 // /add rawdataURL to imageSrc!!!! 805 imageSrcs.append("<HR><BR> "); 806 imageSrcs.append("<p>Raw data for " + cStr); 807 imageSrcs.append("bounding box selection: MinX = " + MinX + ", "); 808 imageSrcs.append("MaxX = " + MaxX + ", MinY = " + MinY 809 + ", MaxY = " + MaxY + " is available at "); 810 imageSrcs.append("</P> "); 811 imageSrcs.append("<A href=\\"" + rawdataURL 812 + "\\">Results</A> "); 813 } 814 815 imageSrcs.append("<HR><BR> "); 816 imageSrcs.append("<p>Download "); 817 imageSrcs 818 .append("<A href=\\"http://activetectonics.la.asu.edu/GEONatASU/LViz.html\\">"); 819 imageSrcs.append("LViz</A> "); 820 imageSrcs 821 .append(" - A free application for visualization of LiDAR point cloud and interpolated surface "); 822 imageSrcs 823 .append("data developed in the Active Tectonics Research Group at Arizona State University."); 824 imageSrcs.append("</P> "); 825 826 StringBuffer html = createHTML(imageSrcs); 827 828 // add the html string to the expression attribute 829 setHTML(model, html); 830 831 // System.out.println(model.exportMoML()); 832 try { 833 String filePath = appPath + "data/tmp/templateFilled" + uniqueId 834 + ".xml"; 835 // //String filePath = appPath + "templateFilled" + uniqueId + 836 // ".xml"; 837 File templateFile = new File(filePath); 838 String templateFileURL = templateFile.getAbsolutePath(); 839 BufferedWriter out = new BufferedWriter(new FileWriter( 840 templateFileURL, false)); 841 842 out.write(model.exportMoML()); 843 out.close(); 844 } catch (Exception ex) { 845 System.out 846 .println("unable to create template filled file templateFilled" 847 + uniqueId + ".xml: " + ex.getMessage()); 848 _log("unable to create template filled file templateFilled" 849 + uniqueId + ".xml: " + ex.getMessage()); 850 } 851 852 } 853 854 private StringBuffer createHTML(StringBuffer imageSrcs) { 855 StringBuffer html = new StringBuffer(); 856 html.append(""<html> <HEAD> "); 857 html 858 .append("<TITLE>LiDAR Processing Workflow Outputs</TITLE> "); 859 html 860 .append("</HEAD> <body bgcolor=\\"#FFFFFF\\"> <TABLE> "); 861 html.append("<TR> <TD>"); 862 html 863 .append("<A HREF=\\"http://activetectonics.la.asu.edu/GEONatASU/index.htm\\" "); 864 html 865 .append("target=\\"_new\\"><IMG SRC=\\"http://agassiz.la.asu.edu/logos/GEONASUWebBanner.jpg\\" "); 866 html 867 .append("alt=\\"GEON at ASU homepage\\"></A></TD> <TD>"); 868 html 869 .append("<a href=\\"http://www.sdsc.edu\\" target=\\"_new\\">"); 870 html 871 .append("<img src=\\"http://www.sdsc.edu/logos/SDSClogo-plusname-red.gif\\" "); 872 html 873 .append("alt=\\"San Diego Supercomputer Center\\" height=\\"60\\" width=\\"216\\"></a>"); 874 html.append("</TD> </TR> </TABLE> "); 875 html 876 .append("<BR><BR> <h1>LiDAR Processing Workflow Outputs</h1> "); 877 html.append("<BR> "); 878 html.append(imageSrcs.toString()); 879 html.append("</body> </html>""); 880 881 return html; 882 } 883 884 private String createImageSrc(String caption, String name) { 885 StringBuffer imageSrc = new StringBuffer(); 886 imageSrc.append("<TABLE cellpadding=2> "); 887 imageSrc.append("<TR><TD align=center>"); 888 imageSrc.append(caption); 889 imageSrc.append("</TD></TR> "); 890 imageSrc.append("<TR><TD><IMG SRC=\\"""); 891 imageSrc.append(" + " + name.toLowerCase()); 892 imageSrc.append(" + "\\" "); 893 imageSrc.append("alt=\\""); 894 imageSrc.append(name); 895 imageSrc.append("\\"></TD></TR> "); 896 imageSrc.append("</TABLE> <BR><BR> "); 897 898 return imageSrc.toString(); 899 } 900 901 private void setHTML(NamedObj model, StringBuffer html) { 902 903 String request = "<property name=\"" + "expression" + "\" value=\"" 904 + html.toString() + "\"/>"; 905 // System.out.println("request: "+request+"\n\n"); 906 907 try { 908 ComponentEntity CA = ((CompositeEntity) model) 909 .getEntity("CreateHTML"); 910 // System.out.println("prev expression: " + 911 // ((Expression)CA).expression.getExpression()); 912 CA.requestChange(new MoMLChangeRequest(model, CA, request)); 913 914 ComponentEntity CA1 = ((CompositeEntity) model) 915 .getEntity("CreateHTML"); 916 // System.out.println("new expression: " + 917 // ((Expression)CA1).expression.getExpression()); 918 } catch (Exception ex) { 919 System.out 920 .println("Exception in momlChangeRequest setting html string: " 921 + ex.getMessage()); 922 _log("Exception in momlChangeRequest setting html string: " 923 + ex.getMessage()); 924 } 925 } 926 927 private void addEntityAndLinks(NamedObj model, String name) { 928 // create composite vis component moml description. 929 StringBuffer vis = createCompositeVis(name); 930 931 // add entity to model 932 model.requestChange(new MoMLChangeRequest(this, model, vis.toString())); 933 934 // ComponentEntity CA = ((CompositeEntity) 935 // model).getEntity("SplineURL"); 936 // System.out.println(model.exportMoML()); 937 938 // // add links and relations to model. 939 940 // Connect Transmitter's output to dynamic component input. 941 // ///// addRelationAndLinks(model, name+".input", 942 // "Transmitter.output"); 943 addRelationAndLinks(model, name, "input", "Transmitter", "output"); 944 // Connect dynamic component's output to CreatHTML input. 945 // ///// addRelationAndLinks(model, "CreateHTML."+name.toLowerCase(), 946 // name+".output"); 947 addRelationAndLinks(model, "CreateHTML", name.toLowerCase(), name, 948 "output"); 949 } 950 951 /** Create a new relation and connect outP to inP */ 952 private void addRelationAndLinks(NamedObj model, String inComp, String inP, 953 String outComp, String outP) { 954 // search for the first available relation number 955 // CompositeEntity CE = (CompositeEntity)model; 956 957 ComponentEntity inEnt = ((CompositeEntity) model).getEntity(inComp); 958 ComponentPort inPort = (ComponentPort) inEnt.getPort(inP); 959 960 ComponentEntity outEnt = ((CompositeEntity) model).getEntity(outComp); 961 ComponentPort outPort = (ComponentPort) outEnt.getPort(outP); 962 963 try { 964 ComponentRelation rel = ((CompositeEntity) model).connect(outPort, 965 inPort); 966 rel.setContainer((CompositeEntity) model); 967 // System.out.println(rel.exportMoML()); 968 } catch (Exception ex) { 969 ex.printStackTrace(); 970 try { 971 PrintWriter pw = new PrintWriter(new FileWriter(logURL, true)); 972 ex.printStackTrace(pw); 973 pw.close(); 974 } catch (Exception e) { 975 } 976 } 977 978 // model.requestChange(new MoMLChangeRequest(this, model, request)); 979 980 // relNum++; 981 982 } 983 984 /** Create a new relation and connect outP to inP */ 985 /* 986 * private void addRelationAndLinks(NamedObj model, String inP, String outP) 987 * { // search for the first available relation number CompositeEntity CE = 988 * (CompositeEntity)model; while(true) { Relation rel = 989 * CE.getRelation("relation"+relNum); if (rel == null) { break; } else 990 * relNum++; } 991 * 992 * // add relation StringBuffer rels = new StringBuffer(); 993 * rels.append(" <relation name=\"relation"+ relNum + 994 * "\" class=\"ptolemy.actor.TypedIORelation\">\n");rels.append( 995 * " <property name=\"width\" class=\"ptolemy.data.expr.Parameter\" value=\"1\">\n" 996 * ); rels.append(" </property>\n"); 997 * rels.append(" </relation>\n"); 998 * 999 * model.requestChange(new MoMLChangeRequest(this, model, rels.toString())); 1000 * 1001 * // add Transmitter's output to the relation. String request = 1002 * "<link port=\"" + outP + "\" relation=\"relation" + relNum + "\"/>"; 1003 * model.requestChange(new MoMLChangeRequest(this, model, request)); 1004 * 1005 * // connect Transmitter's output to dynamic component input request = 1006 * "<link port=\"" + inP + "\" relation=\"relation" + relNum + "\"/>"; 1007 * model.requestChange(new MoMLChangeRequest(this, model, request)); 1008 * 1009 * relNum++; 1010 * 1011 * } 1012 */ 1013 private StringBuffer createCompositeVis(String name) { 1014 1015 // URL extract component, tried using class file unsuccessfully.. 1016 StringBuffer urlExtractContent = new StringBuffer(); 1017 urlExtractContent 1018 .append(" <property name=\"tag\" class=\"ptolemy.data.expr.StringParameter\" value=\"value\">\n"); 1019 urlExtractContent.append(" </property>\n"); 1020 urlExtractContent 1021 .append(" <port name=\"url\" class=\"ptolemy.actor.TypedIOPort\">\n"); 1022 urlExtractContent.append(" <property name=\"output\"/>\n"); 1023 urlExtractContent.append(" </port>\n"); 1024 urlExtractContent 1025 .append(" <port name=\"xmlStr\" class=\"ptolemy.actor.TypedIOPort\">\n"); 1026 urlExtractContent.append(" <property name=\"input\"/>\n"); 1027 urlExtractContent.append(" </port>\n"); 1028 urlExtractContent 1029 .append(" <entity name=\"TokenToString\" class=\"org.geon.TokenToString\">\n"); 1030 urlExtractContent.append(" </entity>\n"); 1031 urlExtractContent 1032 .append(" <entity name=\"ArrayToElements\" class=\"ptolemy.actor.lib.ArrayToElements\">\n"); 1033 urlExtractContent.append(" </entity>\n"); 1034 urlExtractContent 1035 .append(" <entity name=\"Const2\" class=\"ptolemy.actor.lib.Const\">\n"); 1036 urlExtractContent 1037 .append(" <property name=\"value\" class=\"ptolemy.data.expr.Parameter\" value=\""</"+tag+">"\">\n"); 1038 urlExtractContent.append(" </property>\n"); 1039 urlExtractContent.append(" </entity>\n"); 1040 urlExtractContent 1041 .append(" <entity name=\"imageTag\" class=\"org.sdm.spa.XPath\">\n"); 1042 urlExtractContent 1043 .append(" <property name=\"xpath\" class=\"ptolemy.actor.parameters.PortParameter\" value=\""//" + tag\">\n"); 1044 urlExtractContent.append(" </property>\n"); 1045 urlExtractContent.append(" </entity>\n"); 1046 urlExtractContent 1047 .append(" <entity name=\"StringSubstring\" class=\"ptolemy.actor.lib.string.StringSubstring\">\n"); 1048 urlExtractContent.append(" </entity>\n"); 1049 urlExtractContent 1050 .append(" <entity name=\"Const\" class=\"ptolemy.actor.lib.Const\">\n"); 1051 urlExtractContent 1052 .append(" <property name=\"value\" class=\"ptolemy.data.expr.Parameter\" value=\""<"+tag+">"\">\n"); 1053 urlExtractContent.append(" </property>\n"); 1054 urlExtractContent.append(" </entity>\n"); 1055 urlExtractContent 1056 .append(" <entity name=\"StringIndexOf\" class=\"ptolemy.actor.lib.string.StringIndexOf\">\n"); 1057 urlExtractContent.append(" </entity>\n"); 1058 urlExtractContent 1059 .append(" <entity name=\"StringLength\" class=\"ptolemy.actor.lib.string.StringLength\">\n"); 1060 urlExtractContent.append(" </entity>\n"); 1061 urlExtractContent 1062 .append(" <entity name=\"StringToXML\" class=\"ptolemy.actor.lib.conversions.StringToXML\">\n"); 1063 urlExtractContent.append(" </entity>\n"); 1064 urlExtractContent 1065 .append(" <relation name=\"relation9\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1066 urlExtractContent.append(" </relation>\n"); 1067 urlExtractContent 1068 .append(" <relation name=\"relation8\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1069 urlExtractContent.append(" </relation>\n"); 1070 urlExtractContent 1071 .append(" <relation name=\"relation2\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1072 urlExtractContent.append(" </relation>\n"); 1073 urlExtractContent 1074 .append(" <relation name=\"relation7\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1075 urlExtractContent.append(" </relation>\n"); 1076 urlExtractContent 1077 .append(" <relation name=\"relation11\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1078 // <vertex name="vertex1" value="[260.0, 325.0]"> 1079 // </vertex> 1080 urlExtractContent.append(" </relation>\n"); 1081 urlExtractContent 1082 .append(" <relation name=\"relation6\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1083 urlExtractContent.append(" </relation>\n"); 1084 urlExtractContent 1085 .append(" <relation name=\"relation5\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1086 urlExtractContent.append(" </relation>\n"); 1087 urlExtractContent 1088 .append(" <relation name=\"relation4\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1089 urlExtractContent.append(" </relation>\n"); 1090 urlExtractContent 1091 .append(" <relation name=\"relation\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1092 urlExtractContent.append(" </relation>\n"); 1093 urlExtractContent 1094 .append(" <relation name=\"relation10\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1095 urlExtractContent 1096 .append(" <property name=\"width\" class=\"ptolemy.data.expr.Parameter\" value=\"1\">\n"); 1097 urlExtractContent.append(" </property>\n"); 1098 // <vertex name="vertex1" value="[240.0, 580.0]"> 1099 // </vertex> 1100 urlExtractContent.append(" </relation>\n"); 1101 urlExtractContent 1102 .append(" <link port=\"url\" relation=\"relation4\"/>\n"); 1103 urlExtractContent 1104 .append(" <link port=\"xmlStr\" relation=\"relation10\"/>\n"); 1105 urlExtractContent 1106 .append(" <link port=\"TokenToString.input\" relation=\"relation8\"/>\n"); 1107 urlExtractContent 1108 .append(" <link port=\"TokenToString.output\" relation=\"relation11\"/>\n"); 1109 urlExtractContent 1110 .append(" <link port=\"ArrayToElements.input\" relation=\"relation7\"/>\n"); 1111 urlExtractContent 1112 .append(" <link port=\"ArrayToElements.output\" relation=\"relation8\"/>\n"); 1113 urlExtractContent 1114 .append(" <link port=\"Const2.output\" relation=\"relation6\"/>\n"); 1115 urlExtractContent 1116 .append(" <link port=\"Const2.trigger\" relation=\"relation10\"/>\n"); 1117 urlExtractContent 1118 .append(" <link port=\"imageTag.input\" relation=\"relation\"/>\n"); 1119 urlExtractContent 1120 .append(" <link port=\"imageTag.output\" relation=\"relation7\"/>\n"); 1121 urlExtractContent 1122 .append(" <link port=\"StringSubstring.input\" relation=\"relation11\"/>\n"); 1123 urlExtractContent 1124 .append(" <link port=\"StringSubstring.output\" relation=\"relation4\"/>\n"); 1125 urlExtractContent 1126 .append(" <link port=\"StringSubstring.start\" relation=\"relation2\"/>\n"); 1127 urlExtractContent 1128 .append(" <link port=\"StringSubstring.stop\" relation=\"relation9\"/>\n"); 1129 urlExtractContent 1130 .append(" <link port=\"Const.output\" relation=\"relation5\"/>\n"); 1131 urlExtractContent 1132 .append(" <link port=\"Const.trigger\" relation=\"relation10\"/>\n"); 1133 urlExtractContent 1134 .append(" <link port=\"StringIndexOf.searchFor\" relation=\"relation6\"/>\n"); 1135 urlExtractContent 1136 .append(" <link port=\"StringIndexOf.inText\" relation=\"relation11\"/>\n"); 1137 urlExtractContent 1138 .append(" <link port=\"StringIndexOf.output\" relation=\"relation9\"/>\n"); 1139 urlExtractContent 1140 .append(" <link port=\"StringLength.input\" relation=\"relation5\"/>\n"); 1141 urlExtractContent 1142 .append(" <link port=\"StringLength.output\" relation=\"relation2\"/>\n"); 1143 urlExtractContent 1144 .append(" <link port=\"StringToXML.input\" relation=\"relation10\"/>\n"); 1145 urlExtractContent 1146 .append(" <link port=\"StringToXML.output\" relation=\"relation\"/>\n"); 1147 1148 StringBuffer urlExtract = new StringBuffer(); 1149 urlExtract.append(" <entity name=\"" + name 1150 + "URL\" class=\"ptolemy.actor.TypedCompositeActor\">\n"); 1151 urlExtract.append(urlExtractContent.toString()); 1152 urlExtract.append(" </entity>\n"); 1153 1154 // Global Mapper web service. 1155 StringBuffer GlobalMapper = new StringBuffer(); 1156 GlobalMapper.append(" <entity name=\"" + name 1157 + "GM\" class=\"org.sdm.spa.WebService\">\n"); 1158 GlobalMapper 1159 .append(" <property name=\"wsdlUrl\" class=\"ptolemy.data.expr.StringParameter\" "); 1160 GlobalMapper 1161 .append("value=\"http://titan.geongrid.org:8080/axis/services/GlobalMapper?wsdl\">\n"); 1162 GlobalMapper.append(" </property>\n"); 1163 GlobalMapper 1164 .append(" <property name=\"methodName\" class=\"ptolemy.data.expr.StringParameter\" "); 1165 GlobalMapper.append("value=\"getImageForGridAscii\">\n"); 1166 GlobalMapper.append(" </property>\n"); 1167 GlobalMapper 1168 .append(" <port name=\"in0\" class=\"ptolemy.actor.TypedIOPort\">\n"); 1169 GlobalMapper.append(" <property name=\"input\"/>\n"); 1170 GlobalMapper.append(" </port>\n"); 1171 GlobalMapper 1172 .append(" <port name=\"getImageForGridAsciiReturn\" class=\"ptolemy.actor.TypedIOPort\">\n"); 1173 GlobalMapper.append(" <property name=\"output\"/>\n"); 1174 GlobalMapper.append(" </port>\n"); 1175 GlobalMapper.append(" </entity>\n"); 1176 1177 // Setting up the composite of GM and extract URL 1178 StringBuffer vis = new StringBuffer(); 1179 vis.append("<entity name=\"" + name 1180 + "\" class=\"ptolemy.actor.TypedCompositeActor\">\n"); 1181 vis 1182 .append(" <port name=\"input\" class=\"ptolemy.actor.TypedIOPort\">\n"); 1183 vis.append(" <property name=\"input\"/>\n"); 1184 vis.append(" </port>\n"); 1185 vis 1186 .append(" <port name=\"output\" class=\"ptolemy.actor.TypedIOPort\">\n"); 1187 vis.append(" <property name=\"output\"/>\n"); 1188 vis.append(" </port>\n"); 1189 1190 // add the entities. 1191 vis.append(urlExtract.toString()); 1192 vis.append(GlobalMapper.toString()); 1193 1194 // add the links and relations 1195 vis 1196 .append(" <relation name=\"relation4\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1197 vis 1198 .append(" <property name=\"width\" class=\"ptolemy.data.expr.Parameter\" value=\"1\">\n"); 1199 vis.append(" </property>\n"); 1200 vis.append(" </relation>\n"); 1201 vis 1202 .append(" <relation name=\"relation3_1\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1203 vis.append(" </relation>\n"); 1204 vis 1205 .append(" <relation name=\"relation7_4\" class=\"ptolemy.actor.TypedIORelation\">\n"); 1206 vis.append(" </relation>\n"); 1207 vis.append(" <link port=\"input\" relation=\"relation7_4\"/>\n"); 1208 vis.append(" <link port=\"output\" relation=\"relation3_1\"/>\n"); 1209 vis.append(" <link port=\"" + name 1210 + "URL.url\" relation=\"relation3_1\"/>\n"); 1211 vis.append(" <link port=\"" + name 1212 + "URL.xmlStr\" relation=\"relation4\"/>\n"); 1213 vis.append(" <link port=\"" + name 1214 + "GM.in0\" relation=\"relation7_4\"/>\n"); 1215 vis.append(" <link port=\"" + name 1216 + "GM.getImageForGridAsciiReturn\" relation=\"relation4\"/>\n"); 1217 vis.append("</entity>\n"); 1218 1219 return vis; 1220 1221 // System.out.println(urlExtract.toString()); 1222 1223 } 1224 1225 /** Enumerate relations */ 1226 private int relNum = 2; 1227 1228 /** specify whether the user selected download formats */ 1229 private String download = "0"; 1230 1231 // private String xml = ""; 1232 1233 /** Execution uniqueId */ 1234 private String uniqueId = ""; 1235 1236 /** Remote application path */ 1237 private String appPath = ""; 1238 1239 static public void main(String args[]) throws Exception { 1240 System.out.println("init"); 1241 String inputWF = "file://C:/Projects/kepler/workflows/geo/lidar/lidarTemplate.xml"; 1242 File momlFile = new File(inputWF); 1243 System.out.println("BEFORE!!"); 1244 LidarWorkflowExecute we = new LidarWorkflowExecute(); 1245 1246 Map inputs = new TreeMap(); 1247 inputs.put("id", "1"); 1248 1249 // UPDATE PATH!!!!!! 1250 inputs.put("appPath", "C:/Projects/kepler/workflows/geo/lidar/"); 1251 inputs.put("elevarc", "1"); 1252 inputs.put("slopearc", "0"); 1253 inputs.put("aspectarc", "0"); 1254 inputs.put("pcurvarc", "0"); 1255 inputs.put("elevview", "1"); 1256 inputs.put("slopeview", "1"); 1257 inputs.put("pcurvview", "1"); 1258 inputs.put("elevtiff", "1"); 1259 1260 try { 1261 String res = ""; 1262 we.execute(inputWF, inputs); 1263 System.out.println(res); 1264 System.out.println("AFTER"); 1265 1266 } catch (Exception ex) { 1267 ex.printStackTrace(); 1268 try { 1269 PrintWriter pw = new PrintWriter(new FileWriter(logURL, true)); 1270 ex.printStackTrace(pw); 1271 pw.close(); 1272 } catch (Exception e) { 1273 } 1274 } 1275 } 1276 1277 public void _log(String log) { 1278 try { 1279 File logFile = new File(logURL); 1280 FileWriter fw = new FileWriter(logFile, true); 1281 fw.write(log); 1282 fw.flush(); 1283 fw.close(); 1284 } catch (IOException ioex) { 1285 System.out.println("Unable to write " + log + " to " + logURL 1286 + ".\n" + ioex.getMessage()); 1287 } 1288 } 1289 1290 private static String logURL = System.getProperty("user.home") 1291 + File.separator + ".lidar" + File.separator + "lidarLog"; 1292}