use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.
the class CreateExplicitGroupCommand method execute.
@Override
public ExplicitGroup execute(CommandContext ctxt) throws CommandException {
// make sure alias in owner is unique
eg.setOwner(dv);
eg.updateAlias();
ExplicitGroup existing = eg.getGroupProvider().get(eg.getAlias());
if (existing != null) {
throw new GroupAliasExistsException(eg.getGroupAliasInOwner());
}
// persist
return ctxt.explicitGroups().persist(eg);
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.
the class DeleteExplicitGroupCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
ExplicitGroup merged = ctxt.em().merge(explicitGroup);
// Remove this group from all explicit groups it belongs to.
ctxt.em().createNativeQuery("DELETE FROM explicitgroup_explicitgroup " + "WHERE containedexplicitgroups_id=" + merged.getId()).executeUpdate();
ctxt.explicitGroups().removeGroup(merged);
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.
the class ManageGroupsPage method createExplicitGroup.
public void createExplicitGroup(ActionEvent ae) {
ExplicitGroup eg = explicitGroupService.getProvider().makeGroup();
eg.setDisplayName(getExplicitGroupName());
eg.setGroupAliasInOwner(getExplicitGroupIdentifier());
eg.setDescription(getNewExplicitGroupDescription());
if (getNewExplicitGroupRoleAssignees() != null) {
try {
for (RoleAssignee ra : getNewExplicitGroupRoleAssignees()) {
eg.add(ra);
}
} catch (GroupException ge) {
JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Creation failed.", ge.getMessage());
return;
}
}
try {
eg = engineService.submit(new CreateExplicitGroupCommand(dvRequestService.getDataverseRequest(), this.dataverse, eg));
explicitGroups.add(eg);
JsfHelper.addSuccessMessage("Succesfully created group " + eg.getDisplayName() + ". Refresh to update your page.");
} catch (CreateExplicitGroupCommand.GroupAliasExistsException gaee) {
explicitGroupIdentifierField.setValid(false);
FacesContext.getCurrentInstance().addMessage(explicitGroupIdentifierField.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, gaee.getMessage(), null));
} catch (CommandException ex) {
logger.log(Level.WARNING, "Group creation failed", ex);
JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Creation failed.", ex.getMessage());
} catch (Exception ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "The role was not able to be saved.");
logger.log(Level.SEVERE, "Error saving role: " + ex.getMessage(), ex);
}
showAssignmentMessages();
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.
the class MocksFactory method makeExplicitGroup.
public static ExplicitGroup makeExplicitGroup(String name, ExplicitGroupProvider prv) {
long id = nextId();
ExplicitGroup eg = new ExplicitGroup(prv);
eg.setId(id);
eg.setDisplayName(name == null ? "explicitGroup-" + id : name);
eg.setGroupAliasInOwner("eg" + id);
return eg;
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.
the class GroupServiceBeanTest method testFlattenGroupsCollection.
@Test
public void testFlattenGroupsCollection() throws GroupException {
// Setup
MockRoleAssigneeServiceBean roleAssigneeSvc = new MockRoleAssigneeServiceBean();
ExplicitGroupProvider prv = new ExplicitGroupProvider(null, roleAssigneeSvc);
ExplicitGroup gA = new ExplicitGroup(prv);
gA.setDisplayName("A");
ExplicitGroup gAa = new ExplicitGroup(prv);
gAa.setDisplayName("Aa");
ExplicitGroup gAb = new ExplicitGroup(prv);
gAb.setDisplayName("Ab");
ExplicitGroup gAstar = new ExplicitGroup(prv);
gAstar.setDisplayName("A*");
Dataverse dv = MocksFactory.makeDataverse();
Stream.of(gA, gAa, gAb, gAstar).forEach(g -> {
g.setId(MocksFactory.nextId());
g.setOwner(dv);
g.setGroupAliasInOwner(g.getDisplayName());
roleAssigneeSvc.add(g);
g.updateAlias();
});
// create some containment hierarchy.
gA.add(gAa);
gA.add(gAb);
gAb.add(gAstar);
gAa.add(gAstar);
gAa.add(AuthenticatedUsers.get());
// Test
GroupServiceBean sut = new GroupServiceBean();
sut.roleAssigneeSvc = roleAssigneeSvc;
Set<Group> grps = setOf(AllUsers.get(), gA);
List<Group> result = sut.flattenGroupsCollection(grps).collect(toList());
assertEquals("Groups should appear only once", result.size(), new HashSet<>(result).size());
grps.addAll(listOf(gAa, gAb, gAstar, AuthenticatedUsers.get()));
assertEquals("All groups should appear", grps, new HashSet<>(result));
}
Aggregations