Search in sources :

Example 1 with Guestbook

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

the class FileUtilTest method testIsDownloadPopupRequiredHasGuestBook.

@Test
public void testIsDownloadPopupRequiredHasGuestBook() {
    DatasetVersion datasetVersion = new DatasetVersion();
    datasetVersion.setVersionState(DatasetVersion.VersionState.RELEASED);
    Dataset dataset = new Dataset();
    datasetVersion.setDataset(dataset);
    Guestbook guestbook = new Guestbook();
    guestbook.setEnabled(true);
    dataset.setGuestbook(guestbook);
    Dataverse dataverse = new Dataverse();
    guestbook.setDataverse(dataverse);
    assertEquals(true, FileUtil.isDownloadPopupRequired(datasetVersion));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) Guestbook(edu.harvard.iq.dataverse.Guestbook) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 2 with Guestbook

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

the class DeleteGuestbookCommand method execute.

@Override
public Dataverse execute(CommandContext ctxt) throws CommandException {
    Dataverse merged = ctxt.em().merge(editedDv);
    Guestbook doomedAndMerged = ctxt.em().merge(doomed);
    ctxt.em().remove(doomedAndMerged);
    return merged;
}
Also used : Guestbook(edu.harvard.iq.dataverse.Guestbook) Dataverse(edu.harvard.iq.dataverse.Dataverse)

Example 3 with Guestbook

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

the class MoveDatasetCommandTest method setUp.

