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()));
}
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)));
}
Aggregations