From 1e923ec343d1780b0954e90be6c44cf659b27cce Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Thu, 15 Mar 2012 10:28:32 +0100
Subject: [PATCH] OO-170: fix small hibernate query issue, more infos in
 efficiency statement view

---
 .../EfficiencyStatementController.java        | 63 ++++++++++++++-----
 .../IdentityAssessmentEditController.java     |  4 +-
 .../_content/efficiencystatement.html         | 20 +++---
 .../_i18n/LocalStrings_de.properties          |  8 +--
 .../UserCourseInformationsManagerImpl.java    |  5 +-
 5 files changed, 67 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/olat/course/assessment/EfficiencyStatementController.java b/src/main/java/org/olat/course/assessment/EfficiencyStatementController.java
index 6b3f25aae41..9eede8421b6 100644
--- a/src/main/java/org/olat/course/assessment/EfficiencyStatementController.java
+++ b/src/main/java/org/olat/course/assessment/EfficiencyStatementController.java
@@ -54,6 +54,8 @@ import org.olat.core.util.mail.ContactList;
 import org.olat.core.util.mail.ContactMessage;
 import org.olat.core.util.resource.OresHelper;
 import org.olat.core.util.vfs.VFSContainer;
+import org.olat.course.CourseFactory;
+import org.olat.course.ICourse;
 import org.olat.course.assessment.portfolio.EfficiencyStatementArtefact;
 import org.olat.group.BusinessGroup;
 import org.olat.modules.co.ContactFormController;
@@ -61,6 +63,8 @@ import org.olat.portfolio.EPArtefactHandler;
 import org.olat.portfolio.PortfolioModule;
 import org.olat.portfolio.model.artefacts.AbstractArtefact;
 import org.olat.portfolio.ui.artefacts.collect.ArtefactWizzardStepsController;
+import org.olat.repository.RepositoryEntry;
+import org.olat.repository.RepositoryManager;
 import org.olat.user.UserManager;
 import org.olat.user.propertyhandlers.UserPropertyHandler;
 
