Exemplo n.º 1
0
  private void onEvent(NexusDao dao, HasNexusEvent e) throws SQLException {

    NexusEvent event = e.event;

    String repositoryId =
        event.guid.replaceAll(
            "^" + quote(server.url.toASCIIString()) + "/content/repositories/([-a-zA-Z0-9]*)/.*",
            "$1");

    if (repositoryId.length() == 0) {
      return;
    }

    Option<NexusRepositoryDto> r = dao.findRepository(server.uuid, repositoryId);

    if (r.isNone()) {
      return;
    }

    NexusRepositoryDto repository = r.some();

    Option<ArtifactDto> a = dao.findArtifact(repository.uuid, event.artifactId);

    UUID uuid;

    if (a.isNone()) {
      System.out.println("New artifact: " + event.artifactId);
      uuid = dao.insertArtifact(repository.uuid, event.artifactId);
    } else {
      ArtifactDto artifact = a.some();

      //            System.out.println("Updated artifact: " + event.artifactId);

      uuid = artifact.uuid;
    }

    if (e instanceof NewSnapshotEvent) {
      NewSnapshotEvent newSnapshotEvent = (NewSnapshotEvent) e;

      dao.insertNewSnapshotEvent(
          uuid,
          event.guid,
          event.creator,
          event.date,
          newSnapshotEvent.snapshotTimestamp,
          newSnapshotEvent.buildNumber,
          newSnapshotEvent.url.toASCIIString());
    } else if (e instanceof NewReleaseEvent) {
      NewReleaseEvent nre = (NewReleaseEvent) e;

      dao.insertNewReleaseEvent(
          uuid, event.guid, event.creator, event.date, nre.url.toASCIIString());
    } else {
      System.out.println("Unknown event type: " + event.getClass().getName());
    }
  }
Exemplo n.º 2
0
  public void act(Connection c) throws Exception {

    NexusDao dao = new NexusDao(c);

    int newEvents = 0, oldEvents = 0, count = 0, pages = 0;

    int newInFeed;
    do {
      newInFeed = 0;
      NexusFeed feed = client.fetchTimeline("recentlyDeployedArtifacts", 100, count);

      pages++;
      count += feed.events.size();

      List<String> guids = new ArrayList<>();

      for (HasNexusEvent event : feed.events) {
        guids.add(event.event.guid);
      }

      Set<String> oldGuids = dao.selectGuidsByGuids(guids);

      System.out.println("oldGuids.size() = " + oldGuids.size());

      for (HasNexusEvent event : feed.events) {

        //                if (oldGuids.contains(event.event.guid)) {
        //                    oldEvents++;
        //                    continue;
        //                }

        if (dao.countEventByGuid(event.event.guid) != 0) {
          oldEvents++;
          continue;
        }

        newEvents++;
        newInFeed++;

        onEvent(dao, event);
      }

      System.out.println("newInFeed = " + newInFeed);
    } while (newInFeed > 0);

    System.out.println(
        "Timeline updated. New="
            + newEvents
            + ", old="
            + oldEvents
            + ", count="
            + count
            + ", pages="
            + pages);
  }