use of org.commonjava.indy.folo.model.StoreEffect in project indy by Commonjava.
the class FoloTrackingListener method onFileUpload.
public void onFileUpload(@Observes final FileStorageEvent event) {
logger.debug("FILE STORAGE: {}", event);
if (TransferOperation.UPLOAD != event.getType()) {
logger.debug("Not a file upload from client; skipping tracking of storage");
return;
}
EventMetadata metadata = event.getEventMetadata();
final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
if (trackingKey == null) {
logger.info("No tracking key. Not recording.");
return;
}
final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
final Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.info("No transfer. Not recording.");
return;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
logger.info("Invalid transfer source location: {}. Not recording.", location);
return;
} else if (!foloConfig.isGroupContentTracked() && ((KeyedLocation) location).getKey().getType() == group) {
logger.debug("NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", ((KeyedLocation) location).getKey());
return;
}
final TransferOperation op = event.getType();
StoreEffect effect = null;
switch(op) {
case DOWNLOAD:
{
effect = StoreEffect.DOWNLOAD;
break;
}
case UPLOAD:
{
effect = StoreEffect.UPLOAD;
break;
}
default:
{
logger.debug("Ignoring transfer operation: {} for: {}", op, transfer);
return;
}
}
try {
final KeyedLocation keyedLocation = (KeyedLocation) location;
logger.debug("Tracking report: {} += {} in {} ({})", trackingKey, transfer.getPath(), keyedLocation.getKey(), effect);
recordManager.recordArtifact(createEntry(trackingKey, keyedLocation.getKey(), accessChannel, transfer.getPath(), effect, event.getEventMetadata()));
} catch (final FoloContentException | IndyWorkflowException e) {
logger.error(String.format("Failed to record download: %s. Reason: %s", transfer, e.getMessage()), e);
}
}
Aggregations