Пример #1
0
 private static String getSelectedColumnsUpdate(String selectedColumns) {
   String update = null;
   if (StringUtils.isEmpty(selectedColumns)) {
     return "*";
   } else {
     boolean hasRa = false, hasDec = false;
     String[] cols = selectedColumns.split(",");
     for (String col : cols) {
       if (col.equalsIgnoreCase(RA_COL)) {
         hasRa = true;
         if (hasDec) break;
       } else if (col.equalsIgnoreCase(DEC_COL)) {
         hasDec = true;
         if (hasRa) break;
       }
     }
     if (!hasRa) {
       update = selectedColumns + ",ra";
     }
     if (!hasDec) {
       update = (update == null ? selectedColumns : update) + ",decl";
     }
     return update;
   }
 }
Пример #2
0
  static void initPlotTitle(
      PlotState state,
      ImagePlot plot,
      ActiveFitsReadGroup frGroup,
      String dataDesc,
      boolean isMultiImage) {
    WebPlotRequest req = state.getPrimaryWebPlotRequest();
    WebPlotRequest.TitleOptions titleOps = req.getTitleOptions();
    String headerKey = req.getHeaderKeyForTitle();
    if ((isMultiImage
            && (titleOps == WebPlotRequest.TitleOptions.NONE
                || titleOps == WebPlotRequest.TitleOptions.FILE_NAME))
        || (titleOps == WebPlotRequest.TitleOptions.HEADER_KEY && StringUtils.isEmpty(headerKey))) {
      titleOps = WebPlotRequest.TitleOptions.HEADER_KEY;
      headerKey = "EXTNAME";
    }
    String s = req.getPlotDescAppend();
    plot.setPlotDesc("");
    Header header = frGroup.getFitsRead(state.firstBand()).getHeader();

    switch (titleOps) {
      case NONE:
        plot.setPlotDesc("");
        break;
      case PLOT_DESC:
        String base = req.getTitle() == null ? "" : req.getTitle();
        plot.setPlotDesc(base + dataDesc);
        break;
      case FILE_NAME:
        break;
      case HEADER_KEY:
        HeaderCard card = header.findCard(headerKey);
        if (card == null && state.getCubeCnt(state.firstBand()) > 0) {
          card = header.findCard("PLANE" + state.getImageIdx(state.firstBand()));
        }
        String hTitle = card != null ? card.getValue() : "";
        plot.setPlotDesc(hTitle);
        break;
      case PLOT_DESC_PLUS:
        plot.setPlotDesc(req.getTitle() + (s != null ? " " + s : ""));
        break;
      case SERVICE_OBS_DATE:
        if (req.getRequestType() == RequestType.SERVICE) {
          //                    String desc= req.getServiceType()== WebPlotRequest.ServiceType.WISE
          // ? MID_OBS : OBS_DATE;
          String title =
              req.getTitle()
                  + ": "
                  +
                  //                                  desc + ": " +
                  PlotServUtils.getDateValueFromServiceFits(req.getServiceType(), header);
          plot.setPlotDesc(title);
        }
        break;
    }
  }
Пример #3
0
 public void addButton(Button button, Align align, int idx, String width) {
   TTabBar tb =
       align == Align.LEFT ? leftToolbar : align == Align.CENTER ? centerToolbar : rightToolbar;
   idx = idx < 0 || idx > tb.getTabCount() ? tb.getTabCount() : idx;
   tb.insertTab(button.asWidget(), idx);
   TabBar.Tab t = tb.getTab(idx);
   tabs.put(button.getName(), new TabHolder(t, button, tb));
   width = StringUtils.isEmpty(width) ? defaultWidth : width;
   GwtUtil.setStyle(button.asWidget(), "minWidth", width);
 }
Пример #4
0
 private void checkForChange() {
   String sval = getValue();
   boolean isDefault = StringUtils.areEqual(sval, getFieldDef().getDefaultValueAsString());
   // do not validate default
   if (isDefault || validate()) {
     if (!ComparisonUtil.equals(_lastInput, sval)) {
       ValueChangeEvent.fire(this, sval);
       _lastInput = sval;
     }
   }
 }
