use of edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel in project dataverse by IQSS.
the class MocksFactory method makeDataverseFieldTypeInputLevel.
public static DataverseFieldTypeInputLevel makeDataverseFieldTypeInputLevel(DatasetFieldType fieldType) {
DataverseFieldTypeInputLevel retVal = new DataverseFieldTypeInputLevel();
retVal.setId(nextId());
retVal.setInclude(true);
retVal.setDatasetFieldType(fieldType);
return retVal;
}
use of edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel in project dataverse by IQSS.
the class DeleteDataverseCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
// Make sure we don't delete root
if (doomed.getOwner() == null) {
throw new IllegalCommandException("Cannot delete the root dataverse", this);
}
// make sure the dataverse is emptyw
if (ctxt.dvObjects().hasData(doomed)) {
throw new IllegalCommandException("Cannot delete non-empty dataverses", this);
}
// ASSIGNMENTS
for (RoleAssignment ra : ctxt.roles().directRoleAssignments(doomed)) {
ctxt.em().remove(ra);
}
// ROLES
for (DataverseRole ra : ctxt.roles().findByOwnerId(doomed.getId())) {
ctxt.em().remove(ra);
}
// EXPLICIT GROUPS
for (ExplicitGroup eg : ctxt.em().createNamedQuery("ExplicitGroup.findByOwnerId", ExplicitGroup.class).setParameter("ownerId", doomed.getId()).getResultList()) {
ctxt.explicitGroups().removeGroup(eg);
}
// Input Level
for (DataverseFieldTypeInputLevel inputLevel : doomed.getDataverseFieldTypeInputLevels()) {
DataverseFieldTypeInputLevel merged = ctxt.em().merge(inputLevel);
ctxt.em().remove(merged);
}
doomed.setDataverseFieldTypeInputLevels(new ArrayList<>());
// DATAVERSE
Dataverse doomedAndMerged = ctxt.em().merge(doomed);
ctxt.em().remove(doomedAndMerged);
// Remove from index
ctxt.index().delete(doomed);
}
use of edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel in project dataverse by IQSS.
the class CreateDataverseCommand method execute.
@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
if (created.getOwner() == null) {
if (ctxt.dataverses().isRootDataverseExists()) {
throw new IllegalCommandException("Root Dataverse already exists. Cannot create another one", this);
}
}
if (created.getCreateDate() == null) {
created.setCreateDate(new Timestamp(new Date().getTime()));
}
if (created.getCreator() == null) {
final User user = getRequest().getUser();
if (user.isAuthenticated()) {
created.setCreator((AuthenticatedUser) user);
} else {
throw new IllegalCommandException("Guest users cannot create a Dataverse.", this);
}
}
if (created.getDataverseType() == null) {
created.setDataverseType(Dataverse.DataverseType.UNCATEGORIZED);
}
if (created.getDefaultContributorRole() == null) {
created.setDefaultContributorRole(ctxt.roles().findBuiltinRoleByAlias(DataverseRole.EDITOR));
}
// @todo for now we are saying all dataverses are permission root
created.setPermissionRoot(true);
if (ctxt.dataverses().findByAlias(created.getAlias()) != null) {
throw new IllegalCommandException("A dataverse with alias " + created.getAlias() + " already exists", this);
}
// Save the dataverse
Dataverse managedDv = ctxt.dataverses().save(created);
// Find the built in admin role (currently by alias)
DataverseRole adminRole = ctxt.roles().findBuiltinRoleByAlias(DataverseRole.ADMIN);
String privateUrlToken = null;
ctxt.roles().save(new RoleAssignment(adminRole, getRequest().getUser(), managedDv, privateUrlToken));
managedDv.setPermissionModificationTime(new Timestamp(new Date().getTime()));
managedDv = ctxt.dataverses().save(managedDv);
ctxt.index().indexDataverse(managedDv);
if (facetList != null) {
ctxt.facets().deleteFacetsFor(managedDv);
int i = 0;
for (DatasetFieldType df : facetList) {
ctxt.facets().create(i++, df, managedDv);
}
}
if (inputLevelList != null) {
ctxt.fieldTypeInputLevels().deleteFacetsFor(managedDv);
for (DataverseFieldTypeInputLevel obj : inputLevelList) {
obj.setDataverse(managedDv);
ctxt.fieldTypeInputLevels().create(obj);
}
}
return managedDv;
}
use of edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel in project dataverse by IQSS.
the class UpdateDataverseCommand method execute.
@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
Dataverse result = ctxt.dataverses().save(editedDv);
if (facetList != null) {
ctxt.facets().deleteFacetsFor(result);
int i = 0;
for (DatasetFieldType df : facetList) {
ctxt.facets().create(i++, df.getId(), result.getId());
}
}
if (featuredDataverseList != null) {
ctxt.featuredDataverses().deleteFeaturedDataversesFor(result);
int i = 0;
for (Object obj : featuredDataverseList) {
Dataverse dv = (Dataverse) obj;
ctxt.featuredDataverses().create(i++, dv.getId(), result.getId());
}
}
if (inputLevelList != null) {
ctxt.fieldTypeInputLevels().deleteFacetsFor(result);
for (DataverseFieldTypeInputLevel obj : inputLevelList) {
ctxt.fieldTypeInputLevels().create(obj);
}
}
ctxt.index().indexDataverse(result);
return result;
}
use of edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel 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());
}
}
Aggregations