Skip to content

Commit

Permalink
Version 0.3.0 which adds support for the creation and linking of anal…
Browse files Browse the repository at this point in the history
…og instances along with some other minor fixes.
  • Loading branch information
Nathan Stevens committed Aug 20, 2015
1 parent 93aca11 commit be046d8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/org/nyu/edu/dlts/dbCopyFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private void initComponents() {
CellConstraints cc = new CellConstraints();

//======== this ========
setTitle("Archon Data Migrator (ALPHA v0.2.0 08-07-2015)");
setTitle("Archon Data Migrator (v0.3.0 08-19-2015)");
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());

Expand Down
2 changes: 1 addition & 1 deletion src/org/nyu/edu/dlts/dbCopyFrame.jfd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</object>
<void method="setProperty">
<string>title</string>
<string>Archon Data Migrator (ALPHA v0.2.0 08-07-2015)</string>
<string>Archon Data Migrator (v0.3.0 08-19-2015)</string>
</void>
<void method="add">
<object class="com.jformdesigner.model.FormContainer">
Expand Down
61 changes: 39 additions & 22 deletions src/org/nyu/edu/dlts/utils/ASpaceCopyUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.nyu.edu.dlts.utils;

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.httpclient.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -113,9 +112,11 @@ public class ASpaceCopyUtil implements PrintConsole {
// integer to keep track of total number of aspace client threads
private int totalASpaceClients = 1;

// integers to keeps track of the number of digital objects copied
// integers to keeps track of the number of digital objects and locations copied
private int digitalObjectTotal = 0;
private int digitalObjectSuccess = 0;
private int locationTotal = 0;
private int locationSuccess = 0;

// boolean to specify weather to save digital objects by themselves or with the resource records
boolean saveDigitalObjectsWithResources = true;
Expand Down Expand Up @@ -1119,7 +1120,7 @@ public void copyAccessionRecords() throws Exception {

// add an instance that holds the location information
if(accession.has("Locations")) {
addAccessionInstances(accessionJS, accession.getJSONArray("Locations"), accessionTitle);
addLocationInstances(accessionJS, accession.getJSONArray("Locations"), "accession");
}

String uri = repoURI + ASpaceClient.ACCESSION_ENDPOINT;
Expand Down Expand Up @@ -1507,6 +1508,11 @@ public void copyCollectionRecords(int max) throws Exception {
// add the linked accessions
addRelatedAccessions(resourceJS, dbId, arId, repoURI + "/");

// add an instance that holds the location information
if(collection.has("Locations")) {
addLocationInstances(resourceJS, collection.getJSONArray("Locations"), "text");
}

// if we using batch import then we not not going to
resourceJS.put("uri", endpoint + "/" + dbId);
resourceJS.put("jsonmodel_type", "resource");
Expand Down Expand Up @@ -1645,8 +1651,11 @@ public void copyCollectionRecords(int max) throws Exception {
// update the number of digital records that were copied during processing of collection records
updateRecordTotals("Instance Digital Objects", digitalObjectTotal, digitalObjectSuccess);

// update the number of location records copied
updateRecordTotals("Locations", locationTotal, locationSuccess);

// update the number of resource actually copied
updateRecordTotals("Resource Records", total, copyCount);
updateRecordTotals("Collections", total, copyCount);

// TODO -- remove debug code below
System.out.println("\n\nMaximum Batch Length: " + maxBatchLength + " records");
Expand Down Expand Up @@ -1701,13 +1710,19 @@ private void addInstancesForPhysicalComponents(HashSet<String> createdInstances,
} else {
JSONObject parentJS = intellectualComponents.get("" + topParentId);
if(parentJS.has("instances")) {
instancesJA = resourceJS.getJSONArray("instances");
instancesJA = parentJS.getJSONArray("instances");
}

createInstance(null, containerList, instancesJA, parentJS.getString("title"));
}
}

//debug code
if(containerList.size() > 1) {
String message = "Multi-level container processed: " + componentId;
addErrorMessage(message);
}

print("Creating Instance: " + componentId + " Added to Parent: " + parentId);
}
}
Expand Down Expand Up @@ -2155,26 +2170,25 @@ private void addClassifications(String repoURI, JSONObject json, JSONArray class
}

/**
* Method to add an instance to an Accession record
* Method to add an instance to an Accession or Resource record whick hold location information
*
* @param accessionJS
* @param recordJS
* @param locations
* @param accessionTitle
*/
private void addAccessionInstances(JSONObject accessionJS, JSONArray locations, String accessionTitle) throws Exception {
private void addLocationInstances(JSONObject recordJS, JSONArray locations, String instanceType) throws Exception {
JSONArray instancesJA = new JSONArray();

for (int i = 0; i < locations.length(); i++) {
JSONObject instanceJS = new JSONObject();
JSONObject location = locations.getJSONObject(i);

// set the type
instanceJS.put("instance_type", "accession");
instanceJS.put("instance_type", instanceType);

// add the container now
JSONObject containerJS = new JSONObject();

containerJS.put("type_1", "object");
containerJS.put("type_1", "box");
containerJS.put("indicator_1", location.get("Content"));

// add the extent information
Expand Down Expand Up @@ -2214,7 +2228,7 @@ private void addAccessionInstances(JSONObject accessionJS, JSONArray locations,

// if we had any instances add them parent json record
if (instancesJA.length() != 0) {
accessionJS.put("instances", instancesJA);
recordJS.put("instances", instancesJA);
}
}

Expand Down Expand Up @@ -2259,11 +2273,14 @@ private String getLocationURI(String building, String coordinate1, String coordi
if(locationURIMap.containsKey(key)) {
return locationURIMap.get(key);
} else {
locationTotal++;

String id = saveRecord(ASpaceClient.LOCATION_ENDPOINT, locationJS.toString(), "Location->" + key);

if (!id.equalsIgnoreCase(NO_ID)) {
String uri = ASpaceClient.LOCATION_ENDPOINT + "/" + id;
locationURIMap.put(key, uri);
locationSuccess++;
print("Copied Location: " + key + " :: " + id);
return uri;
} else {
Expand Down Expand Up @@ -2906,8 +2923,8 @@ private String getIdFromURI(String uri) {
* @param args
*/
public static void main(String[] args) throws JSONException {
//String host = "http://archives-dev.library.illinois.edu/archondev/tracer";
String host = "http://localhost/~nathan/archon";
String host = "http://archives-dev.library.illinois.edu/archondev/tracer";
//String host = "http://localhost/~nathan/archon";
ArchonClient archonClient = new ArchonClient(host, "admin", "admin");

archonClient.getSession();
Expand All @@ -2931,24 +2948,24 @@ public static void main(String[] args) throws JSONException {
aspaceCopyUtil.copyEnumRecords();
aspaceCopyUtil.copyRepositoryRecords();
aspaceCopyUtil.mapRepositoryGroups();
/*aspaceCopyUtil.copyUserRecords();
aspaceCopyUtil.copyUserRecords();
aspaceCopyUtil.copySubjectRecords();
aspaceCopyUtil.copyCreatorRecords();
aspaceCopyUtil.copyClassificationRecords();
aspaceCopyUtil.findAccessionRecordRepositories();
aspaceCopyUtil.copyAccessionRecords(); */
aspaceCopyUtil.copyAccessionRecords();
aspaceCopyUtil.copyDigitalObjectRecords();
aspaceCopyUtil.copyCollectionRecords(100000);

// removed all unused classifications
//aspaceCopyUtil.deleteUnlinkedClassifications();
aspaceCopyUtil.downloadDigitalObjectFiles(new File("/Users/nathan/temp/archon_files"));

//aspaceCopyUtil.downloadDigitalObjectFiles(new File("/Users/nathan/temp/archon_files"));

// print out the error messages
System.out.println("\n\nSave Errors:\n" + aspaceCopyUtil.getSaveErrorMessages());
// removed all unused classifications
aspaceCopyUtil.deleteUnlinkedClassifications();
} catch (Exception e) {
e.printStackTrace();
}

// print out the error messages
System.out.println("\n\nSave Errors:\n" + aspaceCopyUtil.getSaveErrorMessages());
}
}
11 changes: 9 additions & 2 deletions src/org/nyu/edu/dlts/utils/ASpaceMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ public JSONObject mapEnumList(JSONObject enumList, String endpoint) throws Excep
}
}

// need to add other to extent unit type enum list
if(endpoint.contains("extentunits")) {
valuesJA.put(ASpaceEnumUtil.UNMAPPED);
}

if(count != 0) {
return dynamicEnumJS;
} else {
Expand Down Expand Up @@ -927,7 +932,7 @@ private void addResourceExtent(JSONObject record, JSONObject json) throws Except
JSONObject extentJS = new JSONObject();

extentJS.put("portion", "whole");
extentJS.put("extent_type", "linear_feet");
extentJS.put("extent_type", enumUtil.getASpaceExtentType(record.getInt("ExtentUnitID")));

if (!record.getString("Extent").isEmpty()) {
extentJS.put("number", record.getString("Extent"));
Expand All @@ -943,8 +948,10 @@ private void addResourceExtent(JSONObject record, JSONObject json) throws Except
extentJS = new JSONObject();

extentJS.put("portion", "whole");
extentJS.put("extent_type", "cubic_feet");
extentJS.put("extent_type", ASpaceEnumUtil.UNMAPPED);
extentJS.put("number", altExtent);

extentJA.put(extentJS);
}

json.put("extents", extentJA);
Expand Down

0 comments on commit be046d8

Please sign in to comment.