package org.ecoinformatics.datamanager; import java.io.File; import java.io.FileWriter; import java.util.Iterator; import java.util.Map; import java.util.TreeMap; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.ecoinformatics.datamanager.download.EcogridEndPointInterfaceTest; import org.ecoinformatics.ecogrid.EcogridObjType; import org.ecoinformatics.ecogrid.client.PutServiceClient; public class DataPackagePopulator extends TestCase { public static Log log = LogFactory.getLog(DataPackagePopulator.class); //data file generation constants private static final String EOLCharacter = "\n"; private static final String RECORD_SEP = ","; private static final String DOCID_PREFIX = "union"; private static final int DOCID_SEED = 13; private static final String DATA_FILE_DIR = "/Users/leinfelder/temp"; private final int fileCount = 100; private final int recordCount = 5000; private final int columnCount = 6; //metadata file vars private static final String DOC_ID = "leinfelder.252.2"; private static final String ATTR_LIST_ID = "FIRST1234"; private String sessionId = "4C87FB06241B30A6D26C7B9503FF5F0C"; private EcogridEndPointInterfaceTest endPointInfo = null; /* * Constructors */ /** * Because DataManagerTest is a subclass of TestCase, it must provide a * constructor with a String parameter. * * @param name * the name of a test method to run */ public DataPackagePopulator(String name) { super(name); } /* * Class methods */ /** * Create a suite of tests to be run together. */ public static Test suite() { TestSuite testSuite = new TestSuite(); testSuite.addTest(new DataPackagePopulator("initialize")); testSuite.addTest(new DataPackagePopulator("insertData")); return testSuite; } /* * Instance methods */ /** * Run an initial test that always passes to check that the test harness is * working. */ public void initialize() { assertTrue(1 == 1); } /** * Establish a testing framework by initializing appropriate objects. */ public void setUp() throws Exception { super.setUp(); endPointInfo = new EcogridEndPointInterfaceTest(); } /** * Release any objects after tests are complete. */ public void tearDown() throws Exception { super.tearDown(); } private Map uploadFiles(File dir) throws Exception { log.debug("uploading files in dir=" + dir.getAbsolutePath()); //the return map includes the (docid,file) key/value pairs Map fileMap = new TreeMap(); //TODO get authentication working here with ecogrid //EcogridAuthClient auth = new EcogridAuthClient(endPointInfo.getMetacatEcogridAuthEndPoint()); //String sessionId = auth.login_action("kepler", "kepler"); log.debug("sessionId=" + sessionId); //String sessionId = null; PutServiceClient putClient = new PutServiceClient(endPointInfo.getMetacatEcogridPutEndPoint()); log.debug("created put client=" + putClient); //go through the files and upload them File[] files = dir.listFiles(); for (int i=0; i" + " " + "union test data" + " leinfelder" + "" + "" + " " + "" + "1191029010870" + "" + "public" + "read" + "" + "" + "seed.csv" + "seed" + "seed.csv" + "277" + "1" + "#x0A" + "column" + "," + "" + "" + "" + "ecogrid://knb/leinfelder.9.1" + "" + "" + "" + "" + "column0" + "unique id of the question (systemwide)" + "integer" + "dimensionless" + "" + "1" + "integer" + "" + "" + "" + "" + "column1" + "unique student id" + "integer" + "dimensionless" + "" + "1" + "integer" + "" + "" + "" + "" + "column2" + "unique student id" + "integer" + "dimensionless" + "" + "1" + "integer" + "" + "" + "" + "" + "column3" + "numeric score earned on question" + "integer" + "dimensionless" + "" + "1" + "integer" + "" + "" + "" + "" + "column4" + "numeric score earned on question" + "integer" + "dimensionless" + "" + "1" + "integer" + "" + "" + "" + "" + "column5" + "numeric score earned on question" + "integer" + "dimensionless" + "" + "1" + "integer" + "" + "" + "" + "" + "" + "99" + ""; openingXML = openingXML.replaceAll("#packageId#", DOC_ID); openingXML = openingXML.replaceAll("#attributeListId#", ATTR_LIST_ID); String middleXML = ""; //add the other packages Iterator fileIter = fileMap.keySet().iterator(); while (fileIter.hasNext()) { //get the body of the dataTable element String dataTableTemplate = "#fileName#" + "#fileName#" + "#fileName#" + "#size#" + "1" + "#x0A" + "column" + "," + "" + "" + "" + "ecogrid://knb/#docid#" + "" + "" + "" + "" + "#attributeListId#" + "" + "#recordCount#" + ""; //get the info from the map entry String docid = (String) fileIter.next(); File f = (File) fileMap.get(docid); //do som subsitution dataTableTemplate = dataTableTemplate.replaceAll("#docid#", docid); dataTableTemplate = dataTableTemplate.replaceAll("#fileName#", f.getName() ); dataTableTemplate = dataTableTemplate.replaceAll("#size#", String.valueOf(f.length()) ); dataTableTemplate = dataTableTemplate.replaceAll("#recordCount#", String.valueOf(recordCount) ); dataTableTemplate = dataTableTemplate.replaceAll("#attributeListId#", ATTR_LIST_ID); //tack it on middleXML += dataTableTemplate; } //get the closing of the xml String closingXML = "" + ""; return openingXML + middleXML + closingXML; } }