use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class OutputFacade method decode.
private NativeEntity<Output> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
final OutputEntity outputEntity = objectMapper.convertValue(entity.data(), OutputEntity.class);
final CreateOutputRequest createOutputRequest = CreateOutputRequest.create(outputEntity.title().asString(parameters), outputEntity.type().asString(parameters), toValueMap(outputEntity.configuration(), parameters), // Outputs are assigned to streams in StreamFacade
null);
try {
final Output output = outputService.create(createOutputRequest, username);
return NativeEntity.create(entity.id(), output.getId(), TYPE_V1, output.getTitle(), output);
} catch (ValidationException e) {
throw new IllegalArgumentException(e);
}
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class PipelineRuleFacade method findExisting.
private Optional<NativeEntity<RuleDao>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
final PipelineRuleEntity ruleEntity = objectMapper.convertValue(entity.data(), PipelineRuleEntity.class);
final String title = ruleEntity.title().asString(parameters);
final String source = ruleEntity.source().asString(parameters);
try {
final RuleDao ruleDao = ruleService.loadByName(title);
compareRuleSources(title, source, ruleDao.source());
return Optional.of(NativeEntity.create(entity.id(), ruleDao.id(), TYPE_V1, ruleDao.title(), ruleDao));
} catch (NotFoundException e) {
return Optional.empty();
}
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class ViewFacade method decode.
protected NativeEntity<ViewDTO> decode(EntityV1 entityV1, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, User user) {
final ViewEntity viewEntity = objectMapper.convertValue(entityV1.data(), ViewEntity.class);
final Map<String, ViewStateDTO> viewStateMap = new LinkedHashMap<>(viewEntity.state().size());
for (Map.Entry<String, ViewStateEntity> entry : viewEntity.state().entrySet()) {
final ViewStateEntity entity = entry.getValue();
viewStateMap.put(entry.getKey(), entity.toNativeEntity(parameters, nativeEntities));
}
final ViewDTO.Builder viewBuilder = viewEntity.toNativeEntity(parameters, nativeEntities);
viewBuilder.state(viewStateMap);
final Search search = viewEntity.search().toNativeEntity(parameters, nativeEntities);
final Search persistedSearch = searchDbService.save(search);
final ViewDTO persistedView = viewService.saveWithOwner(viewBuilder.searchId(persistedSearch.id()).build(), user);
return NativeEntity.create(entityV1.id(), persistedView.id(), getModelType(), persistedView.title(), persistedView);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class GrokPatternFacade method decode.
private NativeEntity<GrokPattern> decode(EntityV1 entity) {
final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entity.data(), GrokPatternEntity.class);
final GrokPattern grokPattern = GrokPattern.create(grokPatternEntity.name(), grokPatternEntity.pattern());
try {
final GrokPattern savedGrokPattern = grokPatternService.save(grokPattern);
return NativeEntity.create(entity.id(), savedGrokPattern.id(), TYPE_V1, savedGrokPattern.name(), savedGrokPattern);
} catch (ValidationException e) {
throw new RuntimeException("Couldn't create grok pattern " + grokPattern.name());
}
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class LookupDataAdapterFacade method findExisting.
private Optional<NativeEntity<DataAdapterDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
final LookupDataAdapterEntity dataAdapterEntity = objectMapper.convertValue(entity.data(), LookupDataAdapterEntity.class);
final String name = dataAdapterEntity.name().asString(parameters);
final Optional<DataAdapterDto> existingDataAdapter = dataAdapterService.get(name);
return existingDataAdapter.map(dataAdapter -> NativeEntity.create(entity.id(), dataAdapter.id(), TYPE_V1, dataAdapter.title(), dataAdapter));
}
Aggregations