@Test public void testPopulateSearchObject() throws Exception { String[][] props = new String[4][2]; props[0] = new String[]{"channel","one"}; props[1] = new String[]{"type","computer"}; props[2] = new String[]{"attributed_to","user1"}; props[3] = new String[]{config.getRequestParameterForSize(),"3"}; Map properties = getProperties("1",props); RelatedItemSearch objectToPopulate = factory.createSearchObject(); assertEquals(0,objectToPopulate.getMaxResults()); assertEquals("",objectToPopulate.getRelatedItemId()); assertEquals(0,objectToPopulate.getAdditionalSearchCriteria().getNumberOfProperties()); factory.populateSearchObject(objectToPopulate, RelatedItemSearchType.FREQUENTLY_RELATED_WITH,properties); assertEquals(3,objectToPopulate.getMaxResults()); assertEquals("1",objectToPopulate.getRelatedItemId()); assertEquals(3,objectToPopulate.getAdditionalSearchCriteria().getNumberOfProperties()); assertEquals("attributed_to",objectToPopulate.getAdditionalSearchCriteria().getPropertyName(0)); assertEquals("user1",objectToPopulate.getAdditionalSearchCriteria().getPropertyValue(0)); assertEquals("channel",objectToPopulate.getAdditionalSearchCriteria().getPropertyName(1)); assertEquals("one",objectToPopulate.getAdditionalSearchCriteria().getPropertyValue(1)); assertEquals("type",objectToPopulate.getAdditionalSearchCriteria().getPropertyName(2)); assertEquals("computer",objectToPopulate.getAdditionalSearchCriteria().getPropertyValue(2)); }
@Override public void populateSearchObject(RelatedItemSearch objectToPopulate, RelatedItemSearchType type, Map<String, String> properties) { objectToPopulate.setStartOfRequestNanos(System.nanoTime()); String sizeKey = configuration.getRequestParameterForSize(); String idKey = configuration.getRequestParameterForId(); try { String size = properties.remove(sizeKey); if(size!=null) { objectToPopulate.setMaxResults(Integer.parseInt(size)); } else { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } } catch(NumberFormatException e) { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } objectToPopulate.setRelatedItemId(properties.remove(idKey)); RelatedItemAdditionalProperties props = objectToPopulate.getAdditionalSearchCriteria(); int maxPropertiesToCopy = Math.min(props.getMaxNumberOfAvailableProperties(),properties.size()); log.debug("max properties to copy {}, from properties {}",maxPropertiesToCopy,properties); int i=0; List<String> sortedParameters = new ArrayList<String>(properties.keySet()); Collections.sort(sortedParameters); for(String key : sortedParameters) { if(i==maxPropertiesToCopy) break; props.setProperty(key,properties.get(key),i++); } props.setNumberOfProperties(i); objectToPopulate.setRelatedItemSearchType(type); lookupKeyGenerator.setSearchRequestLookupKeyOn(objectToPopulate); }
RelatedItemSearchFactoryWithSearchLookupKeyFactory implements RelatedItemSearchFactory { @Override public void populateSearchObject(RelatedItemSearch objectToPopulate, RelatedItemSearchType type, Map<String, String> properties) { objectToPopulate.setStartOfRequestNanos(System.nanoTime()); String sizeKey = configuration.getRequestParameterForSize(); String idKey = configuration.getRequestParameterForId(); try { String size = properties.remove(sizeKey); if(size!=null) { objectToPopulate.setMaxResults(Integer.parseInt(size)); } else { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } } catch(NumberFormatException e) { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } objectToPopulate.setRelatedItemId(properties.remove(idKey)); RelatedItemAdditionalProperties props = objectToPopulate.getAdditionalSearchCriteria(); int maxPropertiesToCopy = Math.min(props.getMaxNumberOfAvailableProperties(),properties.size()); log.debug("max properties to copy {}, from properties {}",maxPropertiesToCopy,properties); int i=0; List<String> sortedParameters = new ArrayList<String>(properties.keySet()); Collections.sort(sortedParameters); for(String key : sortedParameters) { if(i==maxPropertiesToCopy) break; props.setProperty(key,properties.get(key),i++); } props.setNumberOfProperties(i); objectToPopulate.setRelatedItemSearchType(type); lookupKeyGenerator.setSearchRequestLookupKeyOn(objectToPopulate); } }
RelatedItemSearchFactoryWithSearchLookupKeyFactory implements RelatedItemSearchFactory { @Override public void populateSearchObject(RelatedItemSearch objectToPopulate, RelatedItemSearchType type, Map<String, String> properties) { objectToPopulate.setStartOfRequestNanos(System.nanoTime()); String sizeKey = configuration.getRequestParameterForSize(); String idKey = configuration.getRequestParameterForId(); try { String size = properties.remove(sizeKey); if(size!=null) { objectToPopulate.setMaxResults(Integer.parseInt(size)); } else { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } } catch(NumberFormatException e) { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } objectToPopulate.setRelatedItemId(properties.remove(idKey)); RelatedItemAdditionalProperties props = objectToPopulate.getAdditionalSearchCriteria(); int maxPropertiesToCopy = Math.min(props.getMaxNumberOfAvailableProperties(),properties.size()); log.debug("max properties to copy {}, from properties {}",maxPropertiesToCopy,properties); int i=0; List<String> sortedParameters = new ArrayList<String>(properties.keySet()); Collections.sort(sortedParameters); for(String key : sortedParameters) { if(i==maxPropertiesToCopy) break; props.setProperty(key,properties.get(key),i++); } props.setNumberOfProperties(i); objectToPopulate.setRelatedItemSearchType(type); lookupKeyGenerator.setSearchRequestLookupKeyOn(objectToPopulate); } RelatedItemSearchFactoryWithSearchLookupKeyFactory(Configuration config, RelatedItemSearchLookupKeyGenerator lookupKeyGenerator); }
RelatedItemSearchFactoryWithSearchLookupKeyFactory implements RelatedItemSearchFactory { @Override public void populateSearchObject(RelatedItemSearch objectToPopulate, RelatedItemSearchType type, Map<String, String> properties) { objectToPopulate.setStartOfRequestNanos(System.nanoTime()); String sizeKey = configuration.getRequestParameterForSize(); String idKey = configuration.getRequestParameterForId(); try { String size = properties.remove(sizeKey); if(size!=null) { objectToPopulate.setMaxResults(Integer.parseInt(size)); } else { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } } catch(NumberFormatException e) { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } objectToPopulate.setRelatedItemId(properties.remove(idKey)); RelatedItemAdditionalProperties props = objectToPopulate.getAdditionalSearchCriteria(); int maxPropertiesToCopy = Math.min(props.getMaxNumberOfAvailableProperties(),properties.size()); log.debug("max properties to copy {}, from properties {}",maxPropertiesToCopy,properties); int i=0; List<String> sortedParameters = new ArrayList<String>(properties.keySet()); Collections.sort(sortedParameters); for(String key : sortedParameters) { if(i==maxPropertiesToCopy) break; props.setProperty(key,properties.get(key),i++); } props.setNumberOfProperties(i); objectToPopulate.setRelatedItemSearchType(type); lookupKeyGenerator.setSearchRequestLookupKeyOn(objectToPopulate); } RelatedItemSearchFactoryWithSearchLookupKeyFactory(Configuration config, RelatedItemSearchLookupKeyGenerator lookupKeyGenerator); @Override RelatedItemSearch createSearchObject(); @Override void populateSearchObject(RelatedItemSearch objectToPopulate,
                                     RelatedItemSearchType type,
                                     Map<String, String> properties); @Override RelatedItemSearch newInstance(); }