@@ -80,6 +84,7 @@ public class EfficiencyStatementController extends MainLayoutBasicController {
 	private final EfficiencyStatement efficiencyStatement;
 	private final Identity statementOwner;
 	private final Long businessGroupKey;
+	private final Long courseRepoKey;
 	
 	//to collect the eff.Statement as artefact
 	private Link collectArtefactLink, homeLink, courseLink, groupLink, contactLink;
@@ -89,42 +94,66 @@ public class EfficiencyStatementController extends MainLayoutBasicController {
 	//contact
 	private ContactFormController contactCtrl;
 	private CloseableModalController cmc;
+	
 	/**
-	 * Constructor
+	 * The constructor shows the efficiency statement given as parameter for the current user
 	 * @param wControl
 	 * @param ureq
 	 * @param courseId
 	 */
-	public EfficiencyStatementController(WindowControl wControl, UserRequest ureq, Long courseRepoEntryKey) {
-		this(wControl, ureq, EfficiencyStatementManager.getInstance().getUserEfficiencyStatement(courseRepoEntryKey, ureq.getIdentity()));
+	public EfficiencyStatementController(WindowControl wControl, UserRequest ureq, EfficiencyStatement efficiencyStatement) {
+		this(wControl, ureq, ureq.getIdentity(), null, null, efficiencyStatement, false, true);
 	}
 	
-	public EfficiencyStatementController(WindowControl wControl, UserRequest ureq, EfficiencyStatement efficiencyStatement) {
-		this(wControl, ureq, ureq.getIdentity(), null, efficiencyStatement, true);
+	/**
+	 * This constructor show the efficiency statement for the course repository key and the current user
+	 * @param wControl
+	 * @param ureq
+	 * @param courseRepoEntryKey
+	 */
+	public EfficiencyStatementController(WindowControl wControl, UserRequest ureq, Long courseRepoEntryKey) {
+		this(wControl, ureq, 
+				ureq.getIdentity(), null, RepositoryManager.getInstance().lookupRepositoryEntry(courseRepoEntryKey, false),
+				EfficiencyStatementManager.getInstance().getUserEfficiencyStatement(courseRepoEntryKey, ureq.getIdentity()), false, true);
 	}
 	
 	public EfficiencyStatementController(WindowControl wControl, UserRequest ureq, Identity statementOwner,
-			BusinessGroup businessGroup, EfficiencyStatement efficiencyStatement, boolean mainLayout) {
+			BusinessGroup businessGroup, RepositoryEntry courseRepo, EfficiencyStatement efficiencyStatement, boolean links, boolean mainLayout) {
 		super(ureq, wControl);
 		
+		this.courseRepoKey = courseRepo == null ? (efficiencyStatement == null ? null : efficiencyStatement.getCourseRepoEntryKey()) : courseRepo.getKey();
+		if(courseRepo == null && courseRepoKey != null) {
+			courseRepo = RepositoryManager.getInstance().lookupRepositoryEntry(courseRepoKey, false);
+		}
+		if(businessGroup == null && courseRepo != null) {
+			ICourse course = CourseFactory.loadCourse(courseRepo.getOlatResource());
+			List<BusinessGroup> groups = course.getCourseEnvironment().getCourseGroupManager().getParticipatingLearningGroupsFromAllContexts(statementOwner);
+			if(groups.size() > 0) {
+				businessGroup = groups.get(0);
+			}
+		}
 		this.businessGroupKey = businessGroup == null ? null : businessGroup.getKey();
 		this.statementOwner = statementOwner;
 		this.efficiencyStatement = efficiencyStatement;
-		init(ureq, statementOwner, businessGroup, true);
+		init(ureq, statementOwner, courseRepo, businessGroup, links, true);
 	}
 		
-	private void init(UserRequest ureq, Identity statementOwner, BusinessGroup group, boolean mainLayout) { 
+	private void init(UserRequest ureq, Identity statementOwner, RepositoryEntry courseRepo, BusinessGroup group, boolean links, boolean mainLayout) { 
 		//extract efficiency statement data
 		//fallback translation for user properties 
 		setTranslator(UserManager.getInstance().getPropertyHandlerTranslator(getTranslator()));		
 		userDataVC = createVelocityContainer("efficiencystatement");
 		if(efficiencyStatement != null) {
-			userDataVC.contextPut("courseTitle", efficiencyStatement.getCourseTitle() + " (" + efficiencyStatement.getCourseRepoEntryKey().toString() + ")");
-			
+			userDataVC.contextPut("courseTitle", efficiencyStatement.getCourseTitle());
+			userDataVC.contextPut("date", StringHelper.formatLocaleDateTime(efficiencyStatement.getLastUpdated(), ureq.getLocale()));
+		} else if(courseRepo != null) {
+			userDataVC.contextPut("courseTitle", courseRepo.getDisplayname());
+		}
+		
+		if(courseRepoKey != null && links) {
 			courseLink = LinkFactory.createButton("course.link", userDataVC, this);
 			courseLink.setCustomEnabledLinkCSS("b_link_course");
 			userDataVC.put("course.link", courseLink);
-			userDataVC.contextPut("date", StringHelper.formatLocaleDateTime(efficiencyStatement.getLastUpdated(), ureq.getLocale()));
 		}
 		
 		userDataVC.contextPut("user", statementOwner.getUser());			
@@ -135,7 +164,7 @@ public class EfficiencyStatementController extends MainLayoutBasicController {
 		List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
 		userDataVC.contextPut("userPropertyHandlers", userPropertyHandlers);
 
-		if(!getIdentity().equals(statementOwner)) {
+		if(!getIdentity().equals(statementOwner) && links) {
 			homeLink = LinkFactory.createButton("home.link", userDataVC, this);
 			homeLink.setCustomEnabledLinkCSS("b_link_to_home");
 			userDataVC.put("home.link", homeLink);
@@ -147,9 +176,11 @@ public class EfficiencyStatementController extends MainLayoutBasicController {
 
 		if(group != null) {
 			userDataVC.contextPut("groupName", group.getName());
-			groupLink = LinkFactory.createButton("group.link", userDataVC, this);
-			groupLink.setCustomEnabledLinkCSS("b_link_group");
-			userDataVC.put("group.link", groupLink);
+			if(links) {
+				groupLink = LinkFactory.createButton("group.link", userDataVC, this);
+				groupLink.setCustomEnabledLinkCSS("b_link_group");
+				userDataVC.put("group.link", groupLink);
+			}
 		}
 		
 		if (efficiencyStatement != null) {
@@ -246,7 +277,7 @@ public class EfficiencyStatementController extends MainLayoutBasicController {
 	
 	private void openCourse(UserRequest ureq) {
 		List<ContextEntry> ces = new ArrayList<ContextEntry>(1);
-		OLATResourceable ores = OresHelper.createOLATResourceableInstance("RepositoryEntry", efficiencyStatement.getCourseRepoEntryKey());
+		OLATResourceable ores = OresHelper.createOLATResourceableInstance("RepositoryEntry", courseRepoKey);
 		ces.add(BusinessControlFactory.getInstance().createContextEntry(ores));
 
 		BusinessControl bc = BusinessControlFactory.getInstance().createFromContextEntries(ces);
diff --git a/src/main/java/org/olat/course/assessment/IdentityAssessmentEditController.java b/src/main/java/org/olat/course/assessment/IdentityAssessmentEditController.java
index 069e7af85c1..b86d7466684 100644
--- a/src/main/java/org/olat/course/assessment/IdentityAssessmentEditController.java
+++ b/src/main/java/org/olat/course/assessment/IdentityAssessmentEditController.java
@@ -88,12 +88,12 @@ public class IdentityAssessmentEditController extends BasicController {
 	 */
 	public IdentityAssessmentEditController(WindowControl wControl, UserRequest ureq, 
 			Identity assessedIdentity, ICourse course, boolean mayEdit) {
-		this(wControl, ureq, assessedIdentity, course, mayEdit, false); 
+		this(wControl, ureq, assessedIdentity, course, mayEdit, true); 
 	}
 		
 	public IdentityAssessmentEditController(WindowControl wControl, UserRequest ureq, 
 			Identity assessedIdentity, ICourse course, boolean mayEdit, boolean headers) {
-		
+
 		super(ureq, wControl);
 		this.mayEdit = mayEdit;
 		this.main = new Panel("main");
diff --git a/src/main/java/org/olat/course/assessment/_content/efficiencystatement.html b/src/main/java/org/olat/course/assessment/_content/efficiencystatement.html
index 3a13a3b8008..3ccff6f6a90 100644
--- a/src/main/java/org/olat/course/assessment/_content/efficiencystatement.html
+++ b/src/main/java/org/olat/course/assessment/_content/efficiencystatement.html
@@ -51,15 +51,6 @@ Ext.onReady(function(){
 		</div>
 		<div class="b_c50r">
 			<table class="b_table">
-				#if($groupName)
-					<tr>
-						<td><label>$r.translate("group")</label></td>
-						<td>$groupName</td>
-						#if($r.available("group.link"))
-							<td>$r.render("group.link")</td>
-						#end
-					</tr>
-				#end
 				#if($courseTitle)
 					<tr>
 						<td><label>$r.translate("course")</label></td>
@@ -68,11 +59,22 @@ Ext.onReady(function(){
 							<td>$r.render("course.link")</td>
 						#end
 					</tr>
+				#end
+				#if($date)
 					<tr>
 						<td><label>$r.translate("date")</label></td>
 						<td>$date</td>
 					</tr>
 				#end
+				#if($groupName)
+					<tr>
+						<td><label>$r.translate("group")</label></td>
+						<td>$groupName</td>
+						#if($r.available("group.link"))
+							<td>$r.render("group.link")</td>
+						#end
+					</tr>
+				#end
 			</table>
 		</div>
 	</div>
diff --git a/src/main/java/org/olat/course/assessment/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/assessment/_i18n/LocalStrings_de.properties
index 84be500eed1..796efe47cfa 100644
--- a/src/main/java/org/olat/course/assessment/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/course/assessment/_i18n/LocalStrings_de.properties
@@ -32,14 +32,15 @@ cmd.filterGroups=Von mir betreute Gruppen mit Zugriff auf gew\u00E4hlten Kursbau
 cmd.showAllCourseNodes=Alle bewertbaren Kursbausteine anzeigen 
 cmd.showAllGroups=Alle von mir betreuten Gruppen anzeigen 
 column=Spalte {0}
-contact.link=Kontakt
+contact.link=Kontaktieren
 command.closeassessment=Schliessen
 command.hidelog=\u00C4nderungsverlauf ausblenden
 command.showlog=\u00C4nderungsverlauf anzeigen
 command.start.bulkwizard=Massenbewertung starten
 course=Kurs\:
+course.link=Kurs \u00F6ffnen
 group=Gruppe\:
-group.link=Gruppe
+group.link=Gruppe \u00F6ffnen
 date=Datum\:
 detailview.title=Detailansicht der Bewertung
 efficiencyStatements.course.noaccess=Dieser Kurs wurde gesperrt, Sie haben keinen Zugang mehr 
@@ -98,8 +99,7 @@ institutionalname=Institution\:
 institutionaluseridentifier=Institutionsnummer (Matrikelnummer)\:
 lastname=Name\:
 log.title=\u00C4nderungsverlauf
-home.link=Visitkarte
-course.link=Kurs
+home.link=Visitenkarte
 menu.bulkfocus=Massenbewertung
 menu.bulkfocus.alt=Massenbewertung von Bewertungs- und Aufgabekursbausteinen.
 menu.groupfocus=Nach Gruppen
diff --git a/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java b/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java
index 5c3f2359356..825c04ac934 100644
--- a/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java
+++ b/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java
@@ -26,6 +26,7 @@
 package org.olat.course.assessment.manager;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -167,7 +168,7 @@ public class UserCourseInformationsManagerImpl extends BasicManager implements U
 				identityKeys.add(identity.getKey());
 			}
 			query.setParameterList("identityKeys", identityKeys);
-			query.setLong("resourceKey", courseResourceId);
+			query.setLong("resId", courseResourceId);
 			@SuppressWarnings("unchecked")
 			List<Object[]> infoList = query.list();
 			Map<Long,Date> dateMap = new HashMap<Long,Date>();
@@ -179,7 +180,7 @@ public class UserCourseInformationsManagerImpl extends BasicManager implements U
 			return dateMap;
 		} catch (Exception e) {
 			logError("Cannot retrieve course informations for: " + courseResourceId, e);
-			return null;
+			return Collections.emptyMap();
 		}
 	}
 }
\ No newline at end of file
-- 
GitLab