Search in sources :

Example 26 with LocalizedValue

use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.

the class VertexServerGeoObject method populate.

@SuppressWarnings("unchecked")
@Override
public void populate(GeoObjectOverTime goTime) {
    Map<String, AttributeType> attributes = goTime.getType().getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.INVALID.getName()) || attributeName.equals(DefaultAttribute.CODE.getName()) || attributeName.equals(DefaultAttribute.UID.getName()) || attributeName.equals(GeoVertex.LASTUPDATEDATE) || attributeName.equals(GeoVertex.CREATEDATE)) {
        // Ignore the attributes
        } else // }
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            this.getValuesOverTime(attributeName).clear();
            for (ValueOverTimeDTO votDTO : goTime.getAllValues(attributeName)) {
                LocalizedValue label = (LocalizedValue) votDTO.getValue();
                this.setDisplayLabel(label, votDTO.getStartDate(), votDTO.getEndDate());
            }
        } else if (this.vertex.hasAttribute(attributeName) && !this.vertex.getMdAttributeDAO(attributeName).isSystem()) {
            this.getValuesOverTime(attributeName).clear();
            ValueOverTimeCollectionDTO collection = goTime.getAllValues(attributeName);
            for (ValueOverTimeDTO votDTO : collection) {
                if (attribute instanceof AttributeTermType) {
                    Iterator<String> it = (Iterator<String>) votDTO.getValue();
                    if (it.hasNext()) {
                        String code = it.next();
                        Term root = ((AttributeTermType) attribute).getRootTerm();
                        String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                        String classifierKey = Classifier.buildKey(parent, code);
                        Classifier classifier = Classifier.getByKey(classifierKey);
                        this.vertex.setValue(attributeName, classifier.getOid(), votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, votDTO.getStartDate(), votDTO.getEndDate());
                    }
                } else if (attribute instanceof AttributeClassificationType) {
                    String value = (String) votDTO.getValue();
                    if (value != null) {
                        Classification classification = Classification.get((AttributeClassificationType) attribute, value);
                        this.vertex.setValue(attributeName, classification.getVertex(), votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, this.date, this.date);
                    }
                } else {
                    Object value = votDTO.getValue();
                    if (value != null) {
                        this.vertex.setValue(attributeName, value, votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, votDTO.getStartDate(), votDTO.getEndDate());
                    }
                }
            }
        }
    });
    this.getValuesOverTime(this.getGeometryAttributeName()).clear();
    for (ValueOverTimeDTO votDTO : goTime.getAllValues(DefaultAttribute.GEOMETRY.getName())) {
        Geometry geom = goTime.getGeometry(votDTO.getStartDate());
        this.setGeometry(geom, votDTO.getStartDate(), votDTO.getEndDate());
    }
    this.setUid(goTime.getUid());
    this.setCode(goTime.getCode());
    this.setInvalid(goTime.getInvalid());
}
Also used : ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Geometry(com.vividsolutions.jts.geom.Geometry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) Iterator(java.util.Iterator) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 27 with LocalizedValue

use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.

the class AccountService method addRolesForOrganization.

