package ws.gazebo.util.ontTool.shp;

import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.geotools.data.DataStore;
import org.geotools.feature.FeatureIterator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengis.feature.Feature;
import org.opengis.feature.Property;
import org.opengis.filter.identity.FeatureId;

public class OntToolShpTest {

	public static final String SHP_TEST_PATH = "src/test/resources/statesp020_nt00032/statesp020.shp";

	private File shpTestFile;

	@Before
	public void setUp() {
		shpTestFile = new File(SHP_TEST_PATH);
	}

	@After
	public void tearDown() {

	}

	@Test
	public final void testOpenShpDataStore() {
		DataStore ds = OntToolShp.openShpDataStore(shpTestFile);
		try {
			String theType = ds.getTypeNames()[0];
			FeatureIterator<Feature> it = OntToolShp.getFeatures(theType, ds);
			try {
				while (it.hasNext()) {
					Feature f = it.next();
					// NB: getName() returns the same result, always
					System.out.println("Feature name: " + f.getName());
					// getIdentifier returns a unique result
					System.out.println("Feature ID: " + f.getIdentifier());
					FeatureId fid = f.getIdentifier();
					// NB: getType() returns a string containing something
					// resembling WKT
					System.out.println("Feature type: " + f.getType());
					Iterator<Property> pit = f.getProperties().iterator();
					while (pit.hasNext()) {
						Property p = pit.next();
						// FIXME: always skip feature named the_geom
						if (p.getName().toString() != "the_geom") {
							System.out.println("Feature " + fid
									+ " Property " + p.getName() + " Value: "
									+ p.getValue());
						}
					}

				}
			} finally {
				it.close();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail("error");
		}

	}

}

@@ -804,16 +804,132 @@
 tFile);%0A
+%09%09printFeatureProperties(ds);%0A%09%09ds.dispose();%0A%0A%09%7D%0A%0A%09public static final void printFeatureProperties(DataStore ds) %7B%0A
 %09%09try %7B%0A
@@ -1111,24 +1111,53 @@
 %0A%09%09%09%09%09// NB:
+ on the statesp020 shapefile,
  getName() r
@@ -1166,16 +1166,24 @@
 urns the
+%0A%09%09%09%09%09//
  same re
@@ -1188,22 +1188,71 @@
 result, 
-always
+regardless of feature - name value%0A%09%09%09%09%09// %22statesp020%22
 %0A%09%09%09%09%09Sy
@@ -1337,21 +1337,38 @@
 s a 
-unique result
+result unique to the shapefile
 %0A%09%09%09
@@ -1868,26 +1868,17 @@
  %22 + fid
-%0A%09%09%09%09%09%09%09%09%09
+ 
 + %22 Prop
@@ -1883,17 +1883,26 @@
 operty %22
- 
+%0A%09%09%09%09%09%09%09%09%09
 + p.getN
@@ -1923,50 +1923,566 @@
 e: %22
-%0A%09%09%09%09%09%09%09%09%09+ p.getValue());%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A
+ + p.getValue());%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%09// Observations:%0A%09%09%09%09%09//%0A%09%09%09%09%09// * Feature Property STATE_FIPS serves as a PRIMARY KEY for%0A%09%09%09%09%09// joining the census table with the statesp020 information%0A%09%09%09%09%09//%0A%09%09%09%09%09// * For purpose of the SGov structural/regional ontologies,%0A%09%09%09%09%09// after the census table is loaded, then the statesp020%0A%09%09%09%09%09// file should only be needed for computing the%0A%09%09%09%09%09// %22order admitted%22 value (Feature property ORDER_ADM here)%0A%09%09%09%09%09// and the %22date admitted%22 value, from the feature%0A%09%09%09%09%09// properties (here) YEAR_ADM, MONTH_ADM, DAY_ADM
 %0A%09%09%09

move printout code into stand-alone method; add observations in comments