use of io.hops.hopsworks.api.dataset.DatasetDTO in project hopsworks by logicalclocks.
the class ProvUsageBuilder method buildAccessible.
public ProvArtifactUsageParentDTO buildAccessible(UriInfo uriInfo, Users user, DatasetPath targetEndpoint, String artifactId, Set<ProvUsageType> type) throws ProvenanceException, GenericException, DatasetException, MetadataException, SchematizedTagException {
if (!accessController.hasAccess(targetEndpoint.getAccessProject(), targetEndpoint.getDataset())) {
throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.FINE);
}
ProvArtifactUsageParentDTO usage = new ProvArtifactUsageParentDTO();
usage.setArtifactId(artifactId);
DatasetDTO datasetDTO = datasetBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.DATASET), user, targetEndpoint);
usage.setDataset(datasetDTO);
usage.setProjectId(targetEndpoint.getDataset().getProject().getId());
usage.setProjectName(targetEndpoint.getDataset().getProject().getName());
ProvOpsParamBuilder params = getBasicUsageOpsParams(targetEndpoint.getDataset(), artifactId);
ProvOpsDTO ops = opsBuilder.build(targetEndpoint.getDataset().getProject(), params, ProvOpsReturnType.AGGREGATIONS);
Optional<ProvOpsDTO> aggregation = ops.getItems().stream().filter(agg -> agg.getAggregation() != null && agg.getAggregation().equals(ProvOpsAggregations.APP_USAGE.toString())).findFirst();
if (!aggregation.isPresent()) {
return usage;
}
Optional<ProvOpsDTO> artifact = aggregation.get().getItems().stream().filter(art -> art.getMlId().equals(artifactId)).findFirst();
if (!artifact.isPresent()) {
return usage;
}
for (ProvUsageType t : type) {
switch(t) {
case READ_CURRENT:
usage.setReadCurrent(usage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA, true));
break;
case WRITE_CURRENT:
usage.setWriteCurrent(usage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA, true));
break;
case READ_LAST:
lastUsage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA).ifPresent(usage::setReadLast);
break;
case WRITE_LAST:
lastUsage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA).ifPresent(usage::setWriteLast);
break;
case READ_HISTORY:
usage.setReadHistory(usage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA, false));
break;
case WRITE_HISTORY:
usage.setWriteHistory(usage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA, false));
break;
}
}
return usage;
}
Aggregations