Search in sources :

Example 11 with AttributeType

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

the class GeoObjectImporter method validateRow.

@Transaction
public void validateRow(FeatureRow row) throws InterruptedException {
    try {
        // Refresh the session because it might expire on long imports
        final long curWorkProgress = this.progressListener.getWorkProgress();
        if ((this.lastValidateSessionRefresh + GeoObjectImporter.refreshSessionRecordCount) < curWorkProgress) {
            SessionFacade.renewSession(Session.getCurrentSession().getOid());
            this.lastValidateSessionRefresh = curWorkProgress;
        }
        try {
            /*
         * 1. Check for location problems
         */
            if (this.configuration.isPostalCode() && PostalCodeFactory.isAvailable(this.configuration.getType())) {
            // Skip location synonym check
            } else if (this.configuration.getHierarchy() != null && this.configuration.getLocations().size() > 0) {
                this.getParent(row);
            }
            /*
         * 2. Check for serialization and term problems
         */
            String code = this.getCode(row);
            ServerGeoObjectIF entity;
            if (code == null || code.length() <= 0) {
                RequiredMappingException ex = new RequiredMappingException();
                ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
                throw ex;
            }
            entity = service.newInstance(this.configuration.getType());
            entity.setCode(code);
            entity.setInvalid(false);
            try {
                LocalizedValue entityName = this.getName(row);
                if (entityName != null && this.hasValue(entityName)) {
                    entity.setDisplayLabel(entityName, this.configuration.getStartDate(), this.configuration.getEndDate());
                }
                Geometry geometry = (Geometry) this.getFormatSpecificImporter().getGeometry(row);
                if (geometry != null) {
                    // geometry.getSRID().
                    if (geometry.isValid()) {
                        entity.setGeometry(geometry, this.configuration.getStartDate(), this.configuration.getEndDate());
                    } else {
                        InvalidGeometryException geomEx = new InvalidGeometryException();
                        throw geomEx;
                    }
                }
                Map<String, AttributeType> attributes = this.configuration.getType().getAttributeMap();
                Set<Entry<String, AttributeType>> entries = attributes.entrySet();
                for (Entry<String, AttributeType> entry : entries) {
                    String attributeName = entry.getKey();
                    if (!attributeName.equals(GeoObject.CODE)) {
                        ShapefileFunction function = this.configuration.getFunction(attributeName);
                        if (function != null) {
                            Object value = function.getValue(row);
                            if (value != null && !this.isEmptyString(value)) {
                                AttributeType attributeType = entry.getValue();
                                this.setValue(entity, attributeType, attributeName, value);
                            }
                        }
                    }
                }
                GeoObjectOverTime go = entity.toGeoObjectOverTime(false);
                go.toJSON().toString();
                if (this.configuration.isExternalImport()) {
                    ShapefileFunction function = this.configuration.getExternalIdFunction();
                    Object value = function.getValue(row);
                    if (value == null || !(value instanceof String || value instanceof Integer || value instanceof Long) || (value instanceof String && ((String) value).length() == 0)) {
                        throw new InvalidExternalIdException();
                    }
                }
            } finally {
                entity.unlock();
            }
        } catch (IgnoreRowException e) {
        // Do nothing
        } catch (Throwable t) {
            RowValidationProblem problem = new RowValidationProblem(t);
            problem.addAffectedRowNumber(curWorkProgress + 1);
            problem.setHistoryId(this.configuration.historyId);
            this.progressListener.addRowValidationProblem(problem);
        }
        this.progressListener.setWorkProgress(curWorkProgress + 1);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Thread.yield();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : InvalidExternalIdException(net.geoprism.registry.etl.InvalidExternalIdException) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) IgnoreRowException(net.geoprism.registry.io.IgnoreRowException) Geometry(com.vividsolutions.jts.geom.Geometry) Entry(java.util.Map.Entry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) RequiredMappingException(net.geoprism.registry.io.RequiredMappingException) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) RowValidationProblem(net.geoprism.registry.etl.RowValidationProblem) InvalidGeometryException(net.geoprism.registry.io.InvalidGeometryException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 12 with AttributeType

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

the class GeoObjectExcelExporter method createWorkbook.

public Workbook createWorkbook() throws IOException {
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(this.type.getLabel().getValue()));
    CreationHelper createHelper = workbook.getCreationHelper();
    Font font = workbook.createFont();
    font.setBold(true);
    CellStyle boldStyle = workbook.createCellStyle();
    boldStyle.setFont(font);
    CellStyle dateStyle = workbook.createCellStyle();
    dateStyle.setDataFormat(createHelper.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(14)));
    Row header = sheet.createRow(0);
    boolean includeCoordinates = this.type.getGeometryType().equals(GeometryType.POINT) || this.type.getGeometryType().equals(GeometryType.MIXED);
    Collection<AttributeType> attributes = new ImportAttributeSerializer(Session.getCurrentLocale(), includeCoordinates, true, locales).attributes(this.type.getType());
    // Get the ancestors of the type
    List<GeoObjectType> dtoAncestors = this.type.getTypeAncestors(this.hierarchy, true);
    List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
    for (GeoObjectType ancestor : dtoAncestors) {
        ancestors.add(ServerGeoObjectType.get(ancestor));
    }
    this.writeHeader(boldStyle, header, attributes, ancestors);
    for (int i = 0; i < this.objects.size(); i++) {
        ServerGeoObjectIF object = this.objects.get(i);
        Row row = sheet.createRow(i + 1);
        this.writeRow(row, object, attributes, ancestors, dateStyle);
    }
    return workbook;
}
Also used : ImportAttributeSerializer(net.geoprism.registry.io.ImportAttributeSerializer) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Font(org.apache.poi.ss.usermodel.Font) LinkedList(java.util.LinkedList) Point(com.vividsolutions.jts.geom.Point) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 13 with AttributeType

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

