Search in sources :

Example 16 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class VertexServerGeoObject method buildDefaultExists.

// private void validateCOTAttr(String attrName)
// {
// ValueOverTimeCollection votc = this.vertex.getValuesOverTime(attrName);
// 
// if (votc == null || votc.size() == 0)
// {
// RequiredAttributeException ex = new RequiredAttributeException();
// ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(attrName));
// throw ex;
// }
// else if (votc != null && votc.size() > 0)
// {
// boolean hasValue = false;
// 
// for (int i = 0; i < votc.size(); ++i)
// {
// ValueOverTime vot = votc.get(i);
// 
// if (vot.getValue() != null)
// {
// if (vot.getValue() instanceof String && ((String)vot.getValue()).length() >
// 0)
// {
// hasValue = true;
// break;
// }
// else if (vot.getValue() instanceof Collection)
// {
// Collection<?> val = (Collection<?>) vot.getValue();
// 
// if (val.size() > 0)
// {
// hasValue = true;
// break;
// }
// }
// else
// {
// hasValue = true;
// break;
// }
// }
// }
// 
// if (!hasValue)
// {
// RequiredAttributeException ex = new RequiredAttributeException();
// ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(attrName));
// throw ex;
// }
// }
// }
public ValueOverTime buildDefaultExists() {
    if (this.getValuesOverTime(DefaultAttribute.EXISTS.getName()).size() != 0) {
        return null;
    }
    Collection<AttributeType> attributes = type.getAttributeMap().values();
    String[] shouldNotProcessArray = new String[] { DefaultAttribute.UID.getName(), DefaultAttribute.SEQUENCE.getName(), DefaultAttribute.LAST_UPDATE_DATE.getName(), DefaultAttribute.CREATE_DATE.getName(), DefaultAttribute.TYPE.getName(), DefaultAttribute.EXISTS.getName() };
    Date startDate = null;
    Date endDate = null;
    for (AttributeType attribute : attributes) {
        boolean shouldProcess = !ArrayUtils.contains(shouldNotProcessArray, attribute.getName());
        if (shouldProcess && attribute.isChangeOverTime()) {
            ValueOverTimeCollection votc = this.getValuesOverTime(attribute.getName());
            for (ValueOverTime vot : votc) {
                if (startDate == null || startDate.after(vot.getStartDate())) {
                    startDate = vot.getStartDate();
                }
                if (endDate == null || endDate.before(vot.getEndDate())) {
                    endDate = vot.getEndDate();
                }
            }
        }
    }
    if (startDate != null && endDate != null) {
        return new ValueOverTime(startDate, endDate, Boolean.TRUE);
    } else {
        return null;
    }
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 17 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class RegistryService method updateAttributeType.

/**
 * Updates an attribute in the given {@link GeoObjectType}.
 *
 * @pre given {@link GeoObjectType} must already exist.
 *
 * @param sessionId
 * @param geoObjectTypeCode
 *          string of the {@link GeoObjectType} to be updated.
 * @param attributeTypeJSON
 *          AttributeType to be added to the GeoObjectType
 * @return updated {@link AttributeType}
 */
@Request(RequestType.SESSION)
public AttributeType updateAttributeType(String sessionId, String geoObjectTypeCode, String attributeTypeJSON) {
    ServerGeoObjectType got = ServerGeoObjectType.get(geoObjectTypeCode);
    ServiceFactory.getGeoObjectTypePermissionService().enforceCanWrite(got.getOrganization().getCode(), got, got.getIsPrivate());
    AttributeType attrType = got.updateAttributeType(attributeTypeJSON);
    return attrType;
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 18 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class RegistryService method createAttributeType.

/**
 * Adds an attribute to the given {@link GeoObjectType}.
 *
 * @pre given {@link GeoObjectType} must already exist.
 *
 * @param sessionId
 *
 * @param geoObjectTypeCode
 *          string of the {@link GeoObjectType} to be updated.
 * @param attributeTypeJSON
 *          AttributeType to be added to the GeoObjectType
 * @return updated {@link GeoObjectType}
 */
@Request(RequestType.SESSION)
public AttributeType createAttributeType(String sessionId, String geoObjectTypeCode, String attributeTypeJSON) {
    ServerGeoObjectType got = ServerGeoObjectType.get(geoObjectTypeCode);
    ServiceFactory.getGeoObjectTypePermissionService().enforceCanWrite(got.getOrganization().getCode(), got, got.getIsPrivate());
    AttributeType attrType = got.createAttributeType(attributeTypeJSON);
    return attrType;
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 19 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType 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)

Example 20 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class UpdateValueOverTimeView method persistValue.

private void persistValue(ValueOverTime vot, UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, List<ValueOverTime> looseVotc) {
    if (this.newValue == null) {
        return;
    }
    if (cotView.getAttributeName().equals("geometry")) {
        Geometry convertedValue = null;
        if (!this.newValue.isJsonNull()) {
            GeoJSONReader reader = new GeoJSONReader();
            convertedValue = reader.read(this.newValue.toString());
            if (!go.isValidGeometry(convertedValue)) {
                GeometryTypeException ex = new GeometryTypeException();
                ex.setActualType(convertedValue.getGeometryType());
                ex.setExpectedType(go.getType().getGeometryType().name());
                throw ex;
            }
        }
        if (vot != null) {
            vot.setValue(convertedValue);
        } else {
            looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, convertedValue));
        }
    } else {
        ServerGeoObjectType type = go.getType();
        AttributeType attype = type.getAttribute(cotView.getAttributeName()).get();
        if (attype instanceof AttributeLocalType) {
            LocalizedValue convertedValue = null;
            if (!this.newValue.isJsonNull()) {
                convertedValue = LocalizedValue.fromJSON(this.newValue.getAsJsonObject());
            }
            final Set<Locale> locales = LocalizationFacade.getInstalledLocales();
            if (vot != null) {
                if (convertedValue != null) {
                    GraphObjectDAO votEmbeddedValue = (GraphObjectDAO) vot.getValue();
                    votEmbeddedValue.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, convertedValue.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
                    for (Locale locale : locales) {
                        if (convertedValue.contains(locale)) {
                            votEmbeddedValue.setValue(locale.toString(), convertedValue.getValue(locale));
                        }
                    }
                } else {
                    vot.setValue(null);
                }
            } else {
                if (convertedValue != null) {
                    MdAttributeEmbeddedDAOIF mdAttrEmbedded = (MdAttributeEmbeddedDAOIF) go.getMdAttributeDAO(attype.getName());
                    VertexObjectDAO votEmbeddedValue = VertexObjectDAO.newInstance((MdVertexDAOIF) mdAttrEmbedded.getEmbeddedMdClassDAOIF());
                    votEmbeddedValue.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, convertedValue.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
                    for (Locale locale : locales) {
                        if (convertedValue.contains(locale)) {
                            votEmbeddedValue.setValue(locale.toString(), convertedValue.getValue(locale));
                        }
                    }
                    looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, votEmbeddedValue));
                } else {
                    looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, null));
                }
            }
        } else // else if (attype.getName().equals(DefaultAttribute.EXISTS.getName()))
        // {
        // if (this.newValue.isJsonNull())
        // {
        // if (vot != null)
        // {
        // vot.setValue(null);
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // null));
        // }
        // }
        // else
        // {
        // JsonArray ja = this.newValue.getAsJsonArray();
        // 
        // if (ja.size() > 0)
        // {
        // String code = ja.get(0).getAsString();
        // 
        // if (code == null || code.length() == 0)
        // {
        // if (vot != null)
        // {
        // vot.setValue(null);
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // null));
        // }
        // }
        // else
        // {
        // Term value = ( (AttributeTermType) attype ).getTermByCode(code).get();
        // GeoObjectStatus gos =
        // ConversionService.getInstance().termToGeoObjectStatus(value);
        // 
        // if (vot != null)
        // {
        // vot.setValue(gos.getOid());
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // gos.getOid()));
        // }
        // }
        // }
        // }
        // }
        {
            Object convertedValue = null;
            if (!this.newValue.isJsonNull()) {
                if (attype instanceof AttributeDateType) {
                    long epoch = this.newValue.getAsLong();
                    convertedValue = new Date(epoch);
                } else if (attype instanceof AttributeTermType) {
                    JsonArray ja = this.newValue.getAsJsonArray();
                    if (ja.size() > 0) {
                        String code = ja.get(0).getAsString();
                        Term root = ((AttributeTermType) attype).getRootTerm();
                        String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                        String classifierKey = Classifier.buildKey(parent, code);
                        Classifier classifier = Classifier.getByKey(classifierKey);
                        convertedValue = classifier.getOid();
                    }
                } else if (attype instanceof AttributeClassificationType) {
                    JsonObject object = this.newValue.getAsJsonObject();
                    String code = object.get("code").getAsString();
                    Classification classification = Classification.get((AttributeClassificationType) attype, code);
                    convertedValue = new AttributeGraphRef.ID(classification.getOid(), classification.getVertex().getRID());
                } else if (attype instanceof AttributeBooleanType) {
                    convertedValue = this.newValue.getAsBoolean();
                } else if (attype instanceof AttributeFloatType) {
                    convertedValue = this.newValue.getAsDouble();
                } else if (attype instanceof AttributeIntegerType) {
                    convertedValue = this.newValue.getAsLong();
                } else {
                    convertedValue = this.newValue.getAsString();
                }
            }
            if (vot != null) {
                vot.setValue(convertedValue);
            } else {
                looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, convertedValue));
            }
        }
    }
}
Also used : Locale(java.util.Locale) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) JsonObject(com.google.gson.JsonObject) Classifier(net.geoprism.ontology.Classifier) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeGraphRef(com.runwaysdk.dataaccess.graph.attributes.AttributeGraphRef) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributeEmbeddedDAOIF(com.runwaysdk.dataaccess.MdAttributeEmbeddedDAOIF) GeometryTypeException(net.geoprism.registry.GeometryTypeException) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Date(java.util.Date) Geometry(com.vividsolutions.jts.geom.Geometry) JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) GraphObjectDAO(com.runwaysdk.dataaccess.graph.GraphObjectDAO) VertexObjectDAO(com.runwaysdk.dataaccess.graph.VertexObjectDAO) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Aggregations

AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)55 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)18 Locale (java.util.Locale)17 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)17 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)16 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)15 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)11 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)11 LinkedList (java.util.LinkedList)10 Classifier (net.geoprism.ontology.Classifier)10 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 Request (com.runwaysdk.session.Request)9 List (java.util.List)9 Test (org.junit.Test)9 JsonArray (com.google.gson.JsonArray)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8