Search in sources :

Example 21 with Project

use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.

the class ProjectBrokerManagerImpl method deleteProjectBroker.

public void deleteProjectBroker(Long projectBrokerId, CourseEnvironment courseEnvironment, CourseNode courseNode) {
    logDebug("Start deleting projectBrokerId=" + projectBrokerId);
    ProjectBroker projectBroker = getOrLoadProjectBoker(projectBrokerId);
    // delete all projects of a project-broker
    List<Project> deleteProjectList = new ArrayList<Project>();
    deleteProjectList.addAll(projectBroker.getProjects());
    for (Iterator<Project> iterator = deleteProjectList.iterator(); iterator.hasNext(); ) {
        Project project = iterator.next();
        deleteProject(project, true, courseEnvironment, courseNode);
        logAudit("ProjectBroker: Deleted project=" + project);
    }
    logDebug("All projects are deleted for ProjectBroker=" + projectBroker);
    projectGroupManager.deleteAccountManagerGroup(courseEnvironment.getCoursePropertyManager(), courseNode);
    ProjectBroker reloadedProjectBroker = (ProjectBroker) dbInstance.loadObject(projectBroker, true);
    dbInstance.deleteObject(reloadedProjectBroker);
    // invalide with removing from cache
    projectCache.remove(projectBrokerId.toString());
    logAudit("ProjectBroker: Deleted ProjectBroker=" + projectBroker);
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) ArrayList(java.util.ArrayList)

Example 22 with Project

use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.

the class ProjectBrokerManagerImpl method cancelProjectEnrollmentOf.

public boolean cancelProjectEnrollmentOf(final Identity identity, final Project project, final ProjectBrokerModuleConfiguration moduleConfig) {
    OLATResourceable projectOres = OresHelper.createOLATResourceableInstance(Project.class, project.getKey());
    Boolean result = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectOres, new SyncerCallback<Boolean>() {

        public Boolean execute() {
            if (existsProject(project.getKey())) {
                // For cluster-safe : reload project object here another node might have changed this in the meantime
                Project reloadedProject = (Project) dbInstance.loadObject(project, true);
                // User can only cancel enrollment, when state is 'NOT_ASSIGNED'
                if (canBeCancelEnrollmentBy(identity, project, moduleConfig)) {
                    businessGroupRelationDao.removeRole(identity, reloadedProject.getProjectGroup(), GroupRoles.participant.name());
                    securityManager.removeIdentityFromSecurityGroup(identity, reloadedProject.getCandidateGroup());
                    logAudit("ProjectBroker: Remove (as participant or waitinglist) identity=" + identity + " from project=" + project);
                    if (isLogDebugEnabled()) {
                        logDebug("ProjectBroker: Remove as participant reloadedProject=" + reloadedProject + "  ParticipantGroup=" + reloadedProject.getProjectGroup() + "  CandidateGroup=" + reloadedProject.getCandidateGroup());
                    }
                    if ((reloadedProject.getMaxMembers() != Project.MAX_MEMBERS_UNLIMITED) && (reloadedProject.getSelectedPlaces() < reloadedProject.getMaxMembers())) {
                        reloadedProject.setState(Project.STATE_NOT_ASSIGNED);
                        updateProjectAndInvalidateCache(reloadedProject);
                    }
                    return Boolean.TRUE;
                } else {
                    return Boolean.FALSE;
                }
            } else {
                // project no longer exist
                return Boolean.FALSE;
            }
        }
    });
    // end of doInSync
    return result.booleanValue();
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 23 with Project

use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.

the class ProjectBrokerManagerImpl method createAndSaveProjectFor.

public Project createAndSaveProjectFor(String title, String description, final Long projectBrokerId, BusinessGroup projectGroup) {
    OLATResourceable projectBrokerOres = OresHelper.createOLATResourceableInstance(this.getClass(), projectBrokerId);
    final Project project = new ProjectImpl(title, description, projectGroup, getProjectBroker(projectBrokerId));
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectBrokerOres, new SyncerExecutor() {

        public void execute() {
            dbInstance.saveObject(project);
            ProjectBroker projectBroker = getOrLoadProjectBoker(projectBrokerId);
            if (!projectBroker.getProjects().contains(project)) {
                projectBroker.getProjects().add(project);
            }
            projectCache.update(projectBrokerId.toString(), projectBroker);
        }
    });
    return project;
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OLATResourceable(org.olat.core.id.OLATResourceable) ProjectImpl(org.olat.course.nodes.projectbroker.datamodel.ProjectImpl) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor)

Example 24 with Project

use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.

the class ProjectBrokerManagerImpl method enrollProjectParticipant.

