Search in sources :

Example 81 with Dataverse

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

the class UpdatePermissionRootCommandTest method setUp.

@Before
public void setUp() {
    mockBean = new DataverseServiceBean() {

        @Override
        public Dataverse save(Dataverse dv) {
            serviceBeanCalled = true;
            return dv;
        }
    };
    testCommandContext = new TestCommandContext() {

        @Override
        public DataverseServiceBean dataverses() {
            return mockBean;
        }
    };
    serviceBeanCalled = false;
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) DataverseServiceBean(edu.harvard.iq.dataverse.DataverseServiceBean) Dataverse(edu.harvard.iq.dataverse.Dataverse) Before(org.junit.Before)

Example 82 with Dataverse

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

the class SchemaDotOrgExporterTest method testExportDataset.

/**
 * Test of exportDataset method, of class SchemaDotOrgExporter.
 */
@Test
public void testExportDataset() throws Exception {
    System.out.println("exportDataset");
    File datasetVersionJson = new File("src/test/resources/json/dataset-finch1.json");
    String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
    JsonReader jsonReader1 = Json.createReader(new StringReader(datasetVersionAsJson));
    JsonObject json1 = jsonReader1.readObject();
    JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
    DatasetVersion version = jsonParser.parseDatasetVersion(json1.getJsonObject("datasetVersion"));
    version.setVersionState(DatasetVersion.VersionState.RELEASED);
    SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
    Date publicationDate = dateFmt.parse("19551105");
    version.setReleaseTime(publicationDate);
    version.setVersionNumber(1l);
    // TODO: It might be nice to test TermsOfUseAndAccess some day
    version.setTermsOfUseAndAccess(null);
    Dataset dataset = new Dataset();
    dataset.setProtocol("doi");
    dataset.setAuthority("myAuthority");
    dataset.setIdentifier("myIdentifier");
    version.setDataset(dataset);
    Dataverse dataverse = new Dataverse();
    dataverse.setName("LibraScholar");
    dataset.setOwner(dataverse);
    System.setProperty(SITE_URL, "https://librascholar.org");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    schemaDotOrgExporter.exportDataset(version, json1, byteArrayOutputStream);
    String jsonLd = byteArrayOutputStream.toString();
    System.out.println("schema.org JSON-LD: " + JsonUtil.prettyPrint(jsonLd));
    JsonReader jsonReader2 = Json.createReader(new StringReader(jsonLd));
    JsonObject json2 = jsonReader2.readObject();
    assertEquals("http://schema.org", json2.getString("@context"));
    assertEquals("Dataset", json2.getString("@type"));
    assertEquals("https://doi.org/myAuthority/myIdentifier", json2.getString("identifier"));
    assertEquals("Darwin's Finches", json2.getString("name"));
    assertEquals("Finch, Fiona", json2.getJsonArray("author").getJsonObject(0).getString("name"));
    assertEquals("Birds Inc.", json2.getJsonArray("author").getJsonObject(0).getString("affiliation"));
    assertEquals("1955-11-05", json2.getString("dateModified"));
    assertEquals("1", json2.getString("version"));
    assertEquals("Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", json2.getString("description"));
    assertEquals("Medicine, Health and Life Sciences", json2.getJsonArray("keywords").getString(0));
    assertEquals("https://schema.org/version/3.3", json2.getString("schemaVersion"));
    assertEquals("DataCatalog", json2.getJsonObject("includedInDataCatalog").getString("@type"));
    assertEquals("LibraScholar", json2.getJsonObject("includedInDataCatalog").getString("name"));
    assertEquals("https://librascholar.org", json2.getJsonObject("includedInDataCatalog").getString("url"));
    assertEquals("Organization", json2.getJsonObject("provider").getString("@type"));
    assertEquals("Dataverse", json2.getJsonObject("provider").getString("name"));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) 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) SimpleDateFormat(java.text.SimpleDateFormat) Dataverse(edu.harvard.iq.dataverse.Dataverse) Date(java.util.Date) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser) Test(org.junit.Test)

Example 83 with Dataverse

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

the class CreateDataverseCommandTest method testCustomOptions.

