@Test public void findOneTest_two_searches() throws Exception { SavedSearchCache cache=new SavedSearchCache(null); foundDocs=new ArrayList<JsonDoc>(); foundDocs.add(makeSearch("testSearch","test","{\"field\":\"a\",\"op\":\"=\",\"rvalue\":1}")); foundDocs.add(makeSearch("testSearch","test","{\"field\":\"a\",\"op\":\"=\",\"rvalue\":1}","1.0.0")); JsonNode doc=cache.getSavedSearch(mediator,null,"testSearch","test","1.0.0"); Assert.assertTrue(doc instanceof ObjectNode); Assert.assertEquals("1.0.0",doc.get("versions").get(0).asText()); }
public JsonNode getSavedSearch(Mediator m, ClientIdentification clid, String searchName, String entity, String version) { LOGGER.debug("Loading {}:{}:{}",searchName,entity,version); ObjectNode doc=null; String loadVersion; if(version==null) { LOGGER.debug("{} version is null, attempting to find default version for entity",entity); EntityMetadata md=m.metadata.getEntityMetadata(entity,null); if(md==null) throw Error.get(CrudConstants.ERR_UNKNOWN_ENTITY,entity+":"+version); loadVersion=md.getVersion().getValue(); LOGGER.debug("Loading {}:{}:{}",searchName,entity,loadVersion); } else { loadVersion=version; } Key key=new Key(searchName,entity,loadVersion); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); if(doc==null) { key=new Key(searchName,entity,null); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); } if(doc==null) { LOGGER.debug("Loading {} from DB",searchName); JsonNode node=getSavedSearchFromDB(m,clid,searchName,entity,loadVersion); if(node instanceof ObjectNode) { LOGGER.debug("Loaded a single search"); doc=(ObjectNode)node; store(doc); } else if(node instanceof ArrayNode) { LOGGER.debug("Loaded an array of searches"); store((ArrayNode)node); doc=findDocForVersion((ArrayNode)node,loadVersion); } if(doc!=null) { store(doc); } } return doc; }
SavedSearchCache { public JsonNode getSavedSearch(Mediator m, ClientIdentification clid, String searchName, String entity, String version) { LOGGER.debug("Loading {}:{}:{}",searchName,entity,version); ObjectNode doc=null; String loadVersion; if(version==null) { LOGGER.debug("{} version is null, attempting to find default version for entity",entity); EntityMetadata md=m.metadata.getEntityMetadata(entity,null); if(md==null) throw Error.get(CrudConstants.ERR_UNKNOWN_ENTITY,entity+":"+version); loadVersion=md.getVersion().getValue(); LOGGER.debug("Loading {}:{}:{}",searchName,entity,loadVersion); } else { loadVersion=version; } Key key=new Key(searchName,entity,loadVersion); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); if(doc==null) { key=new Key(searchName,entity,null); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); } if(doc==null) { LOGGER.debug("Loading {} from DB",searchName); JsonNode node=getSavedSearchFromDB(m,clid,searchName,entity,loadVersion); if(node instanceof ObjectNode) { LOGGER.debug("Loaded a single search"); doc=(ObjectNode)node; store(doc); } else if(node instanceof ArrayNode) { LOGGER.debug("Loaded an array of searches"); store((ArrayNode)node); doc=findDocForVersion((ArrayNode)node,loadVersion); } if(doc!=null) { store(doc); } } return doc; } }
SavedSearchCache { public JsonNode getSavedSearch(Mediator m, ClientIdentification clid, String searchName, String entity, String version) { LOGGER.debug("Loading {}:{}:{}",searchName,entity,version); ObjectNode doc=null; String loadVersion; if(version==null) { LOGGER.debug("{} version is null, attempting to find default version for entity",entity); EntityMetadata md=m.metadata.getEntityMetadata(entity,null); if(md==null) throw Error.get(CrudConstants.ERR_UNKNOWN_ENTITY,entity+":"+version); loadVersion=md.getVersion().getValue(); LOGGER.debug("Loading {}:{}:{}",searchName,entity,loadVersion); } else { loadVersion=version; } Key key=new Key(searchName,entity,loadVersion); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); if(doc==null) { key=new Key(searchName,entity,null); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); } if(doc==null) { LOGGER.debug("Loading {} from DB",searchName); JsonNode node=getSavedSearchFromDB(m,clid,searchName,entity,loadVersion); if(node instanceof ObjectNode) { LOGGER.debug("Loaded a single search"); doc=(ObjectNode)node; store(doc); } else if(node instanceof ArrayNode) { LOGGER.debug("Loaded an array of searches"); store((ArrayNode)node); doc=findDocForVersion((ArrayNode)node,loadVersion); } if(doc!=null) { store(doc); } } return doc; } SavedSearchCache(SavedSearchConfiguration cfg); }
SavedSearchCache { public JsonNode getSavedSearch(Mediator m, ClientIdentification clid, String searchName, String entity, String version) { LOGGER.debug("Loading {}:{}:{}",searchName,entity,version); ObjectNode doc=null; String loadVersion; if(version==null) { LOGGER.debug("{} version is null, attempting to find default version for entity",entity); EntityMetadata md=m.metadata.getEntityMetadata(entity,null); if(md==null) throw Error.get(CrudConstants.ERR_UNKNOWN_ENTITY,entity+":"+version); loadVersion=md.getVersion().getValue(); LOGGER.debug("Loading {}:{}:{}",searchName,entity,loadVersion); } else { loadVersion=version; } Key key=new Key(searchName,entity,loadVersion); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); if(doc==null) { key=new Key(searchName,entity,null); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); } if(doc==null) { LOGGER.debug("Loading {} from DB",searchName); JsonNode node=getSavedSearchFromDB(m,clid,searchName,entity,loadVersion); if(node instanceof ObjectNode) { LOGGER.debug("Loaded a single search"); doc=(ObjectNode)node; store(doc); } else if(node instanceof ArrayNode) { LOGGER.debug("Loaded an array of searches"); store((ArrayNode)node); doc=findDocForVersion((ArrayNode)node,loadVersion); } if(doc!=null) { store(doc); } } return doc; } SavedSearchCache(SavedSearchConfiguration cfg); JsonNode getSavedSearchFromDB(Mediator m,
                                         ClientIdentification clid,
                                         String searchName,
                                         String entity,
                                         String version); JsonNode getSavedSearch(Mediator m,
                                   ClientIdentification clid,
                                   String searchName,
                                   String entity,
                                   String version); }