private void addRolesForOrganization(List<RegistryRole> registryRoleList, Organization organization) {
    LocalizedValue orgDisplayLabel = LocalizedValueConverter.convert(organization.getDisplayLabel());
    // Add the RA role
    Roles adminRole = organization.getRegistryAdminiRole();
    RegistryRole adminRegistryRole = new RegistryRoleConverter().build(adminRole);
    adminRegistryRole.setOrganizationLabel(orgDisplayLabel);
    registryRoleList.add(adminRegistryRole);
    Map<String, ServerGeoObjectType> geoObjectTypeInfo = organization.getGeoObjectTypes();
    for (String typeCode : geoObjectTypeInfo.keySet()) {
        ServerGeoObjectType type = geoObjectTypeInfo.get(typeCode);
        // The cannot be assigned directly to the child type.
        if (type.getSuperType() == null) {
            // Add the RM role
            String rmRoleName = RegistryRole.Type.getRM_RoleName(organization.getCode(), typeCode);
            Roles rmRole = Roles.findRoleByName(rmRoleName);
            RegistryRole rmRegistryRole = new RegistryRoleConverter().build(rmRole);
            rmRegistryRole.setOrganizationLabel(orgDisplayLabel);
            LocalizedValue label = type.getLabel();
            rmRegistryRole.setGeoObjectTypeLabel(label);
            registryRoleList.add(rmRegistryRole);
            // Add the RC role
            String rcRoleName = RegistryRole.Type.getRC_RoleName(organization.getCode(), typeCode);
            Roles rcRole = Roles.findRoleByName(rcRoleName);
            RegistryRole rcRegistryRole = new RegistryRoleConverter().build(rcRole);
            rcRegistryRole.setOrganizationLabel(orgDisplayLabel);
            rcRegistryRole.setGeoObjectTypeLabel(label);
            registryRoleList.add(rcRegistryRole);
            // Add the AC role
            String acRoleName = RegistryRole.Type.getAC_RoleName(organization.getCode(), typeCode);
            Roles acRole = Roles.findRoleByName(acRoleName);
            RegistryRole acRegistryRole = new RegistryRoleConverter().build(acRole);
            acRegistryRole.setOrganizationLabel(orgDisplayLabel);
            acRegistryRole.setGeoObjectTypeLabel(label);
            registryRoleList.add(acRegistryRole);
        }
    }
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Roles(com.runwaysdk.system.Roles)

Example 28 with LocalizedValue

use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.

the class RegistryService method updateTerm.

/**
 * Creates a new {@link Term} object and makes it a child of the term with the
 * given code.
 *
 * @param sessionId
 * @param parentTermCode
 *          TODO
 * @param termJSON
 *          JSON of the term object.
 * @return Updated {@link Term} object.
 */
@Request(RequestType.SESSION)
public Term updateTerm(String sessionId, String parentTermCode, String termJSON) {
    JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
    String termCode = termJSONobj.get(Term.JSON_CODE).getAsString();
    LocalizedValue value = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
    Classifier classifier = TermConverter.updateClassifier(parentTermCode, termCode, value);
    TermConverter termBuilder = new TermConverter(classifier.getKeyName());
    Term returnTerm = termBuilder.build();
    List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
    this.refreshAttributeTermTypeInCache(mdAttrList);
    return returnTerm;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonObject(com.google.gson.JsonObject) Classifier(net.geoprism.ontology.Classifier) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) TermConverter(net.geoprism.registry.conversion.TermConverter) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 29 with LocalizedValue

use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.

the class SynchronizationConfigService method edit.

@Request(RequestType.SESSION)
public JsonObject edit(String sessionId, String oid) {
    JsonObject response = new JsonObject();
    if (oid != null && oid.length() > 0) {
        SynchronizationConfig config = SynchronizationConfig.lock(oid);
        response.add("config", config.toJSON());
    }
    JsonArray orgs = new JsonArray();
    List<Organization> organizations = Organization.getUserAdminOrganizations();
    for (Organization organization : organizations) {
        JsonArray hierarchies = new JsonArray();
        List<ServerHierarchyType> sHierachies = ServerHierarchyType.getForOrganization(organization);
        for (ServerHierarchyType hierarchy : sHierachies) {
            JsonObject object = new JsonObject();
            object.addProperty("label", hierarchy.getDisplayLabel().getValue());
            object.addProperty("code", hierarchy.getCode());
            hierarchies.add(object);
        }
        JsonArray systems = new JsonArray();
        List<ExternalSystem> esystems = ExternalSystem.getForOrganization(organization);
        for (ExternalSystem system : esystems) {
            if (system.isExportSupported()) {
                LocalizedValue label = LocalizedValueConverter.convert(system.getEmbeddedComponent(ExternalSystem.LABEL));
                JsonObject object = new JsonObject();
                object.addProperty("label", label.getValue());
                object.addProperty("oid", system.getOid());
                object.addProperty("type", system.getMdClass().getTypeName());
                systems.add(object);
            }
        }
        JsonObject object = new JsonObject();
        object.addProperty("label", organization.getDisplayLabel().getValue());
        object.addProperty("code", organization.getCode());
        object.add("hierarchies", hierarchies);
        object.add("systems", systems);
        orgs.add(object);
    }
    response.add("orgs", orgs);
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

Example 30 with LocalizedValue

use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.

the class GeoObjectAtTimeShapefileExporter method features.

public FeatureCollection<SimpleFeatureType, SimpleFeature> features(SimpleFeatureType featureType) {
    final int BLOCK_SIZE = 2000;
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    VertexServerGeoObject prev = null;
    do {
        final VertexSelectGeoObjectQuery query = new VertexSelectGeoObjectQuery(type, this.date, prev);
        query.setLimit(BLOCK_SIZE);
        final List<VertexServerGeoObject> objects = query.getResults();
        prev = null;
        for (VertexServerGeoObject object : objects) {
            if (!object.getInvalid()) {
                builder.set(GEOM, object.getGeometry());
                this.attributes.forEach(attribute -> {
                    String name = attribute.getName();
                    String columnName = this.getColumnName(name);
                    Object value = attribute.isChangeOverTime() ? object.getValue(name, this.date) : object.getValue(name);
                    if (attribute instanceof AttributeTermType) {
                        builder.set(columnName, GeoObjectUtil.convertToTermString((AttributeTermType) attribute, value));
                    } else if (attribute instanceof AttributeClassificationType) {
                        builder.set(columnName, GeoObjectUtil.convertToTermString((AttributeClassificationType) attribute, value));
                    } else if (attribute instanceof AttributeLocalType) {
                        builder.set(columnName, ((LocalizedValue) value).getValue());
                    } else {
                        builder.set(columnName, value);
                    }
                });
                AttributeType attribute = this.getType().getAttribute(DefaultAttribute.DISPLAY_LABEL.getName()).get();
                LocalizedValue label = object.getDisplayLabel(this.date);
                builder.set(this.getColumnName(attribute.getName() + " " + MdAttributeLocalInfo.DEFAULT_LOCALE), label.getValue(LocalizedValue.DEFAULT_LOCALE));
                for (Locale locale : locales) {
                    builder.set(this.getColumnName(attribute.getName() + " " + locale.toString()), label.getValue(locale));
                }
                SimpleFeature feature = builder.buildFeature(object.getCode());
                features.add(feature);
            }
            prev = object;
            Thread.yield();
        }
    } while (prev != null);
    return new ListFeatureCollection(featureType, features);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) VertexSelectGeoObjectQuery(net.geoprism.registry.query.graph.VertexSelectGeoObjectQuery) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

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