public void addNexusArtifactEvent(NexusArtifactEvent nae) { Map<String, String> map = new HashMap<String, String>(); map.put(REPOSITORY, nae.getNexusItemInfo().getRepositoryId()); map.put(REPOSITORY_PATH, nae.getNexusItemInfo().getPath()); if (nae.getNexusItemInfo().getRemoteUrl() != null) { map.put(REMOTE_URL, nae.getNexusItemInfo().getRemoteUrl()); } putContext(map, CTX_PREFIX, nae.getEventContext()); putContext(map, ATR_PREFIX, nae.getItemAttributes()); if (nae.getMessage() != null) { map.put(MESSAGE, nae.getMessage()); } map.put(DATE, getDateFormat().format(nae.getEventDate())); map.put(ACTION, nae.getAction()); addToTimeline(map, REPO_EVENT_TYPE, nae.getAction()); }
new NexusArtifactEvent(getEventDate(map), map.get(ACTION), map.get(MESSAGE), ai); nae.addItemAttributes(ctx); nae.addEventContext(ctx); nae.addItemAttributes(atr);
if (NexusArtifactEvent.ACTION_CACHED.equals(event.getAction())) { msg.append("cached from remote URL ").append(event.getNexusItemInfo().getRemoteUrl()).append("."); else if (NexusArtifactEvent.ACTION_DEPLOYED.equals(event.getAction())) { msg.append("deployed."); else if (NexusArtifactEvent.ACTION_DELETED.equals(event.getAction())) { msg.append("deleted."); else if (NexusArtifactEvent.ACTION_RETRIEVED.equals(event.getAction())) { msg.append("served downstream."); else if (NexusArtifactEvent.ACTION_BROKEN.equals(event.getAction())) { msg.append("broken."); if (event.getMessage() != null) { msg.append(" Details: \n"); msg.append(event.getMessage()); else if (NexusArtifactEvent.ACTION_BROKEN_WRONG_REMOTE_CHECKSUM.equals(event.getAction())) { msg.append("proxied, and the remote repository contains wrong checksum for it."); if (event.getMessage() != null) { msg.append(" Details: \n"); msg.append(event.getMessage());
protected String buildLink(NexusArtifactEvent event) { return "content/repositories/" + event.getNexusItemInfo().getRepositoryId() + event.getNexusItemInfo().getPath(); }
protected String buildDescriptionMsgAddress(NexusArtifactEvent event) { if (event.getEventContext().containsKey(AccessManager.REQUEST_REMOTE_ADDRESS)) { return "Request originated from IP address " + (String) event.getEventContext().get(AccessManager.REQUEST_REMOTE_ADDRESS) + ".\n"; } return ""; }
protected Date buildPublishDate(NexusArtifactEvent event) { return event.getEventDate(); }
protected String buildTitle(NexusArtifactEvent event) { return event.getAction(); }
public void addItemAttributes(Map<String, String> atr) { getItemAttributes().putAll(atr); } }
protected SyndContent buildDescription(NexusArtifactEvent event) { SyndContent content = new SyndContentImpl(); content.setType(MediaType.TEXT_PLAIN.toString()); StringBuilder msg = new StringBuilder(); if (event.getMessage() != null) { msg.append(event.getMessage()); msg.append(' '); } msg.append(buildDescriptionMsgItem(event)); msg.append(buildDescriptionMsgAction(event)); msg.append(buildDescriptionMsgAuthor(event)); msg.append(buildDescriptionMsgAddress(event)); content.setValue(msg.toString()); return content; }
@Subscribe @AllowConcurrentEvents public void inspect(final RepositoryItemValidationEventFailed ievt) { final NexusItemInfo ai = new NexusItemInfo(); ai.setRepositoryId(ievt.getItem().getRepositoryId()); ai.setPath(ievt.getItem().getPath()); ai.setRemoteUrl(ievt.getItem().getRemoteUrl()); String action = NexusArtifactEvent.ACTION_BROKEN; if (ievt instanceof RepositoryItemValidationEventFailedChecksum) { action = NexusArtifactEvent.ACTION_BROKEN_WRONG_REMOTE_CHECKSUM; } else if (ievt instanceof RepositoryItemValidationEventFailedFileType) { action = NexusArtifactEvent.ACTION_BROKEN_INVALID_CONTENT; } final NexusArtifactEvent nae = new NexusArtifactEvent(ievt.getEventDate(), action, ievt.getMessage(), ai); getFeedRecorder().addNexusArtifactEvent(nae); } }
NexusArtifactEvent nae = new NexusArtifactEvent(ievt.getEventDate(), action, "", ai); nae.addEventContext(ievt.getItemContext()); nae.addItemAttributes(ievt.getItem().getRepositoryItemAttributes().asMap());
private String buildFilePath(NexusArtifactEvent event) { return event.getNexusItemInfo().getPath(); }
protected String buildAuthor(NexusArtifactEvent event) { if (event.getEventContext().containsKey(AccessManager.REQUEST_USER)) { return (String) event.getEventContext().get(AccessManager.REQUEST_USER); } else { return null; } }
protected Gav buildGAV(final NexusArtifactEvent event) { if (event.getNexusItemInfo() == null) { return null; } try { final Repository repo = getRepositoryRegistry().getRepository(event.getNexusItemInfo().getRepositoryId()); if (MavenRepository.class.isAssignableFrom(repo.getClass())) { return ((MavenRepository) repo).getGavCalculator().pathToGav(event.getNexusItemInfo().getPath()); } return null; } catch (NoSuchRepositoryException e) { log.debug( "Feed entry contained invalid repository id " + event.getNexusItemInfo().getRepositoryId(), e); return null; } }
private boolean filterEvent(NexusArtifactEvent event) { try { Repository repo = this.repositoryRegistry.getRepository(event.getNexusItemInfo().getRepositoryId()); ResourceStoreRequest req = new ResourceStoreRequest(event.getNexusItemInfo().getPath()); if (!this.nexusItemAuthorizer.authorizePath(repo, req, Action.read)) { return false; } } catch (NoSuchRepositoryException e) { // Can't get repository for artifact, therefore we can't authorize access, therefore you don't see it log.debug( "Feed entry contained invalid repository id " + event.getNexusItemInfo().getRepositoryId(), e); return false; } return true; }
private String getGAVString(NexusArtifactEvent event) { if (event.getNexusItemInfo() == null) { return "unknown:unknown:unknown"; } Gav gav = buildGAV(event); if (gav == null) { return event.getNexusItemInfo().getPath(); } StringBuilder result = new StringBuilder(gav.getGroupId()) .append(":").append(gav.getArtifactId()).append(":").append( gav.getVersion() != null ? gav.getVersion() : "unknown"); if (gav.getClassifier() != null) { result.append(":").append(gav.getClassifier()); } return result.toString(); }
protected String getRepositoryName(NexusArtifactEvent event) { String repoId = event.getNexusItemInfo().getRepositoryId(); try { Repository repository = getRepositoryRegistry().getRepository(repoId); return repository.getName(); } catch (NoSuchRepositoryException e) { // that's fine, no need to yell, old timeline entries might correspond to long-time removed reposes return repoId; } }
@Override public boolean shouldBuildEntry(final NexusArtifactEvent event) { if (!super.shouldBuildEntry(event)) { return false; } final Gav gav = buildGAV(event); if (gav != null) { if (gav.isHash() || gav.isSignature()) { return false; } } final String path = event.getNexusItemInfo().getPath(); if (path.contains("maven-metadata.xml")) { return false; } return true; }