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);
}
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);
}
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";
}
};
}
});
}
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.");
}
});
}
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"));
}
Aggregations