Search in sources :

Example 6 with CacheApi

use of org.graylog2.rest.models.system.lookup.CacheApi in project graylog2-server by Graylog2.

the class LookupTableResource method get.

@GET
@Path("tables/{idOrName}")
@ApiOperation(value = "Retrieve the named lookup table")
public LookupTablePage get(@ApiParam(name = "idOrName") @PathParam("idOrName") @NotEmpty String idOrName, @ApiParam(name = "resolve") @QueryParam("resolve") @DefaultValue("false") boolean resolveObjects) {
    Optional<LookupTableDto> lookupTableDto = dbTableService.get(idOrName);
    if (!lookupTableDto.isPresent()) {
        throw new NotFoundException();
    }
    LookupTableDto tableDto = lookupTableDto.get();
    checkPermission(RestPermissions.LOOKUP_TABLES_READ, tableDto.id());
    Set<CacheApi> caches = Collections.emptySet();
    Set<DataAdapterApi> adapters = Collections.emptySet();
    if (resolveObjects) {
        caches = dbCacheService.findByIds(Collections.singleton(tableDto.cacheId())).stream().map(CacheApi::fromDto).collect(Collectors.toSet());
        adapters = dbDataAdapterService.findByIds(Collections.singleton(tableDto.dataAdapterId())).stream().map(DataAdapterApi::fromDto).collect(Collectors.toSet());
    }
    final PaginatedList<LookupTableApi> result = PaginatedList.singleton(LookupTableApi.fromDto(tableDto), 1, 1);
    return new LookupTablePage(null, result.pagination(), result, caches, adapters);
}
Also used : LookupTableApi(org.graylog2.rest.models.system.lookup.LookupTableApi) NotFoundException(javax.ws.rs.NotFoundException) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) CacheApi(org.graylog2.rest.models.system.lookup.CacheApi) DataAdapterApi(org.graylog2.rest.models.system.lookup.DataAdapterApi) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)6 Path (javax.ws.rs.Path)6 CacheDto (org.graylog2.lookup.dto.CacheDto)4 BadRequestException (javax.ws.rs.BadRequestException)3 GET (javax.ws.rs.GET)3 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 CacheApi (org.graylog2.rest.models.system.lookup.CacheApi)3 NotFoundException (javax.ws.rs.NotFoundException)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 LookupTableDto (org.graylog2.lookup.dto.LookupTableDto)2 DataAdapterApi (org.graylog2.rest.models.system.lookup.DataAdapterApi)2 LookupTableApi (org.graylog2.rest.models.system.lookup.LookupTableApi)2 SearchQuery (org.graylog2.search.SearchQuery)2 DBQuery (org.mongojack.DBQuery)2 DBSort (org.mongojack.DBSort)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Multimap (com.google.common.collect.Multimap)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1