@Override
  public IValue execute(Command command, ISession session) throws ThinklabException {

    String concept = command.getArgumentAsString("concept");

    IKBox kbox = KBoxManager.get();
    if (command.hasOption("kbox"))
      kbox = KBoxManager.get().requireGlobalKBox(command.getOptionAsString("kbox"));

    ArrayList<Topology> extents = new ArrayList<Topology>();

    IContext context = null;
    if (!command.getArgumentAsString("context").equals("_NONE_")) {
      context = ModelFactory.get().requireContext(command.getArgumentAsString("context"));
    }

    Constraint c = new Constraint(CoreScience.Observation());

    IInstance inst = session.createObject(Polylist.list(concept));
    c =
        c.restrict(
            new Restriction(
                CoreScience.HAS_OBSERVABLE, new DefaultConformance().getConstraint(inst)));

    if (context != null) {

      ArrayList<Restriction> er = new ArrayList<Restriction>();
      for (IExtent o : context.getExtents()) {
        Restriction r = o.getConstraint("intersects");
        if (r != null) er.add(r);
      }

      if (er.size() > 0) {
        c =
            c.restrict(
                er.size() == 1
                    ? er.get(0)
                    : Restriction.AND(er.toArray(new Restriction[er.size()])));
      }
    }

    IQueryResult r = kbox.query(c);

    session.getOutputStream().print(r.getTotalResultCount() + " possible observation(s) found");

    for (int i = 0; i < r.getTotalResultCount(); i++) {
      Polylist o = r.getResultAsList(i, null);
      session.print(" --- Observation " + i + " ----------------\n");
      session.print(Polylist.prettyPrint(o));
      session.print("\n");
    }

    return null;
  }
Example #2
0
    @Override
    public ListModel getSubModel(Object value, int nRows) {

      final String name = value == null ? "" : value.toString().trim();
      if (nRows < 0) nRows = 20;

      ArrayList<ARIESUserModel.Location> ret = new ArrayList<ARIESUserModel.Location>();

      if (name.isEmpty() && defaultValues != null) {
        ret.addAll(defaultValues);
      } else if (!name.isEmpty()) {
        try {
          IQueryResult qr = null;
          try {
            qr = Geospace.get().lookupFeature(name);
          } catch (ThinklabInvalidQueryException e) {
            // this will catch query compile errors if users write
            // strange characters or are in between writing complex
            // queries with parentheses
          }
          if (qr != null) {
            for (int i = 0; i < nRows && i < qr.getTotalResultCount(); i++) {

              ARIESUserModel.Location r = new ARIESUserModel.Location();
              r.id = qr.getResultField(i, "id");
              r.label = qr.getResultField(i, "label");
              r.description = qr.getResultField(i, "description");
              ret.add(r);
            }
          }
        } catch (ThinklabException e) {
          throw new ThinklabRuntimeException(e);
        }
      }
      ListModel rt = new SimpleListModel(ret);
      return rt;
    }