[kepler-code] r28779 - in trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap: actor actor/survivorship actor/survivorship/dataset data data/akn data/survivorship ptolemy

barseghian at ecoinformatics.org barseghian at ecoinformatics.org
Fri Oct 7 16:41:17 PDT 2011


Author: barseghian
Date: 2011-10-07 16:41:17 -0700 (Fri, 07 Oct 2011)
New Revision: 28779

Added:
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataActor.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataProviderActorHepler.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfig.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfigHelper.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DataSet.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataSet.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProvider.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProviderImpl.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataSet.java
Removed:
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/DataSet.java
Modified:
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/AKNDataActor.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProvider.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderImpl.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderTest.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNIndexer.java
   trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/ptolemy/DataSetStringChoiceProvider.java
Log:
survivorship data actor, and supporting classes.
some refactoring of existing classes to generalize

Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/AKNDataActor.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/AKNDataActor.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/AKNDataActor.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -10,7 +10,7 @@
 import ptolemy.kernel.util.IllegalActionException;
 import ptolemy.kernel.util.NameDuplicationException;
 import edu.cornell.birds.is.bap.data.akn.AKNDataProvider;
-import edu.cornell.birds.is.bap.data.akn.DataSet;
+import edu.cornell.birds.is.bap.data.akn.AKNDataSet;
 import edu.cornell.birds.is.bap.ptolemy.DataSetStringChoiceProvider;
 import edu.cornell.birds.is.bap.ptolemy.StringChoiceParameter;
 
@@ -73,7 +73,7 @@
 		String key = searchText.getKeyForCurrentChoice();
 		logger.debug("speciesSearchText: " + key);
 		
