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