@Test
public void testCustomOptions() throws CommandException {
    Dataverse dv = makeDataverse();
    Timestamp creation = timestamp(1990, 12, 12);
    AuthenticatedUser creator = makeAuthenticatedUser("Joe", "Walsh");
    dv.setCreateDate(creation);
    dv.setId(null);
    dv.setCreator(creator);
    dv.setDefaultContributorRole(null);
    dv.setOwner(makeDataverse());
    dv.setDataverseType(Dataverse.DataverseType.JOURNALS);
    dv.setDefaultContributorRole(roles.findBuiltinRoleByAlias(DataverseRole.MANAGER));
    final DataverseRequest request = makeRequest();
    List<DatasetFieldType> expectedFacets = Arrays.asList(makeDatasetFieldType(), makeDatasetFieldType(), makeDatasetFieldType());
    List<DataverseFieldTypeInputLevel> dftils = Arrays.asList(makeDataverseFieldTypeInputLevel(makeDatasetFieldType()), makeDataverseFieldTypeInputLevel(makeDatasetFieldType()), makeDataverseFieldTypeInputLevel(makeDatasetFieldType()));
    CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, new LinkedList(expectedFacets), new LinkedList(dftils));
    Dataverse result = engine.submit(sut);
    assertEquals(creation, result.getCreateDate());
    assertNotNull(result.getId());
    assertEquals(creator, result.getCreator());
    assertEquals(Dataverse.DataverseType.JOURNALS, result.getDataverseType());
    assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.MANAGER), result.getDefaultContributorRole());
    // Assert that the creator is admin.
    final RoleAssignment roleAssignment = roles.directRoleAssignments(dv).get(0);
    assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.ADMIN), roleAssignment.getRole());
    assertEquals(dv, roleAssignment.getDefinitionPoint());
    assertEquals(roleAssignment.getAssigneeIdentifier(), request.getUser().getIdentifier());
    assertTrue(result.isPermissionRoot());
    assertTrue(result.isThemeRoot());
    assertTrue(indexCalled);
    assertTrue(facetsDeleted);
    int i = 0;
    for (DataverseFacet df : createdFacets) {
        assertEquals(i, df.getDisplayOrder());
        assertEquals(result, df.getDataverse());
        assertEquals(expectedFacets.get(i), df.getDatasetFieldType());
        i++;
    }
    assertTrue(dftilsDeleted);
    for (DataverseFieldTypeInputLevel dftil : createdDftils) {
        assertEquals(result, dftil.getDataverse());
    }
}
Also used : RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Dataverse(edu.harvard.iq.dataverse.Dataverse) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) LinkedList(java.util.LinkedList) DataverseFacet(edu.harvard.iq.dataverse.DataverseFacet) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Test(org.junit.Test)

Example 84 with Dataverse

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

the class CreateRoleCommandTest method testGuestUsersCantAddRoles.

@Test(expected = IllegalCommandException.class)
public void testGuestUsersCantAddRoles() throws CommandException {
    DataverseRole dvr = new DataverseRole();
    dvr.setAlias("roleTest");
    dvr.setName("Tester Role");
    dvr.addPermission(Permission.AddDataset);
    Dataverse dv = MocksFactory.makeDataverse();
    dvr.setOwner(dv);
    CreateRoleCommand sut = new CreateRoleCommand(dvr, new DataverseRequest(GuestUser.get(), IpAddress.valueOf("89.17.33.33")), dv);
    engine.submit(sut);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Test(org.junit.Test)

Example 85 with Dataverse

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

the class PublishDataverseCommand method execute.

@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
    if (dataverse.isReleased()) {
        throw new IllegalCommandException("Dataverse " + dataverse.getAlias() + " has already been published.", this);
    }
    Dataverse parent = dataverse.getOwner();
    // root dataverse doesn't have a parent
    if (parent != null) {
        if (!parent.isReleased()) {
            throw new IllegalCommandException("Dataverse " + dataverse.getAlias() + " may not be published because its host dataverse (" + parent.getAlias() + ") has not been published.", this);
        }
    }
    // Before setting dataverse to released send notifications to users with download file
    List<RoleAssignment> ras = ctxt.roles().directRoleAssignments(dataverse);
    for (RoleAssignment ra : ras) {
        if (ra.getRole().permissions().contains(Permission.DownloadFile)) {
            for (AuthenticatedUser au : ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier()))) {
                ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.ASSIGNROLE, dataverse.getId());
            }
        }
    }
    dataverse.setPublicationDate(new Timestamp(new Date().getTime()));
    dataverse.setReleaseUser((AuthenticatedUser) getUser());
    Dataverse savedDataverse = ctxt.dataverses().save(dataverse);
    /**
     * @todo consider also
     * ctxt.solrIndex().indexPermissionsOnSelfAndChildren(savedDataverse.getId());
     */
    /**
     * @todo what should we do with the indexRespose?
     */
    IndexResponse indexResponse = ctxt.solrIndex().indexPermissionsForOneDvObject(savedDataverse);
    return savedDataverse;
}
Also used : IndexResponse(edu.harvard.iq.dataverse.search.IndexResponse) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

Dataverse (edu.harvard.iq.dataverse.Dataverse)94 Dataset (edu.harvard.iq.dataverse.Dataset)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)31 Test (org.junit.Test)27 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)22 DataFile (edu.harvard.iq.dataverse.DataFile)18 IOException (java.io.IOException)18 Path (javax.ws.rs.Path)16 JsonObject (javax.json.JsonObject)15 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)11 ArrayList (java.util.ArrayList)11 EJBException (javax.ejb.EJBException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 InputStream (java.io.InputStream)10 Date (java.util.Date)10 JsonArrayBuilder (javax.json.JsonArrayBuilder)10 POST (javax.ws.rs.POST)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 SwordError (org.swordapp.server.SwordError)9