use of com.walmartlabs.concord.server.repository.listeners.RepositoryRefreshListener in project concord by walmartlabs.
the class RepositoryRefresher method refresh.
public void refresh(String orgName, String projectName, String repositoryName, boolean sync) {
UUID orgId = orgManager.assertAccess(orgName, true).getId();
ProjectEntry projectEntry = assertProject(orgId, projectName, ResourceAccessLevel.READER, true);
UUID projectId = projectEntry.getId();
RepositoryEntry repositoryEntry = assertRepository(projectEntry, repositoryName);
if (!sync) {
Map<String, Object> event = new HashMap<>();
event.put("event", "repositoryRefresh");
event.put("org", orgName);
event.put("project", projectName);
event.put("repository", repositoryName);
externalEventResource.event("concord", event);
return;
}
try (TemporaryPath tmpRepoPath = IOUtils.tempDir("refreshRepo_")) {
repositoryManager.withLock(repositoryEntry.getUrl(), () -> {
Repository repo = repositoryManager.fetch(projectId, repositoryEntry);
repo.export(tmpRepoPath.path());
return null;
});
tx(tx -> {
for (RepositoryRefreshListener l : listeners) {
l.onRefresh(tx, repositoryEntry, tmpRepoPath.path());
}
});
} catch (Exception e) {
String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
throw new ConcordApplicationException("Error while refreshing repository: \n" + errorMessage, e);
}
}
Aggregations