use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class JsonPrinterTest method setUp.
@Before
public void setUp() {
datasetFieldTypeSvc = new JsonParserTest.MockDatasetFieldSvc();
DatasetFieldType titleType = datasetFieldTypeSvc.add(new DatasetFieldType("title", FieldType.TEXTBOX, false));
DatasetFieldType authorType = datasetFieldTypeSvc.add(new DatasetFieldType("author", FieldType.TEXT, true));
Set<DatasetFieldType> authorChildTypes = new HashSet<>();
authorChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("authorName", FieldType.TEXT, false)));
authorChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("authorAffiliation", FieldType.TEXT, false)));
authorChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("authorIdentifier", FieldType.TEXT, false)));
DatasetFieldType authorIdentifierSchemeType = datasetFieldTypeSvc.add(new DatasetFieldType("authorIdentifierScheme", FieldType.TEXT, false));
authorIdentifierSchemeType.setAllowControlledVocabulary(true);
authorIdentifierSchemeType.setControlledVocabularyValues(Arrays.asList(// FIXME: Why aren't these enforced? Should be ORCID, etc.
new ControlledVocabularyValue(1l, "foo", authorIdentifierSchemeType), new ControlledVocabularyValue(2l, "bar", authorIdentifierSchemeType), new ControlledVocabularyValue(3l, "baz", authorIdentifierSchemeType)));
authorChildTypes.add(datasetFieldTypeSvc.add(authorIdentifierSchemeType));
for (DatasetFieldType t : authorChildTypes) {
t.setParentDatasetFieldType(authorType);
}
authorType.setChildDatasetFieldTypes(authorChildTypes);
DatasetFieldType datasetContactType = datasetFieldTypeSvc.add(new DatasetFieldType("datasetContact", FieldType.TEXT, true));
Set<DatasetFieldType> datasetContactTypes = new HashSet<>();
datasetContactTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType(DatasetFieldConstant.datasetContactEmail, FieldType.EMAIL, false)));
datasetContactTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("datasetContactName", FieldType.TEXT, false)));
datasetContactTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("datasetContactAffiliation", FieldType.TEXT, false)));
for (DatasetFieldType t : datasetContactTypes) {
t.setParentDatasetFieldType(datasetContactType);
}
datasetContactType.setChildDatasetFieldTypes(datasetContactTypes);
DatasetFieldType keywordType = datasetFieldTypeSvc.add(new DatasetFieldType("keyword", DatasetFieldType.FieldType.TEXT, true));
DatasetFieldType descriptionType = datasetFieldTypeSvc.add(new DatasetFieldType("description", DatasetFieldType.FieldType.TEXTBOX, false));
DatasetFieldType subjectType = datasetFieldTypeSvc.add(new DatasetFieldType("subject", DatasetFieldType.FieldType.TEXT, true));
subjectType.setAllowControlledVocabulary(true);
subjectType.setControlledVocabularyValues(Arrays.asList(new ControlledVocabularyValue(1l, "mgmt", subjectType), new ControlledVocabularyValue(2l, "law", subjectType), new ControlledVocabularyValue(3l, "cs", subjectType)));
DatasetFieldType pubIdType = datasetFieldTypeSvc.add(new DatasetFieldType("publicationIdType", DatasetFieldType.FieldType.TEXT, false));
pubIdType.setAllowControlledVocabulary(true);
pubIdType.setControlledVocabularyValues(Arrays.asList(new ControlledVocabularyValue(1l, "ark", pubIdType), new ControlledVocabularyValue(2l, "doi", pubIdType), new ControlledVocabularyValue(3l, "url", pubIdType)));
DatasetFieldType compoundSingleType = datasetFieldTypeSvc.add(new DatasetFieldType("coordinate", DatasetFieldType.FieldType.TEXT, true));
Set<DatasetFieldType> childTypes = new HashSet<>();
childTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("lat", DatasetFieldType.FieldType.TEXT, false)));
childTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("lon", DatasetFieldType.FieldType.TEXT, false)));
for (DatasetFieldType t : childTypes) {
t.setParentDatasetFieldType(compoundSingleType);
}
compoundSingleType.setChildDatasetFieldTypes(childTypes);
// settingsSvc = new JsonParserTest.MockSettingsSvc();
// jsonPrinter = new JsonPrinter(settingsSvc);
}
use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class JsonPrinterTest method testDatasetContactOutOfBoxNoPrivacy.
@Test
public void testDatasetContactOutOfBoxNoPrivacy() {
MetadataBlock block = new MetadataBlock();
block.setName("citation");
List<DatasetField> fields = new ArrayList<>();
DatasetField datasetContactField = new DatasetField();
DatasetFieldType datasetContactDatasetFieldType = datasetFieldTypeSvc.findByName("datasetContact");
datasetContactDatasetFieldType.setMetadataBlock(block);
datasetContactField.setDatasetFieldType(datasetContactDatasetFieldType);
List<DatasetFieldCompoundValue> vals = new LinkedList<>();
DatasetFieldCompoundValue val = new DatasetFieldCompoundValue();
val.setParentDatasetField(datasetContactField);
val.setChildDatasetFields(Arrays.asList(constructPrimitive("datasetContactEmail", "foo@bar.com"), constructPrimitive("datasetContactName", "Foo Bar"), constructPrimitive("datasetContactAffiliation", "Bar University")));
vals.add(val);
datasetContactField.setDatasetFieldCompoundValues(vals);
fields.add(datasetContactField);
SettingsServiceBean nullServiceBean = null;
JsonPrinter jsonPrinter = new JsonPrinter(nullServiceBean);
JsonObject jsonObject = jsonPrinter.json(block, fields).build();
assertNotNull(jsonObject);
System.out.println("json: " + JsonUtil.prettyPrint(jsonObject.toString()));
assertEquals("Foo Bar", jsonObject.getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactName").getString("value"));
assertEquals("Bar University", jsonObject.getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactAffiliation").getString("value"));
assertEquals("foo@bar.com", jsonObject.getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactEmail").getString("value"));
JsonObject byBlocks = jsonPrinter.jsonByBlocks(fields).build();
System.out.println("byBlocks: " + JsonUtil.prettyPrint(byBlocks.toString()));
assertEquals("Foo Bar", byBlocks.getJsonObject("citation").getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactName").getString("value"));
assertEquals("Bar University", byBlocks.getJsonObject("citation").getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactAffiliation").getString("value"));
assertEquals("foo@bar.com", byBlocks.getJsonObject("citation").getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactEmail").getString("value"));
}
use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class JsonParserTest method setUp.
@Before
public void setUp() {
datasetFieldTypeSvc = new MockDatasetFieldSvc();
keywordType = datasetFieldTypeSvc.add(new DatasetFieldType("keyword", FieldType.TEXT, true));
descriptionType = datasetFieldTypeSvc.add(new DatasetFieldType("description", FieldType.TEXTBOX, false));
subjectType = datasetFieldTypeSvc.add(new DatasetFieldType("subject", FieldType.TEXT, true));
subjectType.setAllowControlledVocabulary(true);
subjectType.setControlledVocabularyValues(Arrays.asList(new ControlledVocabularyValue(1l, "mgmt", subjectType), new ControlledVocabularyValue(2l, "law", subjectType), new ControlledVocabularyValue(3l, "cs", subjectType)));
pubIdType = datasetFieldTypeSvc.add(new DatasetFieldType("publicationIdType", FieldType.TEXT, false));
pubIdType.setAllowControlledVocabulary(true);
pubIdType.setControlledVocabularyValues(Arrays.asList(new ControlledVocabularyValue(1l, "ark", pubIdType), new ControlledVocabularyValue(2l, "doi", pubIdType), new ControlledVocabularyValue(3l, "url", pubIdType)));
compoundSingleType = datasetFieldTypeSvc.add(new DatasetFieldType("coordinate", FieldType.TEXT, true));
Set<DatasetFieldType> childTypes = new HashSet<>();
childTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("lat", FieldType.TEXT, false)));
childTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("lon", FieldType.TEXT, false)));
for (DatasetFieldType t : childTypes) {
t.setParentDatasetFieldType(compoundSingleType);
}
compoundSingleType.setChildDatasetFieldTypes(childTypes);
settingsSvc = new MockSettingsSvc();
sut = new JsonParser(datasetFieldTypeSvc, null, settingsSvc);
}
use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class JsonParserTest method testControlledVocalRepeatsRoundTrip.
@Test
public void testControlledVocalRepeatsRoundTrip() throws JsonParseException {
DatasetField expected = new DatasetField();
DatasetFieldType fieldType = datasetFieldTypeSvc.findByName("subject");
expected.setDatasetFieldType(fieldType);
expected.setControlledVocabularyValues(Arrays.asList(fieldType.getControlledVocabularyValue("mgmt"), fieldType.getControlledVocabularyValue("law"), fieldType.getControlledVocabularyValue("cs")));
JsonObject json = JsonPrinter.json(expected);
DatasetField actual = sut.parseField(json);
assertFieldsEqual(expected, actual);
}
use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class JsonParser method parseMetadataBlocks.
public List<DatasetField> parseMetadataBlocks(JsonObject json) throws JsonParseException {
Set<String> keys = json.keySet();
List<DatasetField> fields = new LinkedList<>();
for (String blockName : keys) {
JsonObject blockJson = json.getJsonObject(blockName);
JsonArray fieldsJson = blockJson.getJsonArray("fields");
for (JsonObject fieldJson : fieldsJson.getValuesAs(JsonObject.class)) {
try {
fields.add(parseField(fieldJson));
} catch (CompoundVocabularyException ex) {
DatasetFieldType fieldType = datasetFieldSvc.findByNameOpt(fieldJson.getString("typeName", ""));
if (lenient && (DatasetFieldConstant.geographicCoverage).equals(fieldType.getName())) {
fields.add(remapGeographicCoverage(ex));
} else {
// if not lenient mode, re-throw exception
throw ex;
}
}
}
}
convertKeywordsToSubjects(fields);
return fields;
}
Aggregations