use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class UndirectedGraphType method update.
@Transaction
public void update(JsonObject object) {
try {
this.appLock();
if (object.has(UndirectedGraphType.JSON_LABEL)) {
LocalizedValue label = LocalizedValue.fromJSON(object.getAsJsonObject(UndirectedGraphType.JSON_LABEL));
LocalizedValueConverter.populate(this.getDisplayLabel(), label);
}
if (object.has(UndirectedGraphType.DESCRIPTION)) {
LocalizedValue description = LocalizedValue.fromJSON(object.getAsJsonObject(UndirectedGraphType.DESCRIPTION));
LocalizedValueConverter.populate(this.getDescription(), description);
}
this.apply();
} finally {
this.unlock();
}
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class ChangeRequest method getGeoObjectDisplayLabel.
public LocalizedValue getGeoObjectDisplayLabel() {
if (this.getChangeRequestType().equals(ChangeRequestType.CreateGeoObject)) {
try {
GeoObjectOverTime goTime = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), ((CreateGeoObjectAction) this.getAllAction().next()).getGeoObjectJson());
// Quick little hack to localize a value when it's not in a database or part of a Runway object.
LocalizedValueStore lvs = new LocalizedValueStore();
lvs.getStoreValue().setLocaleMap(goTime.getDisplayLabel(new Date()).getLocaleMap());
return LocalizedValueConverter.convertNoAutoCoalesce(lvs.getStoreValue());
} catch (Exception e) {
logger.error("Error occurred while getting localized label from GeoObject with code [" + this.getGeoObjectCode() + "].", e);
}
} else {
ServerGeoObjectIF serverGO = new ServerGeoObjectService().getGeoObjectByCode(this.getGeoObjectCode(), this.getGeoObjectTypeCode(), false);
if (serverGO != null) {
return serverGO.getDisplayLabel();
}
}
LocalizedValue lv = new LocalizedValue(this.getGeoObjectCode());
lv.setValue(LocalizedValue.DEFAULT_LOCALE, this.getGeoObjectCode());
return lv;
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class ChangeRequestSortingPatch method doIt.
@Transaction
private void doIt() {
ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
OIterator<? extends ChangeRequest> it = crq.getIterator();
for (ChangeRequest cr : it) {
LocalizedValue goLabel = cr.getGeoObjectDisplayLabel();
ServerGeoObjectType type = cr.getGeoObjectType();
cr.appLock();
cr.getGeoObjectLabel().setLocaleMap(goLabel.getLocaleMap());
cr.getGeoObjectTypeLabel().setLocaleMap(type.getLabel().getLocaleMap());
cr.apply();
}
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class LocalizedValueConverter method convert.
@SuppressWarnings("unchecked")
public static LocalizedValue convert(List<Map<String, Object>> labels, Date date) {
if (date != null) {
LocalDate localDate = date.toInstant().atZone(ZoneId.of("Z")).toLocalDate();
Optional<Map<String, Object>> result = labels.stream().filter(o -> {
LocalDate startDate = ((Date) o.get("startDate")).toInstant().atZone(ZoneId.of("Z")).toLocalDate();
LocalDate endDate = ((Date) o.get("endDate")).toInstant().atZone(ZoneId.of("Z")).toLocalDate();
return (startDate.equals(localDate) || startDate.isBefore(localDate)) && (endDate.equals(localDate) || endDate.isAfter(localDate));
}).findAny();
return LocalizedValueConverter.convert((Map<String, Object>) result.orElseGet(() -> labels.get(labels.size() - 1)).get("value"));
}
return LocalizedValueConverter.convert((Map<String, Object>) labels.get(labels.size() - 1).get("value"));
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class LocalizedValueConverter method convert.
/**
* This method will coalesce the value for all of the locales. So if
* the value is empty for a particular locale, that locale will actually have
* the default locale placed in it. For this reason, usage of this method
* should be deprecated.
*
* Use convertNoAutoCoalesce instead.
*/
@Deprecated
public static LocalizedValue convert(LocalStruct localStruct) {
LocalizedValue label = new LocalizedValue(localStruct.getValue());
label.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, localStruct.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
Set<Locale> locales = LocalizationFacade.getInstalledLocales();
for (Locale locale : locales) {
label.setValue(locale, localStruct.getValue(locale));
}
return label;
}
Aggregations