use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class FoloNPMContentAccessResource method doGet.
@ApiOperation("Retrieve and track NPM file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, response = String.class, message = "Rendered content listing (when path ends with '/index.html' or '/')"), @ApiResponse(code = 200, response = StreamingOutput.class, message = "Content stream") })
@GET
@Path("/{packageName}/{versionTarball: (.*)}")
public Response doGet(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("packageName") final String packageName, @PathParam("versionTarball") final String versionTarball, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
final TrackingKey tk = new TrackingKey(id);
EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.NATIVE);
RequestContextHelper.setContext(CONTENT_TRACKING_ID, id);
final String path = Paths.get(packageName, versionTarball).toString();
final String baseUri = getBasePath(uriInfo, id);
return handler.doGet(NPM_PKG_KEY, type, name, path, baseUri, request, metadata);
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class PackageMetadataGeneratorTest method generateMetadataWhenMissingForScoped.
@Test
public void generateMetadataWhenMissingForScoped() throws Exception {
ChangeSummary summary = new ChangeSummary("test", "Init NPM hosted repo.");
final HostedRepository hostedRepository = new HostedRepository(NPM_PKG_KEY, "npm-builds");
initStore(hostedRepository, summary);
final KeyedLocation location = LocationUtils.toLocation(hostedRepository);
storeFile(location, "@babel/core/-/core-7.7.5.tgz", "tarball/version-1.tgz");
storeFile(location, "@babel/core/-/core-7.7.7.tgz", "tarball/version-2.tgz");
storeFile(location, "@babel/core/7.7.5", "metadata/scoped-version-1.json");
storeFile(location, "@babel/core/7.7.7", "metadata/scoped-version-2.json");
final String babelCoreMetadataPath = "@babel/core/package.json";
// Check the package metadata before generation.
Transfer before = fileManager.retrieve(hostedRepository, babelCoreMetadataPath);
assertNull(before);
Transfer metadataFile = generator.generateFileContent(hostedRepository, babelCoreMetadataPath, new EventMetadata());
assertNotNull(metadataFile);
verifyScopedMetadata(metadataFile);
// Check the package metadata after generation.
Transfer after = fileManager.retrieve(hostedRepository, babelCoreMetadataPath);
assertNotNull(after);
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class PackageStoreListener method doClear.
private boolean doClear(final ArtifactStore store, final String path) throws IOException {
boolean isCleared = false;
logger.info("Updating merged package metadata file: {} in store: {}", path, store);
final Transfer[] toDelete = { fileManager.getStorageReference(store, path), fileManager.getStorageReference(store, path + GroupMergeHelper.MERGEINFO_SUFFIX) };
for (final Transfer item : toDelete) {
logger.info("Attempting to delete: {}", item);
if (item.exists()) {
boolean result = false;
try {
result = fileManager.delete(store, item.getPath(), new EventMetadata().set(StoreDataManager.IGNORE_READONLY, true));
} catch (IndyWorkflowException e) {
logger.warn("Deletion failed for package metadata clear, transfer is {}, failed reason:{}", item, e.getMessage());
}
logger.info("Deleted: {} (success? {})", item, result);
if (item.getPath().endsWith(NPM_METADATA_NAME)) {
isCleared = result;
}
if (fileEvent != null) {
logger.trace("Firing deletion event for: {}", item);
fileEvent.fire(new FileDeletionEvent(item, new EventMetadata()));
}
} else if (item.getPath().endsWith(NPM_METADATA_NAME)) {
// we should return true here to trigger cache cleaning, because file not exists in store does not mean
// metadata not exists in cache.
logger.debug("Package metadata clean for {}: metadata not existed in store, so skipped deletion and mark as deleted", item);
return true;
}
}
return isCleared;
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class MavenContentAccessResource method doDelete.
@Override
@ApiOperation("Delete Maven artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 204, message = "Content was deleted successfully") })
@DELETE
@Path("/{path: (.*)}")
public Response doDelete(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("path") final String path, @ApiParam(name = CHECK_CACHE_ONLY, value = "true or false") @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly) {
EventMetadata metadata = new EventMetadata();
metadata.set(CHECK_CACHE_ONLY, cacheOnly);
return handler.doDelete(MAVEN_PKG_KEY, type, name, path, metadata);
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class MavenContentAccessResource method doCreate.
@Override
@ApiOperation("Store Maven artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 201, message = "Content was stored successfully"), @ApiResponse(code = 400, message = "No appropriate storage location was found in the specified store (this store, or a member if a group is specified).") })
@PUT
@Path("/{path: (.+)?}")
public Response doCreate(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("path") final String path, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
final EventMetadata metadata = new EventMetadata().set(STORE_HTTP_HEADERS, RequestUtils.extractRequestHeadersToMap(request));
Class cls = MavenContentAccessResource.class;
return handler.doCreate(MAVEN_PKG_KEY, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(cls).path(path).build(MAVEN_PKG_KEY, type, name));
}
Aggregations