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, @ApiParam(name = "pageIndex", value = "page index") @QueryParam("pageIndex") final Integer pageIndex, @ApiParam(name = "pageSize", value = "page size") @QueryParam("pageSize") final Integer pageSize) {
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 {
NotFoundCacheDTO dto;
Page page = new Page(pageIndex, pageSize);
if (page != null && page.allowPaging()) {
Pagination<NotFoundCacheDTO> nfcPagination = controller.getMissing(key, page);
dto = nfcPagination.getCurrData();
} else {
dto = controller.getMissing(key);
}
response = responseHelper.formatOkResponseWithJsonEntity(dto, rb -> responseHelper.markDeprecated(rb, altPath));
} catch (final IndyWorkflowException e) {
response = responseHelper.formatResponse(e, (rb) -> responseHelper.markDeprecated(rb, altPath));
}
return response;
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class NfcController method doGetMissing.
private NotFoundCacheDTO doGetMissing(final StoreKey key, int... pagingParams) throws IndyWorkflowException {
final NotFoundCacheDTO dto = new NotFoundCacheDTO();
if (key.getType() == group) {
List<ArtifactStore> stores;
try {
stores = storeManager.query().getOrderedConcreteStoresInGroup(key.getPackageType(), key.getName());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to retrieve concrete constituent for: %s.", e, key);
}
if (stores.size() >= MAX_GROUP_MEMBER_SIZE_FOR_GET_MISSING) {
throw new IndyWorkflowException(SC_UNPROCESSABLE_ENTITY, "Get missing for group failed (too many members), size: " + stores.size());
}
final List<? extends KeyedLocation> locations = toLocations(stores);
for (final KeyedLocation location : locations) {
Set<String> missing;
if (pagingParams != null && pagingParams.length > 0) {
missing = ((AbstractNotFoundCache) cache).getMissing(location, pagingParams[0], pagingParams[1]);
} else {
missing = cache.getMissing(location);
}
if (missing != null && !missing.isEmpty()) {
final List<String> paths = new ArrayList<>(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) {
Set<String> missing;
if (pagingParams != null && pagingParams.length > 0) {
missing = ((AbstractNotFoundCache) cache).getMissing(toLocation(store), pagingParams[0], pagingParams[1]);
} else {
missing = cache.getMissing(toLocation(store));
}
final List<String> paths = new ArrayList<>(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 NfcController method getAllMissing.
public Pagination<NotFoundCacheDTO> getAllMissing(Page page) {
return new DefaultPagination<>(page, (handler) -> {
Map<Location, Set<String>> allMissing = ((AbstractNotFoundCache) cache).getAllMissing(page.getPageIndex(), page.getPageSize());
NotFoundCacheDTO dto = getNotFoundCacheDTO(allMissing);
return dto;
});
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.
the class NFCForGroupsWithGroupsTest method run.
@Test
public void run() throws Exception {
try (InputStream inputStream = client.content().get(c.getKey(), PATH)) {
assertThat(inputStream, nullValue());
}
// NotFoundCacheDTO dto =
// client.module( IndyNfcClientModule.class ).getAllNfcContentInStore( StoreType.group, c.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.group, a.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 ) );
// 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(c.getKey(), PATH)) {
assertThat(inputStream, notNullValue());
}
NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.group, c.getName());
NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().findFirst().orElse(null);
assertThat(nfcSectionDto, nullValue());
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.group, a.getName());
nfcSectionDto = dto.getSections().stream().findFirst().orElse(null);
assertThat(nfcSectionDto, nullValue());
}
Aggregations