use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class NfcController method getMissing.
public NotFoundCacheDTO getMissing(final StoreKey key) throws IndyWorkflowException {
final NotFoundCacheDTO dto = new NotFoundCacheDTO();
if (key.getType() == group) {
List<ArtifactStore> stores;
try {
stores = storeManager.query().packageType(key.getPackageType()).getOrderedConcreteStoresInGroup(key.getName());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to retrieve concrete constituent ArtifactStores for: %s.", e, key);
}
final List<? extends KeyedLocation> locations = toLocations(stores);
for (final KeyedLocation location : locations) {
final Set<String> missing = cache.getMissing(location);
if (missing != null && !missing.isEmpty()) {
final List<String> paths = new ArrayList<String>(missing);
Collections.sort(paths);
dto.addSection(location.getKey(), paths);
}
}
} else {
ArtifactStore store;
try {
store = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to retrieve ArtifactStore: %s.", e, key);
}
if (store != null) {
final Set<String> missing = cache.getMissing(toLocation(store));
final List<String> paths = new ArrayList<String>(missing);
Collections.sort(paths);
dto.addSection(key, paths);
}
}
return dto;
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class NfcResource method deprecatedGetStore.
@Path("/{type: (hosted|group|remote)}/{name}")
@ApiOperation("[Deprecated] Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response deprecatedGetStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
Response response;
final StoreType type = StoreType.get(t);
String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
final StoreKey key = new StoreKey(type, name);
try {
final NotFoundCacheDTO dto = controller.getMissing(key);
response = formatOkResponseWithJsonEntity(dto, serializer, rb -> markDeprecated(rb, altPath));
} catch (final IndyWorkflowException e) {
response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
}
return response;
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class HostedMissingAddToNFCTest method run.
@Test
public void run() throws Exception {
try (InputStream inputStream = client.content().get(hosted.getKey(), JAR_PATH)) {
assertThat(inputStream, notNullValue());
}
try (InputStream inputStream = client.content().get(hosted.getKey(), POM_PATH)) {
assertThat(inputStream, IsNull.nullValue());
}
NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.hosted, hosted.getName());
assertThat(dto, notNullValue());
assertThat(dto.getSections(), notNullValue());
NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().filter(d -> d.getKey().equals(hosted.getKey())).findFirst().orElse(null);
assertThat(nfcSectionDto, notNullValue());
assertThat(nfcSectionDto.getPaths(), notNullValue());
assertThat(nfcSectionDto.getPaths().contains(POM_PATH), equalTo(true));
client.content().store(hosted.getKey(), POM_PATH, new ByteArrayInputStream("This is the pom".getBytes()));
try (InputStream inputStream = client.content().get(hosted.getKey(), POM_PATH)) {
assertThat(inputStream, notNullValue());
}
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.hosted, hosted.getName());
assertThat(dto, notNullValue());
assertThat(dto.getSections(), notNullValue());
nfcSectionDto = dto.getSections().stream().filter(d -> d.getKey().equals(hosted.getKey())).findFirst().orElse(null);
assertThat(nfcSectionDto, notNullValue());
assertThat(nfcSectionDto.getPaths(), nullValue());
try (InputStream inputStream = client.content().get(hosted.getKey(), META_PATH)) {
assertThat(inputStream, notNullValue());
}
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class NFCForTwoGroupsWithSameHostedTest method run.
@Test
public void run() throws Exception {
try (InputStream inputStream = client.content().get(a.getKey(), PATH)) {
assertThat(inputStream, nullValue());
}
// NotFoundCacheDTO dto = client.module( IndyNfcClientModule.class ).getAllNfcContentInStore( StoreType.group, a.getName() );
//
// assertThat( dto, notNullValue() );
// assertThat( dto.getSections(), notNullValue() );
// NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().findFirst().orElse( null );
// assertThat( nfcSectionDto, notNullValue() );
// assertThat( nfcSectionDto.getPaths(), notNullValue() );
// assertThat( nfcSectionDto.getPaths().contains( PATH ), equalTo( true ) );
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContentInStore( StoreType.hosted, x.getName() );
//
// assertThat( dto, notNullValue() );
// assertThat( dto.getSections(), notNullValue() );
// nfcSectionDto = dto.getSections().stream().findFirst().orElse( null );
// assertThat( nfcSectionDto, notNullValue() );
// assertThat( nfcSectionDto.getPaths(), notNullValue() );
// assertThat( nfcSectionDto.getPaths().contains( PATH ), equalTo( true ) );
client.content().store(b.getKey(), PATH, new ByteArrayInputStream("This is the pom".getBytes()));
try (InputStream inputStream = client.content().get(b.getKey(), PATH)) {
assertThat(inputStream, notNullValue());
}
try (InputStream inputStream = client.content().get(a.getKey(), PATH)) {
assertThat(inputStream, notNullValue());
}
NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.group, a.getName());
NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().findFirst().orElse(null);
assertThat(nfcSectionDto, nullValue());
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class NFCGetMissingAndPaginationTest method run.
@Test
public void run() throws Exception {
// Get NFC cache size
// NotFoundCacheInfoDTO info = client.module( IndyNfcClientModule.class ).getInfo( hosted.getKey() );
// assertEquals( info.getSize(), 15 );
NotFoundCacheInfoDTO info = client.module(IndyNfcClientModule.class).getInfo(remote.getKey());
assertEquals(info.getSize(), 15);
info = client.module(IndyNfcClientModule.class).getInfo(group.getKey());
assertEquals(info.getSize(), 15);
// Get NFC for hosted
// NotFoundCacheDTO dto = client.module( IndyNfcClientModule.class )
// .getAllNfcContentInStore( StoreType.hosted, hosted.getName() );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, hosted );
// Get NFC for remote
NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName());
assertThat(dto, notNullValue());
assertThat_DtoContainsPathsForRepository(dto, paths, remote);
// Get NFC for all
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, hosted );
// assertThat_DtoContainsPathsForRepository( dto, paths, remote );
// Pagination - pageIndex starts from 0!
int pageSize = 10;
List<String> pageOne = getPathsInPage(paths, 0, pageSize);
List<String> pageTwo = getPathsInPage(paths, 1, pageSize);
// Get NFC for page one
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName(), 0, pageSize);
assertThat_DtoContainsPathsForRepository(dto, pageOne, remote);
// Get NFC for page two
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName(), 1, pageSize);
assertThat_DtoContainsPathsForRepository(dto, pageTwo, remote);
// Get NFC for all with paging
// pageSize = 10;
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( 0, pageSize );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, hosted );
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( 1, pageSize );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, pageTwo, remote );
// Clear NFC for hosted
// client.module( IndyNfcClientModule.class ).clearInStore( StoreType.hosted, hosted.getName(), null );
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, remote );
// assertThat_DtoContainsNoneForRepository( dto, hosted );
// Clear NFC for remote
client.module(IndyNfcClientModule.class).clearInStore(StoreType.remote, remote.getName(), null);
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName());
assertThat(dto, notNullValue());
assertThat_DtoContainsNoneForRepository(dto, remote);
// assertThat_DtoContainsNoneForRepository( dto, hosted );
// Get NFC cache size and should be 0
// info = client.module( IndyNfcClientModule.class ).getInfo( hosted.getKey() );
// assertEquals( info.getSize(), 0 );
info = client.module(IndyNfcClientModule.class).getInfo(remote.getKey());
assertEquals(info.getSize(), 0);
info = client.module(IndyNfcClientModule.class).getInfo(group.getKey());
assertEquals(info.getSize(), 0);
testExpiration();
client.module(IndyNfcClientModule.class).clearAll();
}
Aggregations