use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNode method createInstanceForCopy.
/**
* @see org.olat.course.nodes.CourseNode#createInstanceForCopy()
*/
@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
// create the instance for the copy
CourseNode copyInstance = super.createInstanceForCopy(isNewTitle, course, author);
// get all the different managers
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
// get the pbID from the source pb
Long oldProjectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
// create a new projectBroker for the copyInstance
ProjectBroker newBroker = projectBrokerManager.createAndSaveProjectBroker();
Long projectBrokerId = newBroker.getKey();
projectBrokerManager.saveProjectBrokerId(projectBrokerId, cpm, copyInstance);
// configure the new Project like the old one
// copy the old accountManagergroup to preserve the
// "persons in charge"
Long originalAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(cpm, this);
if (originalAccountGroupKey != null) {
BusinessGroup originalAccountGroup = projectGroupManager.getAccountManagerGroupFor(cpm, this, course, getShortTitle(), getShortTitle(), null);
BusinessGroup newAccountManagerGroup = bgs.copyBusinessGroup(author, originalAccountGroup, originalAccountGroup.getName(), originalAccountGroup.getDescription(), originalAccountGroup.getMinParticipants(), originalAccountGroup.getMaxParticipants(), false, false, true, false, false, true, false, false);
projectGroupManager.saveAccountManagerGroupKey(newAccountManagerGroup.getKey(), cpm, copyInstance);
bgs.addResourceTo(newAccountManagerGroup, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
}
if (oldProjectBrokerId != null) {
List<Project> projects = projectBrokerManager.getProjectListBy(oldProjectBrokerId);
for (Project project : projects) {
// create projectGroup
BusinessGroup projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
Project newProject = projectBrokerManager.createAndSaveProjectFor(project.getTitle(), project.getDescription(), projectBrokerId, projectGroup);
// copy all project configurations
newProject.setMailNotificationEnabled(project.isMailNotificationEnabled());
newProject.setMaxMembers(project.getMaxMembers());
for (int i = 0; i < project.getCustomFieldSize(); i++) {
newProject.setCustomFieldValue(i, project.getCustomFieldValue(i));
}
projectGroupManager.setDeselectionAllowed(newProject, project.getProjectGroup().isAllowToLeave());
projectBrokerManager.updateProject(newProject);
// attachment file
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, course.getCourseEnvironment(), this), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), copyInstance);
newProject.setAttachedFileName(project.getAttachmentFileName());
projectBrokerManager.updateProject(newProject);
}
}
}
return copyInstance;
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNode method postCopy.
/**
* Do re-arrange the projects in a new project broker after the copy happened
*/
@Override
public void postCopy(CourseEnvironmentMapper envMapper, Processing processType, ICourse course, ICourse sourceCourse) {
super.postCopy(envMapper, processType, course, null);
if (processType.equals(Processing.runstructure)) {
// initialize the managers and services
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
CoursePropertyManager oldCpm = sourceCourse.getCourseEnvironment().getCoursePropertyManager();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
// create new Project broker and get the old one
Long projectBrokerId = projectBrokerManager.createAndSaveProjectBroker().getKey();
projectBrokerManager.saveProjectBrokerId(projectBrokerId, course.getCourseEnvironment().getCoursePropertyManager(), this);
// find the group for account manager and remap the account group
CourseNode sourceCourseNode = sourceCourse.getRunStructure().getNode(getIdent());
Long sourceAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(oldCpm, sourceCourseNode);
if (sourceAccountGroupKey != null) {
Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(sourceAccountGroupKey);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
projectGroupManager.saveAccountManagerGroupKey(copiedGroupKey, cpm, this);
}
Long oldBrokerId = projectBrokerManager.getProjectBrokerId(oldCpm, this);
List<Project> projectsFromGroup = projectBrokerManager.getProjectListBy(oldBrokerId);
// loop create and configure the new Projects
for (Project project : projectsFromGroup) {
Long originalGroupKey = project.getProjectGroup().getKey();
Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
Identity author = envMapper.getAuthor();
BusinessGroup projectGroup = bgs.loadBusinessGroup(copiedGroupKey);
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
}
if (author != null) {
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project newProject = projectBrokerManager.createAndSaveProjectFor(project.getTitle(), project.getDescription(), projectBrokerId, projectGroup);
// copy all project configurations
newProject.setMailNotificationEnabled(project.isMailNotificationEnabled());
newProject.setMaxMembers(project.getMaxMembers());
for (int i = 0; i < project.getCustomFieldSize(); i++) {
newProject.setCustomFieldValue(i, project.getCustomFieldValue(i));
}
projectGroupManager.setDeselectionAllowed(newProject, project.getProjectGroup().isAllowToLeave());
projectBrokerManager.updateProject(newProject);
// attachment file
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, sourceCourse.getCourseEnvironment(), this), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), this);
newProject.setAttachedFileName(project.getAttachmentFileName());
projectBrokerManager.updateProject(newProject);
}
}
}
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class GoToMeetingCourseNode method isCoach.
private final boolean isCoach(RepositoryEntry re, Identity identity) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
int count = bgs.countBusinessGroups(params, re);
return count > 0;
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class COCourseNode method isConfigValid.
/**
* @see org.olat.course.nodes.CourseNode#isConfigValid(org.olat.course.run.userview.UserCourseEnvironment)
*/
public StatusDescription[] isConfigValid(CourseEditorEnv cev) {
oneClickStatusCache = null;
// only here we know which translator to take for translating condition
// error messages
String translatorStr = Util.getPackageName(ConditionEditController.class);
List<StatusDescription> condErrs = isConfigValidWithTranslator(cev, translatorStr, getConditionExpressions());
List<StatusDescription> missingNames = new ArrayList<StatusDescription>();
/*
* check group and area names for existence
*/
String nodeId = getIdent();
ModuleConfiguration mc = getModuleConfiguration();
@SuppressWarnings("unchecked") List<Long> areaKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA_IDS);
if (areaKeys != null) {
BGAreaManager areaManager = CoreSpringFactory.getImpl(BGAreaManager.class);
List<BGArea> areas = areaManager.loadAreas(areaKeys);
a_a: for (Long areaKey : areaKeys) {
for (BGArea area : areas) {
if (area.getKey().equals(areaKey)) {
continue a_a;
}
}
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", areaKey.toString() }, translatorStr);
sd.setDescriptionForUnit(nodeId);
missingNames.add(sd);
}
} else {
String areaStr = (String) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA);
if (areaStr != null) {
String[] areas = areaStr.split(",");
for (int i = 0; i < areas.length; i++) {
String trimmed = areas[i] != null ? areas[i].trim() : areas[i];
if (!trimmed.equals("") && !cev.existsArea(trimmed)) {
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", trimmed }, translatorStr);
sd.setDescriptionForUnit(nodeId);
missingNames.add(sd);
}
}
}
}
@SuppressWarnings("unchecked") List<Long> groupKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP_ID);
if (groupKeys != null) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<BusinessGroupShort> groups = bgs.loadShortBusinessGroups(groupKeys);
a_a: for (Long activeGroupKey : groupKeys) {
for (BusinessGroupShort group : groups) {
if (group.getKey().equals(activeGroupKey)) {
continue a_a;
}
}
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", activeGroupKey.toString() }, translatorStr);
sd.setDescriptionForUnit(nodeId);
missingNames.add(sd);
}
} else {
String groupStr = (String) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP);
if (groupStr != null) {
String[] groups = groupStr.split(",");
for (int i = 0; i < groups.length; i++) {
String trimmed = groups[i] != null ? groups[i].trim() : groups[i];
if (!trimmed.equals("") && !cev.existsGroup(trimmed)) {
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", trimmed }, translatorStr);
sd.setDescriptionForUnit(nodeId);
missingNames.add(sd);
}
}
}
}
missingNames.addAll(condErrs);
oneClickStatusCache = StatusDescriptionHelper.sort(missingNames);
return oneClickStatusCache;
}
use of org.olat.group.BusinessGroupService in project openolat by klemens.
the class ContactsWebService method getMyContacts.
/**
* Retrieve the contacts of the logged in identity.
* @response.representation.200.doc The list of contacts
* @param start
* @param limit
* @param httpRequest The HTTP request
* @return The list of contacts
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMyContacts(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest) {
Identity identity = getIdentity(httpRequest);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<Identity> contacts = bgs.findContacts(identity, start, limit);
int totalCount = bgs.countContacts(identity);
int count = 0;
ContactVO[] userVOs = new ContactVO[contacts.size()];
for (Identity contact : contacts) {
userVOs[count++] = new ContactVO(contact);
}
ContactVOes voes = new ContactVOes();
voes.setUsers(userVOs);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
}
Aggregations