SavedSearchCache { public JsonNode getSavedSearch(Mediator m, ClientIdentification clid, String searchName, String entity, String version) { LOGGER.debug("Loading {}:{}:{}",searchName,entity,version); ObjectNode doc=null; String loadVersion; if(version==null) { LOGGER.debug("{} version is null, attempting to find default version for entity",entity); EntityMetadata md=m.metadata.getEntityMetadata(entity,null); if(md==null) throw Error.get(CrudConstants.ERR_UNKNOWN_ENTITY,entity+":"+version); loadVersion=md.getVersion().getValue(); LOGGER.debug("Loading {}:{}:{}",searchName,entity,loadVersion); } else { loadVersion=version; } Key key=new Key(searchName,entity,loadVersion); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); if(doc==null) { key=new Key(searchName,entity,null); LOGGER.debug("Lookup {}",key); doc=cache.getIfPresent(key); } if(doc==null) { LOGGER.debug("Loading {} from DB",searchName); JsonNode node=getSavedSearchFromDB(m,clid,searchName,entity,loadVersion); if(node instanceof ObjectNode) { LOGGER.debug("Loaded a single search"); doc=(ObjectNode)node; store(doc); } else if(node instanceof ArrayNode) { LOGGER.debug("Loaded an array of searches"); store((ArrayNode)node); doc=findDocForVersion((ArrayNode)node,loadVersion); } if(doc!=null) { store(doc); } } return doc; } SavedSearchCache(SavedSearchConfiguration cfg); JsonNode getSavedSearchFromDB(Mediator m,
                                         ClientIdentification clid,
                                         String searchName,
                                         String entity,
                                         String version); JsonNode getSavedSearch(Mediator m,
                                   ClientIdentification clid,
                                   String searchName,
                                   String entity,
                                   String version); static final String ERR_SAVED_SEARCH; final String savedSearchEntity; final String savedSearchVersion; }