Search in sources :

Example 11 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class LookupTableFacade method findExisting.

private Optional<NativeEntity<LookupTableDto>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
    final String name = lookupTableEntity.name().asString(parameters);
    final String title = lookupTableEntity.title().asString(parameters);
    final Optional<LookupTableDto> lookupTable = lookupTableService.get(name);
    lookupTable.ifPresent(existingLookupTable -> compareLookupTable(name, title, existingLookupTable));
    return lookupTable.map(lt -> NativeEntity.create(entity.id(), lt.id(), TYPE_V1, lt.title(), lt));
}
Also used : LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto)

Example 12 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class ContentPackService method getUninstallDetails.

private ContentPackUninstallDetails getUninstallDetails(ContentPackV1 contentPack, ContentPackInstallation installation) {
    final Entity rootEntity = EntityV1.createRoot(contentPack);
    final ImmutableMap<String, ValueReference> parameters = installation.parameters();
    final ImmutableGraph<Entity> dependencyGraph = buildEntityGraph(rootEntity, contentPack.entities(), parameters);
    final Traverser<Entity> entityTraverser = Traverser.forGraph(dependencyGraph);
    final Iterable<Entity> entitiesInOrder = entityTraverser.breadthFirst(rootEntity);
    final Set<NativeEntityDescriptor> nativeEntityDescriptors = new HashSet<>();
    entitiesInOrder.forEach((entity -> {
        if (entity.equals(rootEntity)) {
            return;
        }
        final Optional<NativeEntityDescriptor> nativeEntityDescriptorOptional = installation.entities().stream().filter(descriptor -> entity.id().equals(descriptor.contentPackEntityId())).findFirst();
        if (nativeEntityDescriptorOptional.isPresent()) {
            NativeEntityDescriptor nativeEntityDescriptor = nativeEntityDescriptorOptional.get();
            if (contentPackInstallationPersistenceService.countInstallationOfEntityById(nativeEntityDescriptor.id()) <= 1) {
                nativeEntityDescriptors.add(nativeEntityDescriptor);
            }
        }
    }));
    return ContentPackUninstallDetails.create(nativeEntityDescriptors);
}
Also used : ElementOrder(com.google.common.graph.ElementOrder) Graphs(org.graylog2.utilities.Graphs) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ContentPack(org.graylog2.contentpacks.model.ContentPack) LoggerFactory(org.slf4j.LoggerFactory) ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) ModelType(org.graylog2.contentpacks.model.ModelType) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) LegacyContentPack(org.graylog2.contentpacks.model.LegacyContentPack) Map(java.util.Map) FailedConstraintsException(org.graylog2.contentpacks.exceptions.FailedConstraintsException) InvalidParameterTypeException(org.graylog2.contentpacks.exceptions.InvalidParameterTypeException) MissingParametersException(org.graylog2.contentpacks.exceptions.MissingParametersException) UnsupportedEntityFacade(org.graylog2.contentpacks.facades.UnsupportedEntityFacade) ImmutableSet(com.google.common.collect.ImmutableSet) ModelId(org.graylog2.contentpacks.model.ModelId) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) EntityWithExcerptFacade(org.graylog2.contentpacks.facades.EntityWithExcerptFacade) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) GraphBuilder(com.google.common.graph.GraphBuilder) InvalidParametersException(org.graylog2.contentpacks.exceptions.InvalidParametersException) Parameter(org.graylog2.contentpacks.model.parameters.Parameter) Optional(java.util.Optional) ConstraintChecker(org.graylog2.contentpacks.constraints.ConstraintChecker) ContentPackUninstallDetails(org.graylog2.contentpacks.model.ContentPackUninstallDetails) EmptyDefaultValueException(org.graylog2.contentpacks.exceptions.EmptyDefaultValueException) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) Entity(org.graylog2.contentpacks.model.entities.Entity) HashMap(java.util.HashMap) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ValueType(org.graylog2.contentpacks.model.entities.references.ValueType) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Inject(javax.inject.Inject) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) EntityFacade(org.graylog2.contentpacks.facades.EntityFacade) Logger(org.slf4j.Logger) ContentPackUninstallation(org.graylog2.contentpacks.model.ContentPackUninstallation) ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) UnexpectedEntitiesException(org.graylog2.contentpacks.exceptions.UnexpectedEntitiesException) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Traverser(com.google.common.graph.Traverser) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Collections(java.util.Collections) Graph(com.google.common.graph.Graph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) Optional(java.util.Optional) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) HashSet(java.util.HashSet)

Example 13 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference 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);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) CreateOutputRequest(org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest)

Example 14 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference 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();
    }
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) PipelineRuleEntity(org.graylog2.contentpacks.model.entities.PipelineRuleEntity) NotFoundException(org.graylog2.database.NotFoundException)

Example 15 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference 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);
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) Search(org.graylog.plugins.views.search.Search) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)18 Entity (org.graylog2.contentpacks.model.entities.Entity)16 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Map (java.util.Map)10 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)10 ModelType (org.graylog2.contentpacks.model.ModelType)10 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)10 Set (java.util.Set)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Graph (com.google.common.graph.Graph)8 GraphBuilder (com.google.common.graph.GraphBuilder)8 ImmutableGraph (com.google.common.graph.ImmutableGraph)8 MutableGraph (com.google.common.graph.MutableGraph)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Collection (java.util.Collection)7