Search in sources :

Example 6 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class DatasetPage method createPrivateUrl.

public void createPrivateUrl() {
    try {
        PrivateUrl createdPrivateUrl = commandEngine.submit(new CreatePrivateUrlCommand(dvRequestService.getDataverseRequest(), dataset));
        privateUrl = createdPrivateUrl;
        JH.addMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dataset.privateurl.infoMessageAuthor", Arrays.asList(getPrivateUrlLink(privateUrl))));
        privateUrlWasJustCreated = true;
    } catch (CommandException ex) {
        String msg = BundleUtil.getStringFromBundle("dataset.privateurl.noPermToCreate", PrivateUrlUtil.getRequiredPermissions(ex));
        logger.info("Unable to create a Private URL for dataset id " + dataset.getId() + ". Message to user: " + msg + " Exception: " + ex);
        JH.addErrorMessage(msg);
    }
}
Also used : CreatePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Example 7 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class DeletePrivateUrlCommandTest method setUp.

@Before
public void setUp() {
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public PrivateUrlServiceBean privateUrl() {
            return new PrivateUrlServiceBean() {

                @Override
                public PrivateUrl getPrivateUrlFromDatasetId(long datasetId) {
                    if (datasetId == noPrivateUrlToDelete) {
                        return null;
                    } else if (datasetId == hasPrivateUrlToDelete) {
                        Dataset dataset = new Dataset();
                        dataset.setId(hasPrivateUrlToDelete);
                        String token = null;
                        PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
                        RoleAssignment roleAssignment = new RoleAssignment(null, privateUrlUser, dataset, token);
                        return new PrivateUrl(roleAssignment, dataset, "FIXME");
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public List<RoleAssignment> directRoleAssignments(RoleAssignee roas, DvObject dvo) {
                    RoleAssignment roleAssignment = new RoleAssignment();
                    List<RoleAssignment> list = new ArrayList<>();
                    list.add(roleAssignment);
                    return list;
                }

                @Override
                public void revoke(RoleAssignment ra) {
                // no-op
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Before(org.junit.Before)

Example 8 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method testAttemptCreatePrivateUrlOnNonDraft.

@Test
public void testAttemptCreatePrivateUrlOnNonDraft() {
    dataset = new Dataset();
    List<DatasetVersion> versions = new ArrayList<>();
    DatasetVersion datasetVersion = new DatasetVersion();
    datasetVersion.setVersionState(DatasetVersion.VersionState.RELEASED);
    versions.add(datasetVersion);
    dataset.setVersions(versions);
    dataset.setId(latestVersionIsNotDraft);
    String expected = "Can't create Private URL because the latest version of dataset id " + latestVersionIsNotDraft + " is not a draft.";
    String actual = null;
    PrivateUrl privateUrl = null;
    try {
        privateUrl = testEngine.submit(new CreatePrivateUrlCommand(null, dataset));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 9 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method testDatasetNull.

@Test
public void testDatasetNull() {
    dataset = null;
    String expected = "Can't create Private URL. Dataset is null.";
    String actual = null;
    PrivateUrl privateUrl = null;
    try {
        privateUrl = testEngine.submit(new CreatePrivateUrlCommand(null, dataset));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 10 with PrivateUrl

use of edu.harvard.iq.dataverse.privateurl.PrivateUrl in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method testCreatePrivateUrlSuccessfully.

@Test
public void testCreatePrivateUrlSuccessfully() throws CommandException {
    dataset = new Dataset();
    dataset.setId(createDatasetLong);
    PrivateUrl privateUrl = testEngine.submit(new CreatePrivateUrlCommand(null, dataset));
    assertNotNull(privateUrl);
    assertNotNull(privateUrl.getDataset());
    assertNotNull(privateUrl.getRoleAssignment());
    PrivateUrlUser expectedUser = new PrivateUrlUser(dataset.getId());
    assertEquals(expectedUser.getIdentifier(), privateUrl.getRoleAssignment().getAssigneeIdentifier());
    assertEquals(expectedUser.isSuperuser(), false);
    assertEquals(expectedUser.isAuthenticated(), false);
    assertEquals(expectedUser.getDisplayInfo().getTitle(), "Private URL Enabled");
    assertNotNull(privateUrl.getToken());
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=" + privateUrl.getToken(), privateUrl.getLink());
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) Test(org.junit.Test)

Aggregations

PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)14 Dataset (edu.harvard.iq.dataverse.Dataset)9 Test (org.junit.Test)7 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)6 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)5 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)5 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)3 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)2 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)2 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)2 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)2 PrivateUrlServiceBean (edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)1 DvObject (edu.harvard.iq.dataverse.DvObject)1 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1