Search in sources :

Example 16 with GeoObjectOverTime

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

the class UpdateGeoObjectAction method apply.

@Override
public void apply() {
    String sJson = this.getGeoObjectJson();
    GeoObjectOverTime geoObject = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), sJson);
    ServerGeoObjectType type = ServerGeoObjectType.get(geoObject.getType());
    geoObjectPermissionService.enforceCanWriteCR(type.getOrganization().getCode(), type);
    super.apply();
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)

Example 17 with GeoObjectOverTime

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

the class UpdateGeoObjectAction method execute.

@Override
public void execute() {
    String sJson = this.getGeoObjectJson();
    GeoObjectOverTime goTime = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), sJson);
    ServerGeoObjectService builder = new ServerGeoObjectService();
    builder.apply(goTime, false, false);
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)

Example 18 with GeoObjectOverTime

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

the class RegistryController method getGeoObjectOverTimeByCode.

@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_TIME_GET_CODE)
public ResponseIF getGeoObjectOverTimeByCode(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TIME_GET_CODE_PARAM_CODE) String code, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TIME_GET_CODE_PARAM_TYPE_CODE) String typeCode) throws JSONException {
    GeoObjectOverTime geoObject = this.registryService.getGeoObjectOverTimeByCode(request.getSessionId(), code, typeCode);
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    return new RestBodyResponse(geoObject.toJSON(serializer));
}
Also used : GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 19 with GeoObjectOverTime

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

the class GeoObjectImporter method importRowInTrans.

