|
From: <rv...@us...> - 2012-02-23 15:43:23
|
Revision: 1088
http://treebase.svn.sourceforge.net/treebase/?rev=1088&view=rev
Author: rvos
Date: 2012-02-23 15:43:14 +0000 (Thu, 23 Feb 2012)
Log Message:
-----------
Added test to ensure we don't get NullPointerExceptions
Modified Paths:
--------------
trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java
Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java
===================================================================
--- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 15:25:03 UTC (rev 1087)
+++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 15:43:14 UTC (rev 1088)
@@ -175,9 +175,11 @@
// XXX need to filter out orphaned matrices or matrices whose studies are unpublished
Collection<Matrix> orphanedMatrices = new HashSet<Matrix>();
for ( Matrix m : matches ) {
- if ( m.getStudy() == null || (m.getStudy().isPublished() == false) ) {
- orphanedMatrices.add(m);
- }
+ if ( null != m ) {
+ if ( m.getStudy() == null || m.getStudy().isPublished() == false ) {
+ orphanedMatrices.add(m);
+ }
+ }
}
matches.removeAll(orphanedMatrices);
return matches;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rv...@us...> - 2012-02-23 20:03:29
|
Revision: 1091
http://treebase.svn.sourceforge.net/treebase/?rev=1091&view=rev
Author: rvos
Date: 2012-02-23 20:03:22 +0000 (Thu, 23 Feb 2012)
Log Message:
-----------
This commit should fix the NPE we were getting at SearchResultsFrozen.java:41 because the result set should now no longer contain null values (it could be an empty set, though). To ensure that this is so and everything behaves as it should I am removing the cludge around line 176.
Modified Paths:
--------------
trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java
Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java
===================================================================
--- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 19:07:30 UTC (rev 1090)
+++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/MatrixSearchController.java 2012-02-23 20:03:22 UTC (rev 1091)
@@ -14,6 +14,7 @@
import org.apache.log4j.Logger;
import org.cipres.treebase.TreebaseUtil;
import org.cipres.treebase.RangeExpression.MalformedRangeExpression;
+import org.cipres.treebase.domain.TBPersistable;
import org.cipres.treebase.domain.matrix.CharacterMatrix;
import org.cipres.treebase.domain.matrix.Matrix;
import org.cipres.treebase.domain.matrix.MatrixService;
@@ -120,7 +121,6 @@
return results;
}
- @SuppressWarnings("unchecked")
private Collection<Matrix> doSearch(
HttpServletRequest request,
HttpServletResponse response,
@@ -128,64 +128,68 @@
BindException errors,
String searchTerm) throws InstantiationException {
- Collection<Matrix> matches = null;
+ Collection<Matrix> results = new HashSet<Matrix>();
MatrixService matrixService = getSearchService().getMatrixService();
switch(searchType) {
- case byID:
- matches = (Collection<Matrix>) doSearchByIDString(request, matrixService, Matrix.class, searchTerm);
- break;
-
- case byTB1ID:
- matches = new HashSet<Matrix>();
- matches.add(matrixService.findByTB1StudyID(searchTerm));
- break;
-
- case byTitle:
- matches = matrixService
- .findSomethingBySubstring(Matrix.class, "title", searchTerm);
- break;
-
- case byType:
- matches = matrixService
- .findSomethingByItsDescription(Matrix.class, "matrixKind", searchTerm, false);
- break;
-
- case byNCHAR:
- try {
- matches = matrixService
- .findSomethingByRangeExpression(CharacterMatrix.class, "nChar", searchTerm);
- } catch (MalformedRangeExpression e) {
- addMessage(request, "Malformed range expression: " + e.getMessage());
+ case byID: {
+ addMatchesToResults(doSearchByIDString(request, matrixService, Matrix.class, searchTerm), results);
+ break;
}
- break;
-
-
- case byNTAX:
- try {
- matches = matrixService
- .findSomethingByRangeExpression(CharacterMatrix.class, "nTax", searchTerm);
- } catch (MalformedRangeExpression e) {
- addMessage(request, "Malformed range expression: " + e.getMessage());
+ case byTB1ID: {
+ Matrix match = matrixService.findByTB1StudyID(searchTerm);
+ if ( null != match ) {
+ results.add(match);
+ }
+ break;
}
- break;
+ case byTitle: {
+ addMatchesToResults(matrixService.findSomethingBySubstring(Matrix.class, "title", searchTerm), results);
+ break;
+ }
+ case byType: {
+ addMatchesToResults(matrixService.findSomethingByItsDescription(Matrix.class, "matrixKind", searchTerm, false),results);
+ break;
+ }
+ case byNCHAR: {
+ try {
+ addMatchesToResults(matrixService.findSomethingByRangeExpression(CharacterMatrix.class, "nChar", searchTerm),results);
+ } catch (MalformedRangeExpression e) {
+ addMessage(request, "Malformed range expression: " + e.getMessage());
+ }
+ break;
+ }
+ case byNTAX: {
+ try {
+ addMatchesToResults(matrixService.findSomethingByRangeExpression(CharacterMatrix.class, "nTax", searchTerm),results);
+ } catch (MalformedRangeExpression e) {
+ addMessage(request, "Malformed range expression: " + e.getMessage());
+ }
+ break;
+ }
}
// XXX need to filter out orphaned matrices or matrices whose studies are unpublished
Collection<Matrix> orphanedMatrices = new HashSet<Matrix>();
- for ( Matrix m : matches ) {
- if ( null != m ) {
- if ( m.getStudy() == null || m.getStudy().isPublished() == false ) {
- orphanedMatrices.add(m);
- }
- }
+ for ( Matrix m : results ) {
+ if ( m.getStudy() == null || m.getStudy().isPublished() == false ) {
+ orphanedMatrices.add(m);
+ }
}
- matches.removeAll(orphanedMatrices);
- return matches;
+ results.removeAll(orphanedMatrices);
+ return results;
}
+ @SuppressWarnings("unchecked")
+ private void addMatchesToResults(Collection<? extends TBPersistable> matches,
+ Collection<Matrix> results) {
+ if ( null != matches && ! matches.isEmpty() ) {
+ results.addAll((Collection<? extends Matrix>) matches);
+ }
+ }
+
SearchResultsType currentSearchType() {
return SearchResultsType.MATRIX;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|