Skip to content

Commit

Permalink
Removed MongoDB related code
Browse files Browse the repository at this point in the history
  • Loading branch information
luk-kaminski committed May 7, 2024
1 parent c0214aa commit e44df82
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
*/
package org.graylog.plugins.formatting.units.db;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.Indexes;
import jakarta.inject.Inject;
import com.google.inject.Singleton;
import org.graylog.plugins.formatting.units.model.BaseUnit;
import org.graylog.plugins.formatting.units.model.Conversion;
import org.graylog.plugins.formatting.units.model.DerivedUnit;
import org.graylog.plugins.formatting.units.model.Unit;
import org.graylog.plugins.formatting.units.model.UnitView;
import org.graylog2.database.MongoCollections;

import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -36,26 +32,22 @@
import static org.graylog.plugins.formatting.units.model.Conversion.ConversionAction.MULTIPLY;


@Singleton
public class UnitService {

static final String UNITS_COLL_NAME = "units";

private final MongoCollection<Unit> unitMongoCollection;

@Inject
public UnitService(final MongoCollections mongoCollections) {
unitMongoCollection = mongoCollections.get(UNITS_COLL_NAME, Unit.class);
unitMongoCollection.createIndex(Indexes.ascending(Unit.UNIT_TYPE, Unit.NAME), new IndexOptions().unique(true));
unitMongoCollection.createIndex(Indexes.ascending(Unit.UNIT_TYPE, Unit.ABBREVIATION), new IndexOptions().unique(true));
}

public void save(final Unit unit) {
unitMongoCollection.insertOne(unit);
}
private List<Unit> units = List.of(
new BaseUnit("b", "byte", "size", true, false),
new BaseUnit("s", "second", "time", false, true),
new DerivedUnit("min", "minute", "time", new Conversion(60, MULTIPLY)),
new DerivedUnit("h", "hour", "time", new Conversion(60 * 60, MULTIPLY)),
new DerivedUnit("d", "day", "time", new Conversion(24 * 60 * 60, MULTIPLY)),
new DerivedUnit("m", "month", "time", new Conversion(30 * 24 * 60 * 60, MULTIPLY)),
new BaseUnit("%", "percent", "percent", false, false)
);

public Map<String, List<UnitView>> getAll() {
Map<String, List<UnitView>> groupedByUnitType = new HashMap<>();
unitMongoCollection.find().forEach(unit -> {
units.forEach(unit -> {
groupedByUnitType.putIfAbsent(unit.unitType(), new LinkedList<>());
final List<UnitView> unitsOfTheSameUnitType = groupedByUnitType.get(unit.unitType());

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.inject.Scopes;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.graylog.plugins.formatting.units.migrations.V20240422120000_SetInitialUnits;
import org.graylog.plugins.formatting.units.rest.UnitResource;
import org.graylog.plugins.views.audit.ViewsAuditEventTypes;
import org.graylog.plugins.views.favorites.FavoritesResource;
Expand Down Expand Up @@ -240,7 +239,6 @@ protected void configure() {
addMigration(V20200204122000_MigrateUntypedViewsToDashboards.class);
addMigration(V20200409083200_RemoveRootQueriesFromMigratedDashboards.class);
addMigration(V20200730000000_AddGl2MessageIdFieldAliasForEvents.class);
addMigration(V20240422120000_SetInitialUnits.class);

addAuditEventTypes(ViewsAuditEventTypes.class);

Expand Down

This file was deleted.

0 comments on commit e44df82

Please sign in to comment.