/** * Checks whether the name is explicitly marked as preferred for any locale. Note that this * method is different from {@link #isPreferredForLocale(Locale)} in that it checks if the given * name is marked as preferred irrespective of the locale in which it is preferred. * * @see #isPreferredForLocale(Locale) */ public Boolean isPreferred() { return getLocalePreferred(); }
/** * Checks whether the name is explicitly marked as preferred for the given locale * * @param locale the locale in which the name is preferred * @return true if the name is marked as preferred for the given locale otherwise false. */ public Boolean isPreferredForLocale(Locale locale) { return getLocalePreferred() && this.locale.equals(locale); }
private void makeLocaleNotPreferred(ConceptName conceptName) { if (conceptName.getLocalePreferred()) { conceptName.setLocalePreferred(false); } }
/** * Getter for localePreferred * * @return localPreferred * * @deprecated as of 2.0, use {@link #getLocalePreferred()} */ @Deprecated @JsonIgnore public Boolean isLocalePreferred() { return getLocalePreferred(); }
} else if (matches.size() > 1) { for (ConceptName match : matches) { if (match.getLocalePreferred()) { return match;
if (ObjectUtils.nullSafeEquals(nameInLocale.getLocalePreferred(), true)) { return nameInLocale; if (ObjectUtils.nullSafeEquals(nameInLocale.getLocalePreferred(), true)) { Locale nameLocale = nameInLocale.getLocale(); if (forLocale.getLanguage().equals(nameLocale.getLanguage())) {
pStmt.setString(2, (conceptName.getConceptNameType() != null) ? conceptName.getConceptNameType().toString() : null); pStmt.setBoolean(3, conceptName.getLocalePreferred()); pStmt.setBoolean(4, conceptName.getVoided()); pStmt.setDate(5, conceptName.getVoided() ? new Date(System.currentTimeMillis()) : null);
if (nameInLocale.getLocalePreferred() != null) { if (nameInLocale.getLocalePreferred() && !preferredNameForLocaleFound) { if (nameInLocale.isIndexTerm()) { nameInLocale.setLocalePreferred(false); else if (nameInLocale.getLocalePreferred() && preferredNameForLocaleFound) {
/** * The Concept should unmark the old conceptName as the locale preferred one to enforce the rule * that a each locale should have only one preferred name per concept * * @see Concept#setPreferredName(ConceptName) */ @Test public void setPreferredName_shouldOnlyAllowOnePreferredName() { Locale primaryLocale = Locale.US; Concept testConcept = createConcept(1, primaryLocale); ConceptName initialPreferred = createConceptName(3, "Aspirin", primaryLocale, null, true); testConcept.addName(initialPreferred); Assert.assertEquals(true, initialPreferred.getLocalePreferred()); ConceptName newPreferredName = createConceptName(4, "Doctor", primaryLocale, null, false); testConcept.setPreferredName(newPreferredName); assertEquals(false, initialPreferred.getLocalePreferred()); assertEquals(true, newPreferredName.getLocalePreferred()); }
errors.reject("Concept.name.empty"); if (nameInLocale.getLocalePreferred() != null) { if (nameInLocale.getLocalePreferred() && !preferredNameForLocaleFound) { if (nameInLocale.isIndexTerm()) { log.warn("Preferred name in locale '" + conceptNameLocale.toString() else if (nameInLocale.getLocalePreferred() && preferredNameForLocaleFound) { log.warn("Found multiple preferred names in locale '" + conceptNameLocale.toString() + "'"); errors.reject("Concept.error.multipleLocalePreferredNames");
/** * This test is run against the xml test dataset for all concepts to ensure that in every locale * with one or more names, there isn't more than one name explicitly marked as locale preferred. * NOTE that it doesn't test a particular API method directly */ @Test public void saveConcept_shouldEnsureThatEveryConcepNameLocaleHasExactlyOnePreferredName() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { for (Locale locale : allowedLocales) { Collection<ConceptName> namesInLocale = concept.getNames(locale); if (!CollectionUtils.isEmpty(namesInLocale)) { int preferredNamesFound = 0; for (ConceptName conceptName : namesInLocale) { if (conceptName.getLocalePreferred()) { preferredNamesFound++; Assert.assertTrue("Found multiple preferred names for conceptId: " + concept.getConceptId() + " in the locale '" + locale + "'", preferredNamesFound < 2); } } } } } }
/** * This test fetches all concepts in the xml test dataset and ensures that every locale that has * atleast one conceptName has a name marked as preferred. NOTE that it doesn't test a * particular API method directly. */ @Test public void saveConcept_shouldAlwaysReturnAPreferredNameForEveryLocaleThatHasAtleastOneUnvoidedName() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { for (Locale locale : allowedLocales) { if (!CollectionUtils.isEmpty(concept.getNames(locale))) { Assert.assertNotNull("Concept with Id: " + concept.getConceptId() + " has no preferred name in locale:" + locale, concept.getPreferredName(locale)); Assert.assertEquals(true, concept.getPreferredName(locale).getLocalePreferred()); } } } }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("locale", getObject().getLocale()); assertPropEquals("localePreferred", getObject().getLocalePreferred()); assertPropEquals("conceptNameType", getObject().getConceptNameType()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("locale", getObject().getLocale()); assertPropEquals("localePreferred", getObject().getLocalePreferred()); assertPropEquals("conceptNameType", getObject().getConceptNameType()); assertPropPresent("auditInfo"); }