Index: test/edu/ucsb/nceas/metacat/util/MetacatPopulatorTest.java
===================================================================
--- test/edu/ucsb/nceas/metacat/util/MetacatPopulatorTest.java	(revision 6537)
+++ test/edu/ucsb/nceas/metacat/util/MetacatPopulatorTest.java	(revision 6538)
@@ -77,8 +77,10 @@
             MetacatPopulator mp = new MetacatPopulator(
                     "http://knb.ecoinformatics.org/knb",  
                     /*"http://localhost:8080/knb"*/
-                    "http://knb-mn.ecoinformatics.org/knb/d1", 
-                    /*"msucci"*//*"connolly.301"*/ "frog", 
+                    "https://demo3.test.dataone.org/knb/d1/mn/v1", 
+                    //"https://knb-test-1.test.dataone.org/knb/d1/mn/v1", 
+                    /*"msucci"*//*"connolly.301"*/ 
+                    "tao.1.1", //"frog", 
                     "uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org", 
                     "kepler");
             mp.populate();
Index: lib/rome-0.9.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/rome-0.9.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/icu4j-3.4.4.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/icu4j-3.4.4.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/jenatest-2.5.5.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/jenatest-2.5.5.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/lucene-core-2.2.0.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/lucene-core-2.2.0.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/arq-extra-2.2.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/arq-extra-2.2.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/jena-2.5.5.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/jena-2.5.5.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/jdom-1.0.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/jdom-1.0.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/commons-logging-1.1.1.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/commons-logging-1.1.1.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/concurrent-jena-1.3.2.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/concurrent-jena-1.3.2.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/json-jena-1.0.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/json-jena-1.0.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/xmlParserAPIs-2.0.2.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/xmlParserAPIs-2.0.2.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/d1_libclient_java-0.6.4-SNAPSHOT.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: lib/foresite-1.0-SNAPSHOT.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/foresite-1.0-SNAPSHOT.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/commons-cli-1.0.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/commons-cli-1.0.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/d1_common_java-0.6.4-SNAPSHOT.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: lib/wstx-asl-3.0.0.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/wstx-asl-3.0.0.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/arq-2.2.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/arq-2.2.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/iri-0.5.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/iri-0.5.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/antlr-2.7.5.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/antlr-2.7.5.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: lib/commons-lang-2.6.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: lib/commons-lang-2.6.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java
===================================================================
--- src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java	(revision 6537)
+++ src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java	(revision 6538)
@@ -31,8 +31,12 @@
 import java.math.BigInteger;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Vector;
 
 import javax.activation.DataHandler;
@@ -45,6 +49,7 @@
 import org.dataone.client.MNode;
 import org.dataone.client.ObjectFormatCache;
 import org.dataone.client.auth.CertificateManager;
+import org.dataone.ore.ResourceMapFactory;
 import org.dataone.service.exceptions.NotFound;
 import org.dataone.service.types.v1.AccessPolicy;
 import org.dataone.service.types.v1.AccessRule;
@@ -58,6 +63,7 @@
 import org.dataone.service.types.v1.SystemMetadata;
 import org.dataone.service.types.v1.util.ChecksumUtil;
 import org.dataone.service.util.Constants;
+import org.dspace.foresite.ResourceMap;
 import org.ecoinformatics.datamanager.DataManager;
 import org.ecoinformatics.datamanager.database.DatabaseConnectionPoolInterface;
 import org.ecoinformatics.datamanager.parser.DataPackage;
@@ -79,6 +85,7 @@
     private String username = null;
     private String password = null;
     private Session session = null;
