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;
}
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"));
}
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());
}
}
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);
}
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;
}
Aggregations