Skip to content

CRUD API

Hyemi Jeong edited this page Oct 24, 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. The meaning of each 'string' type-not real class type of the feature class-parameters of CRUD function is at Feature Class

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
    /*
    Create IndoorFeatures instance
    */
    edu.pnu.stem.dao.IndoorFeaturesDAO.createIndoorFeatures(map, "if1", "indoorfeatures","testdata" , null, "pf1");

    // Create a list of CellSpaceMember and add the id of CellSpaces.
    List<String>cellspacemember = new ArrayList<String>();
    cellspacemember.add("c1");

    // Create a list of CellSpaceBoundaryMember and add the id of CellSpaceBoundarys.
    List<String>cellspaceboundarymember = new ArrayList<String>();
    cellspaceboundarymember.add("csb1");

    /*
    Create PrimalSpaceFeatures instance
    */
    edu.pnu.stem.dao.PrimalSpaceFeaturesDAO.createPrimalSpaceFeatures(map, "if1", "pf1", null,
    null,cellspacemember,cellspaceboundarymember);
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 :

  • To change WKT string to JTS geometry, use read() of WKTReader3D.
  • JTS geometry doesn't have the identifier. InFactory supports the function to set the indentifier at the geometry instance. Use edu.pnu.stem.util.GeometryUtil.setMetadata().
    /*
    Create the CellSpace feature 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 of Solid
    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 a list of partialBoundedBy
    List<String>partialboundedby = new ArrayList<String>();
    partialboundedby.add("csb1");

    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 which will be changed into the XML document. By Container.getDocument(String identifierOfDoc) the documents are read.
  • If no path is given to this function, then the pop-up window for selecting the path of saving will be appeared after creating the XML document of IndoorGML.
edu.pnu.stem.binder.Mashaller.marshalDocument(null, Container.getDocument("doc1"));

Full example code is here : link

Update

The feature already created can be updated by the update function. The below code is to update the CellSpace feature. This example update new name and description of the feature. The parameters are same with those of the create function.

  • Note : The update functions in InFactory support fully-patched.
edu.pnu.stem.dao.CellSpaceDAO.updateCellSpace(map, "pf1", "c1", "room1", "bedroom", cg1, null, partialboundedby);

READ

The read function returns the feature class instances which are defined in InFactory. The detail of the feature classes will be discribed at the JavaDoc of this project.

edu.pnu.stem.dao.CellSpaceDAO.readCellSpace(map, "c1");

DELETE

It works similar with the read function. The IndoorGMLMap instances and the identifier are needed to erase the instance.

  • Note: The relationships that this feature has are automatically erased inside of the delete function.
edu.pnu.stem.dao.CellSpaceDAO.deleteCellSpace(map,"c1");