@Before
public void setUp() {
    auth = makeAuthenticatedUser("Super", "User");
    auth.setSuperuser(true);
    nobody = makeAuthenticatedUser("Nick", "Nobody");
    nobody.setSuperuser(false);
    root = new Dataverse();
    root.setName("root");
    root.setId(1l);
    root.setPublicationDate(new Timestamp(new Date().getTime()));
    childA = new Dataverse();
    childA.setName("childA");
    childA.setId(2l);
    childA.setPublicationDate(new Timestamp(new Date().getTime()));
    childB = new Dataverse();
    childB.setName("childB");
    childB.setId(3l);
    childB.setPublicationDate(new Timestamp(new Date().getTime()));
    grandchildAA = new Dataverse();
    grandchildAA.setName("grandchildAA");
    grandchildAA.setId(4l);
    grandchildAA.setPublicationDate(new Timestamp(new Date().getTime()));
    childDraft = new Dataverse();
    childDraft.setName("childDraft");
    childDraft.setId(5l);
    grandchildBB = new Dataverse();
    grandchildBB.setName("grandchildBB");
    grandchildBB.setId(6l);
    grandchildBB.setPublicationDate(new Timestamp(new Date().getTime()));
    moved = new Dataset();
    moved.setOwner(root);
    moved.setPublicationDate(new Timestamp(new Date().getTime()));
    moved.setId(1l);
    movedResponses = new Dataset();
    movedResponses.setOwner(root);
    movedResponses.setPublicationDate(new Timestamp(new Date().getTime()));
    movedResponses.setId(2l);
    childA.setOwner(root);
    childB.setOwner(root);
    grandchildAA.setOwner(childA);
    grandchildBB.setOwner(childA);
    childDraft.setOwner(childA);
    gbA = new Guestbook();
    gbA.setId(1l);
    gbB = new Guestbook();
    gbB.setId(2l);
    gbC = new Guestbook();
    gbC.setId(3l);
    moved.setGuestbook(gbA);
    movedResponses.setGuestbook(gbA);
    GuestbookResponse gbResp = new GuestbookResponse();
    gbResp.setGuestbook(gbA);
    gbResp.setDataset(movedResponses);
    List<Guestbook> includeA = new ArrayList();
    includeA.add(gbA);
    includeA.add(gbB);
    grandchildAA.setGuestbooks(includeA);
    List<Guestbook> notIncludeA = new ArrayList();
    notIncludeA.add(gbC);
    notIncludeA.add(gbB);
    childB.setGuestbooks(notIncludeA);
    List<Guestbook> none = new ArrayList();
    root.setGuestbooks(none);
    grandchildBB.setGuestbooks(none);
    grandchildBB.setGuestbookRoot(false);
    childA.setGuestbooks(includeA);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public DataverseServiceBean dataverses() {
            return new DataverseServiceBean() {

                @Override
                public Dataverse save(Dataverse dataverse) {
                    // no-op. The superclass accesses databases which we don't have.
                    return dataverse;
                }
            };
        }

        @Override
        public GuestbookServiceBean guestbooks() {
            return new GuestbookServiceBean() {

                @Override
                public Long findCountResponsesForGivenDataset(Long guestbookId, Long datasetId) {
                    // We're going to fake a response for a dataset with responses
                    if (datasetId == 1) {
                        return new Long(0);
                    } else {
                        return new Long(1);
                    }
                }
            };
        }

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

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

        @Override
        public EntityManager em() {
            return new MockEntityManager() {
            };
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) GuestbookServiceBean(edu.harvard.iq.dataverse.GuestbookServiceBean) GuestbookResponse(edu.harvard.iq.dataverse.GuestbookResponse) Dataset(edu.harvard.iq.dataverse.Dataset) Guestbook(edu.harvard.iq.dataverse.Guestbook) ArrayList(java.util.ArrayList) Dataverse(edu.harvard.iq.dataverse.Dataverse) Timestamp(java.sql.Timestamp) DataverseServiceBean(edu.harvard.iq.dataverse.DataverseServiceBean) Date(java.util.Date) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 4 with Guestbook

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

the class MoveDatasetCommand method executeImpl.

@Override
public void executeImpl(CommandContext ctxt) throws CommandException {
    // first check if  user is a superuser
    if ((!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) {
        throw new PermissionException("Move Dataset can only be called by superusers.", this, Collections.singleton(Permission.DeleteDatasetDraft), moved);
    }
    // validate the move makes sense
    if (moved.getOwner().equals(destination)) {
        throw new IllegalCommandException("Dataset already in this Dataverse ", this);
    }
    if (moved.isReleased() && !destination.isReleased()) {
        throw new IllegalCommandException("Published Dataset may not be moved to unpublished Dataverse. You may publish " + destination.getDisplayName() + " and re-try the move.", this);
    }
    // if the datasets guestbook is not contained in the new dataverse then remove it
    if (moved.getGuestbook() != null) {
        Guestbook gb = moved.getGuestbook();
        List<Guestbook> gbs = destination.getGuestbooks();
        boolean inheritGuestbooksValue = !destination.isGuestbookRoot();
        if (inheritGuestbooksValue && destination.getOwner() != null) {
            for (Guestbook pg : destination.getParentGuestbooks()) {
                gbs.add(pg);
            }
        }
        if (gbs == null || !gbs.contains(gb)) {
            if (force == null || !force) {
                throw new IllegalCommandException("Dataset guestbook is not in target dataverse. Please use the parameter ?forceMove=true to complete the move. This will delete the guestbook from the Dataset", this);
            }
            moved.setGuestbook(null);
        }
    }
    // OK, move
    moved.setOwner(destination);
    ctxt.em().merge(moved);
    try {
        boolean doNormalSolrDocCleanUp = true;
        ctxt.index().indexDataset(moved, doNormalSolrDocCleanUp);
    } catch (Exception e) {
        // RuntimeException e ) {
        // , e);
        logger.log(Level.WARNING, "Exception while indexing:" + e.getMessage());
        throw new CommandException("Dataset could not be moved. Indexing failed", this);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) Guestbook(edu.harvard.iq.dataverse.Guestbook) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Aggregations

Guestbook (edu.harvard.iq.dataverse.Guestbook)4 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 Dataset (edu.harvard.iq.dataverse.Dataset)2 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 DataverseServiceBean (edu.harvard.iq.dataverse.DataverseServiceBean)1 GuestbookResponse (edu.harvard.iq.dataverse.GuestbookResponse)1 GuestbookServiceBean (edu.harvard.iq.dataverse.GuestbookServiceBean)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)1 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)1 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)1 IndexServiceBean (edu.harvard.iq.dataverse.search.IndexServiceBean)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Before (org.junit.Before)1 Test (org.junit.Test)1