Search in sources :

Example 1 with DataverseFieldTypeInputLevel

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;
}
Also used : DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)

Example 2 with DataverseFieldTypeInputLevel

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);
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Example 3 with DataverseFieldTypeInputLevel

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;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Timestamp(java.sql.Timestamp) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) Date(java.util.Date) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 4 with DataverseFieldTypeInputLevel

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;
}
Also used : DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 5 with DataverseFieldTypeInputLevel

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

Aggregations

DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)5 Dataverse (edu.harvard.iq.dataverse.Dataverse)4 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)3 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)3 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)2 Timestamp (java.sql.Timestamp)2 DataverseFacet (edu.harvard.iq.dataverse.DataverseFacet)1 ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)1 User (edu.harvard.iq.dataverse.authorization.users.User)1 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1