Search in sources :

Example 6 with LocalizedValue

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();
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 7 with LocalizedValue

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;
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) LocalizedValueStore(com.runwaysdk.localization.LocalizedValueStore) Date(java.util.Date)

Example 8 with LocalizedValue

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();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 9 with LocalizedValue

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"));
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) Universal(com.runwaysdk.system.gis.geo.Universal) Date(java.util.Date) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeLocalInfo(com.runwaysdk.constants.MdAttributeLocalInfo) ServiceFactory(net.geoprism.registry.service.ServiceFactory) MetadataDAO(com.runwaysdk.dataaccess.metadata.MetadataDAO) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) Locale(java.util.Locale) Organization(net.geoprism.registry.Organization) Map(java.util.Map) AttributeLocal(com.runwaysdk.dataaccess.attributes.entity.AttributeLocal) LocalStruct(com.runwaysdk.business.LocalStruct) DateFormat(java.text.DateFormat) Term(org.commongeoregistry.adapter.Term) GraphObjectDAO(com.runwaysdk.dataaccess.graph.GraphObjectDAO) GeoRegistryUtil(net.geoprism.registry.GeoRegistryUtil) Set(java.util.Set) Roles(com.runwaysdk.system.Roles) BusinessFacade(com.runwaysdk.business.BusinessFacade) ZoneId(java.time.ZoneId) List(java.util.List) GraphObject(com.runwaysdk.business.graph.GraphObject) Business(com.runwaysdk.business.Business) LocalDate(java.time.LocalDate) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) Optional(java.util.Optional) Session(com.runwaysdk.session.Session) GraphObject(com.runwaysdk.business.graph.GraphObject) LocalDate(java.time.LocalDate) Map(java.util.Map)

Example 10 with LocalizedValue

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;
}
Also used : Locale(java.util.Locale) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue)

Aggregations

LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)133 Request (com.runwaysdk.session.Request)54 Test (org.junit.Test)52 JsonObject (com.google.gson.JsonObject)27 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)22 TransitionEvent (net.geoprism.registry.graph.transition.TransitionEvent)17 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)16 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)16 Term (org.commongeoregistry.adapter.Term)15 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)15 Date (java.util.Date)13 Locale (java.util.Locale)13 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)13 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)13 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)11 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)11 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)10 JsonArray (com.google.gson.JsonArray)9 Classification (net.geoprism.registry.model.Classification)9 VertexObject (com.runwaysdk.business.graph.VertexObject)7