@@ -99,6 +99,8 @@ public class DVUploader extends AbstractUploader {
99
99
private static boolean directUpload = true ;
100
100
private static boolean trustCerts = false ;
101
101
private static boolean singleFile = false ;
102
+
103
+ private String fixityAlgorithm = "MD5" ;
102
104
103
105
private int timeout = 1200 ;
104
106
private int httpConcurrency = 4 ;
@@ -225,7 +227,54 @@ public boolean parseCustomArg(String arg) {
225
227
}
226
228
return false ;
227
229
}
230
+
231
+
232
+ @ Override
233
+ public void processRequests () {
234
+ httpclient = getSharedHttpClient ();
235
+
236
+ try {
237
+ // This api call will check for the fixityAlgorithm. Before v5.14, Dataverse servers should respond with a 404 and we'll use the default.
238
+ // http://$SERVER/api/files/fixityAlgorithm
239
+
240
+ String serviceUrl = server + "/api/files/fixityAlgorithm" ;
241
+ HttpGet httpget = new HttpGet (serviceUrl );
228
242
243
+ CloseableHttpResponse response = httpclient .execute (httpget , getLocalContext ());
244
+ try {
245
+ switch (response .getStatusLine ().getStatusCode ()) {
246
+ case 200 :
247
+ HttpEntity resEntity = response .getEntity ();
248
+ if (resEntity != null ) {
249
+ String res = EntityUtils .toString (resEntity );
250
+ String alg = (new JSONObject (res )).getJSONObject ("data" ).getString ("message" );
251
+ try {
252
+ MessageDigest .getInstance (alg );
253
+ fixityAlgorithm = alg ;
254
+ println ("Using FixityAlgorithm configured for this Dataverse: " + fixityAlgorithm );
255
+ } catch (NoSuchAlgorithmException e ) {
256
+ println ("Unknown FixityAlgorithm requested by this Dataverse: " + alg + ", using the default: " + fixityAlgorithm );
257
+ }
258
+ }
259
+ break ;
260
+ case 404 :
261
+ println ("FixityAlgorithm API call not available, using the default: " + fixityAlgorithm );
262
+ break ;
263
+ default :
264
+ // Report unexpected errors and assume dataset doesn't exist
265
+ println ("Error response when checking for fixityAlgorithm: "
266
+ + response .getStatusLine ().getReasonPhrase ());
267
+ break ;
268
+ }
269
+ } finally {
270
+ response .close ();
271
+ }
272
+ } catch (IOException e ) {
273
+ println ("Error processing fixityAlgorithm API request: " + e .getMessage ());
274
+ }
275
+ super .processRequests ();
276
+ }
277
+
229
278
private ZipFile zf = null ;
230
279
231
280
@ Override
@@ -951,7 +1000,7 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
951
1000
952
1001
httpput .addHeader ("x-amz-tagging" , "dv-state=temp" );
953
1002
try {
954
- MessageDigest messageDigest = MessageDigest .getInstance ("MD5" );
1003
+ MessageDigest messageDigest = MessageDigest .getInstance (fixityAlgorithm );
955
1004
956
1005
try (InputStream inStream = file .getInputStream (); DigestInputStream digestInputStream = new DigestInputStream (inStream , messageDigest )) {
957
1006
// This is hte new form for requests - keeping the example but won't update until we can change all
@@ -978,7 +1027,10 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
978
1027
jsonData .put ("storageIdentifier" , storageIdentifier );
979
1028
jsonData .put ("fileName" , file .getName ());
980
1029
jsonData .put ("mimeType" , file .getMimeType ());
981
- jsonData .put ("md5Hash" , localchecksum );
1030
+ JSONObject inputChecksumObject = new JSONObject ();
1031
+ inputChecksumObject .put ("@type" , fixityAlgorithm );
1032
+ inputChecksumObject .put ("@value" , localchecksum );
1033
+ jsonData .put ("checksum" , inputChecksumObject );
982
1034
jsonData .put ("fileSize" , file .length ());
983
1035
if (recurse ) {
984
1036
// Dataverse takes paths without an initial / and ending without a /
@@ -991,7 +1043,7 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
991
1043
}
992
1044
}
993
1045
file .setMetadata (jsonData );
994
- dataId = "md5 :" + localchecksum ;
1046
+ dataId = fixityAlgorithm + " :" + localchecksum ;
995
1047
}
996
1048
if (dataId != null ) {
997
1049
retries = 0 ;
@@ -1007,7 +1059,7 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
1007
1059
}
1008
1060
1009
1061
} catch (NoSuchAlgorithmException nsae ) {
1010
- println ("MD5 algorithm not found: " + nsae .getMessage ());
1062
+ println ("Fixity algorithm not found: " + nsae .getMessage ());
1011
1063
}
1012
1064
} else {
1013
1065
@@ -1027,11 +1079,11 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
1027
1079
HttpPartUploadJob .setHttpClientContext (getLocalContext ());
1028
1080
HttpPartUploadJob .setPartSize (maxPartSize );
1029
1081
1030
- //Create a map to store the eTags from the parts and the md5 calculated for the whole file
1082
+ //Create a map to store the eTags from the parts and the fixityAlg calculated for the whole file
1031
1083
Map <String , String > mpUploadInfoMap = new HashMap <String , String >(uploadUrls .length () + 1 );
1032
- //Setup a job to calculate the md5 hash of the file
1084
+ //Setup a job to calculate the fixityAlg hash of the file
1033
1085
//Probably helpful to have it run in parallel, but it could be a pre or post step as well. If the network is fast relative to disk, we may want the executor to use one extra thread for this
1034
- MD5Job mjob = new MD5Job (file , mpUploadInfoMap );
1086
+ DigestJob mjob = new DigestJob (file , mpUploadInfoMap , fixityAlgorithm );
1035
1087
executor .execute (mjob );
1036
1088
1037
1089
//Now set up upload jobs for each part
@@ -1075,15 +1127,15 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
1075
1127
break ;
1076
1128
}
1077
1129
}
1078
- //Technically, the uploads to S3 could succeed and only the md5 fails, but in this case we still want to abort the MP Upload, not complete it.
1079
- if (!mpUploadInfoMap .containsKey ("md5" )) {
1130
+ //Technically, the uploads to S3 could succeed and only the fixityAlg fails, but in this case we still want to abort the MP Upload, not complete it.
1131
+ if (!mpUploadInfoMap .containsKey (fixityAlgorithm )) {
1080
1132
fileUploadComplete = false ;
1081
1133
}
1082
1134
if (fileUploadComplete ) {
1083
1135
println ("Part uploads Completed for " + storageIdentifier );
1084
1136
HttpPut completeUpload = new HttpPut (server + completeUrl + "&key=" + apiKey );
1085
1137
JSONObject eTags = new JSONObject ();
1086
- ((Set <String >) mpUploadInfoMap .keySet ()).stream ().filter (partNo -> (!partNo .equals ("md5" ))).forEachOrdered (partNo -> {
1138
+ ((Set <String >) mpUploadInfoMap .keySet ()).stream ().filter (partNo -> (!partNo .equals (fixityAlgorithm ))).forEachOrdered (partNo -> {
1087
1139
eTags .put (partNo , mpUploadInfoMap .get (partNo ));
1088
1140
});
1089
1141
StringEntity body = new StringEntity (eTags .toString ());
@@ -1097,13 +1149,16 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
1097
1149
if (status == 200 ) {
1098
1150
println ("Successful upload of " + file .getAbsolutePath ());
1099
1151
if (singleFile ) {
1100
- dataId = registerFileWithDataverse (file , path , storageIdentifier , mpUploadInfoMap .get ("md5" ), retries );
1152
+ dataId = registerFileWithDataverse (file , path , storageIdentifier , mpUploadInfoMap .get (fixityAlgorithm ), retries );
1101
1153
} else {
1102
1154
JSONObject jsonData = new JSONObject ();
1103
1155
jsonData .put ("storageIdentifier" , storageIdentifier );
1104
1156
jsonData .put ("fileName" , file .getName ());
1105
1157
jsonData .put ("mimeType" , file .getMimeType ());
1106
- jsonData .put ("md5Hash" , mpUploadInfoMap .get ("md5" ));
1158
+ JSONObject inputChecksumObject = new JSONObject ();
1159
+ inputChecksumObject .put ("@type" , fixityAlgorithm );
1160
+ inputChecksumObject .put ("@value" , mpUploadInfoMap .get (fixityAlgorithm ));
1161
+ jsonData .put ("checksum" , inputChecksumObject );
1107
1162
jsonData .put ("fileSize" , file .length ());
1108
1163
if (recurse ) {
1109
1164
// Dataverse takes paths without an initial / and ending without a /
@@ -1116,7 +1171,7 @@ private String multipartDirectFileUpload(Resource file, String path, int retries
1116
1171
}
1117
1172
}
1118
1173
file .setMetadata (jsonData );
1119
- dataId = "md5 :" + mpUploadInfoMap .get ("md5" );
1174
+ dataId = fixityAlgorithm + " :" + mpUploadInfoMap .get (fixityAlgorithm );
1120
1175
}
1121
1176
} else {
1122
1177
println ("Partial upload of " + file .getAbsolutePath () + ", complete upload failed with status: " + status );
@@ -1171,7 +1226,10 @@ private String registerFileWithDataverse(Resource file, String path, String stor
1171
1226
jsonData .put ("storageIdentifier" , storageIdentifier );
1172
1227
jsonData .put ("fileName" , file .getName ());
1173
1228
jsonData .put ("mimeType" , file .getMimeType ());
1174
- jsonData .put ("md5Hash" , checksum );
1229
+ JSONObject inputChecksumObject = new JSONObject ();
1230
+ inputChecksumObject .put ("@type" , fixityAlgorithm );
1231
+ inputChecksumObject .put ("@value" , checksum );
1232
+ jsonData .put ("checksum" , inputChecksumObject );
1175
1233
jsonData .put ("fileSize" , file .length ());
1176
1234
if (recurse ) {
1177
1235
// Dataverse takes paths without an initial / and ending without a /
0 commit comments