Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Ticket #713: locale_update.patch

File locale_update.patch, 83.4 kB (added by akollegger, 8 months ago)
  • .classpath

    old new  
    55        <classpathentry kind="src" path="src/web"/> 
    66        <classpathentry kind="src" path="test/api"/> 
    77        <classpathentry kind="src" path="test/web"/> 
    8         <classpathentry kind="lib" path="lib/ant-contrib/ant-contrib-1.0b2.jar"/> 
    98        <classpathentry kind="lib" path="lib/antlr/antlr_2.7.6.jar"/> 
    109        <classpathentry kind="lib" path="lib/cglib/cglib-2.1_3.jar"/> 
    1110        <classpathentry kind="lib" path="lib/commons-beanutils/commons-beanutils-1.7.0.jar"/> 
     
    5756        <classpathentry kind="lib" path="metadata/api/spring"/> 
    5857        <classpathentry kind="lib" path="metadata/api/hibernate"/> 
    5958        <classpathentry kind="lib" path="metadata/api/log4j"/> 
     59        <classpathentry kind="lib" path="lib/ant-contrib/ant-contrib-1.0b2.jar"/> 
    6060        <classpathentry kind="output" path="build/"/> 
    6161</classpath> 
  • metadata/api/hibernate/org/openmrs/api/db/hibernate/ConceptWord.hbm.xml

    old new  
    1111                        <key-many-to-one name="concept" column="concept_id" 
    1212                                class="Concept" /> 
    1313                        <key-property name="word" type="java.lang.String" length="255" /> 
    14                         <key-property name="synonym" type="java.lang.String" length="255" /> 
    15                         <key-property name="locale" type="java.lang.String" length="255" /> 
     14                        <key-property name="synonym" type="java.lang.String" length="255" /> 
     15                        <key-property name="locale" type="java.util.Locale" length="255" /> 
    1616                </composite-id> 
    1717 
    1818                <many-to-one name="concept" column="concept_id" class="Concept"  
  • metadata/api/hibernate/org/openmrs/api/db/hibernate/Concept.hbm.xml

    old new  
    3939                        <composite-element class="ConceptName"> 
    4040                                <parent name="concept" /> 
    4141                                <property name="name" type="java.lang.String" length="255" not-null="true"/> 
    42                                 <property name="locale" type="java.lang.String" length="50" not-null="true"/> 
     42                                <property name="locale" type="java.util.Locale" length="50" not-null="true"/> 
    4343                                <property name="shortName" type="java.lang.String" length="255" column="short_name" /> 
    4444                                <property name="description" type="java.lang.String" length="65535" not-null="true" /> 
    4545                                <property name="dateCreated" type="java.util.Date" column="date_created" not-null="true"/> 
     
    7373                        <composite-element class="ConceptSynonym"> 
    7474                                <parent name="concept" /> 
    7575                                <property name="synonym" type="java.lang.String" not-null="true" /> 
    76                                 <property name="locale" type="java.lang.String" not-null="true" /> 
     76                                <property name="locale" type="java.util.Locale" not-null="true" /> 
    7777                                <property name="dateCreated" type="java.util.Date" column="date_created" not-null="true"/> 
    7878                                <many-to-one name="creator" class="User" column="creator" not-null="true"/> 
    7979                        </composite-element> 
  • src/api/org/openmrs/ConceptWord.java

    old new  
    1515 
    1616import java.util.HashSet; 
    1717import java.util.List; 
     18import java.util.Locale; 
    1819import java.util.Set; 
    1920import java.util.Vector; 
    2021 
     
    3637 
    3738        private String synonym; 
    3839 
    39         private String locale; 
     40        private Locale locale; 
    4041 
    4142        private Double weight = 0.0; 
    4243 
     
    4647        public ConceptWord() { 
    4748        } 
    4849 
    49         public ConceptWord(String word, Concept concept, String locale, 
     50        public ConceptWord(String word, Concept concept, Locale locale, 
    5051                        String synonym) { 
    5152                this.concept = concept; 
    5253                this.word = word; 
     
    9596        /** 
    9697         * @return Returns the locale. 
    9798         */ 
    98         public String getLocale() { 
     99        public Locale getLocale() { 
    99100                return locale; 
    100101        } 
    101102 
     
    103104         * @param locale 
    104105         *            The locale to set. 
    105106         */ 
    106         public void setLocale(String locale) { 
     107        public void setLocale(Locale locale) { 
    107108                this.locale = locale; 
    108109        } 
    109110 
  • src/api/org/openmrs/ConceptSynonym.java

    old new  
    3232 
    3333        private Concept concept; 
    3434        private String synonym; 
    35         private String locale; 
     35        private Locale locale; 
    3636        private User creator; 
    3737        private Date dateCreated; 
    3838 
     
    4545        public ConceptSynonym(Concept c, String s, Locale l) { 
    4646                setConcept(c); 
    4747                setSynonym(s); 
    48                 setLocale(l.getLanguage().substring(0, 2)); 
     48                setLocale(l); 
    4949        } 
    5050         
    5151        public boolean equals(Object obj) { 
     
    107107        /** 
    108108         * @return Returns the locale. 
    109109         */ 
    110         public String getLocale() { 
     110        public Locale getLocale() { 
    111111                return locale; 
    112112        } 
    113113 
    114114        /** 
    115115         * @param locale The locale to set. 
    116116         */ 
    117         public void setLocale(String locale) { 
     117        public void setLocale(Locale locale) { 
    118118                this.locale = locale; 
    119119                //id.setLocale(locale); 
    120120        } 
  • src/api/org/openmrs/ConceptName.java

    old new  
    3030        private String name; 
    3131        private String shortName; 
    3232        private String description; 
    33         private String locale; 
     33        private Locale locale; 
    3434        private User creator; 
    3535        private Date dateCreated; 
    3636 
     
    104104        /** 
    105105         *  
    106106         */ 
    107         public String getLocale() { 
     107        public Locale getLocale() { 
    108108                return locale; 
    109109        } 
    110110 
    111         public void setLocale(String locale) { 
     111        public void setLocale(Locale locale) { 
    112112                this.locale = locale; 
    113113        } 
    114          
    115         public void setLocale(Locale locale) { 
    116                 this.locale = locale.getLanguage().substring(0, 2); 
    117         } 
    118114 
    119115        /** 
    120116         * @return Returns the shortName. 
  • src/api/org/openmrs/util/OpenmrsConstants.java

    old new  
    532532        public static final String USER_PROPERTY_NOTIFICATION                   = "notification"; 
    533533        public static final String USER_PROPERTY_NOTIFICATION_ADDRESS   = "notificationAddress"; 
    534534        public static final String USER_PROPERTY_NOTIFICATION_FORMAT    = "notificationFormat";         // text/plain, text/html 
     535 
     536        /** 
     537         * A user property name. The value should be a comma-separated ordered  
     538         * list of fully qualified locales within which the user is a proficient  
     539         * speaker. The list should be ordered from the most to the least proficiency. 
     540         *  
     541         * Example: 
     542         * <code>proficientLocales = en_US, en_GB, en, fr_RW</code> 
     543         */ 
     544        public static final String USER_PROPERTY_PROFICIENT_LOCALES                     = "proficientLocales"; 
    535545         
    536546        /* 
    537547         * Report object properties 
  • src/api/org/openmrs/util/LocaleFactory.java

    old new  
     1package org.openmrs.util; 
     2 
     3 
     4import java.util.Collection; 
     5import java.util.List; 
     6import java.util.Locale; 
     7import java.util.Vector; 
     8 
     9/** 
     10 * A factory for creating Locales. 
     11 *  
     12 * @author <a href="mailto:akollegger@tembopublic.org">Andreas Kollegger</a> 
     13 */ 
     14public class LocaleFactory { 
     15 
     16        /** 
     17         * Default internal locale. 
     18         *  
     19         * ABKTODO: this should be defined/configured somewhere else 
     20         */ 
     21        public static final Locale DEFAULT_LOCALE = Locale.ENGLISH; 
     22         
     23        /** 
     24         * Creates a locale based on a string specification. The specification 
     25         * must be conform with the following format: ll_CC_vv 
     26         *  
     27         * Where: 
     28         *      ll two-character lowercase ISO-639 language code 
     29         *  CC two-character uppercase ISO-3166 country code optional 
     30         *  vv arbitrary length variant code 
     31         *  
     32         * For example: 
     33         *      en_US_Traditional_WIN 
     34         * ...represents English language in the United States with the traditional collation for windows. 
     35         *  
     36         * @param localeSpecification encoded locale specification 
     37         * @return the representative Locale, or null if the specification is invalid 
     38         */ 
     39        public static Locale fromSpecification(String localeSpecification) 
     40        { 
     41                Locale createdLocale = null; 
     42                 
     43                localeSpecification = localeSpecification.trim(); 
     44                 
     45                String[] localeComponents = localeSpecification.split("_"); 
     46                if (localeComponents.length == 1) 
     47                { 
     48                        createdLocale = new Locale(localeComponents[0]); 
     49                } 
     50                else if (localeComponents.length == 2) 
     51                { 
     52                        createdLocale = new Locale(localeComponents[0], localeComponents[1]); 
     53                } 
     54                else if (localeComponents.length > 2) 
     55                { 
     56                        String variant = localeSpecification.substring(localeSpecification.indexOf(localeComponents[2])); 
     57                        createdLocale = new Locale(localeComponents[0], localeComponents[1], variant); 
     58                } 
     59                 
     60                return createdLocale; 
     61        } 
     62} 
  • src/api/org/openmrs/User.java

    old new  
    1313 */ 
    1414package org.openmrs; 
    1515 
     16import java.util.ArrayList; 
    1617import java.util.Collection; 
    1718import java.util.Date; 
    1819import java.util.HashSet; 
    1920import java.util.Iterator; 
     21import java.util.List; 
     22import java.util.Locale; 
    2023import java.util.Map; 
    2124import java.util.Set; 
    2225 
    2326import org.apache.commons.logging.Log; 
    2427import org.apache.commons.logging.LogFactory; 
     28import org.openmrs.util.LocaleFactory; 
    2529import org.openmrs.util.OpenmrsConstants; 
    2630 
    2731/** 
     
    6266        private Date dateVoided; 
    6367        private String voidReason; 
    6468 
     69        private List<Locale> proficientLocales = null; 
     70        private String parsedProficientLocalesProperty = ""; 
     71 
    6572        // Constructors 
    6673 
    6774        /** default constructor */ 
     
    548555        public String getLastName() { 
    549556                return getFamilyName(); 
    550557        } 
     558 
     559        /** 
     560         * Returns a list of Locales for which the User  
     561         * is considered proficient. 
     562     *  
     563     * @return List of the User's proficient locales 
     564     */ 
     565    public List<Locale> getProficientLocales() { 
     566                String proficientLocalesProperty = getUserProperty(OpenmrsConstants.USER_PROPERTY_PROFICIENT_LOCALES); 
     567 
     568        if ((proficientLocales == null) || (!parsedProficientLocalesProperty.equals(proficientLocalesProperty))) { 
     569                parsedProficientLocalesProperty = proficientLocalesProperty; 
     570                proficientLocales = new ArrayList<Locale>(); 
     571                         
     572                        String[] proficientLocalesArray = proficientLocalesProperty.split(","); 
     573                        for (String proficientLocaleSpec : proficientLocalesArray) { 
     574                                if (proficientLocaleSpec.length() > 0) { 
     575                                        Locale proficientLocale = LocaleFactory.fromSpecification(proficientLocaleSpec); 
     576                                        if (!proficientLocales.contains(proficientLocale)) { 
     577                                                proficientLocales.add(proficientLocale); 
     578                                                if (proficientLocale.getCountry() != "") { 
     579                                                        // add the language also 
     580                                                        Locale languageOnlyLocale = LocaleFactory.fromSpecification(proficientLocale.getLanguage()); 
     581                                                        if (!proficientLocales.contains(languageOnlyLocale)) { 
     582                                                                proficientLocales.add(LocaleFactory.fromSpecification(proficientLocale.getLanguage())); 
     583                                                        } 
     584                                                } 
     585                                        } 
     586                                } 
     587                        } 
     588        } 
     589        return proficientLocales; 
     590    } 
    551591} 
  • src/api/org/openmrs/Concept.java

    old new  
    311311         */ 
    312312        public ConceptName getName(Locale locale, boolean exact) { 
    313313                log.debug("Getting conceptName for locale: " + locale); 
    314                  
     314 
     315                ConceptName bestMatch = null; // name from compatible locale (not exactly exact) 
     316                ConceptName defaultName = null; // any available name for the concept 
     317 
    315318                if (locale == null) 
    316                         locale = Locale.US; 
    317                  
    318                 String loc = locale.getLanguage(); 
    319                 if (loc.length() > 2) 
    320                         loc = loc.substring(0, 2); 
    321                 ConceptName defaultName = null; 
     319                        locale = Context.getLocale(); // Don't presume en_US; 
     320 
     321                String desiredLanguage = locale.getLanguage(); 
     322                String desiredCountry = locale.getCountry(); 
     323 
    322324                for (Iterator<ConceptName> i = getNames().iterator(); i.hasNext();) { 
    323                         ConceptName name = i.next(); 
    324                         String lang = name.getLocale(); 
    325                         if (lang.equals(loc)) 
    326                                 return name; 
    327                         if (lang.equals("en")) 
    328                                 defaultName = name; 
     325                        ConceptName possibleName = i.next(); 
     326 
     327                        if (possibleName.getLocale().equals(locale)) { 
     328                                bestMatch = possibleName; 
     329                                break; 
     330                        } else { 
     331                                if (defaultName == null) 
     332                                        defaultName = possibleName; 
     333                                if (bestMatch == null) { 
     334                                        if (possibleName.getLocale() 
     335                                                        .getLanguage() 
     336                                                        .equals(desiredLanguage)) { 
     337                                                bestMatch = possibleName; 
     338                                        } 
     339                                } 
     340                        } 
    329341                } 
    330                  
    331                 //no name with the given locale was found. 
    332                 // return null if exact match desired 
     342 
    333343                if (exact) { 
    334                         log.warn("No concept name found for concept id " + conceptId + " for locale " + loc); 
    335                         return null; 
     344                        if (bestMatch == null) 
     345                                log.warn("No concept name found for concept id " + conceptId 
     346                                        + " for locale " + locale.toString()); 
     347                        return bestMatch; 
    336348                } 
    337                  
    338                 // returning default name locale ("en") if exact match not desired 
    339                 if (defaultName == null) 
    340                         log.warn("No concept name found for default locale for concept id " + conceptId); 
    341                  
     349 
     350                if (bestMatch != null) 
     351                        return bestMatch; 
     352 
     353                log.warn("No compatible concept name found for default locale for concept id " 
     354                        + conceptId); 
     355 
     356                if (defaultName == null) { 
     357                        log.error("No concept names exist for concept id: " + conceptId); 
     358                } 
     359 
    342360                return defaultName; 
    343361        } 
    344362         
     
    420438         * @return Collection of ConceptSynonym attributed to the Concept in the given locale 
    421439         */ 
    422440        public Collection<ConceptSynonym> getSynonyms(Locale locale) { 
    423                 String loc = locale.getLanguage().substring(0, 2); 
     441                String conceptLanguage = locale.getLanguage().substring(0, 2); 
    424442                Collection<ConceptSynonym> syns = new Vector<ConceptSynonym>(); 
    425443                for (ConceptSynonym syn : getSynonyms()) { 
    426                         String lang = syn.getLocale(); 
    427                         if (lang == null) lang = "en"
    428                         if (lang.equals(loc)) 
     444                        String synLanguage = syn.getLocale().getLanguage().substring(0, 2); 
     445                        if (synLanguage == null) synLanguage = Context.getLocale().getLanguage().substring(0, 2)
     446                        if (synLanguage.equals(conceptLanguage)) 
    429447                                syns.add(syn); 
    430448                } 
    431449                log.debug("returning: " + syns); 
  • src/api/org/openmrs/api/db/ConceptDAO.java

    old new  
    212212        /** 
    213213         * Searches on given phrase via the concept word table 
    214214         * @param phrase/search/words String 
    215          * @param locale Locale 
     215         * @param locales Locales to include in search 
    216216         * @param includeRetired boolean 
    217217         * @param requireClasses List<ConceptClass> 
    218218         * @param excludeClasses List<ConceptClass> 
     
    220220         * @param excludeDatatypes List<ConceptDatatype> 
    221221         * @return 
    222222         */ 
    223         public List<ConceptWord> findConcepts(String phrase, Locale locale, boolean includeRetired,  
     223        public List<ConceptWord> findConcepts(String phrase, List<Locale> locales, boolean includeRetired,  
    224224                        List<ConceptClass> requireClasses, List<ConceptClass> excludeClasses, 
    225225                        List<ConceptDatatype> requireDatatypes, List<ConceptDatatype> excludeDatatypes); 
    226226         
  • src/api/org/openmrs/api/db/hibernate/HibernateConceptDAO.java

    old new  
    1414package org.openmrs.api.db.hibernate; 
    1515 
    1616import java.math.BigInteger; 
     17import java.util.ArrayList; 
    1718import java.util.Date; 
    1819import java.util.Iterator; 
    1920import java.util.List; 
     
    499500        } 
    500501 
    501502        // TODO below are functions worthy of a second tier 
    502          
     503 
    503504        /** 
    504505         * @see org.openmrs.api.db.ConceptService#findConcepts(java.lang.String,java.util.Locale,boolean) 
    505506         */ 
    506507        @SuppressWarnings("unchecked") 
    507         public List<ConceptWord> findConcepts(String phrase, Locale loc, boolean includeRetired,  
     508        public List<ConceptWord> findConcepts(String phrase, List<Locale> locales, boolean includeRetired,  
    508509                        List<ConceptClass> requireClasses, List<ConceptClass> excludeClasses, 
    509510                        List<ConceptDatatype> requireDatatypes, List<ConceptDatatype> excludeDatatypes)  
    510511                        { 
    511                 String locale = loc.getLanguage().substring(0, 2);             //only get language portion of locale 
     512                 
    512513                List<String> words = ConceptWord.getUniqueWords(phrase); //assumes getUniqueWords() removes quote(') characters.  (otherwise we would have a security leak) 
    513514                 
    514515                List<ConceptWord> conceptWords = new Vector<ConceptWord>(); 
    515516                 
    516517                if (words.size() > 0) { 
    517                  
     518                        
    518519                        Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(ConceptWord.class, "cw1"); 
    519                         searchCriteria.add(Restrictions.eq("locale", locale)); 
     520                        searchCriteria.add(Expression.in("locale", locales)); 
     521                        // searchCriteria.add(Restrictions.eq("locale", locale)); 
    520522                        if (includeRetired == false) { 
    521523                                searchCriteria.createAlias("concept", "concept"); 
    522524                                searchCriteria.add(Expression.eq("concept.retired", false)); 
     
    531533                                                        .setProjection(Property.forName("concept")) 
    532534                                                        .add(Expression.eqProperty("concept", "cw1.concept")) 
    533535                                                        .add(Restrictions.like("word", w, MatchMode.START)) 
    534                                                         .add(Restrictions.eq("locale", locale)); 
     536                                                        .add(Expression.in("locale", locales)); 
    535537                                junction.add(Subqueries.exists(crit)); 
    536538                        } 
    537539                        searchCriteria.add(junction); 
     
    560562                 
    561563                return conceptWords; 
    562564        } 
     565 
    563566         
    564567        /** 
    565568         * @see org.openmrs.api.db.ConceptService#findConcepts(java.lang.String,java.util.Locale,org.openmrs.Concept,boolean) 
  • src/api/org/openmrs/api/ConceptService.java

    old new  
    350350                        List<ConceptClass> requireClasses, List<ConceptClass> excludeClasses, 
    351351                        List<ConceptDatatype> requireDatatypes,List<ConceptDatatype> excludeDatatypes); 
    352352 
     353 
    353354        /** 
     355         * Searches on given phrase via the concept word table within a sorted list of Locales 
    354356         *  
     357         * @param phrase/search/words 
     358         *            String 
     359         * @param searchLocales 
     360         *            ordered List of Locales within which to search 
     361         * @param includeRetired 
     362         *            boolean 
     363         * @param requireClasses 
     364         *            List<ConceptClass> 
     365         * @param excludeClasses 
     366         *            List<ConceptClass> 
     367         * @param requireDatatypes 
     368         *            List<ConceptDatatype> 
     369         * @param excludeDatatypes 
     370         *            List<ConceptDatatype> 
     371         * @return 
     372         *  
     373         * @see ConceptService.findConcepts(String,Locale,boolean) 
     374         */ 
     375        @Transactional(readOnly=true) 
     376        @Authorized({"View Concepts"}) 
     377        public List<ConceptWord> findConcepts(String phrase, List<Locale> searchLocales, boolean includeRetired,  
     378                        List<ConceptClass> requireClasses, List<ConceptClass> excludeClasses, 
     379                        List<ConceptDatatype> requireDatatypes,List<ConceptDatatype> excludeDatatypes); 
     380         
     381        /** 
     382         *  
    355383         * Finds concepts but only returns the given range 
    356384         *  
    357385         * @param phrase 
  • src/api/org/openmrs/api/impl/AdministrationServiceImpl.java

    old new  
    584584 
    585585                Context.getConceptService().checkIfLocked(); 
    586586                 
    587                 int count = 0; 
    588                 for (Concept concept : Context.getConceptService().getConceptsByName("")) { 
    589                         updateConceptWord(concept); 
    590                         if (count++ > 1000) { 
    591                                 Context.clearSession(); 
    592                                 count = 0; 
    593                         } 
     587                // Run the operation in batches 
     588                ConceptService cs = Context.getConceptService(); 
     589                int batchStartId = 0; 
     590                int endId = cs.getNextAvailableId(); 
     591                int batchSize = 1000; 
     592                 
     593                while (batchStartId < endId) 
     594                { 
     595                        updateConceptWords(batchStartId, batchStartId + batchSize); 
     596                        Context.clearSession(); 
     597                        batchStartId += batchSize; 
    594598                } 
    595599                 
    596600        } 
  • src/api/org/openmrs/api/impl/ConceptServiceImpl.java

    old new  
    476476                        requireDatatypes = new Vector<ConceptDatatype>(); 
    477477                if (excludeDatatypes == null) 
    478478                        excludeDatatypes = new Vector<ConceptDatatype>(); 
     479 
     480                List<Locale> searchLocales = new ArrayList<Locale>(); 
     481                searchLocales.add(locale); 
    479482                 
    480483                List<ConceptWord> conceptWords = getConceptDAO().findConcepts(phrase, 
    481                                locale, includeRetired, requireClasses, excludeClasses, requireDatatypes, excludeDatatypes); 
     484                                                                              searchLocales, includeRetired, requireClasses, excludeClasses, requireDatatypes, excludeDatatypes); 
    482485 
    483486                return weightWords(phrase, locale, conceptWords); 
    484487        } 
    485488 
    486489        /** 
     490     * @see org.openmrs.api.ConceptService#findConcepts(java.lang.String, java.util.List, boolean, java.util.List, java.util.List, java.util.List, java.util.List) 
     491     */ 
     492    public List<ConceptWord> findConcepts(String phrase, 
     493            List<Locale> searchLocales, boolean includeRetired, 
     494            List<ConceptClass> requireClasses, 
     495            List<ConceptClass> excludeClasses, 
     496            List<ConceptDatatype> requireDatatypes, 
     497            List<ConceptDatatype> excludeDatatypes) { 
     498 
     499                if (requireClasses == null) 
     500                        requireClasses = new Vector<ConceptClass>(); 
     501                if (excludeClasses == null) 
     502                        excludeClasses = new Vector<ConceptClass>(); 
     503                if (requireDatatypes == null) 
     504                        requireDatatypes = new Vector<ConceptDatatype>(); 
     505                if (excludeDatatypes == null) 
     506                        excludeDatatypes = new Vector<ConceptDatatype>(); 
     507                 
     508                List<ConceptWord> conceptWords = getConceptDAO(). 
     509                        findConcepts(phrase, searchLocales, includeRetired, requireClasses,  
     510                                     excludeClasses, requireDatatypes, excludeDatatypes); 
     511 
     512                return weightWords(phrase, searchLocales, conceptWords); 
     513    } 
     514     
     515        /** 
    487516         *  
    488517         * Finds concepts but only returns the given range 
    489518         *  
     
    529558 
    530559        /** 
    531560         * This will weight and sort the concepts we are assuming the hits are 
    532          * sorted with synonym matches at the bottom 
     561         * sorted with synonym matches at the bottom. 
    533562         *  
     563         * @deprecated use weightWords() with multiple locales instead 
     564         *  
    534565         * @param phrase 
    535566         *            that was used to get this search 
    536567         * @param locale 
     
    540571         */ 
    541572        protected List<ConceptWord> weightWords(String phrase, Locale locale, 
    542573                        List<ConceptWord> conceptWords) { 
     574                List<Locale> locales = new ArrayList<Locale>(); 
     575                locales.add(locale); 
     576                return weightWords(phrase, locales, conceptWords); 
     577        } 
     578         
     579        /** 
     580         * This will weight and sort the concepts we are assuming the hits are 
     581         * sorted with synonym matches at the bottom 
     582         *  
     583         * @param phrase 
     584         *            that was used to get this search 
     585         * @param locales 
     586         *            that were used to get this search 
     587         * @param conceptWords 
     588         * @return 
     589         */ 
     590        protected List<ConceptWord> weightWords(String phrase, List<Locale> locales, 
     591                        List<ConceptWord> conceptWords) { 
    543592 
    544593                // Map<ConceptId, ConceptWord> 
    545594                Map<Integer, ConceptWord> uniqueConcepts = new HashMap<Integer, ConceptWord>(); 
     
    564613                                // check synonym in case we have multiple synonym hits 
    565614                                String toSplit = initialWord.getSynonym(); 
    566615                                if (toSplit == null || toSplit.equals("")) { 
    567                                         ConceptName cn = initialWord.getConcept().getName(locale); 
    568                                         toSplit = cn.getName(); 
     616                                        ConceptName cn = null; 
     617                                        // find which locale provided the concept name 
     618                                        for (Locale locale : locales) { 
     619                                                cn = initialWord.getConcept().getName(locale); 
     620                                                if (cn != null) { 
     621                                                        toSplit = cn.getName(); 
     622                                                        break; 
     623                                                } 
     624                                        } 
    569625                                } 
    570626                                List<String> nameWords = ConceptWord.getUniqueWords(toSplit); 
    571627 
     
    593649                                if (matchedString.length() == 0) { 
    594650                                        // We weight name matches higher 
    595651                                        tmpWord.increaseWeight(2.0); 
    596                                         matchedString = tmpWord.getConcept().getName(locale) 
    597                                                         .getName(); 
     652                                        for (Locale locale : locales) { 
     653                                                ConceptName cn = tmpWord.getConcept().getName(locale); 
     654                                                if (cn != null) { 
     655                                                        matchedString = cn.getName(); 
     656                                                        break; 
     657                                                } 
     658                                        } 
    598659                                } 
    599660 
    600661                                // increase the weight by a factor of the % of words matched 
  • src/web/org/openmrs/web/OptionsForm.java

    old new  
    1717 
    1818        private String defaultLocation = ""; 
    1919        private String defaultLocale = ""; 
     20        private String proficientLocales = ""; 
    2021        private Boolean showRetiredMessage = true; 
    2122        private Boolean verbose = false; 
    2223         
     
    160161                this.verbose = verbose; 
    161162        } 
    162163 
    163                  
     164        /** 
     165         * Sets the locales within which the user is proficient. 
     166     *  
     167     * @param proficientLocales a comma-separated list of locales 
     168     */ 
     169    public void setProficientLocales(String proficientLocales) { 
     170        this.proficientLocales = proficientLocales; 
     171    } 
    164172 
     173        /** 
     174         * Returns the locales within which the user is proficient. 
     175     *  
     176     */ 
     177        public String getProficientLocales() { 
     178                return proficientLocales; 
     179        } 
     180 
    165181} 
  • src/web/org/openmrs/web/controller/OptionsFormController.java

    old new  
    2929import org.openmrs.api.EncounterService; 
    3030import org.openmrs.api.UserService; 
    3131import org.openmrs.api.context.Context; 
     32import org.openmrs.util.LocaleFactory; 
    3233import org.openmrs.util.OpenmrsConstants; 
    3334import org.openmrs.web.OptionsForm; 
    3435import org.openmrs.web.WebConstants; 
     
    101102                         
    102103                        properties.put(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, opts.getDefaultLocation()); 
    103104                        properties.put(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE, opts.getDefaultLocale()); 
     105                        properties.put(OpenmrsConstants.USER_PROPERTY_PROFICIENT_LOCALES, opts.getProficientLocales()); 
    104106                        properties.put(OpenmrsConstants.USER_PROPERTY_SHOW_RETIRED, opts.getShowRetiredMessage().toString()); 
    105107                        properties.put(OpenmrsConstants.USER_PROPERTY_SHOW_VERBOSE, opts.getVerbose().toString()); 
    106108                        properties.put(OpenmrsConstants.USER_PROPERTY_NOTIFICATION, opts.getNotification() == null ? "" : opts.getNotification().toString()); 
     
    197199                        Map<String, String> props = user.getUserProperties(); 
    198200                        opts.setDefaultLocation(props.get(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION)); 
    199201                        opts.setDefaultLocale(props.get(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE)); 
     202                        opts.setProficientLocales(props.get(OpenmrsConstants.USER_PROPERTY_PROFICIENT_LOCALES)); 
    200203                        opts.setShowRetiredMessage(new Boolean(props.get(OpenmrsConstants.USER_PROPERTY_SHOW_RETIRED))); 
    201204                        opts.setVerbose(new Boolean(props.get(OpenmrsConstants.USER_PROPERTY_SHOW_VERBOSE))); 
    202205                        opts.setUsername(user.getUsername()); 
  • src/web/org/openmrs/web/dwr/ConceptListItem.java

    old new  
    5252                if (word != null) { 
    5353                         
    5454                        Concept concept = word.getConcept(); 
    55                         Locale locale = new Locale(word.getLocale()); 
     55                        Locale locale = word.getLocale(); 
    5656                        initialize(concept, locale); 
    5757                        synonym = word.getSynonym(); 
    5858                } 
  • src/web/org/openmrs/web/dwr/DWRConceptService.java

    old new  
    7575 
    7676                log.info(userId + "|" + phrase + "|" + includeClassNames.toString()); 
    7777 
    78                 Locale locale = Context.getLocale(); 
     78                Locale defaultLocale = Context.getLocale(); 
     79                List<Locale> searchLocales = u.getProficientLocales(); 
     80                if (searchLocales.size() == 0) { 
     81                        searchLocales.add(defaultLocale); 
     82                         
     83                        // if country is specified, also add the generic language locale 
     84                        if (defaultLocale.getCountry() != "") { 
     85                                searchLocales.add(new Locale(defaultLocale.getLanguage())); 
     86                        } 
     87                                 
     88                } 
     89                StringBuffer searchLocalesString = new StringBuffer(); 
     90                for (Locale loc : searchLocales) { 
     91                        searchLocalesString.append(loc.toString() + " "); 
     92                } 
     93                log.info("searching locales: " + searchLocalesString); 
     94                 
    7995                if (includeClassNames == null) 
    8096                        includeClassNames = new Vector<String>(); 
    8197                if (excludeClassNames == null) 
     
    94110                                // corresponding conceptId 
    95111                                Concept c = cs.getConcept(Integer.valueOf(phrase)); 
    96112                                if (c != null) { 
    97                                         ConceptWord word = new ConceptWord(phrase, c, locale 
    98                                                         .getLanguage(), "Concept Id #" + phrase); 
     113                                        ConceptWord word = new ConceptWord(phrase, c, defaultLocale, "Concept Id #" + phrase); 
    99114