Пример #5
0
  protected void setColumnTips(TableMeta meta, ServerRequest request) {

    TableServerRequest req = new TableServerRequest("LSSTCatalogDD");
    req.setPageSize(1000);
    req.setParam(CatalogRequest.CATALOG, request.getParam(ServerParams.REQUESTED_DATA_SET));

    SearchManager sm = new SearchManager();
    DataGroupPart dgp = new DataGroupPart();

    try {
      dgp = sm.getDataGroup(req);
    } catch (Exception e) {
    }

    DataGroup dg = dgp.getData();
    if (dg != null) {
      for (int i = 0; i < dg.size(); i++) {
        DataObject dObj = dg.get(i);
        String tipStr = "";

        String descStr = (String) dObj.getDataElement("description");
        if (!StringUtils.isEmpty(descStr) && !descStr.equalsIgnoreCase("null")) {
          tipStr += descStr;
        }

        String unitStr = (String) dObj.getDataElement("unit");
        if (!StringUtils.isEmpty(unitStr) && !unitStr.equalsIgnoreCase("null")) {
          if (tipStr.length() > 0) {
            tipStr += " ";
          }
          tipStr += "(" + unitStr + ")";
        }

        String nameStr = (String) dObj.getDataElement("name");
        meta.setAttribute(makeAttribKey(DESC_TAG, nameStr.toLowerCase()), tipStr);
      }
    }
  }
Пример #6
0
  // qserv_areaspec_circle does not work at the moment, only qserv_areaspec_box works
  void doGetData(File oFile, List<Param> params, WorldPt wpt) throws DataAccessException {
    DbInstance dbinstance =
        new DbInstance(
            false, // pooled
            "null", // datasourcePath
            QSERV_URI, // dbUrl
            QSERV_USER,
            StringUtils.isEmpty(QSERV_PASS) ? null : QSERV_PASS,
            "com.mysql.jdbc.Driver",
            "lsstdb");
    DataSource ds = JdbcFactory.getDataSource(dbinstance);

    String searchMethod = null;
    String catTable = null;
    String selectedColumns = null;
    String[] constraints = null;
    for (Param p : params) {
      String pname = p.getName();
      if (pname.equals(CatalogRequest.SEARCH_METHOD)) {
        searchMethod = p.getValue();
      } else if (pname.equals(ServerParams.REQUESTED_DATA_SET)) {
        catTable = p.getValue();
      } else if (pname.equals(CatalogRequest.SELECTED_COLUMNS)) {
        selectedColumns = p.getValue();
      } else if (pname.equals(CatalogRequest.CONSTRAINTS)) {
        String val = p.getValue();
        if (!StringUtils.isEmpty(val)) {
          _log.briefDebug("CONSTRAINTS: " + val);
          constraints = val.split(",");
        }
      }
    }

    String update = getSelectedColumnsUpdate(selectedColumns);
    if (update != null) selectedColumns = update;

    String pname;
    String sql;
    if (searchMethod != null && searchMethod.equals(CatalogRequest.Method.CONE.getDesc())) {
      double radius = 0.0;
      for (Param p : params) {
        pname = p.getName();
        if (pname.equals(CatalogRequest.RADIUS)) {
          radius = Double.parseDouble(p.getValue());
        }
      }
      // qserv_areaspec_circle(ra, dec, radius)
      // sql="select * from "+catTable+" where qserv_areaspec_circle("+wpt.getLon()+",
      // "+wpt.getLat()+", "+radius+")";
      // Per Serge, the above query only can not be applied to unpartitioned table
      sql =
          "select "
              + selectedColumns
              + " from "
              + catTable
              + " where scisql_s2PtInCircle(ra, decl, "
              + wpt.getLon()
              + ", "
              + wpt.getLat()
              + ", "
              + radius
              + ")=1";
    } else if (searchMethod != null && searchMethod.equals(CatalogRequest.Method.BOX.getDesc())) {
      double size = 0.0;
      for (Param p : params) {
        pname = p.getName();
        if (pname.equals(CatalogRequest.SIZE)) {
          size = Double.parseDouble(p.getValue());
        }
      }
      double halfsize = size / 2.0;
      double lon1 = wpt.getLon() - halfsize;
      if (lon1 < 0) lon1 += 360;
      double lon2 = wpt.getLon() + halfsize;
      if (lon2 > 360) lon1 -= 360;
      double lat1 = wpt.getLat() - halfsize;
      if (lat1 < -90) lat1 = -180 - lat1;
      double lat2 = wpt.getLat() + halfsize;
      if (lat2 > 90) lat2 = 180 - lat2;

      // qserv_areaspec_box(raA, decA, raB, decB)
      // sql="select * from "+catTable+" where qserv_areaspec_box("+lon1+", "+lat1+", "+lon2+",
      // "+lat2+")";
      // Per Serge, the above query only can not be applied to unpartitioned table
      sql =
          "select * from "
              + catTable
              + " where scisql_s2PtInBox(ra, decl, "
              + lon1
              + ", "
              + lat1
              + ", "
              + lon2
              + ", "
              + lat2
              + ")=1";

    } else {
      throw new RuntimeException(searchMethod + " search is not Implemented");
    }

    // add additional constraints
    if (constraints != null) {
      for (String constr : constraints) {
        sql += " and " + constr;
      }
    }

    // workaround for https://jira.lsstcorp.org/browse/DM-1841
    sql += " LIMIT 3000";

    Connection conn = null;
    Statement stmt = null;
    try {
      conn = DataSourceUtils.getConnection(ds);
      long cTime = System.currentTimeMillis();
      stmt = conn.createStatement();
      _log.briefDebug("Executing SQL query: " + sql);
      // ResultSet rs = stmt.executeQuery(sql);
      IpacTableExtractor.query(null, ds, oFile, 10000, sql);
      _log.briefDebug("SELECT took " + (System.currentTimeMillis() - cTime) + "ms");
    } catch (Exception e) {
      _log.error(e);
      throw new DataAccessException("Query failed: " + e.getMessage());
    } finally {
      if (stmt != null) {
        try {
          closeStatement(stmt);
        } catch (Exception e1) {
        }
      }
      if (conn != null) {
        DataSourceUtils.releaseConnection(conn, ds);
      }
    }
  }
