Search in sources :

Example 11 with NotFoundCacheDTO

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;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) PathParam(javax.ws.rs.PathParam) REST(org.commonjava.indy.bind.jaxrs.util.REST) NfcController(org.commonjava.indy.core.ctl.NfcController) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Pagination(org.commonjava.indy.core.model.Pagination) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Api(io.swagger.annotations.Api) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) DELETE(javax.ws.rs.DELETE) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Logger(org.slf4j.Logger) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) NotFoundCacheInfoDTO(org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO) ApplicationContent(org.commonjava.indy.util.ApplicationContent) Response(javax.ws.rs.core.Response) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) Page(org.commonjava.indy.core.model.Page) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Page(org.commonjava.indy.core.model.Page) StoreKey(org.commonjava.indy.model.core.StoreKey) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with NotFoundCacheDTO

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;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO)

Example 13 with NotFoundCacheDTO

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;
    });
}
Also used : AbstractNotFoundCache(org.commonjava.indy.core.inject.AbstractNotFoundCache) Set(java.util.Set) DefaultPagination(org.commonjava.indy.core.model.DefaultPagination) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LocationUtils.toLocation(org.commonjava.indy.util.LocationUtils.toLocation) Location(org.commonjava.maven.galley.model.Location)

Example 14 with NotFoundCacheDTO

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotFoundCacheSectionDTO(org.commonjava.indy.model.core.dto.NotFoundCacheSectionDTO) IndyNfcClientModule(org.commonjava.indy.client.core.module.IndyNfcClientModule) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Aggregations

NotFoundCacheDTO (org.commonjava.indy.model.core.dto.NotFoundCacheDTO)14 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 StoreType (org.commonjava.indy.model.core.StoreType)5 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)5 ApiResponse (io.swagger.annotations.ApiResponse)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Response (javax.ws.rs.core.Response)4 IndyNfcClientModule (org.commonjava.indy.client.core.module.IndyNfcClientModule)4 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Page (org.commonjava.indy.core.model.Page)3 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2