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);
}
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;
}
Aggregations