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