use of org.commonjava.auditquery.history.ChangeEvent in project indy by Commonjava.
the class RepoChangelogStoreTest method test.
@Test
public void test() throws Exception {
HostedRepository repo = new HostedRepository(MAVEN_PKG_KEY, newName());
final StoreKey hostedKey = repo.getKey();
repo = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
repo.setAllowReleases(!repo.isAllowReleases());
client.stores().update(repo, name.getMethodName());
repo.setReadonly(true);
client.stores().update(repo, name.getMethodName());
List<ChangeEvent> logs = client.module(IndyRepoChangelogClientModule.class).getByStoreKey(repo.getKey());
final AtomicInteger createCount = new AtomicInteger(0);
final AtomicInteger updateCount = new AtomicInteger(0);
logs.forEach(c -> {
assertThat(c.getStoreKey(), equalTo(hostedKey.toString()));
if (c.getChangeType() == ChangeType.CREATE) {
createCount.getAndIncrement();
}
if (c.getChangeType() == ChangeType.UPDATE) {
updateCount.getAndIncrement();
}
});
assertThat(createCount.get(), equalTo(1));
assertThat(updateCount.get(), equalTo(2));
logs = client.module(IndyRepoChangelogClientModule.class).getAll();
final AtomicInteger updateCount2 = new AtomicInteger(0);
final AtomicInteger testRepoCount = new AtomicInteger(0);
logs.forEach(c -> {
if (c.getChangeType() == ChangeType.UPDATE) {
updateCount2.getAndIncrement();
}
if (c.getStoreKey().equals(hostedKey.toString())) {
testRepoCount.getAndIncrement();
}
});
assertThat(updateCount2.get(), equalTo(2));
assertThat(testRepoCount.get(), equalTo(3));
}
use of org.commonjava.auditquery.history.ChangeEvent in project indy by Commonjava.
the class RepoChangelogStoreDisableTest method test.
@Test
public void test() throws Exception {
HostedRepository repo = new HostedRepository(MAVEN_PKG_KEY, newName());
final StoreKey hostedKey = repo.getKey();
repo = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
repo.setAllowReleases(!repo.isAllowReleases());
client.stores().update(repo, name.getMethodName());
repo.setReadonly(true);
client.stores().update(repo, name.getMethodName());
IndyRepoChangelogClientModule repoChangelogClientModule = client.module(IndyRepoChangelogClientModule.class);
List<ChangeEvent> logs = null;
try {
logs = repoChangelogClientModule.getByStoreKey(repo.getKey());
} catch (IndyClientException e) {
assertThat(e.getStatusCode(), equalTo(404));
}
assertNotNull(logs);
assertTrue(logs.isEmpty());
try {
repoChangelogClientModule.getAll();
} catch (IndyClientException e) {
assertThat(e.getStatusCode(), equalTo(404));
}
assertNotNull(logs);
assertTrue(logs.isEmpty());
}
use of org.commonjava.auditquery.history.ChangeEvent in project indy by Commonjava.
the class RepoChangeHandler method handleRepoChange.
private void handleRepoChange(DiffStoreFetcher fetcher, boolean isDelete) {
if (!config.isEnabled()) {
logger.info("Repository changelog module is not enabled. Will ignore all change logs for propagation.");
return;
}
ChangeSummary changeSummary = fetcher.getSummary();
Collection<ArtifactStore> stores = fetcher.getStores();
String user = ChangeSummary.SYSTEM_USER;
String summary = "";
String version = "";
Date timeStamp = new Date();
if (changeSummary != null) {
if (changeSummary.getUser() != null) {
user = changeSummary.getUser();
}
if (changeSummary.getSummary() != null) {
summary = changeSummary.getSummary();
}
if (changeSummary.getRevisionId() != null) {
version = changeSummary.getRevisionId();
} else {
// FIXME: we need version not null here to let it be a key, not sure if timestamp is good here
version = String.format("%s", timeStamp.getTime());
}
}
for (ArtifactStore store : stores) {
try {
ArtifactStore origin = fetcher.getOriginal(store);
ArtifactStore changed = fetcher.getChanged(store);
String patchString = diffRepoChanges(changed, origin);
ChangeEvent changeLog = new ChangeEvent();
changeLog.setEventId(UUID.randomUUID().toString().replace("-", ""));
changeLog.setStoreKey(store.getKey().toString());
changeLog.setChangeTime(new Date());
changeLog.setDiffContent(patchString);
if (isDelete) {
changeLog.setChangeType(ChangeType.DELETE);
} else {
changeLog.setChangeType(origin == null ? ChangeType.CREATE : ChangeType.UPDATE);
}
changeLog.setUser(user);
changeLog.setSummary(summary);
changeLog.setVersion(version);
String key = changeLog.getStoreKey() + "_" + changeLog.getVersion();
repoChangelogCache.put(key, changeLog);
} catch (JsonProcessingException | DiffException e) {
String error = String.format("Something wrong happened when doing repo change log generation for store %s", store.getKey());
logger.error(error, e);
}
}
}
Aggregations