Skip to content

CRUD API

JungHam edited this page Jul 20, 2018 · 11 revisions

InFactory provides the Java library which does CRUD(Create, Read, Update, Delete) on IndoorGML features. In this section the basic rules of using CRUD will be described. More detail on the library such as the name of functions or the specifications of parameters of functions will be explained at JavaDoc.

RESTful API and CRUD API

CREATE

Create document

InFactory saves the IndoorGML documents in the data structure called "Container".

This example code is at edu.pnu.stem.api.testForCRUD.java.

package edu.pnu.stem;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBException;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;

import edu.pnu.stem.api.Container;
import edu.pnu.stem.binder.Convert2JaxbClass;
import edu.pnu.stem.binder.IndoorGMLMap;
import edu.pnu.stem.feature.IndoorFeatures;
import edu.pnu.stem.geometry.jts.WKTReader3D;
import junit.framework.TestCase;

public class testForCRUD extends TestCase{
	 public void testConverter(){	 
		 try {
			IndoorGMLMap map = Container.createDocument("doc1");
		} catch (JAXBException e) {
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
}

From now on, we look at the rest of the main method in sections. Follow the tutorial with copying the rest under the try statement.

Create the complex features
    edu.pnu.stem.dao.IndoorFeaturesDAO.createIndoorFeatures(map, "if1", "indoorfeatures","testdata" , null, "pf1");
    List<String>cellspacemember = new ArrayList<String>();
    cellspacemember.add("c1");
    List<String>cellspaceboundarymember = new ArrayList<String>();
    cellspaceboundarymember.add("csb1");

    edu.pnu.stem.dao.PrimalSpaceFeaturesDAO.createPrimalSpaceFeatures(map, "if1", "pf1", null,
    null,cellspacemember,cellspaceboundarymember);

    List<String>partialboundedby = new ArrayList<String>();
    partialboundedby.add("csb1");

Create the geometry features

The geometry data can be created into two ways :

  • Converting from WKT string to JTS geometry : use WKTReader3D
  • Creating JTS geometry : use GeometryFactory (JTS)

Before create the geometry instances the below instances need to be declared.

  WKTReader3D wktReader = new WKTReader3D();		                  //WKT String parser

After parsing WKT geometry via WKTReader3D, it is needed to set the identifier of the geometry instance. Things to note :

  • JTS geometry doesn't have the identifier. InFactory supports the function to set the indentifier at the geometry instance
    /*
    Create the JTS Solid geometry by parsing WKT String
    */
    String wktsolid = "SOLID (( ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)), ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)), ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)) ))"; //WKT String
    Geometry cg1 = wktReader.read(wktsolid); // WKT reader returns JTS geometry instance
    edu.pnu.stem.util.GeometryUtil.setMetadata(cg1, "id", "cg1"); //Set the identifier to the geometry data

    /*
    Create the CellSpace feature instance
    */

    edu.pnu.stem.dao.CellSpaceDAO.createCellSpace(map, "pf1", "c1", null, null, cg1, null, partialboundedby);

The below code is to create CellSpaceBoundary feature.

    /*
    Create the JTS Surface geometry by parsing WKT String
    */
    String wktSurface = "POLYGON ((72.91597221207489 43.26827584086601 0, 79.90026563212191 43.26827584086601 0, 79.90026563212191 43.26827584086601 15, 72.91597221207489 43.26827584086601 15, 72.91597221207489 43.26827584086601 0))";
    Geometry cbg1 = wkt.read(wktSurface);
    edu.pnu.stem.util.GeometryUtil.setMetadata(cbg1, "id", "cbg1");

    edu.pnu.stem.dao.CellSpaceBoundaryDAO.createCellSpaceBoundary(map, "pf1", "csb1", null , null, cbg1, null);
Get the xml document

InFactory changes IndoorGMLMap class instances into the xml document. The below function helpes to marshall IndoorGMLMap data to the xml document. The function marshalDocument's first parameter means the path where the XML document will be saved. The second parameter means the IndoorGMLMap instance changed into the XML document. The first parameter is the path where the XML document will be saved. The second parameter is the IndoorGMLMap instance which holds the data of the IndoorGML document.

edu.pnu.stem.binder.Mashaller.marshalDocument(null, Container.getDocument("doc1"));

Full example code is here : link

Update

READ

DELETE

Clone this wiki locally