@Transaction
public void importRowInTrans(FeatureRow row, RowData data) {
    // Refresh the session because it might expire on long imports
    final long curWorkProgress = this.progressListener.getWorkProgress();
    if ((this.lastImportSessionRefresh + GeoObjectImporter.refreshSessionRecordCount) < curWorkProgress) {
        SessionFacade.renewSession(Session.getCurrentSession().getOid());
        this.lastImportSessionRefresh = curWorkProgress;
    }
    GeoObjectOverTime go = null;
    String goJson = null;
    ServerGeoObjectIF serverGo = null;
    ServerGeoObjectIF parent = null;
    boolean isNew = false;
    GeoObjectParentErrorBuilder parentBuilder = new GeoObjectParentErrorBuilder();
    try {
        String code = this.getCode(row);
        if (code == null || code.length() <= 0) {
            RequiredMappingException ex = new RequiredMappingException();
            ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
            throw ex;
        }
        if (this.configuration.getImportStrategy().equals(ImportStrategy.UPDATE_ONLY) || this.configuration.getImportStrategy().equals(ImportStrategy.NEW_AND_UPDATE)) {
            serverGo = service.getGeoObjectByCode(code, this.configuration.getType(), false);
        }
        if (serverGo == null) {
            if (this.configuration.getImportStrategy().equals(ImportStrategy.UPDATE_ONLY)) {
                net.geoprism.registry.DataNotFoundException ex = new net.geoprism.registry.DataNotFoundException();
                ex.setTypeLabel(GeoObjectMetadata.get().getClassDisplayLabel());
                ex.setDataIdentifier(code);
                ex.setAttributeLabel(GeoObjectMetadata.get().getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
                throw ex;
            }
            isNew = true;
            serverGo = service.newInstance(this.configuration.getType());
            serverGo.setCode(code);
            serverGo.setInvalid(false);
        } else {
            serverGo.lock();
        }
        try {
            LocalizedValue entityName = this.getName(row);
            if (entityName != null && this.hasValue(entityName)) {
                serverGo.setDisplayLabel(entityName, this.configuration.getStartDate(), this.configuration.getEndDate());
            }
            Geometry geometry = (Geometry) this.getFormatSpecificImporter().getGeometry(row);
            if (geometry != null) {
                // geometry.getSRID().
                if (geometry.isValid()) {
                    serverGo.setGeometry(geometry, this.configuration.getStartDate(), this.configuration.getEndDate());
                } else {
                    // throw new SridException();
                    throw new InvalidGeometryException();
                }
            }
            if (isNew) {
                serverGo.setUid(ServiceFactory.getIdService().getUids(1)[0]);
            }
            // Set exists first so we can validate attributes on it
            // ShapefileFunction existsFunction = this.configuration.getFunction(DefaultAttribute.EXISTS.getName());
            // 
            // if (existsFunction != null)
            // {
            // Object value = existsFunction.getValue(row);
            // 
            // if (value != null && !this.isEmptyString(value))
            // {
            // this.setValue(serverGo, this.configuration.getType().getAttribute(DefaultAttribute.EXISTS.getName()).get(), DefaultAttribute.EXISTS.getName(), value);
            // }
            // }
            // else if (isNew)
            // {
            // ValueOverTime defaultExists = ((VertexServerGeoObject) serverGo).buildDefaultExists();
            // if (defaultExists != null)
            // {
            // serverGo.setValue(DefaultAttribute.EXISTS.getName(), Boolean.TRUE, defaultExists.getStartDate(), defaultExists.getEndDate());
            // }
            // }
            this.setValue(serverGo, this.configuration.getType().getAttribute(DefaultAttribute.EXISTS.getName()).get(), DefaultAttribute.EXISTS.getName(), true);
            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) && !attributeName.equals(DefaultAttribute.EXISTS.getName())) {
                    ShapefileFunction function = this.configuration.getFunction(attributeName);
                    if (function != null) {
                        Object value = function.getValue(row);
                        AttributeType attributeType = entry.getValue();
                        if (value != null && !this.isEmptyString(value)) {
                            // if (!(existsFunction == null && isNew))
                            // {
                            // try
                            // {
                            // ((VertexServerGeoObject) serverGo).enforceAttributeSetWithinRange(serverGo.getDisplayLabel().getValue(), attributeName, this.configuration.getStartDate(), this.configuration.getEndDate());
                            // }
                            // catch (ValueOutOfRangeException e)
                            // {
                            // final SimpleDateFormat format = ValueOverTimeDTO.getTimeFormatter();
                            // 
                            // ImportOutOfRangeException ex = new ImportOutOfRangeException();
                            // ex.setStartDate(format.format(this.configuration.getStartDate()));
                            // 
                            // if (ValueOverTime.INFINITY_END_DATE.equals(this.configuration.getEndDate()))
                            // {
                            // ex.setEndDate(LocalizationFacade.localize("changeovertime.present"));
                            // }
                            // else
                            // {
                            // ex.setEndDate(format.format(this.configuration.getEndDate()));
                            // }
                            // 
                            // throw ex;
                            // }
                            // }
                            this.setValue(serverGo, attributeType, attributeName, value);
                        } else if (this.configuration.getCopyBlank()) {
                            this.setValue(serverGo, attributeType, attributeName, null);
                        }
                    }
                }
            }
            go = serverGo.toGeoObjectOverTime(false);
            goJson = go.toJSON().toString();
            /*
         * Try to get the parent and ensure that this row is not ignored. The
         * getParent method will throw a IgnoreRowException if the parent is
         * configured to be ignored.
         */
            if (this.configuration.isPostalCode() && PostalCodeFactory.isAvailable(this.configuration.getType())) {
                parent = this.parsePostalCode(row);
            } else if (this.configuration.getHierarchy() != null && this.configuration.getLocations().size() > 0) {
                parent = this.getParent(row);
            }
            parentBuilder.setParent(parent);
            if (this.progressListener.hasValidationProblems()) {
                throw new RuntimeException("Did not expect to encounter validation problems during import.");
            }
            data.setGoJson(goJson);
            data.setNew(isNew);
            data.setParentBuilder(parentBuilder);
            serverGo.apply(true);
        } finally {
            if (serverGo != null) {
                serverGo.unlock();
            }
        }
        if (this.configuration.isExternalImport()) {
            ShapefileFunction function = this.configuration.getExternalIdFunction();
            Object value = function.getValue(row);
            serverGo.createExternalId(this.configuration.getExternalSystem(), String.valueOf(value), this.configuration.getImportStrategy());
        }
        if (parent != null) {
            parent.addChild(serverGo, this.configuration.getHierarchy(), this.configuration.getStartDate(), this.configuration.getEndDate());
        } else if (isNew) {
        // GeoEntity child = GeoEntity.getByKey(serverGo.getCode());
        // GeoEntity root = GeoEntity.getByKey(GeoEntity.ROOT);
        // 
        // child.addLink(root,
        // this.configuration.getHierarchy().getEntityType());
        }
        // We must ensure that any problems created during the transaction are
        // logged now instead of when the request returns. As such, if any
        // problems exist immediately throw a ProblemException so that normal
        // exception handling can occur.
        List<ProblemIF> problems = RequestState.getProblemsInCurrentRequest();
        List<ProblemIF> problems2 = new LinkedList<ProblemIF>();
        for (ProblemIF problem : problems) {
            problems2.add(problem);
        }
        if (problems.size() != 0) {
            throw new ProblemException(null, problems2);
        }
        this.progressListener.setImportedRecords(this.progressListener.getImportedRecords() + 1);
    } catch (IgnoreRowException e) {
    // Do nothing
    } catch (Throwable t) {
        buildRecordException(goJson, isNew, parentBuilder, t);
    }
    this.progressListener.setWorkProgress(curWorkProgress + 1);
}
Also used : ProblemException(com.runwaysdk.ProblemException) ProblemIF(com.runwaysdk.ProblemIF) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) IgnoreRowException(net.geoprism.registry.io.IgnoreRowException) Entry(java.util.Map.Entry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) InvalidGeometryException(net.geoprism.registry.io.InvalidGeometryException) LinkedList(java.util.LinkedList) Geometry(com.vividsolutions.jts.geom.Geometry) RequiredMappingException(net.geoprism.registry.io.RequiredMappingException) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 20 with GeoObjectOverTime

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