Пример #7
0
  public void layout() {

    // clear any backgrounded processes.
    for (Timer t : bgList) {
      t.cancel();
    }

    table = new FlexTable();
    mainPanel.clear();
    if (!StringUtils.isEmpty(name) || !StringUtils.isEmpty(helpId)) {

      String n = StringUtils.isEmpty(name) ? "" : name.trim();
      HorizontalPanel h = new HorizontalPanel();
      h.setWidth("100%");
      HTML lname = new HTML("<b>" + n + "</b>");
      if (shortDesc != null) {
        lname.setTitle(shortDesc);
      }
      GwtUtil.setStyles(lname, "textAlign", "center");
      h.add(lname);
      h.setCellWidth(lname, "100%");

      if (!StringUtils.isEmpty(helpId)) {
        final Widget helpIcon = HelpManager.makeHelpIcon(helpId);
        h.add(helpIcon);
        GwtUtil.setStyles(helpIcon, "marginRight", "11px");
      }
      mainPanel.addNorth(h, 20);
    }

    // setup group by selection
    if (groupByCols != null && groupByCols.size() > 1) {
      EnumFieldDef gb = new EnumFieldDef("groupBy");
      gb.setLabel("Group By");
      gb.setDesc("Select a group by column to update the data table");
      gb.setPreferWidth(200);
      gb.setDefaultValue(curGroupByName);
      for (TableDataView.Column item : headers) {
        if (groupByCols.contains(item.getName())) {
          gb.addItem(item.getName(), item.getTitle());
        }
      }
      final SimpleInputField sif = SimpleInputField.createByDef(gb);
      mainPanel.addNorth(sif, 28);
      sif.getField()
          .addValueChangeHandler(
              new ValueChangeHandler() {
                public void onValueChange(ValueChangeEvent ve) {
                  curGroupByName = sif.getValue();
                  layout();
                }
              });
    }

    ScrollPanel sp = new ScrollPanel();
    sp.add(table);

    mainPanel.add(sp);

    table.setStyleName("firefly-summary-table");
    table.setSize("100%", "100%");
    iconColIdx = headers.size();
    String titleCol = null;

    // render headers
    int colIdx = 0;
    for (int i = 0; i < headers.size(); i++) {
      TableDataView.Column col = headers.get(i);
      if (curGroupByName == null || !curGroupByName.equals(col.getName())) {
        table.setText(0, colIdx, col.getTitle());
        table.getCellFormatter().setStyleName(0, colIdx, "title-bar");
        colIdx++;
        if (titleCol == null) {
          titleCol = col.getName();
        }
      }
    }
    table.setText(0, headers.size(), "");
    table.getCellFormatter().setWidth(0, headers.size(), "100%");

    ArrayList<SearchSummaryItem> itemList = searchItems;

    if (!StringUtils.isEmpty(curGroupByName)) {
      itemList = new ArrayList<SearchSummaryItem>();

      GroupFinder finder = new GroupFinder("");
      List<GroupedSummaryItem> groupList = new ArrayList<GroupedSummaryItem>();
      for (int i = 0; i < searchItems.size(); i++) {
        SearchSummaryItem dsi = searchItems.get(i);
        String cGroupValue = dsi.getValue(curGroupByName);
        GroupedSummaryItem cGroup =
            CollectionUtil.findFirst(groupList, finder.setName(cGroupValue));
        if (cGroup == null) {
          cGroup = new GroupedSummaryItem(cGroupValue);
          groupList.add(cGroup);
          itemList.add(cGroup);
        }
        cGroup.addChild(dsi);
      }
    }

    for (SearchSummaryItem ssi : itemList) {
      ssi.setTitleCol(titleCol);
      layout(ssi, 0);
    }
  }