Exemple #1
0
  public Object create(Request request, Response response) throws Exception {
    final Map<String, String[]> project = request.queryMap("project").toMap();

    Project p = Project.fromMap(project);

    repository.save(p);

    response.redirect("/#/index/dashboard");
    return null;
  }
  /** get task statistics */
  public static Collection<TaskStatistics> stats(Request req, Response res) {
    // implement lots of filters
    ArrayList<Set<Long>> filters = new ArrayList<>();

    Map<String, String[]> qpm = req.queryMap().toMap();
    if (qpm.containsKey("commit")) {
      String commit = qpm.get("commit")[0];

      // java loses the type information from subset (probably due to the raw types) so we
      // add an explicit cast
      filters.add(
          ((Set<Fun.Tuple2<String, Long>>)
                  StatsMain.store.commit.subSet(
                      new Fun.Tuple2(commit, null), new Fun.Tuple2(commit, Fun.HI)))
              .stream()
              .map(t -> t.b)
              .collect(Collectors.toSet()));
    }

    // instance type
    if (qpm.containsKey("instanceType")) {
      String instanceType = qpm.get("instanceType")[0];

      filters.add(
          ((Set<Fun.Tuple2<String, Long>>)
                  StatsMain.store.instanceType.subSet(
                      new Fun.Tuple2(instanceType, null), new Fun.Tuple2(instanceType, Fun.HI)))
              .stream()
              .map(t -> t.b)
              .collect(Collectors.toSet()));
    }

    // graph ID
    if (qpm.containsKey("graphId")) {
      String graphId = qpm.get("graphId")[0];

      filters.add(
          ((Set<Fun.Tuple2<String, Long>>)
                  StatsMain.store.graphId.subSet(
                      new Fun.Tuple2(graphId, null), new Fun.Tuple2(graphId, Fun.HI)))
              .stream()
              .map(t -> t.b)
              .collect(Collectors.toSet()));
    }

    // job ID
    if (qpm.containsKey("jobId")) {
      String jobId = qpm.get("jobId")[0];

      filters.add(
          ((Set<Fun.Tuple2<String, Long>>)
                  StatsMain.store.jobId.subSet(
                      new Fun.Tuple2(jobId, null), new Fun.Tuple2(jobId, Fun.HI)))
              .stream()
              .map(t -> t.b)
              .collect(Collectors.toSet()));
    }

    // single point
    if (qpm.containsKey("single")) {
      Boolean singlePoint = Boolean.parseBoolean(qpm.get("single")[0]);

      // we want single point requests: we already have a map for that
      if (singlePoint) filters.add(StatsMain.store.singlePoint);

      // invert the set
      else
        filters.add(
            new StatsStore.InvertedSet<>(StatsMain.store.singlePoint, StatsMain.store.data));
    }

    // isochrone
    if (qpm.containsKey("isochrone")) {
      Boolean isochrone = Boolean.parseBoolean(qpm.get("isochrone")[0]);

      // we want isochrone requests: we already have a map for that
      if (isochrone) filters.add(StatsMain.store.isochrone);

      // invert the set
      else
        filters.add(new StatsStore.InvertedSet<>(StatsMain.store.isochrone, StatsMain.store.data));
    }

    if (filters.isEmpty()) return StatsMain.store.data.values();

    Collection<Long> ret = StatsStore.intersect(filters);

    return ret.stream().map(id -> StatsMain.store.data.get(id)).collect(Collectors.toList());
  }