Search in sources :

Example 1 with I18nEntity

use of org.n52.series.db.beans.i18n.I18nEntity in project SOS by 52North.

the class HibernatePredefinedInsertionHandler method convert.

private UnitEntity convert(Unit unit) {
    UnitEntity entity = new UnitEntity();
    entity.setSymbol(unit.getSymbol(), getDaoFactory().isStaSupportsUrls());
    entity.setName(unit.getName());
    entity.setLink(unit.getLink());
    if (unit.hasTranslations()) {
        Set<I18nEntity<? extends Describable>> trans = new LinkedHashSet<>();
        unit.getTranslations().forEach(i -> {
            I18nUnitEntity i18n = new I18nUnitEntity();
            i18n.setLocale(i.getLocale());
            i18n.setName(i.getName());
            i18n.setDescription(i.getDescription());
            trans.add(i18n);
        });
        entity.setTranslations(trans);
    }
    return entity;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Describable(org.n52.series.db.beans.Describable) I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) UnitEntity(org.n52.series.db.beans.UnitEntity) I18nEntity(org.n52.series.db.beans.i18n.I18nEntity)

Example 2 with I18nEntity

use of org.n52.series.db.beans.i18n.I18nEntity in project SOS by 52North.

the class HibernatePredefinedInsertionHandler method convert.

private PhenomenonEntity convert(Phenomenon phenomenon) {
    PhenomenonEntity entity = new PhenomenonEntity();
    entity.setIdentifier(phenomenon.getIdentifier(), daoFactory.isStaSupportsUrls());
    entity.setName(phenomenon.getName());
    entity.setDescription(phenomenon.getDescription());
    if (phenomenon.hasTranslations()) {
        Set<I18nEntity<? extends Describable>> trans = new LinkedHashSet<>();
        phenomenon.getTranslations().forEach(i -> {
            I18nPhenomenonEntity i18n = new I18nPhenomenonEntity();
            i18n.setLocale(i.getLocale());
            i18n.setName(i.getName());
            i18n.setDescription(i.getDescription());
            trans.add(i18n);
        });
        entity.setTranslations(trans);
    }
    return entity;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) I18nPhenomenonEntity(org.n52.series.db.beans.i18n.I18nPhenomenonEntity) Describable(org.n52.series.db.beans.Describable) I18nPhenomenonEntity(org.n52.series.db.beans.i18n.I18nPhenomenonEntity) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) I18nEntity(org.n52.series.db.beans.i18n.I18nEntity)

Example 3 with I18nEntity

use of org.n52.series.db.beans.i18n.I18nEntity in project SOS by 52North.

the class OfferingCacheUpdateTask method addOfferingNamesAndDescriptionsToCache.

protected void addOfferingNamesAndDescriptionsToCache(OfferingEntity offering, Session session) throws OwsExceptionReport {
    final MultilingualString name = new MultilingualString();
    final MultilingualString description = new MultilingualString();
    if (offering.isSetName()) {
        final Locale locale = defaultLanguage;
        name.addLocalization(locale, offering.getName());
        getCache().setNameForOffering(offering.getIdentifier(), offering.getName());
    } else {
        String offeringName = offering.getIdentifier();
        if (offeringName.startsWith("http")) {
            offeringName = offeringName.substring(offeringName.lastIndexOf('/') + 1, offeringName.length());
        } else if (offeringName.startsWith("urn")) {
            offeringName = offeringName.substring(offeringName.lastIndexOf(':') + 1, offeringName.length());
        }
        if (offeringName.contains("#")) {
            offeringName = offeringName.substring(offeringName.lastIndexOf('#') + 1, offeringName.length());
        }
        name.addLocalization(defaultLanguage, offeringName);
    }
    if (offering.isSetDescription()) {
        final Locale locale = defaultLanguage;
        description.addLocalization(locale, offering.getDescription());
    }
    if (offering.hasTranslations()) {
        for (I18nEntity<? extends Describable> t : offering.getTranslations()) {
            if (t.hasName()) {
                name.addLocalization(t.getLocale(), t.getName());
            }
            if (t.hasDescription()) {
                description.addLocalization(t.getLocale(), t.getDescription());
            }
        }
    }
    getCache().setI18nDescriptionForOffering(offering.getIdentifier(), description);
    getCache().setI18nNameForOffering(offering.getIdentifier(), name);
    addHumanReadableIdentifier(offering.getIdentifier(), offering, name);
}
Also used : Locale(java.util.Locale) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) LocalizedString(org.n52.janmayen.i18n.LocalizedString)

Example 4 with I18nEntity

use of org.n52.series.db.beans.i18n.I18nEntity in project SOS by 52North.

the class I18nNameDescriptionAdder method addNameAndDescription.

default void addNameAndDescription(DescribableEntity entity, AbstractFeature feature, Locale requestedLocale, Locale defaultLocale, boolean showAllLanguageValues) throws OwsExceptionReport {
    if (entity.hasTranslations()) {
        if (requestedLocale != null) {
            // specific locale was requested
            Optional<I18nEntity<? extends Describable>> translation = getTranslation(entity, requestedLocale);
            if (translation.isPresent()) {
                if (translation.get().hasName()) {
                    feature.addName(new CodeType(translation.get().getName(), URI.create(LocaleHelper.encode(requestedLocale))));
                } else {
                    feature.addName(entity.getName());
                }
                if (translation.get().hasDescription()) {
                    feature.setDescription(translation.get().getDescription());
                } else {
                    feature.setDescription(entity.getDescription());
                }
            } else {
                feature.addName(entity.getName());
                feature.setDescription(entity.getDescription());
            }
        } else {
            Optional<I18nEntity<? extends Describable>> translation = defaultLocale != null ? getTranslation(entity, defaultLocale) : Optional.empty();
            if (showAllLanguageValues) {
                // load all names
                for (I18nEntity<? extends Describable> t : entity.getTranslations()) {
                    feature.addName(new CodeType(t.getName(), URI.create(t.getLocale())));
                }
            } else {
                if (translation.isPresent()) {
                    if (translation.get().hasName()) {
                        feature.addName(new CodeType(translation.get().getName(), URI.create(LocaleHelper.encode(defaultLocale))));
                    } else {
                        feature.addName(entity.getName());
                    }
                } else {
                    feature.addName(entity.getName());
                }
            }
            // choose always the description in the default locale
            if (translation.isPresent()) {
                if (translation.get().hasDescription()) {
                    feature.setDescription(translation.get().getDescription());
                } else {
                    feature.setDescription(entity.getDescription());
                }
            } else {
                feature.setDescription(entity.getDescription());
            }
        }
    } else {
        feature.addName(entity.getName());
        feature.setDescription(entity.getDescription());
    }
}
Also used : Describable(org.n52.series.db.beans.Describable) CodeType(org.n52.shetland.ogc.gml.CodeType) I18nEntity(org.n52.series.db.beans.i18n.I18nEntity)

Aggregations

Describable (org.n52.series.db.beans.Describable)3 I18nEntity (org.n52.series.db.beans.i18n.I18nEntity)3 LinkedHashSet (java.util.LinkedHashSet)2 Locale (java.util.Locale)1 LocalizedString (org.n52.janmayen.i18n.LocalizedString)1 MultilingualString (org.n52.janmayen.i18n.MultilingualString)1 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)1 UnitEntity (org.n52.series.db.beans.UnitEntity)1 I18nPhenomenonEntity (org.n52.series.db.beans.i18n.I18nPhenomenonEntity)1 I18nUnitEntity (org.n52.series.db.beans.i18n.I18nUnitEntity)1 CodeType (org.n52.shetland.ogc.gml.CodeType)1