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;
}
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;
}
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);
}
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());
}
}
Aggregations