Changeset 1034
- Timestamp:
- 06/19/09 15:47:06 (4 years ago)
- Location:
- branches/stage/mpdb-server/src/edu/rpi/metpetdb/server
- Files:
-
- 2 modified
-
ExcelServlet.java (modified) (5 diffs)
-
search/SearchDb.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/stage/mpdb-server/src/edu/rpi/metpetdb/server/ExcelServlet.java
r957 r1034 60 60 response.getWriter().write("\n"); 61 61 for (Sample s : samples){ 62 response.getWriter().write( s.getNumber() + "\t");63 response.getWriter().write( s.isPublicData() + "\t");62 response.getWriter().write(nullToEmptyString(s.getNumber()) + "\t"); 63 response.getWriter().write(boolToString(s.isPublicData()) + "\t"); 64 64 response.getWriter().write(s.getSubsampleCount() + "\t"); 65 65 response.getWriter().write(s.getImageCount() + "\t"); … … 67 67 response.getWriter().write(s.getOwner().getName() + "\t"); 68 68 response.getWriter().write(setToString(s.getRegions(),RegionProperty.name) + "\t"); 69 response.getWriter().write( s.getCountry() + "\t");70 response.getWriter().write( s.getRockType() + "\t");69 response.getWriter().write(nullToEmptyString(s.getCountry()) + "\t"); 70 response.getWriter().write(nullToEmptyString(s.getRockType()) + "\t"); 71 71 response.getWriter().write(setToString(s.getMetamorphicGrades(),MetamorphicGradeProperty.name) + "\t"); 72 72 response.getWriter().write(setSampleMineralsToString(s.getMinerals()) + "\t"); … … 74 74 response.getWriter().write(formatlatlng(((Point)s.getLocation()).y) +"\t"); 75 75 response.getWriter().write(formatlatlng(((Point)s.getLocation()).x) +"\t"); 76 response.getWriter().write( s.getSesarNumber() + "\t");77 response.getWriter().write( s.getCollector() + "\t");76 response.getWriter().write(nullToEmptyString(s.getSesarNumber()) + "\t"); 77 response.getWriter().write(nullToEmptyString(s.getCollector()) + "\t"); 78 78 response.getWriter().write(Sample.dateToString(s.getCollectionDate(), s.getDatePrecision()) + "\t"); 79 response.getWriter().write( s.getLocationText() + "\t");79 response.getWriter().write(nullToEmptyString(s.getLocationText()) + "\t"); 80 80 response.getWriter().write("\n"); 81 81 } … … 85 85 86 86 return; 87 } 88 89 private String boolToString(final Boolean b){ 90 return (b) ? "yes" : "no"; 91 } 92 93 private String nullToEmptyString(final Object o){ 94 return (o == null) ? "" : o.toString(); 87 95 } 88 96 … … 101 109 String text = ""; 102 110 for (SampleMineral sm : minerals){ 103 text += sm. getName() + " (" + sm.getAmount()+ "), ";111 text += sm.toString() + ", "; 104 112 } 105 113 if (!text.equals("")){ -
branches/stage/mpdb-server/src/edu/rpi/metpetdb/server/search/SearchDb.java
r1032 r1034 81 81 // Get the subsample ids that correspond to the chemical analyses. 82 82 System.out.println("Search Query Project Subsample Ids:" + chemQuery.getQueryString()); 83 final List<Long> projectedSubsampleIds = chemQuery.list(); 83 84 84 // no chemical analysis fit search, no reason to try finding samples with "no matches" 85 if (projectedSubsampleIds.size() == 0) { 85 String subsampleIds = getLongIdStringForList(chemQuery.list()); 86 if (subsampleIds == null) { 86 87 return new Results<Sample>(0, new ArrayList<Sample>()); 87 88 } 88 String subsampleIds = ""; 89 for (Long id : projectedSubsampleIds){ 90 subsampleIds += ((Long)id).toString() + ","; 91 } 92 if (subsampleIds != ""){ 93 subsampleIds = subsampleIds.substring(0, subsampleIds.length()-1); 94 } 89 95 90 // Get samples third... will need to incorporate top two pieces 96 91 fullQuery = getSamplesQuery(searchSamp, userSearching, session); 97 92 FullTextQuery sampleQuery = fullTextSession.createFullTextQuery(fullQuery, Sample.class); 98 93 System.out.println("Search Query Project Sample Ids:" + fullQuery.toString()); 99 final List<Object[]> projectedSampleIds = sampleQuery.setProjection("id").list();100 if ( projectedSampleIds.size() == 0) {94 String sampleIds = getLongIdString(sampleQuery.setProjection("id").list()); 95 if (sampleIds == null) { 101 96 return new Results<Sample>(0, new ArrayList<Sample>()); 102 97 } 103 String sampleIds = ""; 104 for (Object[] o : projectedSampleIds){ 105 for (Object id : o){ 106 sampleIds += ((Long)id).toString() + ","; 107 } 108 } 109 if (sampleIds != ""){ 110 sampleIds = sampleIds.substring(0, sampleIds.length()-1); 111 } 98 112 99 org.hibernate.Query hql = session.createQuery("from Sample s where s.id in (" + sampleIds + 113 100 ") and exists (select 1 from Subsample ss where ss.sampleId = s.id and ss.id in (" + … … 115 102 org.hibernate.Query sizeQuery = session.createQuery("select count(*) " + hql.getQueryString()); 116 103 System.out.println("Search Query Find Samples by Id and SubsampleId:" + hql.getQueryString()); 117 if (p != null) { 118 hql.setFirstResult(p.getFirstResult()); 119 hql.setMaxResults(p.getMaxResults()); 120 } else { 121 hql.setFirstResult(0); 122 hql.setMaxResults(100); 123 } 104 hql = setPagination(p,hql); 124 105 try { 125 106 //this is here in order to convert java.util.Collection$EmptyList into … … 137 118 System.out.println("Search Query:" + fullQuery.toString()); 138 119 139 final FullTextQuery hibQuery = fullTextSession.createFullTextQuery( 140 fullQuery, Sample.class); 141 142 if (p != null) { 143 hibQuery.setFirstResult(p.getFirstResult()); 144 hibQuery.setMaxResults(p.getMaxResults()); 145 } else { 146 //place an upper limit of 100 search results 147 hibQuery.setFirstResult(0); 148 hibQuery.setMaxResults(100); 149 } 150 try { 151 //this is here in order to convert java.util.Collection$EmptyList into 152 //the correct representation so it can be serialized by GWT 153 List<Sample> list = hibQuery.list(); 154 if (list.size() == 0) 155 list = new ArrayList<Sample>(); 156 int resultSize = 0; 120 try { 157 121 if (session.getEnabledFilter("boundingBox")!=null){ 158 122 FullTextQuery sizeHibQuery = fullTextSession.createFullTextQuery( 159 123 fullQuery, Sample.class); 160 final List<Object[]> projectedSampleIds = sizeHibQuery.setProjection("id").list(); 161 String sampleIds = ""; 162 for (Object[] o : projectedSampleIds){ 163 for (Object id : o){ 164 sampleIds += ((Long)id).toString() + ","; 165 } 124 String sampleIds = getLongIdString(sizeHibQuery.setProjection("id").list()); 125 if (sampleIds == null) { 126 return new Results<Sample>(0, new ArrayList<Sample>()); 166 127 } 167 if (sampleIds != ""){ 168 sampleIds = sampleIds.substring(0, sampleIds.length()-1); 169 } 170 org.hibernate.Query sizeQuery = session.createQuery("select count(*) from Sample s where s.id in (" + sampleIds + ")"); 171 resultSize = ((Long)sizeQuery.uniqueResult()).intValue(); 128 org.hibernate.Query resultQuery = session.createQuery("from Sample s where s.id in (" + sampleIds + ")"); 129 org.hibernate.Query sizeQuery = session.createQuery("select count(*) " + resultQuery.getQueryString()); 130 resultQuery = setPagination(p,resultQuery); 131 List<Sample> list = resultQuery.list(); 132 if (list.size() == 0) 133 list = new ArrayList<Sample>(); 134 final Results<Sample> results = new Results<Sample>(((Long)sizeQuery.uniqueResult()).intValue(),list); 135 return results; 172 136 } else { 173 resultSize = hibQuery.getResultSize(); 174 } 175 final Results<Sample> results = new Results<Sample>(resultSize, list); 176 return results; 137 FullTextQuery hibQuery = fullTextSession.createFullTextQuery( 138 fullQuery, Sample.class); 139 hibQuery = setPagination(p,hibQuery); 140 //this is here in order to convert java.util.Collection$EmptyList into 141 //the correct representation so it can be serialized by GWT 142 List<Sample> list = hibQuery.list(); 143 if (list.size() == 0) 144 list = new ArrayList<Sample>(); 145 final Results<Sample> results = new Results<Sample>(hibQuery.getResultSize(), list); 146 return results; 147 } 177 148 } catch (CallbackException e) { 178 149 throw ConvertSecurityException.convertToException(e); … … 201 172 System.out.println("Search Query:" + fullQuery.toString()); 202 173 203 if (p != null) { 204 fullQuery.setFirstResult(p.getFirstResult()); 205 fullQuery.setMaxResults(p.getMaxResults()); 206 } else { 207 //place an upper limit of 100 search results 208 fullQuery.setFirstResult(0); 209 fullQuery.setMaxResults(100); 210 } 174 fullQuery = setPagination(p,fullQuery); 211 175 try { 212 176 //this is here in order to convert java.util.Collection$EmptyList into … … 229 193 .createFullTextQuery(tempSampleQuery, Subsample.class); 230 194 System.out.println("Search Query Project Subsample Ids:" + sampleQuery.toString()); 231 final List<Object[]> projectedSubsampleIds = sampleQuery.setProjection("id").list(); 232 // no samples fit search, no reason to try finding chemical analyses with "no matches" 233 if (projectedSubsampleIds.size() == 0) { 195 String subsampleIds = getLongIdString(sampleQuery.setProjection("id").list()); 196 if (subsampleIds == null) { 234 197 return new Results<ChemicalAnalysis>(0, new ArrayList<ChemicalAnalysis>()); 235 }236 String subsampleIds = "";237 for (Object[] o : projectedSubsampleIds){238 for (Object id : o){239 subsampleIds += ((Long)id).toString() + ",";240 }241 }242 if (subsampleIds != ""){243 subsampleIds = subsampleIds.substring(0, subsampleIds.length()-1);244 198 } 245 199 // Get chemical analyses third... will need to incorporate top two pieces 246 200 org.hibernate.Query chemQuery = getChemicalsQuery(searchSamp, userSearching, session, RETURN_CHEMICAL_ANALYSIS_ID); 247 201 System.out.println("Search Query Project Chemical Analysis Ids:" + chemQuery.getQueryString()); 248 final List<Integer> projectedChemIds = chemQuery.list(); 249 if (projectedChemIds.size() == 0){ 202 203 String chemIds = getIntIdStringForList(chemQuery.list()); 204 if (chemIds == null) { 250 205 return new Results<ChemicalAnalysis>(0, new ArrayList<ChemicalAnalysis>()); 251 }252 String chemIds = "";253 for (Integer id : projectedChemIds){254 chemIds += ((Integer)id).toString() + ",";255 }256 if (chemIds != ""){257 chemIds = chemIds.substring(0, chemIds.length()-1);258 206 } 259 207 org.hibernate.Query hql = session.createQuery("from ChemicalAnalysis ca where ca.id in (" + chemIds + … … 262 210 org.hibernate.Query sizeQuery = session.createQuery("select count(*) " + hql.getQueryString()); 263 211 System.out.println("Search Query Find Chemical Analyses by Id and SubsampleId:" + hql.getQueryString()); 264 265 if (p != null) { 266 hql.setFirstResult(p.getFirstResult()); 267 hql.setMaxResults(p.getMaxResults()); 268 } else { 269 hql.setFirstResult(0); 270 hql.setMaxResults(100); 271 } 212 213 hql = setPagination(p,hql); 272 214 try { 273 215 //this is here in order to convert java.util.Collection$EmptyList into … … 680 622 return false; 681 623 } 624 625 private static org.hibernate.Query setPagination(PaginationParameters p, org.hibernate.Query q){ 626 if (p != null){ 627 q.setFirstResult(p.getFirstResult()); 628 q.setMaxResults(p.getMaxResults()); 629 } else { 630 q.setFirstResult(0); 631 q.setMaxResults(100); 632 } 633 return q; 634 } 635 636 private static FullTextQuery setPagination(PaginationParameters p, FullTextQuery q){ 637 if (p != null){ 638 q.setFirstResult(p.getFirstResult()); 639 q.setMaxResults(p.getMaxResults()); 640 } else { 641 q.setFirstResult(0); 642 q.setMaxResults(100); 643 } 644 return q; 645 } 646 647 private static String getLongIdStringForList(final List<Long> projectedIds){ 648 if (projectedIds.size() == 0) { 649 return null; 650 } 651 String ids = ""; 652 for (Long o : projectedIds){ 653 ids += o.toString() + ","; 654 } 655 if (ids != ""){ 656 ids = ids.substring(0, ids.length()-1); 657 } 658 return ids; 659 } 660 661 private static String getIntIdStringForList(final List<Integer> projectedIds){ 662 if (projectedIds.size() == 0) { 663 return null; 664 } 665 String ids = ""; 666 for (Integer o : projectedIds){ 667 ids += o.toString() + ","; 668 } 669 if (ids != ""){ 670 ids = ids.substring(0, ids.length()-1); 671 } 672 return ids; 673 } 674 675 private static String getLongIdString(final List<Object[]> projectedIds){ 676 if (projectedIds.size() == 0) { 677 return null; 678 } 679 String ids = ""; 680 for (Object[] o : projectedIds){ 681 for (Object id : o){ 682 ids += ((Long)id).toString() + ","; 683 } 684 } 685 if (ids != ""){ 686 ids = ids.substring(0, ids.length()-1); 687 } 688 return ids; 689 } 682 690 }
