예제 #1
0
  private void splitJourneyLocation(
      ConcurrentMap<String, IRI> variableTypes,
      List<LDObject> journeyLocation,
      List<LDObject> journeyDatas,
      BindingSet bindings) {
    LDObject locationsData = new LDObject();
    LDObject journeyData = new LDObject();

    bindings
        .getBindingNames()
        .stream()
        .forEach(
            bindingName -> {
              org.openrdf.model.Value value = bindings.getBinding(bindingName).getValue();
              QueryResultsParser.updateVariableTypes(variableTypes, bindingName, value);

              if (Arrays.asList("id", "creationDate", "name", "status").contains(bindingName)) {
                journeyData.addKeyValue(new KeyValue(bindingName, value.stringValue()));
              } else {
                locationsData.addKeyValue(new KeyValue(bindingName, value.stringValue()));
              }

              if ("locationId".equalsIgnoreCase(bindingName)) {
                journeyData.addKeyValue(new KeyValue(bindingName, value.stringValue()));
              }
            });

    journeyLocation.add(locationsData);
    journeyDatas.add(journeyData);
  }
예제 #2
0
  /**
   * Execute a SELECT SPARQL query against the graphs
   *
   * @param qs SELECT SPARQL query
   * @return list of solutions, each containing a hashmap of bindings
   */
  public List<HashMap<String, Value>> runSPARQL(String qs) {
    try {
      RepositoryConnection con = currentRepository.getConnection();
      try {
        TupleQuery query = con.prepareTupleQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
        TupleQueryResult qres = query.evaluate();
        ArrayList<HashMap<String, Value>> reslist = new ArrayList<HashMap<String, Value>>();
        while (qres.hasNext()) {
          BindingSet b = qres.next();

          Set<String> names = b.getBindingNames();
          HashMap<String, Value> hm = new HashMap<String, Value>();
          for (String n : names) {
            hm.put(n, b.getValue(n));
          }
          reslist.add(hm);
        }
        return reslist;
      } finally {
        con.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
예제 #3
0
    public static ArrayList<QueryData> parseOSMOQueryData(TupleQueryResult qres) {
      ArrayList<QueryData> queryDataList = new ArrayList<QueryData>();

      try {
        while (qres.hasNext()) {
          BindingSet b = qres.next();
          Set names = b.getBindingNames();
          QueryData queryData = new QueryData();

          for (Object n : names) {
            if (((String) n).equalsIgnoreCase("queryID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              queryData.setId(str);
              System.out.print("srvcStatus id: " + queryData.getId() + " ");
            } else if (((String) n).equalsIgnoreCase("queryString")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              queryData.setQueryString(str);
              System.out.print("srvcStatusTime : " + queryData.getQueryString() + " ");
            }
          }
          queryDataList.add(queryData);
        } // while
        return queryDataList;
      } catch (QueryEvaluationException e) {
        e.printStackTrace();
        return null;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }
예제 #4
0
  protected int verifyQueryResult(
      CloseableIteration<? extends BindingSet, QueryEvaluationException> resultIter,
      int expectedBindingCount)
      throws QueryEvaluationException {
    int resultCount = 0;

    while (resultIter.hasNext()) {
      BindingSet resultBindings = resultIter.next();
      resultCount++;

      assertEquals(
          "Wrong number of binding names for binding set",
          expectedBindingCount,
          resultBindings.getBindingNames().size());

      int bindingCount = 0;
      Iterator<Binding> bindingIter = resultBindings.iterator();
      while (bindingIter.hasNext()) {
        bindingIter.next();
        bindingCount++;
      }

      assertEquals("Wrong number of bindings in binding set", expectedBindingCount, bindingCount);
    }

    return resultCount;
  }
  @Override
  protected BindingSet getNextElement() throws QueryEvaluationException {
    if (hashTable == null) {
      setupHashTable();
    }

    while (currentScanElem == null) {
      if (scanList.size() > 0) {
        currentScanElem = scanList.remove(0);
      } else {
        if (restIter.hasNext()) {
          currentScanElem = restIter.next();
        } else {
          // no more elements available
          return null;
        }
      }

      if (currentScanElem instanceof EmptyBindingSet) {
        // the empty bindingset should be merged with all bindingset in
        // the hash table
        hashTableValues = new ArrayList<BindingSet>();
        for (BindingSet key : hashTable.keySet()) {
          hashTableValues.addAll(hashTable.get(key));
        }
      } else {
        BindingSet key = calcKey(currentScanElem, joinAttributes);

        if (hashTable.containsKey(key)) {
          hashTableValues = new ArrayList<BindingSet>(hashTable.get(key));
        } else {
          currentScanElem = null;
          hashTableValues = null;
        }
      }
    }

    BindingSet nextHashTableValue = hashTableValues.remove(0);

    QueryBindingSet result = new QueryBindingSet(currentScanElem);

    for (String name : nextHashTableValue.getBindingNames()) {
      Binding b = nextHashTableValue.getBinding(name);
      if (!result.hasBinding(name)) {
        result.addBinding(b);
      }
    }

    if (hashTableValues.size() == 0) {
      // we've exhausted the current scanlist entry
      currentScanElem = null;
      hashTableValues = null;
    }

    return result;
  }
예제 #6
0
    public static RootOAMOData parseOAMORootData(TupleQueryResult qres) {
      RootOAMOData rootOAMOData = new RootOAMOData();

      try {
        // while (qres.hasNext())
        // {
        BindingSet b = qres.next();
        Set names = b.getBindingNames();

        for (Object n : names) {
          if (((String) n).equalsIgnoreCase("oamoName")) {
            String str =
                (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
            rootOAMOData.setOamoName(str);
            System.out.print("oamoName: " + rootOAMOData.getOamoName());
          } else if (((String) n).equalsIgnoreCase("userID")) {
            String str =
                (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
            rootOAMOData.setUserID(str);
            System.out.print("userID: " + rootOAMOData.getUserID());
          }
          // else if(((String) n).equalsIgnoreCase("serviceID"))
          // {
          // String str = (b.getValue((String) n)==null) ? null :
          // b.getValue((String) n).stringValue();
          // rootOAMOData.setServiceID(str);
          // System.out.print("serviceID: "+rootOAMOData.getServiceID());
          // }
          else if (((String) n).equalsIgnoreCase("oamoDesc")) {
            String str =
                (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
            rootOAMOData.setOamoDesc(str);
            System.out.println("oamoDesc : " + rootOAMOData.getOamoDesc() + " ");
          } else if (((String) n).equalsIgnoreCase("oamoGraphMeta")) {
            String str =
                (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
            rootOAMOData.setOamoGraphMeta(str);
            System.out.println("oamoGraphMeta : " + rootOAMOData.getOamoGraphMeta() + " ");
          }
        }
        // }//while
        return rootOAMOData;
      } catch (QueryEvaluationException e) {
        e.printStackTrace();
        return null;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }
예제 #7
0
    public static ArrayList<WidgetPresentationData> parseWidgetPreListByService(
        TupleQueryResult qres) {
      ArrayList<WidgetPresentationData> widgetPresentationDataList =
          new ArrayList<WidgetPresentationData>();
      try {
        while (qres.hasNext()) {
          BindingSet b = qres.next();
          Set names = b.getBindingNames();
          WidgetPresentationData widgetPreData = new WidgetPresentationData();

          for (Object n : names) {
            if (((String) n).equalsIgnoreCase("widgetPreID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              widgetPreData.setId(str);
              System.out.print("widgetPreID: " + widgetPreData.getId() + " ");
            } else if (((String) n).equalsIgnoreCase("widgetID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              widgetPreData.setWidgetID(str);
              System.out.print("widgetID: " + widgetPreData.getWidgetID() + " ");
            } else if (((String) n).equalsIgnoreCase("widgetAttrID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              widgetPreData.setWidgetAttrID(str);
              System.out.print("widgetAttr: " + widgetPreData.getWidgetAttrID() + " ");
            }
          }
          widgetPresentationDataList.add(widgetPreData);
        } // while
        return widgetPresentationDataList;
      } catch (QueryEvaluationException e) {
        e.printStackTrace();
        return null;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }
예제 #8
0
    public static ArrayList<RootOsmoData> parseOSMOListOfOAMO(TupleQueryResult qres) {
      ArrayList<RootOsmoData> osmoDataList = new ArrayList<RootOsmoData>();

      try {
        while (qres.hasNext()) {
          BindingSet b = qres.next();
          Set names = b.getBindingNames();

          RootOsmoData osmoData = new RootOsmoData();

          for (Object n : names) {
            if (((String) n).equalsIgnoreCase("serviceID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              osmoData.setId(str);
              System.out.print("serviceID: " + osmoData.getId() + " ");
            } else if (((String) n).equalsIgnoreCase("srvcName")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              osmoData.setName(str);
              System.out.print("srvcName : " + osmoData.getName() + " ");
            } else if (((String) n).equalsIgnoreCase("srvcDesc")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              osmoData.setDesc(str);
              System.out.print("srvcDesc : " + osmoData.getDesc() + " ");
            }
          }
          osmoDataList.add(osmoData);
        } // while
        return osmoDataList;
      } catch (QueryEvaluationException e) {
        e.printStackTrace();
        return null;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }
예제 #9
0
    public static ArrayList<WidgetAttr> parseWidgetAttributes(TupleQueryResult qres) {
      ArrayList<WidgetAttr> widgetAttrList = new ArrayList<WidgetAttr>();
      try {
        while (qres.hasNext()) {
          BindingSet b = qres.next();
          Set names = b.getBindingNames();
          WidgetAttr widgetAttr = new WidgetAttr();

          for (Object n : names) {
            if (((String) n).equalsIgnoreCase("widgetAttrID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              widgetAttr.setId(str);
              System.out.print("widgetattr id: " + widgetAttr.getId() + " ");
            } else if (((String) n).equalsIgnoreCase("widgetAttrName")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              widgetAttr.setName(str);
              System.out.print("widgetAttrName: " + widgetAttr.getName() + " ");
            } else if (((String) n).equalsIgnoreCase("widgetAttrDesc")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              widgetAttr.setValue(str);
              System.out.print("widgetAttrDesc: " + widgetAttr.getValue() + " ");
            }
          }
          widgetAttrList.add(widgetAttr);
        } // while
        return widgetAttrList;
      } catch (QueryEvaluationException e) {
        e.printStackTrace();
        return null;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }
예제 #10
0
    public static ArrayList<ServiceStatusData> parseServiceStatusOfOSMO(TupleQueryResult qres) {
      ArrayList<ServiceStatusData> serviceStatusDataList = new ArrayList<ServiceStatusData>();
      try {
        while (qres.hasNext()) {
          BindingSet b = qres.next();
          Set names = b.getBindingNames();
          ServiceStatusData srvcStatusData = new ServiceStatusData();

          for (Object n : names) {
            if (((String) n).equalsIgnoreCase("srvcStatusID")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              srvcStatusData.setSrvcStatusID(str);
              System.out.print("srvcStatus id: " + srvcStatusData.getSrvcStatusID() + " ");
            } else if (((String) n).equalsIgnoreCase("srvcStatusTime")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              srvcStatusData.setSrvcStatusTime(str);
              System.out.print("srvcStatusTime : " + srvcStatusData.getSrvcStatusTime() + " ");
            } else if (((String) n).equalsIgnoreCase("srvcStatus")) {
              String str =
                  (b.getValue((String) n) == null) ? null : b.getValue((String) n).stringValue();
              srvcStatusData.setSrvcStatus(str);
              System.out.print("srvcStatusStatus : " + srvcStatusData.getSrvcStatus() + " ");
            }
          }
          serviceStatusDataList.add(srvcStatusData);
        } // while
        return serviceStatusDataList;
      } catch (QueryEvaluationException e) {
        e.printStackTrace();
        return null;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }