.upsert(upsert));
}
+ @Override
+ public List<UpdateRequest> normalize(Object object, Object key) {
+ Preconditions.checkArgument(object.getClass().isAssignableFrom(ActiveRuleParamDto.class), "Cannot Normalize class");
+ Preconditions.checkArgument(key.getClass().isAssignableFrom(ActiveRuleKey.class), "key is not an ActiveRuleKey");
+
+ return normalize((ActiveRuleParamDto)object, (ActiveRuleKey)key);
+ }
+
public List<UpdateRequest> normalize(ActiveRuleParamDto param, ActiveRuleKey key) {
Preconditions.checkArgument(key != null, "Cannot normalize ActiveRuleParamDto for null key of ActiveRule");
*/
package org.sonar.server.rule.index;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import org.elasticsearch.action.update.UpdateRequest;
super(IndexDefinition.RULE, db);
}
+
@Override
public List<UpdateRequest> normalize(RuleKey key) {
DbSession dbSession = db.openSession(false);
}
}
- public List<UpdateRequest> normalize(RuleParamDto param, RuleKey key) {
+ @Override
+ public List<UpdateRequest> normalize(Object object, Object key) {
+ Preconditions.checkArgument(object.getClass().isAssignableFrom(RuleParamDto.class), "Cannot Normalize class");
+ Preconditions.checkArgument(key.getClass().isAssignableFrom(RuleKey.class), "key is not an ActiveRuleKey");
+
+ return normalize((RuleParamDto)object, (RuleKey)key);
+ }
+
+ private List<UpdateRequest> normalize(RuleParamDto param, RuleKey key) {
Map<String, Object> newParam = new HashMap<String, Object>();
newParam.put(RuleParamField.NAME.field(), param.getName());
protected abstract Map mapKey();
- protected Map mapDomain(){
+ protected Map mapDomain() {
Map<String, Object> mapping = new HashMap<String, Object>();
mapping.put("dynamic", false);
mapping.put("_id", mapKey());
mapping.put("type", "nested");
Map<String, Object> mappings = new HashMap<String, Object>();
for (IndexField nestedField : field.nestedFields()) {
- if(nestedField != null) {
+ if (nestedField != null) {
mappings.put(nestedField.field(), mapField(nestedField));
}
}
@Override
public void upsert(Object obj, K key) throws Exception {
- if (this.normalizer.canNormalize(obj.getClass(), key.getClass())) {
- this.updateDocument(this.normalizer.normalizeOther(obj, key), key);
- } else {
- throw new IllegalStateException("Index " + this.getIndexName() +
- " cannot execute UPDATE for class: " + obj.getClass());
- }
+ this.updateDocument(this.normalizer.normalize(obj, key), key);
}
@Override
@Override
public void delete(Object obj, K key) throws Exception {
- if (this.normalizer.canNormalize(obj.getClass(), key.getClass())) {
- //TODO don't really know what to do here for the moment...
- } else {
- throw new IllegalStateException("Index " + this.getIndexName() +
- " cannot execute DELETE for class: " + obj.getClass());
- }
+ throw new IllegalStateException("Cannot delete nested Object from ES. Should be using Update");
}
@Override
import org.sonar.server.db.DbClient;
import java.io.Serializable;
-import java.util.List;
public abstract class BaseNormalizer<E extends Dto<K>, K extends Serializable> {
this.definition = definition;
}
- public boolean canNormalize(Class<?> objectClass, Class<?> keyClass) {
- try {
- return this.getClass().getMethod("normalize", objectClass, keyClass) != null;
- } catch (NoSuchMethodException e) {
- return false;
- }
- }
-
- public List<UpdateRequest> normalizeOther(Object object, Object key) {
- try {
- return (List<UpdateRequest>) this.getClass()
- .getMethod("normalize", object.getClass(), key.getClass())
- .invoke(this, object, key);
- } catch (Exception e) {
- throw new IllegalStateException("Could not invoke Normalizer Method", e);
- }
- }
+ public abstract java.util.List<UpdateRequest> normalize(Object object, Object key);
public abstract java.util.List<UpdateRequest> normalize(K key);