@@ -92,7 +92,9 @@ public static void setupMocks() {
9292
9393 }
9494
95- /** A minimal example to assure that the XMLMetadataTemplate generates output consistent with the DataCite XML v4.5 schema.
95+ /**
96+ * A minimal example to assure that the XMLMetadataTemplate generates output
97+ * consistent with the DataCite XML v4.5 schema.
9698 */
9799 @ Test
98100 public void testDataCiteXMLCreation () throws IOException {
@@ -126,7 +128,7 @@ public void testDataCiteXMLCreation() throws IOException {
126128 doiMetadata .setAuthors (authors );
127129 doiMetadata .setPublisher ("Dataverse" );
128130 XmlMetadataTemplate template = new XmlMetadataTemplate (doiMetadata );
129-
131+
130132 Dataset d = new Dataset ();
131133 GlobalId doi = new GlobalId ("doi" , "10.5072" , "FK2/ABCDEF" , null , null , null );
132134 d .setGlobalId (doi );
@@ -159,11 +161,12 @@ public void testDataCiteXMLCreation() throws IOException {
159161 try {
160162 StreamSource source = new StreamSource (new StringReader (xml ));
161163 source .setSystemId ("DataCite XML for test dataset" );
162- assertTrue (XmlValidator .validateXmlSchema (source , new URL ("https://schema.datacite.org/meta/kernel-4/metadata.xsd" )));
164+ assertTrue (XmlValidator .validateXmlSchema (source ,
165+ new URL ("https://schema.datacite.org/meta/kernel-4/metadata.xsd" )));
163166 } catch (SAXException e ) {
164167 System .out .println ("Invalid schema: " + e .getMessage ());
165168 }
166-
169+
167170 }
168171
169172 /**
@@ -189,38 +192,39 @@ public void testDataCiteXMLCreationAllFields() throws IOException {
189192 dv .setVersionState (VersionState .DRAFT );
190193
191194 testDatasetField .setDatasetVersion (dv );
192-
195+
193196 File datasetVersionJson = new File ("src/test/java/edu/harvard/iq/dataverse/export/dataset-all-defaults.txt" );
194197 String datasetVersionAsJson = new String (Files .readAllBytes (Paths .get (datasetVersionJson .getAbsolutePath ())));
195198 JsonObject datasetJson = JsonUtil .getJsonObject (datasetVersionAsJson );
196-
197- GlobalId doi = new GlobalId ("doi" , datasetJson .getString ("authority" ), datasetJson .getString ("identifier" ), null , null , null );
199+
200+ GlobalId doi = new GlobalId ("doi" , datasetJson .getString ("authority" ), datasetJson .getString ("identifier" ),
201+ null , null , null );
198202 d .setGlobalId (doi );
199203
200-
201- List < DatasetField > fields = assertDoesNotThrow (() -> XmlMetadataTemplateTest .parseMetadataBlocks (datasetJson .getJsonObject ("datasetVersion" ).getJsonObject ("metadataBlocks" )));
204+ List < DatasetField > fields = assertDoesNotThrow (() -> XmlMetadataTemplateTest
205+ .parseMetadataBlocks (datasetJson .getJsonObject ("datasetVersion" ).getJsonObject ("metadataBlocks" )));
202206 dv .setDatasetFields (fields );
203-
207+
204208 ArrayList <DatasetVersion > dsvs = new ArrayList <>();
205209 dsvs .add (0 , dv );
206210 d .setVersions (dsvs );
207211 DatasetType dType = new DatasetType ();
208212 dType .setName (DatasetType .DATASET_TYPE_DATASET );
209213 d .setDatasetType (dType );
210- String xml = DOIDataCiteRegisterService .getMetadataFromDvObject (
211- dv . getDataset (). getGlobalId (). asString (), new DataCitation (dv ).getDataCiteMetadata (), dv .getDataset ());
214+ String xml = DOIDataCiteRegisterService .getMetadataFromDvObject (dv . getDataset (). getGlobalId (). asString (),
215+ new DataCitation (dv ).getDataCiteMetadata (), dv .getDataset ());
212216 System .out .println ("Output from dataset-all-defaults is " + xml );
213217 try {
214218 StreamSource source = new StreamSource (new StringReader (xml ));
215219 source .setSystemId ("DataCite XML for test dataset" );
216- assertTrue (XmlValidator .validateXmlSchema (source , new URL ("https://schema.datacite.org/meta/kernel-4/metadata.xsd" )));
220+ assertTrue (XmlValidator .validateXmlSchema (source ,
221+ new URL ("https://schema.datacite.org/meta/kernel-4/metadata.xsd" )));
217222 } catch (SAXException e ) {
218223 System .out .println ("Invalid schema: " + e .getMessage ());
219224 }
220-
225+
221226 }
222227
223-
224228 /**
225229 * Mock Utility Methods - These methods support importing DatasetFields from the
226230 * Dataverse JSON export format. They assume that any DatasetFieldType
@@ -230,9 +234,9 @@ public void testDataCiteXMLCreationAllFields() throws IOException {
230234 * references and DatasetFieldType-related error checking removed.
231235 */
232236 public static List <DatasetField > parseMetadataBlocks (JsonObject json ) throws JsonParseException {
233-
237+
234238 Map <String , DatasetFieldType > existingTypes = new HashMap <>();
235-
239+
236240 Set <String > keys = json .keySet ();
237241 List <DatasetField > fields = new LinkedList <>();
238242
@@ -259,18 +263,18 @@ private static List<DatasetField> parseFieldsFromArray(JsonArray fieldsArray, Bo
259263 }
260264 return fields ;
261265
262- }
266+ }
263267
264-
265- public static DatasetField parseField ( JsonObject json , Boolean testType , MetadataBlock block , Map <String , DatasetFieldType > existingTypes ) throws JsonParseException {
268+ public static DatasetField parseField ( JsonObject json , Boolean testType , MetadataBlock block ,
269+ Map <String , DatasetFieldType > existingTypes ) throws JsonParseException {
266270 if (json == null ) {
267271 return null ;
268272 }
269273
270274 DatasetField ret = new DatasetField ();
271275 String fieldName = json .getString ("typeName" , "" );
272276 String typeClass = json .getString ("typeClass" , "" );
273- if (!existingTypes .containsKey (fieldName )) {
277+ if (!existingTypes .containsKey (fieldName )) {
274278 boolean multiple = json .getBoolean ("multiple" );
275279 DatasetFieldType fieldType = new DatasetFieldType ();
276280 fieldType .setName (fieldName );
@@ -294,32 +298,35 @@ public static DatasetField parseField(JsonObject json, Boolean testType, Metad
294298
295299 return ret ;
296300 }
297-
298- public static void parseCompoundValue (DatasetField dsf , DatasetFieldType compoundType , JsonObject json , Boolean testType , MetadataBlock block , Map <String , DatasetFieldType > existingTypes ) throws JsonParseException {
301+
302+ public static void parseCompoundValue (DatasetField dsf , DatasetFieldType compoundType , JsonObject json ,
303+ Boolean testType , MetadataBlock block , Map <String , DatasetFieldType > existingTypes )
304+ throws JsonParseException {
299305 List <ControlledVocabularyException > vocabExceptions = new ArrayList <>();
300306 List <DatasetFieldCompoundValue > vals = new LinkedList <>();
301307 if (compoundType .isAllowMultiples ()) {
302308 int order = 0 ;
303309 try {
304310 json .getJsonArray ("value" ).getValuesAs (JsonObject .class );
305311 } catch (ClassCastException cce ) {
306- throw new JsonParseException ("Invalid values submitted for " + compoundType .getName () + ". It should be an array of values." );
312+ throw new JsonParseException ("Invalid values submitted for " + compoundType .getName ()
313+ + ". It should be an array of values." );
307314 }
308315 for (JsonObject obj : json .getJsonArray ("value" ).getValuesAs (JsonObject .class )) {
309316 DatasetFieldCompoundValue cv = new DatasetFieldCompoundValue ();
310317 List <DatasetField > fields = new LinkedList <>();
311318 for (String fieldName : obj .keySet ()) {
312319 JsonObject childFieldJson = obj .getJsonObject (fieldName );
313- DatasetField f = null ;
320+ DatasetField f = null ;
314321 try {
315322 f = parseField (childFieldJson , testType , block , existingTypes );
316- } catch (ControlledVocabularyException ex ) {
323+ } catch (ControlledVocabularyException ex ) {
317324 vocabExceptions .add (ex );
318325 }
319-
320- if (f != null ) {
326+
327+ if (f != null ) {
321328 f .setParentDatasetFieldCompoundValue (cv );
322- fields .add (f );
329+ fields .add (f );
323330 }
324331 }
325332 if (!fields .isEmpty ()) {
@@ -330,22 +337,20 @@ public static void parseCompoundValue(DatasetField dsf, DatasetFieldType compoun
330337 order ++;
331338 }
332339
333-
334-
335340 } else {
336-
341+
337342 DatasetFieldCompoundValue cv = new DatasetFieldCompoundValue ();
338343 List <DatasetField > fields = new LinkedList <>();
339344 JsonObject value = json .getJsonObject ("value" );
340345 for (String key : value .keySet ()) {
341346 JsonObject childFieldJson = value .getJsonObject (key );
342347 DatasetField f = null ;
343348 try {
344- f = parseField (childFieldJson , testType , block , existingTypes );
345- } catch (ControlledVocabularyException ex ) {
349+ f = parseField (childFieldJson , testType , block , existingTypes );
350+ } catch (ControlledVocabularyException ex ) {
346351 vocabExceptions .add (ex );
347352 }
348- if (f != null ) {
353+ if (f != null ) {
349354 f .setParentDatasetFieldCompoundValue (cv );
350355 fields .add (f );
351356 }
@@ -354,10 +359,11 @@ public static void parseCompoundValue(DatasetField dsf, DatasetFieldType compoun
354359 cv .setChildDatasetFields (fields );
355360 vals .add (cv );
356361 }
357-
358- }
362+
363+ }
359364 if (!vocabExceptions .isEmpty ()) {
360- throw new CompoundVocabularyException ( "Invalid controlled vocabulary in compound field " , vocabExceptions , vals );
365+ throw new CompoundVocabularyException ("Invalid controlled vocabulary in compound field " , vocabExceptions ,
366+ vals );
361367 }
362368
363369 for (DatasetFieldCompoundValue dsfcv : vals ) {
@@ -366,13 +372,15 @@ public static void parseCompoundValue(DatasetField dsf, DatasetFieldType compoun
366372 dsf .setDatasetFieldCompoundValues (vals );
367373 }
368374
369- public static void parsePrimitiveValue (DatasetField dsf , DatasetFieldType dft , JsonObject json ) throws JsonParseException {
375+ public static void parsePrimitiveValue (DatasetField dsf , DatasetFieldType dft , JsonObject json )
376+ throws JsonParseException {
370377 List <DatasetFieldValue > vals = new LinkedList <>();
371378 if (dft .isAllowMultiples ()) {
372- try {
373- json .getJsonArray ("value" ).getValuesAs (JsonObject .class );
379+ try {
380+ json .getJsonArray ("value" ).getValuesAs (JsonObject .class );
374381 } catch (ClassCastException cce ) {
375- throw new JsonParseException ("Invalid values submitted for " + dft .getName () + ". It should be an array of values." );
382+ throw new JsonParseException (
383+ "Invalid values submitted for " + dft .getName () + ". It should be an array of values." );
376384 }
377385 for (JsonString val : json .getJsonArray ("value" ).getValuesAs (JsonString .class )) {
378386 DatasetFieldValue datasetFieldValue = new DatasetFieldValue (dsf );
@@ -382,10 +390,12 @@ public static void parsePrimitiveValue(DatasetField dsf, DatasetFieldType dft ,
382390 }
383391
384392 } else {
385- try {json .getString ("value" );}
386- catch (ClassCastException cce ) {
387- throw new JsonParseException ("Invalid value submitted for " + dft .getName () + ". It should be a single value." );
388- }
393+ try {
394+ json .getString ("value" );
395+ } catch (ClassCastException cce ) {
396+ throw new JsonParseException (
397+ "Invalid value submitted for " + dft .getName () + ". It should be a single value." );
398+ }
389399 DatasetFieldValue datasetFieldValue = new DatasetFieldValue ();
390400 datasetFieldValue .setValue (json .getString ("value" , "" ).trim ());
391401 datasetFieldValue .setDatasetField (dsf );
@@ -394,15 +404,17 @@ public static void parsePrimitiveValue(DatasetField dsf, DatasetFieldType dft ,
394404
395405 dsf .setDatasetFieldValues (vals );
396406 }
397-
398- public static void parseControlledVocabularyValue (DatasetField dsf , DatasetFieldType cvvType , JsonObject json ) throws JsonParseException {
407+
408+ public static void parseControlledVocabularyValue (DatasetField dsf , DatasetFieldType cvvType , JsonObject json )
409+ throws JsonParseException {
399410 List <ControlledVocabularyValue > vals = new LinkedList <>();
400411 try {
401412 if (cvvType .isAllowMultiples ()) {
402413 try {
403414 json .getJsonArray ("value" ).getValuesAs (JsonObject .class );
404415 } catch (ClassCastException cce ) {
405- throw new JsonParseException ("Invalid values submitted for " + cvvType .getName () + ". It should be an array of values." );
416+ throw new JsonParseException (
417+ "Invalid values submitted for " + cvvType .getName () + ". It should be an array of values." );
406418 }
407419 for (JsonString strVal : json .getJsonArray ("value" ).getValuesAs (JsonString .class )) {
408420 String strValue = strVal .getString ();
@@ -416,7 +428,8 @@ public static void parseControlledVocabularyValue(DatasetField dsf, DatasetField
416428 try {
417429 json .getString ("value" );
418430 } catch (ClassCastException cce ) {
419- throw new JsonParseException ("Invalid value submitted for " + cvvType .getName () + ". It should be a single value." );
431+ throw new JsonParseException (
432+ "Invalid value submitted for " + cvvType .getName () + ". It should be a single value." );
420433 }
421434 String strValue = json .getString ("value" , "" );
422435 ControlledVocabularyValue cvv = new ControlledVocabularyValue ();
0 commit comments