Search in sources :

Example 1 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    HttpServletRequest aHttpServletRequest = null;
    dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public AuthenticationServiceBean authentication() {
            return new AuthenticationServiceBean() {

                @Override
                public AuthenticatedUser getAuthenticatedUser(String id) {
                    return MocksFactory.makeAuthenticatedUser("First", "Last");
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new NoOpTestEntityManager();
        }

        @Override
        public DatasetServiceBean datasets() {
            return new DatasetServiceBean() {

                {
                    em = new NoOpTestEntityManager();
                }

                @Override
                public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
                    return null;
                }

                @Override
                public WorkflowComment addWorkflowComment(WorkflowComment comment) {
                    return comment;
                }

                @Override
                public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public PermissionServiceBean permissions() {
            return new PermissionServiceBean() {

                @Override
                public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
                    // We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
                    return Collections.emptyList();
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) Permission(edu.harvard.iq.dataverse.authorization.Permission) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 2 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class DDIExporterTest method testExportDataset.

@Test
public void testExportDataset() throws Exception {
    System.out.println("exportDataset");
    // FIXME: switch ddi/dataset-finch1.json
    // File datasetVersionJson = new File("src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.json");
    File datasetVersionJson = new File("src/test/resources/json/dataset-finch1.json");
    String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
    JsonReader jsonReader = Json.createReader(new StringReader(datasetVersionAsJson));
    JsonObject json = jsonReader.readObject();
    JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
    DatasetVersion version = jsonParser.parseDatasetVersion(json.getJsonObject("datasetVersion"));
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DDIExporter instance = new DDIExporter();
    boolean nullPointerFixed = false;
    if (nullPointerFixed) {
        instance.exportDataset(version, json, byteArrayOutputStream);
    }
    System.out.println("out: " + XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString()));
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser) Test(org.junit.Test)

Example 3 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class DDIExporterTest method testExportDatasetContactEmailAbsent.

@Test
public void testExportDatasetContactEmailAbsent() throws Exception {
    File datasetVersionJson = new File("src/test/java/edu/harvard/iq/dataverse/export/ddi/datasetContactEmailAbsent.json");
    String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
    JsonReader jsonReader = Json.createReader(new StringReader(datasetVersionAsJson));
    JsonObject json = jsonReader.readObject();
    // JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, settingsSvc);
    JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
    DatasetVersion version = jsonParser.parseDatasetVersion(json.getJsonObject("datasetVersion"));
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DDIExporter instance = new DDIExporter();
    instance.exportDataset(version, json, byteArrayOutputStream);
    System.out.println(XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString()));
    assertFalse(byteArrayOutputStream.toString().contains("finch@mailinator.com"));
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser) Test(org.junit.Test)

Example 4 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class DDIExporterTest method testExportDatasetContactEmailPresent.

@Test
public void testExportDatasetContactEmailPresent() throws Exception {
    File datasetVersionJson = new File("src/test/java/edu/harvard/iq/dataverse/export/ddi/datasetContactEmailPresent.json");
    String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
    JsonReader jsonReader = Json.createReader(new StringReader(datasetVersionAsJson));
    JsonObject json = jsonReader.readObject();
    JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
    DatasetVersion version = jsonParser.parseDatasetVersion(json.getJsonObject("datasetVersion"));
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DDIExporter instance = new DDIExporter();
    instance.exportDataset(version, json, byteArrayOutputStream);
    System.out.println(XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString()));
    assertTrue(byteArrayOutputStream.toString().contains("finch@mailinator.com"));
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser) Test(org.junit.Test)

Example 5 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class MocksFactory method makeDatasetVersion.

public static DatasetVersion makeDatasetVersion(List<DataFileCategory> categories) {
    final DatasetVersion retVal = new DatasetVersion();
    final List<DataFile> files = makeFiles(10);
    final List<FileMetadata> metadatas = new ArrayList<>(10);
    Random rand = new Random();
    files.forEach(df -> {
        df.getFileMetadata().addCategory(categories.get(rand.nextInt(categories.size())));
        metadatas.add(df.getFileMetadata());
    });
    retVal.setFileMetadatas(metadatas);
    List<DatasetField> fields = new ArrayList<>();
    DatasetField field = new DatasetField();
    field.setId(nextId());
    field.setSingleValue("Sample Field Value");
    field.setDatasetFieldType(makeDatasetFieldType());
    fields.add(field);
    retVal.setDatasetFields(fields);
    return retVal;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) Random(java.util.Random) DatasetField(edu.harvard.iq.dataverse.DatasetField) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion)

Aggregations

DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)85 Dataset (edu.harvard.iq.dataverse.Dataset)43 Test (org.junit.Test)36 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)25 ArrayList (java.util.ArrayList)24 DataFile (edu.harvard.iq.dataverse.DataFile)19 JsonObject (javax.json.JsonObject)15 Date (java.util.Date)13 StringReader (java.io.StringReader)11 IOException (java.io.IOException)10 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)9 Timestamp (java.sql.Timestamp)9 EJBException (javax.ejb.EJBException)9 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)8 JsonObjectBuilder (javax.json.JsonObjectBuilder)8 JsonReader (javax.json.JsonReader)8 DatasetField (edu.harvard.iq.dataverse.DatasetField)7 Dataverse (edu.harvard.iq.dataverse.Dataverse)7 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)7 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)7