Changeset 1019

Show
Ignore:
Timestamp:
06/15/09 13:15:20 (4 years ago)
Author:
goldfd
Message:

Untokenized several search fields (regions, country, collector, minerals, rock type, metamorphic grade). This means that the phrases are not broken up into individual words, so that when you search by "New York", you will not get "New Jersey".

The search interface will now filter out regions, countries, collectors, references, and users that are associated with samples that can be viewed by the current user.

Location:
trunk
Files:
30 modified

Legend:

Unmodified
Added
Removed
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/input/attributes/specific/search/SearchCollectorsAttribute.java

    r873 r1019  
    2929                                        @Override 
    3030                                        public void begin() { 
    31                                                 MpDb.sample_svc.allCollectors(this); 
     31                                                int userId = 0; 
     32                                                if (MpDb.isLoggedIn()) 
     33                                                        userId = MpDb.currentUser().getId(); 
     34                                                MpDb.sample_svc.viewableCollectorsForUser(userId, this); 
    3235                                        } 
    3336                                        public void onSuccess(final Object result) { 
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/input/attributes/specific/search/SearchCountriesAttribute.java

    r873 r1019  
    2929                                        @Override 
    3030                                        public void begin() { 
    31                                                 MpDb.sample_svc.allCountries(this); 
     31                                                int userId = 0; 
     32                                                if (MpDb.isLoggedIn()) 
     33                                                        userId = MpDb.currentUser().getId(); 
     34                                                MpDb.sample_svc.viewableCountriesForUser(userId, this); 
    3235                                        } 
    3336                                        public void onSuccess(final Object result) { 
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/input/attributes/specific/search/SearchOwnersAttribute.java

    r891 r1019  
    2929                                        @Override 
    3030                                        public void begin() { 
    31                                                 MpDb.user_svc.allNames(this); 
     31                                                int userId = 0; 
     32                                                if (MpDb.isLoggedIn()) 
     33                                                        userId = MpDb.currentUser().getId(); 
     34                                                MpDb.user_svc.viewableNamesForUser(userId, this); 
    3235                                        } 
    3336                                        public void onSuccess(final Object result) { 
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/input/attributes/specific/search/SearchReferenceAttribute.java

    r873 r1019  
    2929                                        @Override 
    3030                                        public void begin() { 
    31                                                 MpDb.reference_svc.allReferences(this); 
     31                                                int userId = 0; 
     32                                                if (MpDb.isLoggedIn()) 
     33                                                        userId = MpDb.currentUser().getId(); 
     34                                                MpDb.reference_svc.viewableReferencesForUser(userId, this); 
    3235                                        } 
    3336                                        public void onSuccess(final Object result) { 
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/input/attributes/specific/search/SearchRegionAttribute.java

    r873 r1019  
    2929                                        @Override 
    3030                                        public void begin() { 
    31                                                 MpDb.region_svc.allNames(this); 
     31                                                int userId = 0; 
     32                                                if (MpDb.isLoggedIn()) 
     33                                                        userId = MpDb.currentUser().getId(); 
     34                                                MpDb.region_svc.viewableNamesForUser(userId, this); 
    3235                                        } 
    3336                                        public void onSuccess(final Object result) { 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/Element.java

    r753 r1019  
    1515        private String name; 
    1616        private String alternateName; 
    17         @Field(index = Index.TOKENIZED, store = Store.NO) 
     17        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    1818        private String symbol; 
    1919        private int atomicNumber; 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/MetamorphicGrade.java

    r734 r1019  
    1212        private short id; 
    1313 
    14         @Field(index = Index.TOKENIZED, store = Store.NO) 
     14        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    1515        private String name; 
    1616         
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/Mineral.java

    r963 r1019  
    1717        private Short parentId; 
    1818        private Short realMineralId; 
    19         @Field(index = Index.TOKENIZED, store = Store.NO) 
     19        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    2020        private String name; 
    2121 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/Oxide.java

    r873 r1019  
    1313        private short oxideId; 
    1414        private short oxidationState; 
    15         @Field(index = Index.TOKENIZED, store = Store.NO) 
     15        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    1616        private String species; 
    1717        private Float weight; 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/Region.java

    r734 r1019  
    1111        private short id; 
    1212 
    13         @Field(index = Index.TOKENIZED) 
     13        @Field(index = Index.UN_TOKENIZED) 
    1414        private String name; 
    1515         
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/RockType.java

    r741 r1019  
    99 
    1010        private short id; 
    11         @Field(index = Index.TOKENIZED, store = Store.NO) 
     11        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    1212        private String rockType; 
    1313         
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/Sample.java

    r1013 r1019  
    6969        private String description; 
    7070 
    71         @Field(index = Index.TOKENIZED, store = Store.NO) 
     71        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    7272        private String country; 
    7373 
    74         @Field(index = Index.TOKENIZED, store = Store.NO) 
     74        @Field(index = Index.UN_TOKENIZED, store = Store.NO) 
    7575        private String collector; 
    7676 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/ReferenceService.java

    r811 r1019  
    99public interface ReferenceService extends RemoteService { 
    1010        Set<String> allReferences() throws MpDbException; 
     11         
     12        Set<String> viewableReferencesForUser(final int userId) throws MpDbException; 
    1113} 
    1214 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/ReferenceServiceAsync.java

    r535 r1019  
    77public interface ReferenceServiceAsync { 
    88        void allReferences(AsyncCallback<Set<String>> ac); 
     9         
     10        void viewableReferencesForUser(int userId, AsyncCallback<Set<String>> ac); 
    911} 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/RegionService.java

    r811 r1019  
    99public interface RegionService extends RemoteService { 
    1010        Set<String> allNames() throws MpDbException; 
     11         
     12        Set<String> viewableNamesForUser(final int userId) throws MpDbException; 
    1113} 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/RegionServiceAsync.java

    r535 r1019  
    55import com.google.gwt.user.client.rpc.AsyncCallback; 
    66 
     7import edu.rpi.metpetdb.client.error.MpDbException; 
     8 
    79public interface RegionServiceAsync { 
    810        void allNames(AsyncCallback<Set<String>> ac); 
     11         
     12        void viewableNamesForUser(int userId, AsyncCallback<Set<String>> ac); 
    913} 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/SampleService.java

    r889 r1019  
    3636        Set<String> allCountries() throws MpDbException; 
    3737         
     38        Set<String> viewableCollectorsForUser(final int userId) throws MpDbException; 
     39         
     40        Set<String> viewableCountriesForUser(final int userId) throws MpDbException; 
     41         
    3842        List<Sample> allSamplesForUser(final long id) throws MpDbException; 
    3943 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/SampleServiceAsync.java

    r889 r1019  
    3939        void allCountries(AsyncCallback<Set<String>> ac); 
    4040         
     41        void viewableCountriesForUser(int userId, AsyncCallback<Set<String>> ac); 
     42         
     43        void viewableCollectorsForUser(int userId, AsyncCallback<Set<String>> ac); 
     44         
    4145        void allSamplesForUser(long id, AsyncCallback<List<Sample>> ac); 
    4246} 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/UserService.java

    r929 r1019  
    132132        Set<String> allNames() throws MpDbException; 
    133133         
     134        Set<String> viewableNamesForUser(final int userId) throws MpDbException; 
     135         
    134136        User confirmUser(String confirmationCode) throws MpDbException, 
    135137                        LoginRequiredException; 
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/service/UserServiceAsync.java

    r919 r1019  
    3434 
    3535        void allNames(AsyncCallback<Set<String>> ac); 
     36         
     37        void viewableNamesForUser(int userId, AsyncCallback<Set<String>> ac); 
    3638 
    3739        void save(User u, AsyncCallback<User> ac); 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/dao/Reference.hbm.xml

    r535 r1019  
    1111    </id> 
    1212    <property name="name" column="name"/> 
     13     
     14      <filter name="hasSamplePublicOrUser" 
     15                condition="(exists (select 1 from sample_reference sr where sr.reference_id = reference_id   
     16                                                                and exists ( select 1 from samples s where s.sample_id = sr.sample_id  
     17                                                                                        and (s.public_data = 'Y' or s.user_id = :userId))))" /> 
    1318  </class> 
    1419   
    … …  
    2328    order by r.name 
    2429   </query> 
     30   Â 
     31   <filter-def name="hasSamplePublicOrUser"> 
     32        <filter-param name="userId" type="int" /> 
     33  </filter-def> 
    2534</hibernate-mapping> 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/dao/Region.hbm.xml

    r535 r1019  
    1111    </id> 
    1212    <property name="name" column="name"/> 
     13     
     14                 
     15     <filter name="hasSamplePublicOrUser" 
     16                condition="(exists (select 1 from sample_regions sr where sr.region_id = region_id   
     17                                                                and exists ( select 1 from samples s where s.sample_id = sr.sample_id  
     18                                                                                        and (s.public_data = 'Y' or s.user_id = :userId))))" /> 
    1319  </class> 
    1420   
    … …  
    2733    order by r.name 
    2834   </query> 
     35   Â 
     36   <filter-def name="hasSamplePublicOrUser"> 
     37        <filter-param name="userId" type="int" /> 
     38  </filter-def> 
    2939</hibernate-mapping> 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/dao/User.hbm.xml

    r1015 r1019  
    3636     
    3737    <many-to-one name="role" column="role_id"/> 
     38     
     39    <filter name="hasSamplePublicOrUser" 
     40                condition="(exists (select 1 from samples s where s.user_id = user_id and s.public_data = 'Y')  
     41                        or user_id = :userId)" /> 
    3842  </class> 
    3943   
    … …  
    7377     order by lower(u.name) 
    7478   </query> 
     79     Â 
     80   <filter-def name="hasSamplePublicOrUser"> 
     81        <filter-param name="userId" type="int" /> 
     82  </filter-def> 
    7583</hibernate-mapping> 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/impl/ReferenceServiceImpl.java

    r811 r1019  
    88import edu.rpi.metpetdb.server.MpDbServlet; 
    99import edu.rpi.metpetdb.server.dao.impl.ReferenceDAO; 
     10import edu.rpi.metpetdb.server.dao.impl.RegionDAO; 
    1011 
    1112public class ReferenceServiceImpl extends MpDbServlet implements ReferenceService { 
    … …  
    1314         
    1415        public Set<String> allReferences() throws MpDbException { 
    15                 final Object[] l =  (new ReferenceDAO(this.currentSession())).allReferences(); 
     16                return objectArrayToStringSet((new ReferenceDAO(this.currentSession())).allReferences()); 
     17        } 
     18         
     19        public Set<String> viewableReferencesForUser(final int userId) throws MpDbException { 
     20                this.currentSession().enableFilter("hasSamplePublicOrUser").setParameter("userId", userId); 
     21                return objectArrayToStringSet((new ReferenceDAO(this.currentSession())).allReferences()); 
     22        }       Â 
     23         
     24        private Set<String> objectArrayToStringSet(final Object[] o){ 
    1625                final Set<String> options = new HashSet(); 
    17                 for (int i = 0; i < l.length; i++){ 
    18                         if (l[i] != null) 
    19                                 options.add(l[i].toString()); 
     26                for (int i = 0; i < o.length; i++){ 
     27                        if (o[i] != null) 
     28                                options.add(o[i].toString()); 
    2029                } 
    2130                return options; 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/impl/RegionServiceImpl.java

    r811 r1019  
    55 
    66import edu.rpi.metpetdb.client.error.MpDbException; 
     7import edu.rpi.metpetdb.client.model.User; 
    78import edu.rpi.metpetdb.client.service.RegionService; 
    89import edu.rpi.metpetdb.server.MpDbServlet; 
    … …  
    1314         
    1415        public Set<String> allNames() throws MpDbException { 
    15                 final Object[] l =  (new RegionDAO(this.currentSession())).allNames(); 
     16                return objectArrayToStringSet((new RegionDAO(this.currentSession())).allNames()); 
     17        } 
     18         
     19        public Set<String> viewableNamesForUser(final int userId) throws MpDbException { 
     20                this.currentSession().enableFilter("hasSamplePublicOrUser").setParameter("userId", userId); 
     21                return objectArrayToStringSet((new RegionDAO(this.currentSession())).allNames()); 
     22        } 
     23         
     24        private Set<String> objectArrayToStringSet(final Object[] o){ 
    1625                final Set<String> options = new HashSet(); 
    17                 for (int i = 0; i < l.length; i++){ 
    18                         if (l[i] != null) 
    19                                 options.add(l[i].toString()); 
     26                for (int i = 0; i < o.length; i++){ 
     27                        if (o[i] != null) 
     28                                options.add(o[i].toString()); 
    2029                } 
    2130                return options; 
    2231        } 
    2332 
    24  
    2533} 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/impl/SampleServiceImpl.java

    r993 r1019  
    1515import edu.rpi.metpetdb.client.service.SampleService; 
    1616import edu.rpi.metpetdb.server.MpDbServlet; 
     17import edu.rpi.metpetdb.server.dao.impl.RegionDAO; 
    1718import edu.rpi.metpetdb.server.dao.impl.SampleDAO; 
    1819 
    … …  
    4546         
    4647        public Set<String> allCollectors() throws MpDbException { 
    47                 final Object[] l =  (new SampleDAO(this.currentSession())).allCollectors(); 
    48                 final Set<String> options = new HashSet<String>(); 
    49                 for (int i = 0; i < l.length; i++){ 
    50                         if (l[i] != null) 
    51                                 options.add(l[i].toString()); 
    52                 } 
    53                 return options; 
     48                return objectArrayToStringSet((new SampleDAO(this.currentSession())).allCollectors()); 
     49        } 
     50         
     51        public Set<String> viewableCollectorsForUser(final int userId) throws MpDbException { 
     52                this.currentSession().enableFilter("samplePublicOrUser").setParameter("userId", userId); 
     53                return objectArrayToStringSet((new SampleDAO(this.currentSession())).allCollectors()); 
    5454        } 
    5555         
    5656        public Set<String> allCountries() throws MpDbException { 
    57                 final Object[] l =  (new SampleDAO(this.currentSession())).allCountries(); 
    58                 final Set<String> options = new HashSet<String>(); 
    59                 for (int i = 0; i < l.length; i++){ 
    60                         if (l[i] != null) 
    61                                 options.add(l[i].toString()); 
    62                 } 
    63                 return options; 
     57                return objectArrayToStringSet((new SampleDAO(this.currentSession())).allCountries()); 
    6458        } 
     59         
     60        public Set<String> viewableCountriesForUser(final int userId) throws MpDbException { 
     61                this.currentSession().enableFilter("samplePublicOrUser").setParameter("userId", userId); 
     62                return objectArrayToStringSet((new SampleDAO(this.currentSession())).allCountries()); 
     63        } 
     64         
    6565 
    6666        public Sample details(final long id) throws MpDbException { 
    … …  
    113113                dao.delete(s); 
    114114        } 
     115         
     116        private Set<String> objectArrayToStringSet(final Object[] o){ 
     117                final Set<String> options = new HashSet(); 
     118                for (int i = 0; i < o.length; i++){ 
     119                        if (o[i] != null) 
     120                                options.add(o[i].toString()); 
     121                } 
     122                return options; 
     123        } 
    115124} 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/impl/SearchServiceImpl.java

    r915 r1019  
    2828        public Results<Sample> sampleSearch(final PaginationParameters p, 
    2929                        SearchSample searchSamp, User userSearching) throws MpDbException { 
    30                 return (SearchDb.sampleSearch(p, searchSamp, userSearching)); 
     30                return (SearchDb.sampleSearch(p, searchSamp, userSearching, this.currentSession())); 
    3131        } 
    3232 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/impl/UserServiceImpl.java

    r929 r1019  
    2828import edu.rpi.metpetdb.server.EmailSupport; 
    2929import edu.rpi.metpetdb.server.MpDbServlet; 
     30import edu.rpi.metpetdb.server.dao.impl.RegionDAO; 
    3031import edu.rpi.metpetdb.server.dao.impl.RoleChangeDAO; 
    3132import edu.rpi.metpetdb.server.dao.impl.UserDAO; 
    … …  
    6667                return (user); 
    6768        } 
    68  
     69         
    6970        public Set<String> allNames() throws MpDbException { 
    70                 final Object[] l = (new UserDAO(this.currentSession())).allNames(); 
    71                 final Set<String> options = new HashSet<String>(); 
    72                 for (int i = 0; i < l.length; i++) { 
    73                         if (l[i] != null) 
    74                                 options.add(l[i].toString()); 
     71                return objectArrayToStringSet((new UserDAO(this.currentSession())).allNames()); 
     72        } 
     73         
     74        public Set<String> viewableNamesForUser(final int userId) throws MpDbException { 
     75                this.currentSession().enableFilter("hasSamplePublicOrUser").setParameter("userId", userId); 
     76                return objectArrayToStringSet((new UserDAO(this.currentSession())).allNames()); 
     77        } 
     78         
     79        private Set<String> objectArrayToStringSet(final Object[] o){ 
     80                final Set<String> options = new HashSet(); 
     81                for (int i = 0; i < o.length; i++){ 
     82                        if (o[i] != null) 
     83                                options.add(o[i].toString()); 
    7584                } 
    7685                return options; 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/search/SearchDb.java

    r1011 r1019  
    5252 
    5353        public static Results<Sample> sampleSearch(final PaginationParameters p, 
    54                         SearchSample searchSamp, User userSearching) throws MpDbException { 
     54                        SearchSample searchSamp, User userSearching, Session session) throws MpDbException { 
    5555 
    5656                // Either do chemical analysis -> subsample -> Sample search if they 
    … …  
    6464                else 
    6565                        userId = u.getId(); 
    66                 Session session = DataStore.open(); 
    6766                DataStore.enableSecurityFilters(session, userId); 
    6867                FullTextSession fullTextSession = Search.createFullTextSession(session); 
    … …  
    130129                                return results; 
    131130                        } catch (CallbackException e) { 
    132                                 session.clear(); 
    133131                                throw ConvertSecurityException.convertToException(e); 
    134                         } finally { 
    135                                 session.close(); 
    136132                        } 
    137133                } 
    … …  
    159155                        return results; 
    160156                } catch (CallbackException e) { 
    161                         session.clear(); 
    162157                        throw ConvertSecurityException.convertToException(e); 
    163                 } finally { 
    164                         session.close(); 
    165158                } 
    166159        } 
    … …  
    204197                                return results; 
    205198                        } catch (CallbackException e) { 
    206                                 session.clear(); 
    207199                                throw ConvertSecurityException.convertToException(e); 
    208                         } finally { 
    209                                 session.close(); 
    210                         } 
     200                        }  
    211201                } else { 
    212202                        Query fullQuery; 
    … …  
    268258                                return results; 
    269259                        } catch (CallbackException e) { 
    270                                 session.clear(); 
    271260                                throw ConvertSecurityException.convertToException(e); 
    272                         } finally { 
    273                                 session.close(); 
    274                         } 
     261                        }  
    275262                } 
    276263        } 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/search/SearchIPhone.java

    r1011 r1019  
    1212import javax.servlet.http.HttpServletResponse; 
    1313 
     14import org.hibernate.Session; 
    1415import org.postgis.LinearRing; 
    1516import org.postgis.Point; 
    … …  
    138139         
    139140        private Results<Sample> search(final Collection<String> regions){ 
     141                Session session = DataStore.open(); 
    140142                try{ 
    141143                        SearchSample s = new SearchSample(); 
    142144                        for (String r : regions){ 
    143145                                s.addRegion(r); 
    144                         } 
    145                         return SearchDb.sampleSearch(null, s, null); 
     146                        }       Â 
     147                        return search(s); 
    146148                } 
    147149                catch (Exception e){ 
    148150                        throw new IllegalStateException(e.getMessage()); 
    149                 } 
    150         } 
    151  
    152         private Results<Sample> search(final Double lat, final Double lng){ 
     151                } finally{ 
     152                        session.close(); 
     153                } 
     154        } 
     155         
     156        private Results<Sample> search(final SearchSample s){ 
     157                Session session = DataStore.open(); 
     158                try{ 
     159                        return SearchDb.sampleSearch(null, s, null, session); 
     160                } 
     161                catch(Exception e){ 
     162                        throw new IllegalStateException(e.getMessage()); 
     163                } finally { 
     164                        session.close(); 
     165                } 
     166        } 
     167 
     168        private Results<Sample> search(final Double lat, final Double lng){             Â 
    153169                try{ 
    154170                        SearchSample s = new SearchSample(); 
    … …  
    182198                        boundingBox.dimension = 2; 
    183199                        s.setBoundingBox(boundingBox); 
    184                         return SearchDb.sampleSearch(null, s, null); 
     200                        return search(s); 
    185201 
    186202                } catch (final Exception ioe){Â