RelatedItemSearchFactoryWithSearchLookupKeyFactory implements RelatedItemSearchFactory { @Override public void populateSearchObject(RelatedItemSearch objectToPopulate, RelatedItemSearchType type, Map<String, String> properties) { objectToPopulate.setStartOfRequestNanos(System.nanoTime()); String sizeKey = configuration.getRequestParameterForSize(); String idKey = configuration.getRequestParameterForId(); try { String size = properties.remove(sizeKey); if(size!=null) { objectToPopulate.setMaxResults(Integer.parseInt(size)); } else { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } } catch(NumberFormatException e) { objectToPopulate.setMaxResults(configuration.getDefaultNumberOfResults()); } objectToPopulate.setRelatedItemId(properties.remove(idKey)); RelatedItemAdditionalProperties props = objectToPopulate.getAdditionalSearchCriteria(); int maxPropertiesToCopy = Math.min(props.getMaxNumberOfAvailableProperties(),properties.size()); log.debug("max properties to copy {}, from properties {}",maxPropertiesToCopy,properties); int i=0; List<String> sortedParameters = new ArrayList<String>(properties.keySet()); Collections.sort(sortedParameters); for(String key : sortedParameters) { if(i==maxPropertiesToCopy) break; props.setProperty(key,properties.get(key),i++); } props.setNumberOfProperties(i); objectToPopulate.setRelatedItemSearchType(type); lookupKeyGenerator.setSearchRequestLookupKeyOn(objectToPopulate); } RelatedItemSearchFactoryWithSearchLookupKeyFactory(Configuration config, RelatedItemSearchLookupKeyGenerator lookupKeyGenerator); @Override RelatedItemSearch createSearchObject(); @Override void populateSearchObject(RelatedItemSearch objectToPopulate,
                                     RelatedItemSearchType type,
                                     Map<String, String> properties); @Override RelatedItemSearch newInstance();  }