use of org.commonjava.indy.content.browse.model.ContentBrowseResult in project indy by Commonjava.
the class TestUtils method getExpectedRemoteContent.
static String getExpectedRemoteContent(ExpectationServer server, AbstractRepository repo, String rootPath, ObjectMapper mapper) throws IOException {
final String url = server.formatUrl("");
ContentBrowseResult result = new ContentBrowseResult();
result.setStoreKey(repo.getKey());
final String rootStorePath = PathUtils.normalize(url, "api/browse", repo.getKey().toString().replaceAll(":", "/"));
result.setParentUrl(PathUtils.normalize(rootStorePath, "foo", "/"));
result.setParentPath("foo/");
result.setPath("foo/bar/");
result.setStoreBrowseUrl(rootStorePath);
result.setStoreContentUrl(PathUtils.normalize(url, "api/content", repo.getKey().toString().replaceAll(":", "/")));
result.setSources(Collections.singletonList(rootStorePath));
ContentBrowseResult.ListingURLResult listResult = new ContentBrowseResult.ListingURLResult();
final String path = rootPath + "foo-bar.txt";
listResult.setListingUrl(PathUtils.normalize(rootStorePath, path));
listResult.setPath(path);
Set<String> sources = new HashSet<>();
sources.add("indy:" + repo.getKey().toString() + path);
listResult.setSources(sources);
result.setListingUrls(Collections.singletonList(listResult));
return mapper.writeValueAsString(result);
}
use of org.commonjava.indy.content.browse.model.ContentBrowseResult in project indy by Commonjava.
the class RepoProxyCreatorMavenContentBrowseTest method run.
@Test
public void run() throws Exception {
final StoreKey remoteKey = new StoreKey(MAVEN_PKG_KEY, StoreType.remote, REPO_NAME);
RemoteRepository remote = client.stores().load(remoteKey, RemoteRepository.class);
assertThat(remote, nullValue());
ContentBrowseResult result = client.module(IndyContentBrowseClientModule.class).getContentList(hosted.getKey(), "foo");
assertThat(result, notNullValue());
remote = client.stores().load(remoteKey, RemoteRepository.class);
assertThat(remote, notNullValue());
assertThat(result.getStoreKey(), equalTo(hosted.getKey()));
assertThat(result.getParentUrl(), containsString("maven/hosted/test"));
assertThat(result.getStoreBrowseUrl(), containsString("maven/hosted/test"));
assertThat(result.getStoreContentUrl(), containsString("maven/hosted/test"));
}
use of org.commonjava.indy.content.browse.model.ContentBrowseResult in project indy by Commonjava.
the class ContentBrowseResource method processHead.
// @ApiOperation( "Retrieve directory content under the given artifact store (type/name) and directory path." )
// @ApiResponses( { @ApiResponse( code = 404, message = "Content is not available" ),
// @ApiResponse( code = 200, response = String.class, message = "Rendered content listing" ) } )
// @HEAD
// @Path( "/{path: (.*)}" )
// public Response headForDirectory(
// final @ApiParam( allowableValues = "maven,npm", required = true ) @PathParam( "packageType" )
// String packageType,
// final @ApiParam( allowableValues = "hosted,group,remote", required = true ) @PathParam( "type" )
// String type, final @ApiParam( required = true ) @PathParam( "name" ) String name,
// final @PathParam( "path" ) String path, final UriInfo uriInfo,
// @Context final HttpServletRequest request )
// {
// return processHead( packageType, type, name, path, uriInfo, request );
// }
//
// @ApiOperation( "Retrieve directory content under the given artifact store (type/name) and directory path." )
// @ApiResponses( { @ApiResponse( code = 404, message = "Content is not available" ),
// @ApiResponse( code = 200, response = String.class, message = "Rendered content listing" ) } )
// @HEAD
// @Path( "/" )
// public Response headForRoot(
// final @ApiParam( allowableValues = "maven,npm", required = true ) @PathParam( "packageType" )
// String packageType,
// final @ApiParam( allowableValues = "hosted,group,remote", required = true ) @PathParam( "type" )
// String type, final @ApiParam( required = true ) @PathParam( "name" ) String name,
// final @PathParam( "path" ) String path, @Context final UriInfo uriInfo,
// @Context final HttpServletRequest request )
// {
// return processHead( packageType, type, name, "", uriInfo, request );
// }
private Response processHead(final String packageType, final String type, final String name, final String path, final UriInfo uriInfo, final HttpServletRequest request) {
if (!PackageTypes.contains(packageType)) {
return Response.status(400).build();
}
Response response;
ContentBrowseResult result = null;
try {
result = getBrowseResult(packageType, type, name, path, uriInfo);
final AcceptInfo acceptInfo = jaxRsRequestHelper.findAccept(request, ApplicationContent.application_json);
final String content = mapper.writeValueAsString(result);
Response.ResponseBuilder builder = Response.ok().header(ApplicationHeader.content_type.key(), acceptInfo.getRawAccept()).header(ApplicationHeader.content_length.key(), Long.toString(content.length())).header(ApplicationHeader.last_modified.key(), HttpUtils.formatDateHeader(new Date())).header(ApplicationHeader.md5.key(), contentDigester.digest(result.getStoreKey(), path, new EventMetadata()).getDigests().get(ContentDigest.MD5).toUpperCase()).header(ApplicationHeader.sha1.key(), contentDigester.digest(result.getStoreKey(), path, new EventMetadata()).getDigests().get(ContentDigest.SHA_1).toUpperCase());
;
response = builder.build();
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to list content: %s from: %s. Reason: %s", StringUtils.isBlank(path) ? "/" : path, name, e.getMessage()), e);
response = responseHelper.formatResponse(e);
} catch (JsonProcessingException e) {
response = responseHelper.formatResponse(e, "Failed to serialize DTO to JSON: " + result);
}
return response;
}
use of org.commonjava.indy.content.browse.model.ContentBrowseResult in project indy by Commonjava.
the class RepoProxyCreatorNPMContentBrowseTest method run.
@Test
public void run() throws Exception {
final StoreKey remoteKey = new StoreKey(NPM_PKG_KEY, StoreType.remote, REPO_NAME);
RemoteRepository remote = client.stores().load(remoteKey, RemoteRepository.class);
assertThat(remote, nullValue());
ContentBrowseResult result = client.module(IndyContentBrowseClientModule.class).getContentList(hosted.getKey(), "");
assertThat(result, notNullValue());
remote = client.stores().load(remoteKey, RemoteRepository.class);
assertThat(remote, notNullValue());
assertThat(result.getStoreKey(), equalTo(hosted.getKey()));
assertThat(result.getStoreBrowseUrl(), containsString("npm/hosted/test"));
assertThat(result.getStoreContentUrl(), containsString("npm/hosted/test"));
}
Aggregations