Skip to content
Snippets Groups Projects
Commit 9014a3aa authored by srosse's avatar srosse
Browse files

OO-1871: load the project with all its dependencies ( but the custom fields )

parent 62a77847
No related branches found
No related tags found
No related merge requests found
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.course.nodes.projectbroker.service;
import java.util.List;
import org.olat.core.commons.persistence.DB;
import org.olat.course.nodes.projectbroker.datamodel.Project;
import org.olat.course.nodes.projectbroker.datamodel.ProjectImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Project queries must migrate here.
*
*
* Initial date: 01.02.2016<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
@Service
public class ProjectDAO {
@Autowired
private DB dbInstance;
/**
* The method load the project or return null if not found. The query fetch
* all dependencies but the custom fields.
*
* @param projectKey
* @return The project
*/
public Project loadProject(Long projectKey) {
StringBuilder sb = new StringBuilder();
sb.append("select project from ").append(ProjectImpl.class.getName()).append(" as project ")
.append(" left join fetch project.projectGroup pGroup")
.append(" left join fetch pGroup.baseGroup bGroup")
.append(" left join fetch project.candidateGroup cGroup")
.append(" left join fetch project.projectBroker pBroker")
.append(" where project.key=:projectKey");
List<Project> projects = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Project.class)
.setParameter("projectKey", projectKey)
.getResultList();
return projects == null || projects.isEmpty() ? null : projects.get(0);
}
}
...@@ -68,6 +68,8 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou ...@@ -68,6 +68,8 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou
@Autowired @Autowired
private DB dbInstance; private DB dbInstance;
@Autowired @Autowired
private ProjectDAO projectDao;
@Autowired
private BaseSecurity securityManager; private BaseSecurity securityManager;
@Autowired @Autowired
private ProjectBrokerManager projectBrokerManager; private ProjectBrokerManager projectBrokerManager;
...@@ -260,7 +262,7 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou ...@@ -260,7 +262,7 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou
@Override @Override
public BusinessGroupAddResponse acceptCandidates(final List<Identity> identities, final Project project, final Identity actionIdentity, final boolean autoSignOut, final boolean isAcceptSelectionManually) { public BusinessGroupAddResponse acceptCandidates(final List<Identity> identities, final Project project, final Identity actionIdentity, final boolean autoSignOut, final boolean isAcceptSelectionManually) {
final Project reloadedProject = (Project) dbInstance.loadObject(project, true); final Project reloadedProject = projectDao.loadProject(project.getKey());
final BusinessGroupAddResponse response = new BusinessGroupAddResponse(); final BusinessGroupAddResponse response = new BusinessGroupAddResponse();
BusinessGroupAddResponse state = businessGroupService.addParticipants(actionIdentity, null, identities, reloadedProject.getProjectGroup(), null); BusinessGroupAddResponse state = businessGroupService.addParticipants(actionIdentity, null, identities, reloadedProject.getProjectGroup(), null);
response.getAddedIdentities().addAll(state.getAddedIdentities()); response.getAddedIdentities().addAll(state.getAddedIdentities());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment