Search in sources :

Example 6 with DataAdapterApi

use of org.graylog2.rest.models.system.lookup.DataAdapterApi 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)

Example 7 with DataAdapterApi

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

the class LookupTableResource method validateAdapter.

@POST
@Path("adapters/validate")
@NoAuditEvent("Validation only")
@ApiOperation(value = "Validate the data adapter config")
@RequiresPermissions(RestPermissions.LOOKUP_TABLES_READ)
public ValidationResult validateAdapter(@Valid @ApiParam DataAdapterApi toValidate) {
    final ValidationResult validation = new ValidationResult();
    final Optional<DataAdapterDto> dtoOptional = dbDataAdapterService.get(toValidate.name());
    if (dtoOptional.isPresent()) {
        // an adapter exist with the given name, check that the IDs are the same, this might be an update
        final DataAdapterDto adapterDto = dtoOptional.get();
        // noinspection ConstantConditions
        if (!adapterDto.id().equals(toValidate.id())) {
            // an adapter exists with a different id, so the name is already in use, fail validation
            validation.addError("name", "The data adapter name is already in use.");
        }
    }
    final Optional<Multimap<String, String>> configValidations = toValidate.config().validate(lookupDataAdapterValidationContext);
    configValidations.ifPresent(validation::addAll);
    return validation;
}
Also used : Multimap(com.google.common.collect.Multimap) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)7 Path (javax.ws.rs.Path)7 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)5 BadRequestException (javax.ws.rs.BadRequestException)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)4 GET (javax.ws.rs.GET)3 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 DataAdapterApi (org.graylog2.rest.models.system.lookup.DataAdapterApi)3 NotFoundException (javax.ws.rs.NotFoundException)2 POST (javax.ws.rs.POST)2 LookupTableDto (org.graylog2.lookup.dto.LookupTableDto)2 CacheApi (org.graylog2.rest.models.system.lookup.CacheApi)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 DuplicateKeyException (com.mongodb.DuplicateKeyException)1