Search in sources :

Example 1 with EmbeddedPersistable

use of org.graylog2.plugin.database.EmbeddedPersistable in project graylog2-server by Graylog2.

the class InputServiceImpl method addStaticField.

@Override
public void addStaticField(Input input, final String key, final String value) throws ValidationException {
    final EmbeddedPersistable obj = new EmbeddedPersistable() {

        @Override
        public Map<String, Object> getPersistedFields() {
            return ImmutableMap.<String, Object>of(InputImpl.FIELD_STATIC_FIELD_KEY, key, InputImpl.FIELD_STATIC_FIELD_VALUE, value);
        }
    };
    embed(input, InputImpl.EMBEDDED_STATIC_FIELDS, obj);
    publishChange(InputUpdated.create(input.getId()));
}
Also used : DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) EmbeddedPersistable(org.graylog2.plugin.database.EmbeddedPersistable)

Example 2 with EmbeddedPersistable

use of org.graylog2.plugin.database.EmbeddedPersistable in project graylog2-server by Graylog2.

the class PersistedServiceImpl method embed.

protected <T extends Persisted> void embed(T model, String key, EmbeddedPersistable o) throws ValidationException {
    Map<String, List<ValidationResult>> errors = validate(model.getEmbeddedValidations(key), o.getPersistedFields());
    if (!errors.isEmpty()) {
        throw new ValidationException(errors);
    }
    Map<String, Object> fields = Maps.newHashMap(o.getPersistedFields());
    fieldTransformations(fields);
    BasicDBObject dbo = new BasicDBObject(fields);
    collection(model).update(new BasicDBObject("_id", new ObjectId(model.getId())), new BasicDBObject("$push", new BasicDBObject(key, dbo)));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) List(java.util.List) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectId (org.bson.types.ObjectId)1 EmbeddedPersistable (org.graylog2.plugin.database.EmbeddedPersistable)1 ValidationException (org.graylog2.plugin.database.ValidationException)1