Search in sources :

Example 6 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentNullDataset.

@Test
public void testGetDraftDatasetVersionFromRoleAssignmentNullDataset() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject dataset = null;
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    DatasetVersion datasetVersion = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
    assertNull(datasetVersion);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 7 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentSuccess.

@Test
public void testGetPrivateUrlFromRoleAssignmentSuccess() {
    String dataverseSiteUrl = "https://dataverse.example.edu";
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
    assertNotNull(privateUrl);
    assertEquals(new Long(42), privateUrl.getDataset().getId());
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=cd71e9d7-73a7-4ec8-b890-3d00499e8693", privateUrl.getLink());
}
Also used : 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) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 8 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetUserFromRoleAssignmentNonDataset.

@Test
public void testGetUserFromRoleAssignmentNonDataset() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    DvObject nonDataset = new Dataverse();
    nonDataset.setId(123l);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, nonDataset, privateUrlToken);
    PrivateUrlUser privateUrlUserOut = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(ra);
    assertNull(privateUrlUserOut);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 9 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlRedirectDataFail.

@Test
public void testGetPrivateUrlRedirectDataFail() {
    DataverseRole aRole = null;
    long datasetId = 42;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    ra.setDefinitionPoint(null);
    PrivateUrlRedirectData privateUrlRedirectData = null;
    privateUrlRedirectData = PrivateUrlUtil.getPrivateUrlRedirectData(ra);
    assertNull(privateUrlRedirectData);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 10 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testIdentifier2roleAssignee.

@Test
public void testIdentifier2roleAssignee() {
    RoleAssignee returnValueFromEmptyString = null;
    try {
        returnValueFromEmptyString = PrivateUrlUtil.identifier2roleAssignee("");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
        assertEquals(ex.getMessage(), "Could not find dataset id in ''");
    }
    assertNull(returnValueFromEmptyString);
    RoleAssignee returnValueFromNonColon = null;
    String peteIdentifier = "@pete";
    try {
        returnValueFromNonColon = PrivateUrlUtil.identifier2roleAssignee(peteIdentifier);
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
        assertEquals(ex.getMessage(), "Could not find dataset id in '" + peteIdentifier + "'");
    }
    assertNull(returnValueFromNonColon);
    RoleAssignee returnValueFromNonNumber = null;
    String nonNumberIdentifier = PrivateUrlUser.PREFIX + "nonNumber";
    try {
        returnValueFromNonNumber = PrivateUrlUtil.identifier2roleAssignee(nonNumberIdentifier);
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
        assertEquals(ex.getMessage(), "Could not find dataset id in '" + nonNumberIdentifier + "'");
    }
    assertNull(returnValueFromNonNumber);
    RoleAssignee returnFromValidIdentifier = null;
    String validIdentifier = PrivateUrlUser.PREFIX + 42;
    returnFromValidIdentifier = PrivateUrlUtil.identifier2roleAssignee(validIdentifier);
    assertNotNull(returnFromValidIdentifier);
    assertEquals("#42", returnFromValidIdentifier.getIdentifier());
    assertEquals("Private URL Enabled", returnFromValidIdentifier.getDisplayInfo().getTitle());
    Assert.assertTrue(returnFromValidIdentifier instanceof PrivateUrlUser);
    PrivateUrlUser privateUrlUser42 = (PrivateUrlUser) returnFromValidIdentifier;
    assertEquals(42, privateUrlUser42.getDatasetId());
}
Also used : PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Aggregations

RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)35 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)19 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Test (org.junit.Test)17 Dataset (edu.harvard.iq.dataverse.Dataset)13 DvObject (edu.harvard.iq.dataverse.DvObject)11 ArrayList (java.util.ArrayList)6 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 GroupException (edu.harvard.iq.dataverse.authorization.groups.GroupException)3 ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 AssignRoleCommand (edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand)2 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)2 LinkedList (java.util.LinkedList)2 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 POST (javax.ws.rs.POST)2