the class VertexServerGeoObject method toGeoObjectOverTime.

public GeoObjectOverTime toGeoObjectOverTime(boolean generateUid) {
    Map<String, ValueOverTimeCollectionDTO> votAttributeMap = GeoObjectOverTime.buildVotAttributeMap(type.getType());
    Map<String, Attribute> attributeMap = GeoObjectOverTime.buildAttributeMap(type.getType());
    GeoObjectOverTime geoObj = new GeoObjectOverTime(type.getType(), votAttributeMap, attributeMap);
    Map<String, AttributeType> attributes = type.getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
            ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
            for (ValueOverTime vot : votc) {
                Object value = this.getDisplayLabel(vot.getStartDate());
                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                votDTO.setValue(value);
                votcDTO.add(votDTO);
            }
            geoObj.setValueCollection(attributeName, votcDTO);
        } else // }
        if (vertex.hasAttribute(attributeName)) {
            if (attribute.isChangeOverTime()) {
                ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
                ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
                for (ValueOverTime vot : votc) {
                    // if (attributeName.equals(DefaultAttribute.STATUS.getName()))
                    // {
                    // Term statusTerm =
                    // ServiceFactory.getConversionService().geoObjectStatusToTerm(this.getStatus(vot.getStartDate()));
                    // 
                    // ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(),
                    // vot.getStartDate(), vot.getEndDate(), votcDTO);
                    // votDTO.setValue(statusTerm.getCode());
                    // votcDTO.add(votDTO);
                    // }
                    // else
                    // {
                    Object value = vot.getValue();
                    if (value != null) {
                        if (attribute instanceof AttributeTermType) {
                            Classifier classifier = Classifier.get((String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classifier.getClassifierId());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else if (attribute instanceof AttributeClassificationType) {
                            String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
                            ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                            Classification classification = Classification.getByOid(classificationType, (String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classification.toTerm());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else {
                            ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                            votDTO.setValue(value);
                            votcDTO.add(votDTO);
                        }
                    }
                // }
                }
                geoObj.setValueCollection(attributeName, votcDTO);
            } else {
                Object value = this.getValue(attributeName);
                if (value != null) {
                    if (attribute instanceof AttributeTermType) {
                        Classifier classifier = Classifier.get((String) value);
                        try {
                            geoObj.setValue(attributeName, classifier.getClassifierId());
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else if (attribute instanceof AttributeClassificationType) {
                        String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
                        MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
                        MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
                        VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
                        try {
                            geoObj.setValue(attributeName, classification.getObjectValue(AbstractClassification.CODE));
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else {
                        geoObj.setValue(attributeName, value);
                    }
                }
            }
        }
    });
    if (// && !vertex.isAppliedToDB())
    generateUid && vertex.isNew()) {
        geoObj.setUid(RegistryIdService.getInstance().next());
    // geoObj.setStatus(ServiceFactory.getAdapter().getMetadataCache().getTerm(DefaultTerms.GeoObjectStatusTerm.NEW.code).get(),
    // this.date, this.date);
    } else {
        geoObj.setUid(vertex.getObjectValue(RegistryConstants.UUID));
    }
    ValueOverTimeCollection votc = this.getValuesOverTime(this.getGeometryAttributeName());
    ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(geoObj.getGeometryAttributeType());
    for (ValueOverTime vot : votc) {
        Object value = vot.getValue();
        ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
        votDTO.setValue(value);
        votcDTO.add(votDTO);
    }
    geoObj.setValueCollection(DefaultAttribute.GEOMETRY.getName(), votcDTO);
    geoObj.setCode(vertex.getObjectValue(DefaultAttribute.CODE.getName()));
    return geoObj;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) Attribute(org.commongeoregistry.adapter.dataaccess.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) VertexObject(com.runwaysdk.business.graph.VertexObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) TermValueException(net.geoprism.registry.io.TermValueException) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) 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) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Aggregations

GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)30 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 Test (org.junit.Test)9 Geometry (com.vividsolutions.jts.geom.Geometry)5 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 Endpoint (com.runwaysdk.mvc.Endpoint)4 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)4 Request (com.runwaysdk.session.Request)4 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)4 ServerParentTreeNodeOverTime (net.geoprism.registry.view.ServerParentTreeNodeOverTime)4 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 ValueOverTimeCollectionDTO (org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO)4 JsonObject (com.google.gson.JsonObject)3 VertexObject (com.runwaysdk.business.graph.VertexObject)3 SimpleDateFormat (java.text.SimpleDateFormat)3 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)3 TestUserInfo (net.geoprism.registry.test.TestUserInfo)3 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)3