@Override
public boolean enrollProjectParticipant(final Identity identity, final Project project, final ProjectBrokerModuleConfiguration moduleConfig, final int nbrSelectedProjects, final boolean isParticipantInAnyProject) {
    final boolean debug = isLogDebugEnabled();
    OLATResourceable projectOres = OresHelper.createOLATResourceableInstance(Project.class, project.getKey());
    logDebug("enrollProjectParticipant: start identity=" + identity + "  project=" + project);
    Boolean result = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            if (existsProject(project.getKey())) {
                // For cluster-safe : reload project object here another node might have changed this in the meantime
                Project reloadedProject = (Project) dbInstance.loadObject(project, true);
                if (debug) {
                    logDebug("enrollProjectParticipant: project.getMaxMembers()=" + reloadedProject.getMaxMembers());
                    logDebug("enrollProjectParticipant: project.getSelectedPlaces()=" + reloadedProject.getSelectedPlaces());
                }
                if (canBeProjectSelectedBy(identity, reloadedProject, moduleConfig, nbrSelectedProjects, isParticipantInAnyProject)) {
                    if (moduleConfig.isAcceptSelectionManually()) {
                        securityManager.addIdentityToSecurityGroup(identity, reloadedProject.getCandidateGroup());
                        logAudit("ProjectBroker: Add as candidate identity=" + identity + " to project=" + reloadedProject);
                        if (debug) {
                            logDebug("ProjectBroker: Add as candidate reloadedProject=" + reloadedProject + "  CandidateGroup=" + reloadedProject.getCandidateGroup());
                        }
                    } else {
                        businessGroupRelationDao.addRole(identity, reloadedProject.getProjectGroup(), GroupRoles.participant.name());
                        logAudit("ProjectBroker: Add as participant identity=" + identity + " to project=" + reloadedProject);
                        if (debug) {
                            logDebug("ProjectBroker: Add as participant reloadedProject=" + reloadedProject + "  ParticipantGroup=" + reloadedProject.getProjectGroup());
                        }
                        if ((reloadedProject.getMaxMembers() != Project.MAX_MEMBERS_UNLIMITED) && (reloadedProject.getSelectedPlaces() >= reloadedProject.getMaxMembers())) {
                            reloadedProject.setState(Project.STATE_ASSIGNED);
                            updateProjectAndInvalidateCache(reloadedProject);
                        }
                    }
                    return Boolean.TRUE;
                } else {
                    if (debug) {
                        logDebug("ProjectBroker: project-group was full for identity=" + identity + " , project=" + reloadedProject);
                    }
                    return Boolean.FALSE;
                }
            } else {
                // project no longer exist
                return Boolean.FALSE;
            }
        }
    });
    // end of doInSync
    return result.booleanValue();
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 25 with Project

use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.

the class ProjectBrokerManagerImpl method getProjectListBy.

/**
 * @param projectbroker_id
 * @return List of projects for certain project-broker
 */
public List<Project> getProjectListBy(final Long projectBrokerId) {
    final boolean debug = isLogDebugEnabled();
    long rstart = 0;
    if (debug) {
        logDebug("getProjectListBy for projectBroker=" + projectBrokerId);
        rstart = System.currentTimeMillis();
    }
    OLATResourceable projectBrokerOres = OresHelper.createOLATResourceableInstance(this.getClass(), projectBrokerId);
    List<Project> projectList = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectBrokerOres, new SyncerCallback<List<Project>>() {

        public List<Project> execute() {
            ProjectBroker projectBroker = getOrLoadProjectBoker(projectBrokerId);
            return projectBroker.getProjects();
        }
    });
    if (debug) {
        long rstop = System.currentTimeMillis();
        logDebug("time to fetch project with projectbroker_id " + projectBrokerId + " :" + (rstop - rstart), null);
    }
    return projectList;
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Project (org.olat.course.nodes.projectbroker.datamodel.Project)70 ProjectBroker (org.olat.course.nodes.projectbroker.datamodel.ProjectBroker)30 Identity (org.olat.core.id.Identity)22 OLATResourceable (org.olat.core.id.OLATResourceable)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)12 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)12 ProjectEvent (org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)10 ProjectBrokerManager (org.olat.course.nodes.projectbroker.service.ProjectBrokerManager)10 BusinessGroup (org.olat.group.BusinessGroup)10 BusinessGroupService (org.olat.group.BusinessGroupService)10 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)8 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 ProjectGroupManager (org.olat.course.nodes.projectbroker.service.ProjectGroupManager)8 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)8 File (java.io.File)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 XStream (com.thoughtworks.xstream.XStream)4 IOException (java.io.IOException)4