From 0619e1134b92e832c6e7b47ea22a6f79d37fa7d3 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Mon, 6 Jul 2015 14:42:28 -0500 Subject: [PATCH] Omaha #4612 Get all sites matching the preferredafosFirstLetter. Former-commit-id: 1768bf7d8c3183e762361f1c18b47e28c95f5359 --- .../plugin/text/dao/StdTextProductDao.java | 88 ++++++++++--------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java index d70d68b19e..b1b5874dd7 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java @@ -101,6 +101,7 @@ import com.raytheon.uf.edex.database.purge.PurgeLogger; * 10/28/2014 3454 bphillip Fix usage of getSession() * Jan 27, 2015 4031 rferrel Resolve AFOS PILs site conflict using preferredAfosFirstLetter. * May 05, 2015 4462 rferrel {@link #write(StdTextProduct)} when missing set the textProduct's site. + * Jul 06, 2015 4612 rferrel Get all sites matching the preferredafosFirstLetter. * * * @author garmendariz @@ -132,7 +133,7 @@ public class StdTextProductDao extends CoreDao { private static final String NNN_ID = "nnnid"; - private static final String SITE = "site"; + private static final String SITES = "sites"; private static final String PRODUCT = "product"; @@ -161,7 +162,7 @@ public class StdTextProductDao extends CoreDao { + " and " + ProdXXX_ID + " = :" + XXX_ID - + " and " + ProdSITE + " = :" + SITE + + " and " + ProdSITE + " in (:" + SITES + ")" + " order by " + REFTIME + " desc" + ", " + INSERTTIME + " desc"; @@ -309,7 +310,7 @@ public class StdTextProductDao extends CoreDao { List products = null; try { - final List> siteAfosIdList = querySiteAfosId( + final List> siteAfosIdList = querySiteAfosId( ccc, nnn, xxx); products = txTemplate @@ -337,14 +338,14 @@ public class StdTextProductDao extends CoreDao { query.setMaxResults(version + 1); } - for (Pair siteAfosId : siteAfosIdList) { - String site = siteAfosId.getFirst(); + for (Pair siteAfosId : siteAfosIdList) { + String[] sites = siteAfosId.getFirst(); AFOSProductId afosId = siteAfosId.getSecond(); - if (site != null) { + if (sites != null) { query.setParameter(CCC_ID, afosId.getCcc()); query.setParameter(NNN_ID, afosId.getNnn()); query.setParameter(XXX_ID, afosId.getXxx()); - query.setParameter(SITE, site); + query.setParameterList(SITES, sites); List results = query.list(); if (results != null && results.size() > 0) { @@ -387,15 +388,15 @@ public class StdTextProductDao extends CoreDao { } /** - * Get desired site for the afosId the pairs are order by AfosId. + * Get desired sites for the afosId the pairs are order by AfosId. * * @param ccc * @param nnn * @param xxx * @return siteAfosIds */ - private List> querySiteAfosId(final String ccc, - final String nnn, final String xxx) { + private List> querySiteAfosId( + final String ccc, final String nnn, final String xxx) { boolean hasCCC = ((ccc != null) && (ccc.length() > 0) && (!ccc .equals("000"))); boolean hasNNN = ((nnn != null) && (nnn.length() > 0) && (!nnn @@ -405,10 +406,10 @@ public class StdTextProductDao extends CoreDao { final boolean createInitialFilter = !(hasCCC && hasNNN && hasXXX); return txTemplate - .execute(new TransactionCallback>>() { + .execute(new TransactionCallback>>() { @Override - public List> doInTransaction( + public List> doInTransaction( TransactionStatus status) { String paddedccc = StringUtils.rightPad(ccc, MAX_FIELD_LENGTH); @@ -417,7 +418,7 @@ public class StdTextProductDao extends CoreDao { String paddedxxx = StringUtils.rightPad(xxx, MAX_FIELD_LENGTH); Session session = getCurrentSession(); - List> siteProductPairList = null; + List> siteProductPairList = null; StdTextProduct stdTextProduct = getStdTextProductInstance(); if (createInitialFilter) { @@ -472,30 +473,30 @@ public class StdTextProductDao extends CoreDao { .keySet()); Collections.sort(indices); for (int index : indices) { - String site = getSite(siteMap.get(index) + String[] sites = getSite(siteMap.get(index) .toArray()); AFOSProductId afosId = orderedAfosIds .get(index); - Pair pair = new Pair( - site, afosId); - siteProductPairList.add(pair); + siteProductPairList + .add(new Pair( + sites, afosId)); } } else { - siteProductPairList = new ArrayList>( + siteProductPairList = new ArrayList>( 0); } } else { AFOSProductId afosId = new AFOSProductId(paddedccc, paddednnn, paddedxxx); - String site = getSite(afosId); - if (site == null) { - siteProductPairList = new ArrayList>( + String[] sites = getSite(afosId); + if (sites == null) { + siteProductPairList = new ArrayList>( 0); } else { siteProductPairList = new ArrayList<>(1); siteProductPairList - .add(new Pair( - site, afosId)); + .add(new Pair( + sites, afosId)); } } return siteProductPairList; @@ -504,12 +505,12 @@ public class StdTextProductDao extends CoreDao { } /** - * Get site based on the ordering from preferredAfosFirstLetter. + * Get sites based on the ordering from preferredAfosFirstLetter. * * @param afosId - * @return site or null when no data. + * @return sites or null when no data. */ - private String getSite(AFOSProductId afosId) { + private String[] getSite(AFOSProductId afosId) { String ccc = afosId.getCcc(); String nnn = afosId.getNnn(); String xxx = afosId.getXxx(); @@ -534,17 +535,18 @@ public class StdTextProductDao extends CoreDao { } /** - * From the array of sites determine which one is the preferred site. + * From the array of sites determine which ones are preferred sites. * * @param values * - Assume sites with common afosId - * @return site first site based on preferredAfosFirstLetter + * @return sites based on preferredAfosFirstLetter */ - private String getSite(Object[] values) { + private String[] getSite(Object[] values) { if (values != null) { if (values.length == 1) { - return (String) values[0]; + return new String[] { (String) values[0] }; } else if (values.length > 1) { + List results = new ArrayList<>(values.length); String[] sites = new String[values.length]; for (int i = 0; i < values.length; ++i) { sites[i] = (String) values[i]; @@ -552,17 +554,20 @@ public class StdTextProductDao extends CoreDao { for (char c : preferredAfosFirstLetter) { for (String site : sites) { if (site.charAt(0) == c) { - return site; + results.add(site); } } + if (!results.isEmpty()) { + return results.toArray(new String[results.size()]); + } } if (logger.isInfoEnabled()) { String message = "None of the sites first character in preferred AFOS first letter list \"" + new String(preferredAfosFirstLetter) - + "\". Using site: " + sites[0]; + + "\". Using sites: " + sites; logger.info(message); } - return sites[0]; + return sites; } } return null; @@ -586,7 +591,7 @@ public class StdTextProductDao extends CoreDao { Session session = null; try { - List> siteAfosIdList = querySiteAfosId( + List> siteAfosIdList = querySiteAfosId( ccc, nnn, xxx); session = getSession(); @@ -640,7 +645,7 @@ public class StdTextProductDao extends CoreDao { Session session = null; try { - List> siteAfosIdList = querySiteAfosId( + List> siteAfosIdList = querySiteAfosId( ccc, nnn, xxx); session = getSession(); @@ -687,7 +692,7 @@ public class StdTextProductDao extends CoreDao { * @throws HibernateException */ private List listProducts(Criteria criteria, - List> siteAfosIdList) + List> siteAfosIdList) throws HibernateException { List prodList = criteria.list(); @@ -699,9 +704,9 @@ public class StdTextProductDao extends CoreDao { products = new ArrayList<>(prodList.size()); Iterator iter = prodList.iterator(); - Iterator> siteAfosIdIter = siteAfosIdList + Iterator> siteAfosIdIter = siteAfosIdList .iterator(); - Pair pair = siteAfosIdIter.next(); + Pair pair = siteAfosIdIter.next(); while (iter.hasNext()) { StdTextProduct prod = (StdTextProduct) iter.next(); @@ -715,8 +720,11 @@ public class StdTextProductDao extends CoreDao { pair = siteAfosIdIter.next(); } String site = prod.getSite(); - if (site.equals(pair.getFirst())) { - products.add(prod); + for (String pSite : pair.getFirst()) { + if (site.equals(pSite)) { + products.add(prod); + break; + } } } }