aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java109
1 files changed, 71 insertions, 38 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java b/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
index 3d0aaf0..3bf93c4 100755
--- a/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
+++ b/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
@@ -12,6 +12,7 @@ import org.codehaus.httpcache4j.cache.*;
import java.sql.*;
import java.util.*;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.*;
public class NexusImporter {
@@ -75,65 +76,97 @@ class NexusServer implements TransactionalActor {
NexusDao dao = new NexusDao(c);
- NexusFeed feed = client.fetchTimeline("recentlyDeployedArtifacts");
+ int newEvents = 0, oldEvents = 0, count = 0, pages = 0;
- int newEvents = 0, oldEvents = 0;
+ int newInFeed;
+ do {
+ newInFeed = 0;
+ NexusFeed feed = client.fetchTimeline("recentlyDeployedArtifacts", 100, count);
- for (NexusEvent event : feed.events) {
+ pages++;
+ count += feed.events.size();
- if(dao.countEventByGuid(event.guid) != 0) {
- oldEvents++;
- continue;
+ List<String> guids = new ArrayList<>();
+
+ for (HasNexusEvent event : feed.events) {
+ guids.add(event.event.guid);
}
- newEvents++;
+ Set<String> oldGuids = dao.selectGuidsByGuids(guids);
- String repositoryId = event.guid.replaceAll("^" + quote(server.url.toASCIIString()) + "/content/repositories/([-a-zA-Z0-9]*)/.*", "$1");
+ System.out.println("oldGuids.size() = " + oldGuids.size());
- if(repositoryId.length() == 0) {
- continue;
- }
+ for (HasNexusEvent event : feed.events) {
+
+// if (oldGuids.contains(event.event.guid)) {
+// oldEvents++;
+// continue;
+// }
- Option<NexusRepositoryDto> r = dao.findRepository(server.uuid, repositoryId);
+ if (dao.countEventByGuid(event.event.guid) != 0) {
+ oldEvents++;
+ continue;
+ }
- if(r.isNone()) {
- continue;
+ newEvents++;
+ newInFeed++;
+
+ onEvent(dao, event);
}
- NexusRepositoryDto repository = r.some();
+ System.out.println("newInFeed = " + newInFeed);
+ } while (newInFeed > 0);
- Option<ArtifactDto> a = dao.findArtifact(repository.uuid, event.artifactId);
+ System.out.println("Timeline updated. New=" + newEvents + ", old=" + oldEvents + ", count=" + count + ", pages=" + pages);
+ }
- UUID uuid;
+ private void onEvent(NexusDao dao, HasNexusEvent e) throws SQLException {
- if(a.isNone()) {
- System.out.println("New artifact: " + event.artifactId);
- uuid = dao.insertArtifact(repository.uuid, event.artifactId);
- }
- else {
- ArtifactDto artifact = a.some();
+ NexusEvent event = e.event;
- System.out.println("Updated artifact: " + event.artifactId);
-// dao.updateSnapshotTimestamp(artifact.uuid, newSnapshotEvent.snapshotTimestamp);
+ String repositoryId = event.guid.replaceAll("^" + quote(server.url.toASCIIString()) + "/content/repositories/([-a-zA-Z0-9]*)/.*", "$1");
- uuid = artifact.uuid;
- }
+ if(repositoryId.length() == 0) {
+ return;
+ }
- if (event instanceof NewSnapshotEvent) {
- NewSnapshotEvent newSnapshotEvent = (NewSnapshotEvent) event;
+ Option<NexusRepositoryDto> r = dao.findRepository(server.uuid, repositoryId);
- dao.insertNewSnapshotEvent(uuid, event.guid, newSnapshotEvent.snapshotTimestamp,
- newSnapshotEvent.buildNumber, newSnapshotEvent.url.toASCIIString());
- } else if (event instanceof NewReleaseEvent) {
- NewReleaseEvent nre = (NewReleaseEvent) event;
+ if(r.isNone()) {
+ return;
+ }
- dao.insertNewReleaseEvent(uuid, event.guid, nre.url.toASCIIString());
- } else {
- System.out.println("Unknown event type: " + event.getClass().getName());
- }
+ 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);
- System.out.println("Timeline updated. New=" + newEvents + ", old=" + oldEvents);
+ 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());
+ }
}
// public void act(Connection c) throws Exception {