-		DataSet data = akn.getDatSetForCommonName(key);
+		AKNDataSet data = (AKNDataSet)akn.getDatSetForCommonName(key);
 		
 		if (data != null) {
 			localFileNamePort.broadcast(new StringToken(data.getLocalPath()));

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataActor.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataActor.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataActor.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,93 @@
+package edu.cornell.birds.is.bap.actor.survivorship;
+
+import org.apache.log4j.Logger;
+
+import ptolemy.actor.TypedAtomicActor;
+import ptolemy.actor.TypedIOPort;
+//import ptolemy.data.StringToken;
+import ptolemy.data.StringToken;
+import ptolemy.data.type.BaseType;
+import ptolemy.kernel.CompositeEntity;
+import ptolemy.kernel.util.IllegalActionException;
+import ptolemy.kernel.util.NameDuplicationException;
+import edu.cornell.birds.is.bap.data.survivorship.SurvivorshipDataProvider;
+import edu.cornell.birds.is.bap.data.survivorship.SurvivorshipDataSet;
+import edu.cornell.birds.is.bap.ptolemy.DataSetStringChoiceProvider;
+import edu.cornell.birds.is.bap.ptolemy.StringChoiceParameter;
+
+public class SurvivorshipDataActor extends TypedAtomicActor {
+
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -4953886954929940770L;
+
+	private static final Logger logger = Logger.getLogger(SurvivorshipDataActor.class);
+	
+	private SurvivorshipDataProviderActorHepler springHelper;
+	private SurvivorshipDataProvider sdp;
+	
+    public TypedIOPort localFileNamePort = null;
+    public TypedIOPort dataOutPort = null;
+    public TypedIOPort cemeteryNamePort = null;
+    public TypedIOPort dataDescriptionPort = null;
+    public StringChoiceParameter searchText = null;
+	
+	public SurvivorshipDataActor(CompositeEntity container, String name)
+			throws NameDuplicationException, IllegalActionException {
+		super(container, name);
+		init(null);
+	}
+
+	public SurvivorshipDataActor(CompositeEntity container, String name, String providerName)
+			throws NameDuplicationException, IllegalActionException {
+		super(container, name);
+		init(providerName);
+	}	
+	
+	protected void init(String providerName) throws IllegalActionException, NameDuplicationException {
+		
+		if (providerName == null) {
+			springHelper = new SurvivorshipDataProviderActorHepler();
+		} else {
+			springHelper = new SurvivorshipDataProviderActorHepler(providerName);
+		}
+		
+		sdp = springHelper.getDataProvider();
+		
+		localFileNamePort = new TypedIOPort(this, "localFileName", false, true);
+		localFileNamePort.setTypeEquals(BaseType.STRING);
+		
+		dataOutPort = new TypedIOPort(this, "data", false, true);
+		dataOutPort.setTypeEquals(BaseType.STRING);
+
+		cemeteryNamePort = new TypedIOPort(this, "cemeteryName", false, true);
+		cemeteryNamePort.setTypeEquals(BaseType.STRING);
+		
+		dataDescriptionPort = new TypedIOPort(this, "dataDescription", false, true);
+		dataDescriptionPort.setTypeEquals(BaseType.STRING);
+		
+		searchText = new StringChoiceParameter(this, "cemeterySearchText", new DataSetStringChoiceProvider(sdp.getDataSetsMapByName()));
+		searchText.setDisplayName("Cemetery Search Text");
+		searchText.setExpression(searchText.getChoices()[0]); // set default to first option;		
+	}
+
+	@Override
+	public void fire() throws IllegalActionException {
+		super.fire();
+
+		String choice = searchText.stringValue();
+		String key = searchText.getKeyForCurrentChoice();
+		logger.debug("cemeterySearchText: " + key);
+		
+		SurvivorshipDataSet data = (SurvivorshipDataSet) sdp.getDatSetForName(key);
+		
+		if (data != null) {
+			localFileNamePort.broadcast(new StringToken(data.getLocalPath()));
+			cemeteryNamePort.broadcast(new StringToken(choice));
+			dataDescriptionPort.broadcast(new StringToken(sdp.getDescription()));
+		}
+	}
+
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataActor.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataProviderActorHepler.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataProviderActorHepler.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataProviderActorHepler.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,65 @@
+package edu.cornell.birds.is.bap.actor.survivorship;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.BeansException;
+
+import ptolemy.kernel.ComponentEntity;
+import ptolemy.kernel.util.StringAttribute;
+import edu.cornell.birds.is.bap.actor.SpringApplicationContextHelper;
+import edu.cornell.birds.is.bap.data.survivorship.SurvivorshipDataProvider;
+
+public class SurvivorshipDataProviderActorHepler extends SpringApplicationContextHelper {
+
+	protected static final Logger logger = Logger.getLogger(SurvivorshipDataProviderActorHepler.class);
+	
+	private SurvivorshipDataProvider dataProvider;
+	
+	public SurvivorshipDataProviderActorHepler() {
+		super();
+		init("survivorshipDataProvider");
+	}
+	
+	/**
+	 * Name of the bean specifying the AKNDataProvider bean.
+	 * 
+	 * @param beanName
+	 */
+	public SurvivorshipDataProviderActorHepler(String beanName) {
+		super();
+		init(beanName);
+	}
+	
+	private void init(String beanName) {
+		try {
+			dataProvider = (SurvivorshipDataProvider) getBean(beanName);
+			logger.info("SurvivorshipDataProvider loaded from bean named " + beanName);
+		}
+		catch (BeansException e) {
+			logger.info("SurvivorshipDataProvider could not be loaded from bean named " + beanName, e);
+		}	
+	}
+	
+	
+	public boolean isActive() {
+		return dataProvider != null;
+	}
+
+	public static String getJobID(ComponentEntity entity) {
+		StringAttribute jobIDAttribute = (StringAttribute) entity.toplevel().getAttribute("jobID");
+		String jobID = null;
+		if (jobIDAttribute == null) {
+			logger.error("Cannot find jobID attribute in topLevel.");
+			jobID = entity.toplevel().getFullName();
+		}
+		else {
+			jobID = jobIDAttribute.getValueAsString();
+		}
+        logger.debug("jobID: " + jobID);
+        return jobID;
+	}
+
+	public SurvivorshipDataProvider getDataProvider() {
+		return dataProvider;
+	}
+	
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/SurvivorshipDataProviderActorHepler.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfig.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfig.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfig.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,263 @@
+package edu.cornell.birds.is.bap.actor.survivorship.dataset;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.Logger;
+
+import ptolemy.actor.TypedIOPort;
+import ptolemy.data.BooleanToken;
+import ptolemy.data.RecordToken;
+import ptolemy.data.StringToken;
+import ptolemy.data.Token;
+import ptolemy.kernel.util.IllegalActionException;
+import edu.cornell.birds.is.bap.actor.ActorUtils;
+
+
+/**
+ * Defines where a Survivorship dataset can be found, and provides
+ * a description of it. Meant primarily for Spring configuration.
+ */
+public class SurvivorshipDatasetConfig {
+	
+	protected static final Logger logger = Logger.getLogger(SurvivorshipDatasetConfig.class);
+	
+	//static public final String DATASET_ECOREGION_PLANT_RICHNESS_SUMMARY = "wildfinder.ecoregion.plant.richness_summary"; 
+	//static public final String DATASET_ECOREGION_SPECIES_OCCURRENCE = "wildfinder.ecoregion.species.occurrence"; 
+	//static public final String DATASET_ECOREGION_AREA = "wildfinder.ecoregion.area"; 
+	static public final String DATASET_UNKNOWN = "unknown";
+	
+	static public final String LABEL_DATASET_TYPE = "datasetType";  
+	static public final String LABEL_COLUMN_DELIMITER = "columnDelimiter";  
+	static public final String LABEL_HAS_HEADER = "hasHeader";  
+	static public final String LABEL_FILE_LOCATION = "fileLocation";  
+	
+	private String fileLocation;
+	private String datasetDescription;
+	private String datasetType;
+	private String columnDelimiter;
+	private Boolean hasHeader;
+	private String data;
+	private boolean fileBasedData = true;
+	
+	public SurvivorshipDatasetConfig() {
+		super();
+	}
+	
+	public SurvivorshipDatasetConfig(RecordToken recordToken) {
+		super();
+		
+		if (recordToken != null) {
+			Token token = recordToken.get(LABEL_DATASET_TYPE);
+			if (token != null) setDatasetType(((StringToken)token ).stringValue());
+			
+			token = recordToken.get(LABEL_COLUMN_DELIMITER);
+			if (token != null) setColumnDelimiter(((StringToken)token ).stringValue());
+			
+			token = recordToken.get(LABEL_FILE_LOCATION);
+			if (token != null) setFileLocation(((StringToken)token ).stringValue());
+			
+			token = recordToken.get(LABEL_HAS_HEADER);
+			if (token != null) setHasHeader(((BooleanToken)token).booleanValue());
+		}
+	}
+	
+	/**
+	 * @return the datasetDescription
+	 */
+	public String getDatasetDescription() {
+		return datasetDescription;
+	}
+	/**
+	 * @param datasetDescription the datasetDescription to set
+	 */
+	public void setDatasetDescription(String datasetDescription) {
+		this.datasetDescription = datasetDescription;
+	}
+	/**
+	 * @return the fileLocation
+	 */
+	public String getFileLocation() {
+		return fileLocation;
+	}
+	/**
+	 * @param fileLocation the fileLocation to set
+	 */
+	public void setFileLocation(String fileLocation) {
+		
+		if (fileLocation != null) {
+			fileLocation = fileLocation.replaceAll("\\\\\\\\", "/");
+			fileLocation = fileLocation.replaceAll("\\\\", "/");
+		}
+		this.fileLocation = fileLocation;
+	}
+	/**
+	 * @return the columnDelimiter
+	 */
+	public String getColumnDelimiter() {
+		return columnDelimiter;
+	}
+	/**
+	 * @param columnDelimiter the columnDelimiter to set
+	 */
+	public void setColumnDelimiter(String columnDelimiter) {
+		this.columnDelimiter = columnDelimiter;
+	}
+	/**
+	 * @return the hasHeader
+	 */
+	public Boolean getHasHeader() {
+		return hasHeader;
+	}
+	/**
+	 * @param hasHeader the hasHeader to set
+	 */
+	public void setHasHeader(Boolean hasHeader) {
+		this.hasHeader = hasHeader;
+	}
+
+	/**
+	 * @return the datasetType
+	 */
+	public String getDatasetType() {
+		return datasetType;
+	}
+	/**
+	 * @param datasetType the datasetType to set
+	 */
+	public void setDatasetType(String datasetType) {
+		this.datasetType = datasetType;
+	}
+
+	public RecordToken getRecordToken() throws IllegalActionException {
+
+		ArrayList<String> labels = new ArrayList<String>(); 
+		ArrayList<Token> values = new ArrayList<Token>(); 
+		
+		if (getFileLocation() != null) {
+			labels.add(LABEL_FILE_LOCATION);
+			values.add(new StringToken(getFileLocation()));
+		}
+		if (getColumnDelimiter() != null) {
+			labels.add(LABEL_COLUMN_DELIMITER);
+			values.add(new StringToken(getColumnDelimiter()));
+		}
+		if (getHasHeader() != null) {
+			labels.add(LABEL_HAS_HEADER);
+			values.add(new BooleanToken(getHasHeader().booleanValue()));
+		}
+		if (getDatasetType() != null) {
+			labels.add(LABEL_DATASET_TYPE);
+			values.add(new StringToken(getDatasetType()));
+		}		
+		String[] labelsArray = new String[labels.size()];
+		Token[] valuesArray = new Token[values.size()];
+		labelsArray = labels.toArray(labelsArray);
+		valuesArray = values.toArray(valuesArray);
+		return new RecordToken(labelsArray, valuesArray);
+	}
+	
+	public static SurvivorshipDatasetConfig getDatasetConfigInstance(TypedIOPort port, boolean defaultIgnoreFirstRow, String defaultColumnSeparator ) throws IllegalActionException {
+		
+		if (port != null && port.getWidth() > 0 && port.hasToken(0)) 
+			return getDatasetConfigInstance(port.get(0), defaultIgnoreFirstRow, defaultColumnSeparator);
+		return null;
+	}
+
+	public static SurvivorshipDatasetConfig getDatasetConfigInstance(Token inputToken, boolean defaultIgnoreFirstRow, String defaultColumnSeparator ) throws IllegalActionException {
+//		Token tk = inPort.get(0);
+		if (inputToken instanceof RecordToken) {
+			RecordToken rtk = (RecordToken) inputToken;
+			SurvivorshipDatasetConfig dataconfig = new SurvivorshipDatasetConfig(rtk);
+			// at minimum we expect fileLocation and datasetType to be set 
+			if (dataconfig.getHasHeader() == null) 
+//				dataconfig.setHasHeader(((BooleanToken) ignoreFirstRow.getToken()).booleanValue());
+				dataconfig.setHasHeader(defaultIgnoreFirstRow);
+			if (dataconfig.getColumnDelimiter() == null) 
+				dataconfig.setColumnDelimiter(ActorUtils.getCookedColumnSeparator(dataconfig.getColumnDelimiter()));
+			return dataconfig;
+		}
+		else if (inputToken instanceof StringToken) {
+			// assume string is a datastream;
+			SurvivorshipDatasetConfig datasetConfig = new SurvivorshipDatasetConfig();
+			datasetConfig.setHasHeader(defaultIgnoreFirstRow);
+			datasetConfig.setColumnDelimiter(defaultColumnSeparator);
+			datasetConfig.setDatasetType(DATASET_UNKNOWN);
+			datasetConfig.setData(((StringToken)inputToken).stringValue());
+			datasetConfig.setFileBasedData(false);
+			return datasetConfig;
+		}
+		logger.warn("Unexpected token type. Not RecordToken or StringToken.");
+		return null;
+	}	
+	
+	private static boolean isFileLocationValid(String filename) {
+		if (filename != null) {
+			File f = new File (filename);
+			return f.exists();
+		}
+		return false;
+	}
+	
+	public boolean isFileLocationValid() {
+		return isFileLocationValid(getFileLocation());
+	}
+	
+	public static SurvivorshipDatasetConfig getUnknownDatasetConfiguration() {
+		
+		SurvivorshipDatasetConfig c = new SurvivorshipDatasetConfig();
+		c.setDatasetType(DATASET_UNKNOWN);
+		c.setColumnDelimiter("\t");;
+		c.setHasHeader(false);
+		return c;
+	}
+
+	/**
+	 * @return the data
+	 */
+	public String getData() {
+		return data;
+	}
+
+	/**
+	 * @param data the data to set
+	 */
+	public void setData(String data) {
+		this.data = data;
+	}
+
+	/**
+	 * @return the fileBasedData
+	 */
+	public boolean isFileBasedData() {
+		return fileBasedData;
+	}
+
+	/**
+	 * @param fileBasedData the fileBasedData to set
+	 */
+	public void setFileBasedData(boolean fileBasedData) {
+		this.fileBasedData = fileBasedData;
+	}
+	
+	/**
+	 * load data from file into the "data" property
+	 *
+	 */
+	public void loadData() {
+		if (!isFileBasedData()) return; // already loaded
+	
+		try {
+			String s = FileUtils.readFileToString(new File(getFileLocation()));
+			setData(s);
+			setFileBasedData(false);
+		}
+		catch (IOException e) {
+			logger.error("IOException", e);
+		}
+	}
+	
+    
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfig.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfigHelper.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfigHelper.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfigHelper.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,48 @@
+package edu.cornell.birds.is.bap.actor.survivorship.dataset;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.BeansException;
+
+import edu.cornell.birds.is.bap.actor.SpringApplicationContextHelper;
+
+public class SurvivorshipDatasetConfigHelper extends SpringApplicationContextHelper {
+
+	protected static final Logger logger = Logger.getLogger(SurvivorshipDatasetConfigHelper.class);
+	
+	private SurvivorshipDatasetConfig dataProvider;
+	
+	public SurvivorshipDatasetConfigHelper() {
+		super();
+		init("survivorshipDatasetConfig");
+	}
+	
+	/**
+	 * Name of the bean specifying the SurvivorshipDataProvider bean.
+	 * 
+	 * @param beanName
+	 */
+	public SurvivorshipDatasetConfigHelper(String beanName) {
+		super();
+		init(beanName);
+	}
+	
+	private void init(String beanName) {
+		try {
+			dataProvider = (SurvivorshipDatasetConfig) getBean(beanName);
+			logger.info("SurvivorshipDatasetConfig loaded from bean named " + beanName);
+		}
+		catch (BeansException e) {
+			logger.info("SurvivorshipDatasetConfig could not be loaded from bean named " + beanName, e);
+		}	
+	}
+	
+	
+	public boolean isActive() {
+		return dataProvider != null;
+	}
+
+	public SurvivorshipDatasetConfig getDataProvider() {
+		return dataProvider;
+	}
+	
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/actor/survivorship/dataset/SurvivorshipDatasetConfigHelper.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Copied: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DataSet.java (from rev 28529, trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/DataSet.java)
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DataSet.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/DataSet.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,32 @@
+package edu.cornell.birds.is.bap.data;
+
+public abstract class DataSet {
+	
+	private String localPath;
+	private int rowCount = 0;
+
+	public String getLocalPath() {
+		return localPath;
+	}
+
+	public void setLocalPath(String localPath) {
+		this.localPath = localPath;
+	}
+	
+	public String toString() {
+		return "localPath: " + getLocalPath();
+	}
+	
+	public abstract String getGUIDisplayName();
+	
+	/**
+	 * @return the rowCount
+	 */
+	public int getRowCount() {
+		return rowCount;
+	}
+
+	public void incrRowCount() {
+		rowCount++;
+	}	
+}

Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProvider.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProvider.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProvider.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -2,6 +2,8 @@
 
 import java.util.Map;
 
+import edu.cornell.birds.is.bap.data.DataSet;
+
 public interface AKNDataProvider {
 
 	public DataSet getDatSetForCommonName(String commonName);

Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderImpl.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderImpl.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderImpl.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -11,6 +11,8 @@
 
 import org.apache.log4j.Logger;
 
+import edu.cornell.birds.is.bap.data.DataSet;
+
 public class AKNDataProviderImpl implements AKNDataProvider {
 
 	private static final Logger logger = Logger.getLogger(AKNDataProviderImpl.class);
@@ -54,7 +56,7 @@
 			String commonName = columns[0];
 			String sciName = columns[1];
 			String fileName = columns[2];
-			DataSet data = new DataSet();
+			AKNDataSet data = new AKNDataSet();
 			data.setCommonName(commonName);
 			data.setLocalPath(getSpeciesFilePath(fileName));
 			data.setSciName(sciName);

Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderTest.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderTest.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataProviderTest.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -18,7 +18,7 @@
 		String[] names = {"Seaside Sparrow", "Blue Jay", "blue jay", "Texas Toast-eater"};
 		
 		for (String name : names) {
-			DataSet data = akn.getDatSetForCommonName(name);
+			AKNDataSet data = (AKNDataSet) akn.getDatSetForCommonName(name);
 			if (data == null)
 				logger.info("No match for [" + name + "]");
 			else 

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataSet.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataSet.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataSet.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,36 @@
+package edu.cornell.birds.is.bap.data.akn;
+
+import edu.cornell.birds.is.bap.data.DataSet;
+
+public class AKNDataSet extends DataSet {
+	
+	private String localPath;
+	private String commonName;
+	private String sciName;
+
+	public String getLocalPath() {
+		return localPath;
+	}
+
+	public String getCommonName() {
+		return commonName;
+	}
+
+	public void setCommonName(String commonName) {
+		this.commonName = commonName;
+	}
+
+	public String getSciName() {
+		return sciName;
+	}
+
+	public void setSciName(String sciName) {
+		this.sciName = sciName;
+	}
+
+	@Override
+	public String getGUIDisplayName() {
+		return getCommonName() + " (" + getSciName() + ")";
+	}
+	
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNDataSet.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNIndexer.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNIndexer.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/AKNIndexer.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -26,7 +26,7 @@
 	private static int MIN_RECORDS_FOR_PUBLISHING = 1000;
 	private static int NUMBER_COLUMNS = 129;
 	
-	private Map<String, DataSet> speciesMap = new HashMap<String, DataSet>();
+	private Map<String, AKNDataSet> speciesMap = new HashMap<String, AKNDataSet>();
 	private String path;
 	private String fileExtension = "txt";
 	private String sourceSeparator = "\t";
@@ -109,10 +109,10 @@
 		
 		String species = columns[COL_COMMON_NAME];
 		
-		DataSet ds = speciesMap.get(species);
+		AKNDataSet ds = speciesMap.get(species);
 		File file = null;
 		if (ds == null) {
-			ds = new DataSet();
+			ds = new AKNDataSet();
 			ds.setCommonName(species);
 			ds.setLocalPath(getFilePath(species));
 			
@@ -190,7 +190,7 @@
 		FileWriter writer = new FileWriter(indexFile);
 		
 		for (String species : speciesMap.keySet()) {
-			DataSet ds = speciesMap.get(species);
+			AKNDataSet ds = speciesMap.get(species);
 			if (ds.getRowCount() >= minRecordsForPublishing)
 				writer.write(species + "\t" + ds.getSciName() + "\t" + getSpeciesFileName(species) + "\n");
 			else
@@ -225,14 +225,14 @@
 	/**
 	 * @return the speciesMap
 	 */
-	public Map<String, DataSet> getSpeciesMap() {
+	public Map<String, AKNDataSet> getSpeciesMap() {
 		return speciesMap;
 	}
 
 	/**
 	 * @param speciesMap the speciesMap to set
 	 */
-	public void setSpeciesMap(Map<String, DataSet> speciesMap) {
+	public void setSpeciesMap(Map<String, AKNDataSet> speciesMap) {
 		this.speciesMap = speciesMap;
 	}
 

Deleted: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/DataSet.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/DataSet.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/akn/DataSet.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -1,48 +0,0 @@
-package edu.cornell.birds.is.bap.data.akn;
-
-public class DataSet {
-	
-	private String localPath;
-	private String commonName;
-	private String sciName;
-	private int rowCount = 0;
-
-	public String getLocalPath() {
-		return localPath;
-	}
-
-	public void setLocalPath(String localPath) {
-		this.localPath = localPath;
-	}
-	
-	public String toString() {
-		return "localPath: " + getLocalPath();
-	}
-
-	public String getCommonName() {
-		return commonName;
-	}
-
-	public void setCommonName(String commonName) {
-		this.commonName = commonName;
-	}
-
-	public String getSciName() {
-		return sciName;
-	}
-
-	public void setSciName(String sciName) {
-		this.sciName = sciName;
-	}
-	
-	/**
-	 * @return the rowCount
-	 */
-	public int getRowCount() {
-		return rowCount;
-	}
-
-	public void incrRowCount() {
-		rowCount++;
-	}	
-}

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProvider.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProvider.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProvider.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,14 @@
+package edu.cornell.birds.is.bap.data.survivorship;
+
+import java.util.Map;
+
+import edu.cornell.birds.is.bap.data.DataSet;
+
+public interface SurvivorshipDataProvider {
+
+	public DataSet getDatSetForName(String name);
+	public Map<String, DataSet> getDataSetsMapByName();
+	public String getDescription();
+	public String getDataFormat();
+	
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProvider.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProviderImpl.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProviderImpl.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProviderImpl.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,176 @@
+package edu.cornell.birds.is.bap.data.survivorship;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import edu.cornell.birds.is.bap.data.DataSet;
+
+public class SurvivorshipDataProviderImpl implements SurvivorshipDataProvider {
+
+	private static final Logger logger = Logger.getLogger(SurvivorshipDataProviderImpl.class);
+	
+	private Map<String, DataSet> demographyMap = new HashMap<String, DataSet>();
+	private String pathToParentDirectory;
+	private boolean initialized = false;
+	private String tokenSeparator = "\t";
+	private String indexFileName = "index.txt";
+	//FIXME
+	private String description = "FIXME default survivorship description";
+	private String dataFormat;
+
+	@SuppressWarnings("unchecked")
+	public Map<String, DataSet> getDataSetsMapByName() {
+		if (!isInitialized()){
+			return Collections.EMPTY_MAP;
+		}
+		return demographyMap;
+	}
+
+	public DataSet getDatSetForName(String name) {
+		if (!isInitialized()){ 
+			return null;
+		}
+		return demographyMap.get(name.toLowerCase().trim());
+	}
+	
+	protected void loadIndex(String indexFileName, String separator) throws IOException {
+		File f = new File(getFilePath(indexFileName));
+
+		BufferedReader reader = new BufferedReader(
+				new InputStreamReader(new FileInputStream(f), "ISO-8859-1"));
+		
+		String row;
+		int line = 0;
+		
+		while ((row = reader.readLine()) != null) {
+			line++;
+			String[] columns = row.split(separator);
+			if (columns.length != 3) {
+				logger.warn("Skipping line in index: " + line);
+				continue;
+			}
+			String name = columns[0];
+			String location = columns[1];
+			String fileName = columns[2];
+			SurvivorshipDataSet data = new SurvivorshipDataSet();
+			data.setName(name);
+			data.setLocation(location);
+			data.setLocalPath(getFilePath(fileName));
+			demographyMap.put(name.toLowerCase(), data);
+		}
+		reader.close();
+		
+		logger.debug("index loaded: " + demographyMap);
+	}
+	
+	protected String getFilePath(String fileName) {
+		//return getPathToParentDirectory() + File.separator + getSpeciesDirectoryName() + File.separator + fileName;
+		return getPathToParentDirectory() + File.separator + fileName;
+	}
+
+	public String getPathToParentDirectory() {
+		return pathToParentDirectory;
+	}
+
+	public void setPathToParentDirectory(String pathToParentDirectory) {
+		this.pathToParentDirectory = pathToParentDirectory;
+	}
+
+	
+	public boolean isInitialized() {
+
+		if (!initialized) {
+			logger.info("Initializing...");
+			logger.info("pathToParentDirectory: " + getPathToParentDirectory());
+			
+			logger.info("index file name: " + getIndexFileName());
+			try {
+				loadIndex(getIndexFileName(), getTokenSeparator());
+				initialized = true;
+				logger.info("Loaded " + demographyMap.size() + " demography files.");
+			}
+			catch (IOException e) {
+				logger.error("Cannot initialize.", e);
+			}
+		}
+		return initialized;
+	}
+	
+
+	public void setInitialized(boolean initialized) {
+		this.initialized = initialized;
+	}
+
+	public String getTokenSeparator() {
+		return tokenSeparator;
+	}
+
+	public void setTokenSeparator(String tokenSeparator) {
+		this.tokenSeparator = tokenSeparator;
+	}
+
+	/**
+	 * @return the indexFileName
+	 */
+	public String getIndexFileName() {
+		return indexFileName;
+	}
+
+	/**
+	 * @param indexFileName the indexFileName to set
+	 */
+	public void setIndexFileName(String indexFileName) {
+		this.indexFileName = indexFileName;
+	}
+
+	/**
+	 * @return the dataFormat
+	 */
+	public String getDataFormat() {
+		return dataFormat;
+	}
+
+	/**
+	 * @param dataFormat the dataFormat to set
+	 */
+	public void setDataFormat(String dataFormat) {
+		this.dataFormat = dataFormat;
+	}
+
+	/**
+	 * @return the demographyMap
+	 */
+	public Map<String, DataSet> getDemographyMap() {
+		return demographyMap;
+	}
+
+	/**
+	 * @param demographyMap the demographyMap to set
+	 */
+	public void setSpeciesMap(Map<String, DataSet> demographyMap) {
+		this.demographyMap = demographyMap;
+	}
+
+	/**
+	 * @return the description
+	 */
+	public String getDescription() {
+		return description;
+	}
+
+	/**
+	 * @param description the description to set
+	 */
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataProviderImpl.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataSet.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataSet.java	                        (rev 0)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataSet.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -0,0 +1,32 @@
+package edu.cornell.birds.is.bap.data.survivorship;
+
+import edu.cornell.birds.is.bap.data.DataSet;
+
+public class SurvivorshipDataSet extends DataSet {
+	
+	private String name;
+	private String location;
+
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	public String getLocation() {
+		return location;
+	}
+
+	public void setLocation(String location) {
+		this.location = location;
+	}
+	
+	@Override
+	public String getGUIDisplayName(){
+		return name;
+	}
+	
+}


Property changes on: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/data/survivorship/SurvivorshipDataSet.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/ptolemy/DataSetStringChoiceProvider.java
===================================================================
--- trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/ptolemy/DataSetStringChoiceProvider.java	2011-10-07 23:36:41 UTC (rev 28778)
+++ trunk/modules/science-pipes-backend/src/edu/cornell/birds/is/bap/ptolemy/DataSetStringChoiceProvider.java	2011-10-07 23:41:17 UTC (rev 28779)
@@ -4,7 +4,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import edu.cornell.birds.is.bap.data.akn.DataSet;
+import edu.cornell.birds.is.bap.data.DataSet;
 
 
 public class DataSetStringChoiceProvider implements StringChoiceProvider {
@@ -24,7 +24,7 @@
 		for (String key : datasetsMap.keySet()) {
 			DataSet ds = datasetsMap.get(key);
 			
-			String choice = ds.getCommonName() + " (" + ds.getSciName() + ")";
+			String choice = ds.getGUIDisplayName();
 			choiceMap.put(choice, key);
 			valueMap.put(key, choice);
 			this.choices[i] = choice; 



More information about the Kepler-cvs mailing list