+    private String subjectDN = null;
     
     /**
      * create a new MetacatPopulator with given source and destination urls.  
@@ -100,6 +107,7 @@
         this.destinationUrl = destUrl;
         // TODO: use specific certificate?
         this.session = null; //new Session();
+        this.subjectDN = CertificateManager.getInstance().getSubjectDN(CertificateManager.getInstance().loadCertificate());
     }
     
     /**
@@ -130,8 +138,12 @@
         MNode mn = D1Client.getMN(destinationUrl + "/");
         
         printHeader("Processing " + docs.size() + " results.");
-        for(int i=0; i<docs.size(); i++)
-        {
+        for (int i=0; i<docs.size(); i++) {
+        	
+        	// for generating the ORE map
+            Map<Identifier, List<Identifier>> idMap = new HashMap<Identifier, List<Identifier>>();
+            List<Identifier> dataIds = new ArrayList<Identifier>();
+            
             //for each document in the query
             Document doc = docs.get(i);
             String docid = doc.docid;
@@ -147,30 +159,28 @@
         	DataManager dataManager = DataManager.getInstance(connectionPool, connectionPool.getDBAdapterName());
         	DataPackage dataPackage = dataManager.parseMetadata(is);
         	
-            if (dataPackage == null)
-            {
+            if (dataPackage == null) {
                 continue;
             }
+            
             //go through the DistributionMetadata and download any described data
-            
             is = stringToStream(doctext);
             doc.doctext = doctext;
 
             printHeader("creating document on destination " + destinationUrl);            
             SystemMetadata sysmeta = generateSystemMetadata(doc);
+            
+            // iterate through the data objects
             if (dataPackage.getEntityList() != null) {
-	            for(int j=0; j < dataPackage.getEntityList().length; j++)
-	            {
+	            for (int j=0; j < dataPackage.getEntityList().length; j++) {
 	                String dataDocUrl = dataPackage.getEntityList()[j].getURL();
-	                String dataDocMimeType = 
-	                	dataPackage.getEntityList()[j].getDataFormat();
+	                String dataDocMimeType = dataPackage.getEntityList()[j].getDataFormat();
 	                if (dataDocMimeType == null) {
 		                dataDocMimeType = 
 		                	ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue();
 	                }
 	                String dataDocLocalId = "";
-	                if(dataDocUrl.trim().startsWith("ecogrid://knb/"))
-	                { //we only handle ecogrid urls right now
+	                if (dataDocUrl.trim().startsWith("ecogrid://knb/")) { //we only handle ecogrid urls right now
 	                    dataDocLocalId = dataDocUrl.substring(dataDocUrl.indexOf("ecogrid://knb/") + 
 	                            "ecogrid://knb/".length(), dataDocUrl.length());
 	                    //get the file
@@ -182,11 +192,8 @@
 	                    Identifier did = new Identifier();
 	                    did.setValue(dataDocLocalId);
 	                    
-	                    //add the desribeby to the eml's sysmeta
-	                    // TODO Use ORE
-//	                    System.out.println("adding describe for doc " + 
-//	                            sysmeta.getIdentifier().getValue() + " :" + did.getValue());
-//	                    sysmeta.addDescribe(did);
+	                    // add the data identifier for ORE map 
+	                    dataIds.add(did);
 	                    
 	                    //create sysmeta for the data doc                    
 	                    SystemMetadata dataDocSysMeta = generateSystemMetadata(doc);
@@ -205,37 +212,30 @@
 	                    String sizeStr = 
 	                    	Long.toString(dataDocText.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
 	                    dataDocSysMeta.setSize(new BigInteger(sizeStr));
-	                    // TODO use ORE map
-	                    //dataDocSysMeta.addDescribedBy(sysmeta.getIdentifier());
+
 	                    boolean error = false;
 	                    
 	                    //create the data doc on d1
-	                    try
-	                    {
+	                    try {
 	                        mn.create(session, dataDocSysMeta.getIdentifier(), IOUtils.toInputStream(dataDocText), dataDocSysMeta);
 	                    }
-	                    catch(Exception e)
-	                    {
+	                    catch(Exception e) {
 	                        error = true;
 	                        System.out.println("ERROR: Could not create data document with id " + 
 	                                dataDocSysMeta.getIdentifier().getValue() + " : " + e.getMessage());
 	                    }
-	                    finally
-	                    {
-	                        if (error)
-	                        {
+	                    finally {
+	                        if (error) {
 	                            printHeader("Insertion of document " + dataDocSysMeta.getIdentifier().getValue() + 
 	                                    "FAILED.");
 	                        }
-	                        else
-	                        {
+	                        else {
 	                            printHeader("Done inserting document " + dataDocSysMeta.getIdentifier().getValue() +
 	                                " which is described by " + sysmeta.getIdentifier().getValue());
 	                        }
 	                    }
 	                }
-	                else
-	                {
+	                else {
 	                    System.out.println("WARNING: Could not process describes url " +
 	                            dataDocUrl + " for document " + doc.docid + 
 	                    ".  Only ecogrid://knb/ urls are currently supported.");
@@ -243,23 +243,39 @@
 	            }
             }
             
-            try
-            {
-              Identifier id = mn.create(session, sysmeta.getIdentifier(), 
-                    IOUtils.toInputStream(doc.doctext), sysmeta);
+            try {
+              Identifier id = 
+            	  mn.create(session, sysmeta.getIdentifier(), IOUtils.toInputStream(doc.doctext), sysmeta);
               System.out.println("Success inserting document " + id.getValue());
               
+              // no need for an ORE map if there's no data
+              if (!dataIds.isEmpty()) {
+	              // generate the ORE map for this datapackage
+	              Identifier resourceMapId = new Identifier();
+	              resourceMapId.setValue("resourceMap_" + sysmeta.getIdentifier().getValue());
+	              idMap.put(sysmeta.getIdentifier(), dataIds);
+	              ResourceMap rm = ResourceMapFactory.getInstance().createResourceMap(resourceMapId, idMap);
+	              String resourceMapXML = ResourceMapFactory.getInstance().serializeResourceMap(rm);
+	              Document rmDoc = new Document(resourceMapId.getValue(), "http://www.openarchives.org/ore/terms", "", "");
+	              rmDoc.doctext = resourceMapXML;
+	              SystemMetadata resourceMapSysMeta = generateSystemMetadata(rmDoc);
+	              mn.create(session, resourceMapId, IOUtils.toInputStream(resourceMapXML), resourceMapSysMeta);
+	              
+	              // clean up the permissions (FORCE public read)
+	              for (Identifier dataId: dataIds) {
+	            	  mn.setAccessPolicy(session, dataId, sysmeta.getAccessPolicy());
+	            	  System.out.println("Set public access policy for: " + dataId.getValue());
+	              }
             }
-            catch(Exception e)
-            {
+              
+            }
+            catch(Exception e) {
                 e.printStackTrace();
                 System.out.println("Could not create document with id " + 
                         sysmeta.getIdentifier().getValue() + " : " + e.getMessage());
-                
             }
-            finally
-            {
-                printHeader("Done inserting document " + sysmeta.getIdentifier().getValue());
+            finally {
+                printHeader("Done processing document " + sysmeta.getIdentifier().getValue());
             }
         }
         
@@ -273,8 +289,7 @@
      * @return
      */
     private SystemMetadata generateSystemMetadata(Document doc)
