Skip to content

Commit de23c84

Browse files
committed
move sysmeta as param to dialect constructor
1 parent 04a5a88 commit de23c84

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/main/java/edu/ucsb/nceas/mdqengine/MDQEngine.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,8 @@ public Run runSuite(Suite suite, InputStream input, Map<String, Object> params,
9898

9999
String content = IOUtils.toString(input, "UTF-8");
100100
String metadataContent = content;
101-
// detect either json or xml, default xml
102-
String contentType = "xml";
103-
String formatId = sysMeta.getFormatId().getValue();
104101

105-
if (formatId.contains("json")){
106-
contentType = "json";
107-
}
108-
109-
MetadataDialect docDialect = MetadataDialectFactory.createDialect(contentType,
102+
MetadataDialect docDialect = MetadataDialectFactory.createDialect(sysMeta,
110103
IOUtils.toInputStream(metadataContent, "UTF-8"));
111104

112105
docDialect.setSystemMetadata(sysMeta);

src/main/java/edu/ucsb/nceas/mdqengine/processor/MetadataDialectFactory.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javax.xml.parsers.ParserConfigurationException;
77

8+
import org.dataone.service.types.v2.SystemMetadata;
89
import org.xml.sax.SAXException;
910

1011
/**
@@ -17,24 +18,28 @@ public class MetadataDialectFactory {
1718
/**
1819
* Creates a MetadataDialect implementation based on the provided content type.
1920
*
20-
* @param contentType the format identifier of the metadata (e.g., "xml" or "json")
21+
* @param contentType the format identifier of the metadata (e.g., "xml" or
22+
* "json")
2123
* @param metadataContent an InputStream of the metadata content to be parsed
22-
* @return The appropriate concrete implementation of the MetadataDialect according to content type.
24+
* @return The appropriate concrete implementation of the MetadataDialect
25+
* according to content type.
2326
* @throws IllegalArgumentException
2427
* @throws SAXException
2528
* @throws IOException
2629
* @throws ParserConfigurationException
2730
*/
28-
public static MetadataDialect createDialect(String contentType, InputStream metadataContent)
31+
public static MetadataDialect createDialect(SystemMetadata sysMeta, InputStream metadataContent)
2932
throws IllegalArgumentException, SAXException, IOException, ParserConfigurationException {
30-
switch (contentType.toLowerCase()) {
31-
case "xml":
32-
return new XMLDialect(metadataContent);
33-
case "json":
34-
return new JSONDialect(metadataContent);
35-
default:
36-
throw new IllegalArgumentException("Unsupported content type: " + contentType);
33+
34+
// detect either json or xml, default xml
35+
String formatId = sysMeta.getFormatId().getValue();
36+
37+
if (formatId.contains("json")) {
38+
return new JSONDialect(metadataContent);
39+
} else {
40+
return new XMLDialect(metadataContent);
3741
}
42+
3843
}
3944

4045
}

0 commit comments

Comments
 (0)