Search in sources :

Example 1 with SettingsServiceBean

use of edu.harvard.iq.dataverse.settings.SettingsServiceBean 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"));
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) DatasetField(edu.harvard.iq.dataverse.DatasetField) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) DatasetFieldCompoundValue(edu.harvard.iq.dataverse.DatasetFieldCompoundValue) LinkedList(java.util.LinkedList) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) Test(org.junit.Test)

Example 2 with SettingsServiceBean

use of edu.harvard.iq.dataverse.settings.SettingsServiceBean in project dataverse by IQSS.

the class RestrictFileCommandTest method setUp.

@Before
public void setUp() {
    dataset = makeDataset();
    file = makeDataFile();
    engine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public SettingsServiceBean settings() {
            return new SettingsServiceBean() {

                // override for a public install,
                // assume false
                @Override
                public boolean isTrueForKey(SettingsServiceBean.Key key, boolean defaultValue) {
                    return publicInstall;
                }
            };
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) Before(org.junit.Before)

Example 3 with SettingsServiceBean

use of edu.harvard.iq.dataverse.settings.SettingsServiceBean in project dataverse by IQSS.

the class DatasetFieldWalker method walk.

/**
 * Convenience method to walk over a field.
 * @param dsf the field to walk over.
 * @param l the listener to execute on {@code dsf}'s values and structure.
 */
public static void walk(DatasetField dsf, Listener l) {
    DatasetFieldWalker joe = new DatasetFieldWalker(l);
    SettingsServiceBean nullServiceBean = null;
    joe.walk(dsf, nullServiceBean);
}
Also used : SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean)

Aggregations

SettingsServiceBean (edu.harvard.iq.dataverse.settings.SettingsServiceBean)3 DatasetField (edu.harvard.iq.dataverse.DatasetField)1 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)1 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)1 MetadataBlock (edu.harvard.iq.dataverse.MetadataBlock)1 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)1 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 JsonObject (javax.json.JsonObject)1 Before (org.junit.Before)1 Test (org.junit.Test)1