public String toJson() { Map<String, Object> x = new HashMap<String, Object>(); x.put("equals", equals); x.put("notEquals", notEquals); x.put("exists", exists); x.put("touched", touched); if(action!=null) { x.put("action", action.toString()); } return SerializationUtils.toJson(x); }
requireAction(Action.valueOf((String)queryObject.get("action")));
bob.add(MongoDocument.ACTION_KEY, md.getAction().toString());
@SuppressWarnings("unchecked") @Override public final void fromJson(String json) throws JsonException { try { Map<String, Object> m = SerializationUtils.fromJson(json); if(m.containsKey(ID_KEY)) { documentMap.put(ID_KEY, m.get(ID_KEY)); } if(m.containsKey(ACTION_KEY) && m.get(ACTION_KEY)!=null) { documentMap.put(ACTION_KEY, Action.valueOf((String)m.get(ACTION_KEY))); } if(m.containsKey(METADATA_KEY)) { Map<String, Object> metadata = (Map<String, Object>) m.get(METADATA_KEY); for(Map.Entry<String, Object> e : metadata.entrySet()) { putMetadataField(e.getKey(), metadata.get(e.getKey())); } } if(m.containsKey(CONTENTS_KEY)) { Map<String, Object> content = (Map<String, Object>) m.get(CONTENTS_KEY); for(Map.Entry<String, Object> e : content.entrySet()) { putContentField(e.getKey(), content.get(e.getKey())); } } } catch(JsonParseException e) { internalLogger.error("Caught JsonParseException, throwing JsonException"); throw new JsonException(e); } }
@SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } }
@Override public void output(LocalDocument document) { final Action action = document.getAction(); logger.debug(action.toString()); switch (action) { case ADD: add(document); break; case DELETE: delete(document); break; case UPDATE: update(document); break; default: throw new IllegalArgumentException("Action must be ADD, DELETE or UPDATE."); } }
@Override public void setAction(Action action) { actionTouched = true; if(action==null) { documentMap.put(ACTION_KEY, null); } else { documentMap.put(ACTION_KEY, action.toString()); } }
@Override public final void requireAction(Action action) { qb = qb.put(MongoDocument.ACTION_KEY).is(action.toString()); this.action = action; }
@Override public Action getAction() { Object o = documentMap.get(ACTION_KEY); if(o!=null) { return Action.valueOf((String)o); } return null; }