-      throws Exception
-    {
+      throws Exception {
         SystemMetadata sm = new SystemMetadata();
         //set the id
         Identifier id = new Identifier();
@@ -283,14 +298,11 @@
         
         //set the object format
         ObjectFormat format = ObjectFormatCache.getInstance().getFormat(doc.doctype);
-        if(format == null)
-        {
-            if(doc.doctype.trim().equals("BIN"))
-            {
+        if (format == null) {
+            if (doc.doctype.trim().equals("BIN")) {
                 format = ObjectFormatCache.getInstance().getFormat("application/octet-stream");
             }
-            else
-            {
+            else {
                 format = ObjectFormatCache.getInstance().getFormat("text/plain");
             }
         }
@@ -305,20 +317,18 @@
         String sizeStr = Long.toString(doc.doctext.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
         sm.setSize(new BigInteger(sizeStr));
         
-        //submitter
+        //submitter, rights holder
         Subject p = new Subject();
-        p.setValue("unknown");
+        p.setValue(subjectDN);
         sm.setSubmitter(p);
         sm.setRightsHolder(p);
-        try
-        {
+        try {
             Date dateCreated = parseMetacatDate(doc.createDate);
             sm.setDateUploaded(dateCreated);
             Date dateUpdated = parseMetacatDate(doc.updateDate);
             sm.setDateSysMetadataModified(dateUpdated);
         }
-        catch(Exception e)
-        {
+        catch(Exception e) {
             System.out.println("couldn't parse a date: " + e.getMessage());
             Date dateCreated = new Date();
             sm.setDateUploaded(dateCreated);
@@ -338,18 +348,16 @@
         subject.setValue(Constants.SUBJECT_PUBLIC);
 		accessRule.addSubject(subject);
 		accessPolicy.addAllow(accessRule);
+		
 		sm.setAccessPolicy(accessPolicy);
         
         return sm;
     }
     
-    private void printHeader(String s)
-    {
+    private void printHeader(String s) {
         System.out.println("****** " + s + " *******");
     }
     
-    
-    
     /**
      * parse the metacat date which looks like 2010-06-08 (YYYY-MM-DD) into
      * a proper date object
