Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog2.streams;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.QueryBuilder;
import com.mongodb.WriteResult;
import org.bson.types.ObjectId;
import org.graylog.security.entities.EntityOwnershipService;
import org.graylog2.database.MongoConnection;
import org.graylog2.database.NotFoundException;
import org.graylog2.database.PersistedServiceImpl;
import org.graylog2.events.ClusterEventBus;
import org.graylog2.indexer.IndexSet;
import org.graylog2.indexer.MongoIndexSet;
import org.graylog2.indexer.indexset.IndexSetConfig;
import org.graylog2.indexer.indexset.IndexSetService;
import org.graylog2.notifications.Notification;
import org.graylog2.notifications.NotificationService;
import org.graylog2.plugin.Tools;
import org.graylog2.plugin.database.ValidationException;
import org.graylog2.plugin.database.users.User;
import org.graylog2.plugin.streams.Output;
import org.graylog2.plugin.streams.Stream;
import org.graylog2.plugin.streams.StreamRule;
import org.graylog2.rest.resources.streams.requests.CreateStreamRequest;
import org.graylog2.streams.events.StreamDeletedEvent;
import org.graylog2.streams.events.StreamsChangedEvent;
import org.mongojack.DBProjection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.client.model.Projections.excludeId;
import static com.mongodb.client.model.Projections.fields;
import static com.mongodb.client.model.Projections.include;
import static org.graylog2.streams.StreamImpl.FIELD_INDEX_SET_ID;
import static org.graylog2.streams.StreamImpl.FIELD_TITLE;
public class StreamServiceImpl extends PersistedServiceImpl implements StreamService {
private static final Logger LOG = LoggerFactory.getLogger(StreamServiceImpl.class);
private final StreamRuleService streamRuleService;
private final OutputService outputService;
private final IndexSetService indexSetService;
private final MongoIndexSet.Factory indexSetFactory;
private final NotificationService notificationService;
private final EntityOwnershipService entityOwnershipService;
private final ClusterEventBus clusterEventBus;
@Inject
public StreamServiceImpl(MongoConnection mongoConnection,
StreamRuleService streamRuleService,
OutputService outputService,
IndexSetService indexSetService,
MongoIndexSet.Factory indexSetFactory,
NotificationService notificationService,
EntityOwnershipService entityOwnershipService,
ClusterEventBus clusterEventBus) {
super(mongoConnection);
this.streamRuleService = streamRuleService;
this.outputService = outputService;
this.indexSetService = indexSetService;
this.indexSetFactory = indexSetFactory;
this.notificationService = notificationService;
this.entityOwnershipService = entityOwnershipService;
this.clusterEventBus = clusterEventBus;
}
@Nullable
private IndexSet getIndexSet(DBObject dbObject) {
return getIndexSet((String) dbObject.get(FIELD_INDEX_SET_ID));
}
@Nullable
private IndexSet getIndexSet(String id) {
if (isNullOrEmpty(id)) {
return null;
}
final Optional indexSetConfig = indexSetService.get(id);
return indexSetConfig.flatMap(c -> Optional.of(indexSetFactory.create(c))).orElse(null);
}
public Stream load(ObjectId id) throws NotFoundException {
final DBObject o = get(StreamImpl.class, id);
if (o == null) {
throw new NotFoundException("Stream <" + id + "> not found!");
}
final List streamRules = streamRuleService.loadForStreamId(id.toHexString());
final Set