Search in sources :

Example 1 with PrivateUrl

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

the class GetPrivateUrlCommandTest method testDatasetWithoutAnId.

@Test
public void testDatasetWithoutAnId() throws Exception {
    dataset = new Dataset();
    PrivateUrl privateUrl = testEngine.submit(new GetPrivateUrlCommand(null, dataset));
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Example 2 with PrivateUrl

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

the class CreatePrivateUrlCommandTest method testAlreadyExists.

@Test
public void testAlreadyExists() {
    dataset.setId(privateUrlAlreadyExists);
    String expected = "Private URL already exists for dataset id " + privateUrlAlreadyExists + ".";
    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 3 with PrivateUrl

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

the class CreatePrivateUrlCommandTest method setUp.

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

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

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

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

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public SystemConfig systemConfig() {
            return new SystemConfig() {

                @Override
                public String getDataverseSiteUrl() {
                    return "https://dataverse.example.edu";
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) SystemConfig(edu.harvard.iq.dataverse.util.SystemConfig) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Before(org.junit.Before)

Example 4 with PrivateUrl

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

the class Datasets method deletePrivateUrl.

@DELETE
@Path("{id}/privateUrl")
public Response deletePrivateUrl(@PathParam("id") String idSupplied) {
    return response(req -> {
        Dataset dataset = findDatasetOrDie(idSupplied);
        PrivateUrl privateUrl = execCommand(new GetPrivateUrlCommand(req, dataset));
        if (privateUrl != null) {
            execCommand(new DeletePrivateUrlCommand(req, dataset));
            return ok("Private URL deleted.");
        } else {
            return notFound("No Private URL to delete.");
        }
    });
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) GetPrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand) DeletePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.DeletePrivateUrlCommand) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with PrivateUrl

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

the class JsonPrinterTest method testJson_PrivateUrl.

@Test
public void testJson_PrivateUrl() {
    DataverseRole aRole = new DataverseRole();
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    Dataset dataset = new Dataset();
    String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    String dataverseSiteUrl = "https://dataverse.example.edu";
    PrivateUrl privateUrl = new PrivateUrl(ra, dataset, dataverseSiteUrl);
    JsonObjectBuilder job = JsonPrinter.json(privateUrl);
    assertNotNull(job);
    JsonObject jsonObject = job.build();
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("token"));
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("link"));
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getJsonObject("roleAssignment").getString("privateUrlToken"));
    assertEquals("#42", jsonObject.getJsonObject("roleAssignment").getString("assignee"));
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) 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