the class ServerGeoObjectType method createAttributeType.

public AttributeType createAttributeType(String attributeTypeJSON) {
    JsonObject attrObj = JsonParser.parseString(attributeTypeJSON).getAsJsonObject();
    AttributeType attrType = AttributeType.parse(attrObj);
    return createAttributeType(attrType);
}
Also used : AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) JsonObject(com.google.gson.JsonObject)

Example 14 with AttributeType

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

the class ServerGeoObjectType method deleteMdAttributeFromAttributeType.

/**
 * Delete the {@link MdAttributeConcreteDAOIF} from the given {
 *
 * @param type
 *          TODO
 * @param mdBusiness
 * @param attributeName
 */
@Transaction
public void deleteMdAttributeFromAttributeType(String attributeName) {
    MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(this.mdBusiness, attributeName);
    if (mdAttributeConcreteDAOIF != null) {
        if (mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF || mdAttributeConcreteDAOIF instanceof MdAttributeMultiTermDAOIF) {
            String attributeTermKey = TermConverter.buildtAtttributeKey(this.mdBusiness.getTypeName(), mdAttributeConcreteDAOIF.definesAttribute());
            try {
                Classifier attributeTerm = Classifier.getByKey(attributeTermKey);
                attributeTerm.delete();
            } catch (DataNotFoundException e) {
            }
        }
        mdAttributeConcreteDAOIF.getBusinessDAO().delete();
        Optional<AttributeType> optional = this.type.getAttribute(attributeName);
        if (optional.isPresent()) {
            ListType.deleteMdAttribute(this.universal, optional.get());
        }
    }
    MdAttributeDAOIF mdAttributeDAO = this.mdVertex.definesAttribute(attributeName);
    if (mdAttributeDAO != null) {
        mdAttributeDAO.getBusinessDAO().delete();
    }
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Classifier(net.geoprism.ontology.Classifier) MdAttributeMultiTermDAOIF(com.runwaysdk.dataaccess.MdAttributeMultiTermDAOIF) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 15 with AttributeType

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

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