Merge branch 'develop' into peer_reviewdate_feature
This commit is contained in:
commit
c50b214c8d
src
main/java/se/su/dsv/scipro
admin/pages/settings
components
data
opponent/panels
peer
pages
panels
repository/panels
security/auth
workerthreads
test/java/se/su/dsv/scipro/wicket
@ -5,8 +5,21 @@
|
||||
<wicket:extend>
|
||||
|
||||
<div class="append-bottom">
|
||||
<h5 class="peer-title">Settings for levels</h5>
|
||||
<h5 class="peer-title">General settings</h5>
|
||||
<form wicket:id="peerSettingsForm">
|
||||
<form wicket:id="peerRatingsSettingsForm">
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="peerRatingsEnabled">Enable peers to rate reviews and the display of ratings: </label></td>
|
||||
<td><input type="checkbox" wicket:id="peerRatingsEnabled" name="peerRatingsEnabled"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="peerDisplayNumberOfReviewsPerformed">Display users number of reviews performed on portal page</label></td>
|
||||
<td><input type="checkbox" wicket:id="peerDisplayNumberOfReviewsPerformed" name="peerDisplayNumberOfReviewsPerformed"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<h5 class="peer-title">Settings for levels</h5>
|
||||
<ul class="no-list-style">
|
||||
<li wicket:id="projectClassList" class="append-bottom">
|
||||
<h5 wicket:id="projectClassName" class="peer-box-subtitle"></h5>
|
||||
|
@ -3,15 +3,19 @@ package se.su.dsv.scipro.admin.pages.settings;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.form.Button;
|
||||
import org.apache.wicket.markup.html.form.CheckBox;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.model.CompoundPropertyModel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
import se.su.dsv.scipro.admin.pages.AbstractAdminSettingsPage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClassSettings;
|
||||
|
||||
@ -19,6 +23,8 @@ public class AdminPeerSettingsPage extends AbstractAdminSettingsPage {
|
||||
|
||||
@SpringBean
|
||||
private ProjectClassDao projectClassDao;
|
||||
@SpringBean
|
||||
private GeneralSystemSettingsDao generalSystemSettingsDao;
|
||||
|
||||
public AdminPeerSettingsPage(final PageParameters pp){
|
||||
super(pp);
|
||||
@ -43,11 +49,30 @@ public class AdminPeerSettingsPage extends AbstractAdminSettingsPage {
|
||||
}
|
||||
|
||||
});
|
||||
CompoundPropertyModel<GeneralSystemSettings> ratingsModel = new CompoundPropertyModel<GeneralSystemSettings>(generalSystemSettingsDao.getGeneralSystemSettingsInstance());
|
||||
PeerRatingsSettingsForm peerRatingsSettingsForm = new PeerRatingsSettingsForm("peerRatingsSettingsForm", ratingsModel);
|
||||
peerSettingsForm.add(peerRatingsSettingsForm);
|
||||
|
||||
peerSettingsForm.add(new Button("submit"));
|
||||
add(peerSettingsForm);
|
||||
}
|
||||
|
||||
private class PeerRatingsSettingsForm extends Form<GeneralSystemSettings> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public PeerRatingsSettingsForm(String id, IModel<GeneralSystemSettings> model) {
|
||||
super(id, model);
|
||||
|
||||
CheckBox peerRatingsEnabled = new CheckBox("peerRatingsEnabled");
|
||||
add(peerRatingsEnabled);
|
||||
CheckBox peerDisplayNumberOfReviewsPerformed = new CheckBox("peerDisplayNumberOfReviewsPerformed");
|
||||
add(peerDisplayNumberOfReviewsPerformed);
|
||||
}
|
||||
@Override
|
||||
public void onSubmit(){
|
||||
setModelObject(generalSystemSettingsDao.save(getModelObject()));
|
||||
}
|
||||
}
|
||||
|
||||
private class PeerProjectClassSettingsForm extends Form<ProjectClassSettings> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
package se.su.dsv.scipro.components;
|
||||
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
/**
|
||||
* An invisible Panel that can trigger the hiding of wicket-enclosures which EmptyPanel doesn't do.
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public final class InvisiblePanel extends WebMarkupContainer {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvisiblePanel(String id) {
|
||||
super(id);
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible(){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +1,44 @@
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
* @author Martin Peters
|
||||
*
|
||||
*/
|
||||
|
||||
@Repository("generalSystemSettingsDao")
|
||||
public class GeneralSystemSettingsDaoJPAImp extends AbstractDaoJPAImp<GeneralSystemSettings>
|
||||
implements GeneralSystemSettingsDao {
|
||||
|
||||
|
||||
private static final long INSTANCE_ID = 1L;
|
||||
|
||||
public GeneralSystemSettingsDaoJPAImp() {
|
||||
super(GeneralSystemSettings.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = false)
|
||||
public GeneralSystemSettings getGeneralSystemSettingsInstance(){
|
||||
GeneralSystemSettings generalSystemSettings = load(1L);
|
||||
GeneralSystemSettings generalSystemSettings = load(INSTANCE_ID);
|
||||
if (generalSystemSettings == null) {
|
||||
generalSystemSettings = new GeneralSystemSettings();
|
||||
generalSystemSettings = new GeneralSystemSettings(INSTANCE_ID);
|
||||
save(generalSystemSettings);
|
||||
}
|
||||
return generalSystemSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = false)
|
||||
public GeneralSystemSettings save(GeneralSystemSettings object){
|
||||
if(object.getId() == null)
|
||||
throw new UnsupportedOperationException("You're not supposed to be creating new instances of this object manually!");
|
||||
return super.save(object);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ package se.su.dsv.scipro.data.dataobjects;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@ -27,8 +26,9 @@ public class GeneralSystemSettings extends DomainObject{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private Long id = null;
|
||||
@Override
|
||||
public Long getId() { return id; }
|
||||
|
||||
@Basic(optional=false)
|
||||
private int finalSeminarMaxActiveParticipants = 6;
|
||||
@ -40,7 +40,26 @@ public class GeneralSystemSettings extends DomainObject{
|
||||
private int daysBeforeFinalSeminarCanRegisterAsOpponent = 3;
|
||||
|
||||
@Basic(optional=true)
|
||||
private int projectPartnerDaysToLive;
|
||||
private int projectPartnerDaysToLive;
|
||||
|
||||
@Basic(optional=false)
|
||||
private boolean finalSeminarThesisMustBeAPDF = false;
|
||||
|
||||
@Basic(optional=false)
|
||||
private boolean peerRatingsEnabled = true;
|
||||
|
||||
@Basic(optional=false)
|
||||
private boolean peerDisplayNumberOfReviewsPerformed = true;
|
||||
|
||||
public GeneralSystemSettings(){
|
||||
}
|
||||
/**
|
||||
* Not part of the public API, do NOT USE
|
||||
*/
|
||||
public GeneralSystemSettings(Long id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public int getProjectPartnerDaysToLive() {
|
||||
return projectPartnerDaysToLive;
|
||||
@ -50,10 +69,6 @@ public class GeneralSystemSettings extends DomainObject{
|
||||
this.projectPartnerDaysToLive = projectPartnerDaysToLive;
|
||||
}
|
||||
|
||||
@Basic(optional=false)
|
||||
private boolean finalSeminarThesisMustBeAPDF = false;
|
||||
|
||||
|
||||
public int getDaysBeforeFinalSeminarCanRegisterAsActiveParticipant() {
|
||||
return daysBeforeFinalSeminarCanRegisterAsActiveParticipant;
|
||||
}
|
||||
@ -80,26 +95,27 @@ public class GeneralSystemSettings extends DomainObject{
|
||||
this.finalSeminarMaxActiveParticipants = finalSeminarMaxActiveParticipants;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the finalSeminarThesisMustBeAPDF
|
||||
*/
|
||||
public boolean isFinalSeminarThesisMustBeAPDF() {
|
||||
return finalSeminarThesisMustBeAPDF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param finalSeminarThesisMustBeAPDF the finalSeminarThesisMustBeAPDF to set
|
||||
*/
|
||||
public void setFinalSeminarThesisMustBeAPDF(boolean finalSeminarThesisMustBeAPDF) {
|
||||
this.finalSeminarThesisMustBeAPDF = finalSeminarThesisMustBeAPDF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
||||
public void setPeerRatingsEnabled(boolean peerRatingsEnabled) {
|
||||
this.peerRatingsEnabled = peerRatingsEnabled;
|
||||
}
|
||||
public boolean isPeerRatingsEnabled() {
|
||||
return peerRatingsEnabled;
|
||||
}
|
||||
public void setPeerDisplayNumberOfReviewsPerformed(boolean peerDisplayNumberOfReviewsPerformed) {
|
||||
this.peerDisplayNumberOfReviewsPerformed = peerDisplayNumberOfReviewsPerformed;
|
||||
}
|
||||
public boolean isPeerDisplayNumberOfReviewsPerformed() {
|
||||
return peerDisplayNumberOfReviewsPerformed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package se.su.dsv.scipro.opponent.panels;
|
||||
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.panel.Fragment;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
@ -11,7 +9,6 @@ import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClassSettings;
|
||||
import se.su.dsv.scipro.icons.HelpIconDialog;
|
||||
import se.su.dsv.scipro.icons.HelpIconPanelDialog;
|
||||
|
||||
public class AvailableFinalSeminarHelpPanel extends Panel {
|
||||
@ -29,47 +26,29 @@ public class AvailableFinalSeminarHelpPanel extends Panel {
|
||||
int registerAsOpponent = 0;
|
||||
int registerAsActiveParticpant = 0;
|
||||
int maxActiveParticpants = 0;
|
||||
GeneralSystemSettings settings = generalSystemSettingsDao
|
||||
.getGeneralSystemSettingsInstance();
|
||||
GeneralSystemSettings settings = generalSystemSettingsDao.getGeneralSystemSettingsInstance();
|
||||
|
||||
settings = generalSystemSettingsDao.save(settings);
|
||||
registerAsActiveParticpant = settings
|
||||
.getDaysBeforeFinalSeminarCanRegisterAsActiveParticipant();
|
||||
registerAsOpponent = settings
|
||||
.getDaysBeforeFinalSeminarCanRegisterAsOpponent();
|
||||
registerAsActiveParticpant = settings.getDaysBeforeFinalSeminarCanRegisterAsActiveParticipant();
|
||||
registerAsOpponent = settings.getDaysBeforeFinalSeminarCanRegisterAsOpponent();
|
||||
maxActiveParticpants = settings.getFinalSeminarMaxActiveParticipants();
|
||||
|
||||
ProjectClassSettings bachelorSettings = projectClassDao
|
||||
.getProjectClass(ProjectClass.BACHELOR)
|
||||
.getProjectClassSettings();
|
||||
ProjectClassSettings masterSettings = projectClassDao.getProjectClass(
|
||||
ProjectClass.MASTER).getProjectClassSettings();
|
||||
int maxOpponentsBachelor = bachelorSettings
|
||||
.getMaxOpponentsOnFinalSeminar();
|
||||
ProjectClassSettings bachelorSettings = projectClassDao.getProjectClass(ProjectClass.BACHELOR).getProjectClassSettings();
|
||||
ProjectClassSettings masterSettings = projectClassDao.getProjectClass(ProjectClass.MASTER).getProjectClassSettings();
|
||||
int maxOpponentsBachelor = bachelorSettings.getMaxOpponentsOnFinalSeminar();
|
||||
int maxOpponentsMaster = masterSettings.getMaxOpponentsOnFinalSeminar();
|
||||
int maxActiveParticipationBachelor = bachelorSettings
|
||||
.getMaxFinalSeminarActiveParticipation();
|
||||
int maxActiveParticipationMaster = masterSettings
|
||||
.getMaxFinalSeminarActiveParticipation();
|
||||
int maxOppositionsBachelor = bachelorSettings
|
||||
.getMaxRegisterAsOpponent();
|
||||
int maxActiveParticipationBachelor = bachelorSettings.getMaxFinalSeminarActiveParticipation();
|
||||
int maxActiveParticipationMaster = masterSettings.getMaxFinalSeminarActiveParticipation();
|
||||
int maxOppositionsBachelor = bachelorSettings.getMaxRegisterAsOpponent();
|
||||
int maxOppositionsMaster = masterSettings.getMaxRegisterAsOpponent();
|
||||
add(new Label("maxActiveParticpants",
|
||||
String.valueOf(maxActiveParticpants)));
|
||||
add(new Label("activeRegister",
|
||||
String.valueOf(registerAsActiveParticpant)));
|
||||
add(new Label("maxActiveParticpants", String.valueOf(maxActiveParticpants)));
|
||||
add(new Label("activeRegister", String.valueOf(registerAsActiveParticpant)));
|
||||
add(new Label("opponentRegister", String.valueOf(registerAsOpponent)));
|
||||
add(new Label("maxOpponentsBachelor",
|
||||
String.valueOf(maxOpponentsBachelor)));
|
||||
add(new Label("maxOpponentsBachelor", String.valueOf(maxOpponentsBachelor)));
|
||||
add(new Label("maxOpponentsMaster", String.valueOf(maxOpponentsMaster)));
|
||||
add(new Label("maxActiveBachelor",
|
||||
String.valueOf(maxActiveParticipationBachelor)));
|
||||
add(new Label("maxActiveMaster",
|
||||
String.valueOf(maxActiveParticipationMaster)));
|
||||
add(new Label("maxOppositionsBachelor",
|
||||
String.valueOf(maxOppositionsBachelor)));
|
||||
add(new Label("maxOppositionsMaster",
|
||||
String.valueOf(maxOppositionsMaster)));
|
||||
add(new Label("maxActiveBachelor", String.valueOf(maxActiveParticipationBachelor)));
|
||||
add(new Label("maxActiveMaster", String.valueOf(maxActiveParticipationMaster)));
|
||||
add(new Label("maxOppositionsBachelor", String.valueOf(maxOppositionsBachelor)));
|
||||
add(new Label("maxOppositionsMaster", String.valueOf(maxOppositionsMaster)));
|
||||
}
|
||||
|
||||
public Panel getHelpIcon(String id) {
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.markup.html.panel.EmptyPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
@ -24,14 +25,12 @@ public class ProjectFinalSeminarContainerPanel extends Panel {
|
||||
|
||||
final List<FinalSeminar> seminars = finalSeminarDao.findFinalSeminarsByProject(project);
|
||||
|
||||
add(new OpponentPanel("addSeminar", project){
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean isVisible(){
|
||||
return seminars.size() == 0 && isSupervisorView;
|
||||
}
|
||||
});
|
||||
if(isSupervisorView && !seminars.isEmpty() ){
|
||||
add(new OpponentPanel("addSeminar", project));
|
||||
}
|
||||
else {
|
||||
add(new EmptyPanel("addSeminar"));
|
||||
}
|
||||
add(new Label("noSeminarsMessage", "No final seminar has been created for this project"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
package se.su.dsv.scipro.peer.pages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
import se.su.dsv.scipro.basepages.MenuPage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MailEventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.MailEvent;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.QuestionDao;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.ReviewTemplateDao;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.Question;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.QuestionOption;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.ReviewTemplate;
|
||||
import se.su.dsv.scipro.security.auth.Authorization;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
|
||||
@Authorization(authorizedRoles={Roles.SYSADMIN})
|
||||
public class PeerTestPage extends MenuPage {
|
||||
|
||||
@SpringBean
|
||||
private QuestionDao questionDao;
|
||||
@SpringBean
|
||||
private ReviewTemplateDao rtDao;
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
@SpringBean
|
||||
private MailEventDao mailEventDao;
|
||||
|
||||
public PeerTestPage(){
|
||||
ReviewTemplate rt = new ReviewTemplate();
|
||||
rt.setName("Template for something");
|
||||
Question q = new Question();
|
||||
q.setQuestion("Really?");
|
||||
q.setRadioChoiceQuestion(true);
|
||||
q.setReviewTemplate(rt);
|
||||
q.getRadioOptions().add(new QuestionOption(q, "Yes"));
|
||||
q.getRadioOptions().add(new QuestionOption(q, "No"));
|
||||
|
||||
rt.getQuestions().add(q);
|
||||
//rt = rtDao.save(rt);
|
||||
System.out.println(questionDao.findAll());
|
||||
System.out.println(questionDao.findAll().get(0).getRadioOptions());
|
||||
|
||||
User recipient = userDao.getUserByUsername("mpeters");
|
||||
User replyUser = userDao.getUserByUsername("dan-kjel");
|
||||
ArrayList<User> senderstmp = new ArrayList<User>();
|
||||
senderstmp.add(replyUser);
|
||||
MailEvent me = new MailEvent("subject åäö","this is the message åäö",recipient,"SciPro-avsändare åäö","no-reply@thesis.dsv.su.se", senderstmp,null);
|
||||
me = mailEventDao.save(me);
|
||||
}
|
||||
|
||||
}
|
@ -72,10 +72,13 @@
|
||||
</div>
|
||||
<!-- End left column -->
|
||||
<div class="span-6 last">
|
||||
<wicket:enclosure>
|
||||
<div class="rounded-box">
|
||||
<span class="box-title">Most frequent reviewers</span>
|
||||
<div wicket:id="mostFrequentPanel" class="append-bottom"></div>
|
||||
</div>
|
||||
</wicket:enclosure>
|
||||
<wicket:enclosure>
|
||||
<div class="rounded-box">
|
||||
<span class="box-title">Best rated reviewers</span>
|
||||
<div wicket:id="bestRatedPanel" class="append-bottom"></div>
|
||||
@ -83,6 +86,7 @@
|
||||
<div>
|
||||
<i><span class="small right">Last 12 months</span></i>
|
||||
</div>
|
||||
</wicket:enclosure>
|
||||
</div>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
|
@ -11,6 +11,7 @@ import org.apache.wicket.markup.html.link.Link;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.PageableListView;
|
||||
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
|
||||
import org.apache.wicket.markup.html.panel.EmptyPanel;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.Model;
|
||||
@ -19,7 +20,10 @@ import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.apache.wicket.util.string.Strings;
|
||||
|
||||
import se.su.dsv.scipro.components.ExpandableMultiLineLabel;
|
||||
import se.su.dsv.scipro.components.InvisiblePanel;
|
||||
import se.su.dsv.scipro.components.SciProTooltipBehavior;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClassSettings;
|
||||
@ -46,6 +50,8 @@ public class PeerPortalPanel extends Panel {
|
||||
private PeerPortalController peerPortalController;
|
||||
@SpringBean
|
||||
private PeerReviewDao peerReviewDao;
|
||||
@SpringBean
|
||||
private GeneralSystemSettingsDao generalSystemSettingsDao;
|
||||
|
||||
|
||||
public PeerPortalPanel(final String id, final ProjectClass projectClass){
|
||||
@ -208,10 +214,20 @@ public class PeerPortalPanel extends Panel {
|
||||
PagingNavigator bottomRequestListNavigator = new RequestListNavigator("bottomNavigator", requestList);
|
||||
add(bottomRequestListNavigator);
|
||||
|
||||
|
||||
|
||||
add(new MostFrequentReviewersPanel("mostFrequentPanel"));
|
||||
add(new BestRatedReviewersPanel("bestRatedPanel"));
|
||||
GeneralSystemSettings gsettings = generalSystemSettingsDao.getGeneralSystemSettingsInstance();
|
||||
final String mostFrequentPanel = "mostFrequentPanel";
|
||||
final String bestRatedPanel = "bestRatedPanel";
|
||||
|
||||
if(gsettings.isPeerDisplayNumberOfReviewsPerformed()){
|
||||
add(new MostFrequentReviewersPanel(mostFrequentPanel));
|
||||
} else {
|
||||
add(new InvisiblePanel(mostFrequentPanel));
|
||||
}
|
||||
if( gsettings.isPeerRatingsEnabled() ){
|
||||
add(new BestRatedReviewersPanel(bestRatedPanel));
|
||||
} else {
|
||||
add(new InvisiblePanel(bestRatedPanel));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package se.su.dsv.scipro.peer.panels;
|
||||
|
||||
import org.apache.wicket.feedback.FeedbackMessage;
|
||||
import org.apache.wicket.feedback.IFeedbackMessageFilter;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
|
||||
@ -20,14 +18,7 @@ public class PeerReviewPanel extends Panel {
|
||||
add(new DisplayReviewPanel("displayReview", review));
|
||||
add(new CommentThreadPanel("comments",review, 4));
|
||||
|
||||
add(new FeedbackPanel("feedback", new IFeedbackMessageFilter() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean accept(FeedbackMessage message) {
|
||||
return message.getLevel() == FeedbackMessage.INFO;
|
||||
}
|
||||
}));
|
||||
add(new FeedbackPanel("feedback"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
<div class="span-12 last">
|
||||
<form wicket:id="reviewForm">
|
||||
<div wicket:id="topFeedbackPanel" class="last"></div>
|
||||
<!-- <div wicket:id="topFeedbackPanel" class="last"></div>-->
|
||||
|
||||
<div class="prepend-top last">
|
||||
<h5 class="peer-title" wicket:id="questionsHeading">Questions</h5>
|
||||
|
@ -283,7 +283,7 @@ public class PeerReviewPerformReviewPanel extends Panel {
|
||||
"Please confirm that you have completed the review and taken care to highlight both strengths and weaknesses."));
|
||||
add(submitButton);
|
||||
|
||||
add(new ComponentFeedbackPanel("topFeedbackPanel",submitButton));
|
||||
//add(new ComponentFeedbackPanel("topFeedbackPanel",submitButton));
|
||||
add(new ComponentFeedbackPanel("bottomFeedbackPanel",submitButton));
|
||||
}//PerformReviewForm
|
||||
|
||||
|
@ -15,8 +15,10 @@
|
||||
</ul>
|
||||
|
||||
<div>
|
||||
<wicket:enclosure>
|
||||
<strong>Review rating:</strong>
|
||||
<div wicket:id="ratingPanel"></div>
|
||||
</wicket:enclosure>
|
||||
</div>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
|
@ -8,15 +8,13 @@ import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
import se.su.dsv.scipro.components.InvisiblePanel;
|
||||
import se.su.dsv.scipro.data.DomainObjectDetachableModel;
|
||||
import se.su.dsv.scipro.data.dataobjects.FileDescription;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.PeerReviewDao;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.PeerReview;
|
||||
import se.su.dsv.scipro.repository.components.FileDownloadLink;
|
||||
import se.su.dsv.scipro.repository.components.FileOpenLink;
|
||||
|
||||
public class ReviewPageReviewDetailsPanel extends Panel {
|
||||
|
||||
@ -24,6 +22,8 @@ public class ReviewPageReviewDetailsPanel extends Panel {
|
||||
|
||||
@SpringBean
|
||||
private PeerReviewDao peerReviewDao;
|
||||
@SpringBean
|
||||
private GeneralSystemSettingsDao generalSystemSettingsDao;
|
||||
|
||||
public ReviewPageReviewDetailsPanel(final String id, final PeerReview review) {
|
||||
super(id);
|
||||
@ -36,7 +36,13 @@ public class ReviewPageReviewDetailsPanel extends Panel {
|
||||
add(review.getReviewer().getUser().getDisplayComponent("reviewer"));
|
||||
add(review.getProject().getHeadSupervisor().getUser().getDisplayComponent("supervisor"));
|
||||
add(new DateLabel("acceptDate", new Model<Date>(review.getDateCreated()), dpc));
|
||||
add(new PeerReviewRatingPanel("ratingPanel", reviewModel ));
|
||||
|
||||
final String ratingPanel = "ratingPanel";
|
||||
if(generalSystemSettingsDao.getGeneralSystemSettingsInstance().isPeerRatingsEnabled()){
|
||||
add(new PeerReviewRatingPanel(ratingPanel, reviewModel ));
|
||||
} else {
|
||||
add(new InvisiblePanel(ratingPanel));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ public class ProjectFilePanel extends AbstractFilePanel {
|
||||
|
||||
private long projectId;
|
||||
|
||||
private static final String PROJECT_URL_KEY = "id";
|
||||
|
||||
@Override
|
||||
protected String getBasePath(){
|
||||
return super.fileRepository.getProjectRootPath(projectId);
|
||||
@ -36,7 +34,7 @@ public class ProjectFilePanel extends AbstractFilePanel {
|
||||
public ProjectFilePanel(String id, PageParameters pp, FilePanelContainer fpc) {
|
||||
super(id, pp, fpc);
|
||||
|
||||
Long projectId = pp.getAsLong(PROJECT_URL_KEY);
|
||||
Long projectId = pp.getAsLong(Project.PP_PROJECT_ID);
|
||||
if(projectId == null){
|
||||
failAndRedirect();
|
||||
}
|
||||
@ -60,13 +58,13 @@ public class ProjectFilePanel extends AbstractFilePanel {
|
||||
|
||||
public static PageParameters getPrefabricatedPageParameters(Project project){
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.put(PROJECT_URL_KEY, project.getId());
|
||||
pp.put(Project.PP_PROJECT_ID, project.getId());
|
||||
return pp;
|
||||
}
|
||||
|
||||
public static PageParameters getPrefabricatedPageParameters(Long projectId){
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.put(PROJECT_URL_KEY, projectId);
|
||||
pp.put(Project.PP_PROJECT_ID, projectId);
|
||||
return pp;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
public class RoleBasedAuthorizationStrategy implements IAuthorizationStrategy {
|
||||
|
||||
public boolean isActionAuthorized(Component component, Action action) {
|
||||
//System.out.println("Comp: "+component+" action: "+action);
|
||||
boolean ok = false;
|
||||
Class<? extends Component> authRequired = null;
|
||||
if (component instanceof BookmarkablePageLink<?>) {
|
||||
@ -38,10 +39,11 @@ public class RoleBasedAuthorizationStrategy implements IAuthorizationStrategy {
|
||||
if ( !annotation.requiresLoggedInUser() )
|
||||
ok = true;
|
||||
else {
|
||||
SciProSession session = SciProSession.get();
|
||||
//Check for presence of login and if present check for authorization
|
||||
if( SciProSession.get().isLoggedIn() ){//&& annotation.authorizedRoles().length > 0){ If no roles added, ok will be false
|
||||
if( session.isLoggedIn() ){//&& annotation.authorizedRoles().length > 0){ If no roles added, ok will be false
|
||||
for( Roles role : annotation.authorizedRoles() ){
|
||||
if( SciProSession.get().authorizedForRole(role) ){
|
||||
if( session.authorizedForRole(role) ){
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
@ -69,17 +71,15 @@ public class RoleBasedAuthorizationStrategy implements IAuthorizationStrategy {
|
||||
}
|
||||
|
||||
public <T extends Component> boolean isInstantiationAuthorized(Class<T> componentClass) {
|
||||
|
||||
//Not annotated classes aren't checked further
|
||||
Authorization annotation = (Authorization) componentClass.getAnnotation(Authorization.class);
|
||||
if (annotation != null) {
|
||||
|
||||
//If component doesn't require login anyone may do it any time
|
||||
if( !annotation.requiresLoggedInUser() )
|
||||
return true;
|
||||
|
||||
SciProSession session = SciProSession.get();
|
||||
//If page requires login and user isn't logged in, send them to login page first
|
||||
if( annotation.requiresLoggedInUser() && !SciProSession.get().isLoggedIn() )
|
||||
if( annotation.requiresLoggedInUser() && !session.isLoggedIn() )
|
||||
throw new RestartResponseAtInterceptPageException(LoginPage.class);
|
||||
|
||||
//We only check pages for instantiation authorization, other components are handled via ActionAuthorization
|
||||
@ -88,7 +88,7 @@ public class RoleBasedAuthorizationStrategy implements IAuthorizationStrategy {
|
||||
|
||||
//Check the users role for authorization to instantiate the component
|
||||
for(Roles role : annotation.authorizedRoles()){
|
||||
if( SciProSession.get().authorizedForRole(role) )
|
||||
if( session.authorizedForRole(role) )
|
||||
return true;
|
||||
}
|
||||
//No roles were added to the annotation or user was not authorized for the roles that were added
|
||||
|
@ -42,7 +42,6 @@ public class MailEventWorker extends AbstractWorker {
|
||||
for( MailEvent mailEvent : mailEvents ){
|
||||
try{
|
||||
this.beginTransaction();
|
||||
//System.out.println("Emailing, events:"+mailEventDao.countAll());
|
||||
|
||||
final String subject = mailEvent.getSubject();
|
||||
final String fromName = mailEvent.getFromName();
|
||||
@ -73,7 +72,6 @@ public class MailEventWorker extends AbstractWorker {
|
||||
mailEvent = mailEventDao.reLoad(mailEvent); //Re-attach to session so delete works
|
||||
mailEventDao.delete(mailEvent);
|
||||
|
||||
System.out.println("Email sent, events: "+mailEventDao.countAll());
|
||||
this.commitTransaction();
|
||||
|
||||
} catch(Exception e){
|
||||
|
177
src/test/java/se/su/dsv/scipro/wicket/BaseWicketTest.java
Normal file
177
src/test/java/se/su/dsv/scipro/wicket/BaseWicketTest.java
Normal file
@ -0,0 +1,177 @@
|
||||
package se.su.dsv.scipro.wicket;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.wicket.Request;
|
||||
import org.apache.wicket.Response;
|
||||
import org.apache.wicket.Session;
|
||||
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
|
||||
import org.apache.wicket.spring.test.ApplicationContextMock;
|
||||
import org.apache.wicket.util.tester.WicketTester;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
|
||||
import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;
|
||||
|
||||
import se.su.dsv.scipro.SciProApplication;
|
||||
import se.su.dsv.scipro.data.controllers.FinalSeminarUploadController;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.BoardMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CommentDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CommentThreadDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.EventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FileDescriptionDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FinalSeminarActiveParticipationDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FinalSeminarDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FinalSeminarOppositionDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GeneralSystemSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GroupEventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.HandInActivityDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MessageBoardDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectEventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectScheduleDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RoleDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ScheduleTemplateDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.StringResourceDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.WorkerDataDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.peer.data.dao.controllers.PeerPortalController;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.PeerRequestDao;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.PeerReviewDao;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.ReviewRatingDao;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.ReviewTemplateDao;
|
||||
import se.su.dsv.scipro.repository.FileRepository;
|
||||
import se.su.dsv.scipro.repository.util.RepositoryManager;
|
||||
/**
|
||||
* A class that serves as a base for testing Wicket-pages, it containts a WicketTester and a mocked-up
|
||||
* applicationContext that can easily be extended or modified to suit the individual tests
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class BaseWicketTest {
|
||||
|
||||
protected WicketTester tester;
|
||||
|
||||
/*
|
||||
* Add beans to be mocked-up. Note that the name of the field is identical
|
||||
* to the name that will be given to the bean in the applicationContext.
|
||||
*/
|
||||
@Mock EventDao eventDao;
|
||||
@Mock UserDao userDao;
|
||||
@Mock RoleDao roleDao;
|
||||
@Mock ProjectDao projectDao;
|
||||
@Mock ProjectClassDao projectClassDao;
|
||||
@Mock UserSettingsDao userSettingsDao;
|
||||
@Mock FinalSeminarDao finalSeminarDao;
|
||||
@Mock FinalSeminarOppositionDao finalSeminarOppositionDao;
|
||||
@Mock PeerReviewDao peerReviewDao;
|
||||
@Mock PeerRequestDao peerRequestDao;
|
||||
@Mock ProjectEventDao projectEventDao;
|
||||
@Mock BoardMessageDao boardMessageDao;
|
||||
@Mock MessageBoardDao messageBoardDao;
|
||||
@Mock CommentThreadDao commentThreadDao;
|
||||
@Mock ProjectScheduleDao projectScheduleDao;
|
||||
@Mock FileDescriptionDao fileDescriptionDao;
|
||||
@Mock FileRepository fileRepository;
|
||||
@Mock WorkerDataDao workerDataDao;
|
||||
@Mock ReviewRatingDao reviewRatingDao;
|
||||
@Mock PeerPortalController peerPortalController;
|
||||
@Mock CommentDao commentDao;
|
||||
@Mock ReviewTemplateDao reviewTemplateDao;
|
||||
@Mock FinalSeminarActiveParticipationDao finalSeminarActiveParticipationDao;
|
||||
@Mock FinalSeminarUploadController finalSeminarUploadController;
|
||||
@Mock GeneralSystemSettingsDao generalSystemSettingsDao;
|
||||
@Mock ProjectClassSettingsDao projectClassSettingsDao;
|
||||
@Mock GroupEventDao groupEventDao;
|
||||
@Mock HandInActivityDao handInActivityDao;
|
||||
@Mock ScheduleTemplateDao scheduleTemplateDao;
|
||||
|
||||
@Mock RepositoryManager repositoryManager;
|
||||
@Mock StringResourceDao stringResourceDao;
|
||||
|
||||
@Mock EntityManagerFactoryInfo entityManagerFactory = Mockito.mock(LocalEntityManagerFactoryBean.class);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
/*
|
||||
* Setup a new mock applicationContext
|
||||
*/
|
||||
final ApplicationContextMock acm = new ApplicationContextMock();
|
||||
|
||||
/*
|
||||
* Initialize annotated Mockups
|
||||
*/
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
/*
|
||||
* Add mocked-up beans to applicationContext, replaces a lot of lines like: acm.putBean("userDao", userDao);
|
||||
*/
|
||||
for(Field f : BaseWicketTest.class.getDeclaredFields()){
|
||||
if( f.isAnnotationPresent(Mock.class) ){
|
||||
try {
|
||||
acm.putBean(f.getName(), f.get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up behavior that is always true for any test, like behavior of reLoad-methods
|
||||
*/
|
||||
Mockito.when(projectDao.reLoad( Mockito.any(Project.class) )).thenAnswer(new Answer<Project>() {
|
||||
@Override
|
||||
public Project answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Project) invocation.getArguments()[0];
|
||||
}
|
||||
});
|
||||
|
||||
Mockito.when(generalSystemSettingsDao.getGeneralSystemSettingsInstance()).thenReturn(new GeneralSystemSettings());
|
||||
|
||||
/*
|
||||
* Setup a new wicket-tester instance
|
||||
*/
|
||||
tester = new WicketTester(new SciProApplication(){
|
||||
/* (non-Javadoc)
|
||||
* @see se.su.dsv.scipro.WicketApplication#getGuiceInjector()
|
||||
*/
|
||||
@Override
|
||||
protected SpringComponentInjector getSpringInjector() {
|
||||
return new SpringComponentInjector(this, acm, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session newSession(Request request, Response response) {
|
||||
if(MockSciProSession.currentSession == null){
|
||||
//Default session is a student-session
|
||||
MockSciProSession.currentSession = new MockSciProSession(request);
|
||||
}
|
||||
return MockSciProSession.currentSession;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void setLoggedIn(boolean loggedIn){
|
||||
MockSciProSession.currentSession.setLoggedIn(loggedIn);
|
||||
}
|
||||
protected void setUser(User user){
|
||||
MockSciProSession.currentSession.setUser(user);
|
||||
}
|
||||
protected void setActiveProject(Project activeProject){
|
||||
MockSciProSession.currentSession.setActiveProject(activeProject);
|
||||
}
|
||||
|
||||
}
|
91
src/test/java/se/su/dsv/scipro/wicket/MockSciProSession.java
Normal file
91
src/test/java/se/su/dsv/scipro/wicket/MockSciProSession.java
Normal file
@ -0,0 +1,91 @@
|
||||
package se.su.dsv.scipro.wicket;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.wicket.Request;
|
||||
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.security.auth.roles.Employee;
|
||||
import se.su.dsv.scipro.security.auth.roles.IRole;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
import se.su.dsv.scipro.security.auth.roles.Student;
|
||||
import se.su.dsv.scipro.security.auth.roles.SysAdmin;
|
||||
/**
|
||||
*
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class MockSciProSession extends SciProSession {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static MockSciProSession currentSession = null;
|
||||
|
||||
private IRole currentRole = new Student();
|
||||
public Project mockActiveProject = null;
|
||||
public User mockUser = null;
|
||||
|
||||
public MockSciProSession(Request request) {
|
||||
super(request);
|
||||
}
|
||||
/**
|
||||
* Set if the user is logged in or not
|
||||
* @param loggedIn
|
||||
*/
|
||||
public void setLoggedIn(boolean loggedIn){
|
||||
try {
|
||||
Field field = SciProSession.class.getDeclaredField("loggedIn");
|
||||
field.setAccessible(true);
|
||||
field.set(this, loggedIn);
|
||||
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authorizedForRole(Roles role) {
|
||||
return currentRole.authorizedForRole(role);
|
||||
}
|
||||
@Override
|
||||
public boolean hasActualRole(Roles role){
|
||||
return currentRole.isActualRole(role);
|
||||
}
|
||||
|
||||
public void setLoggedinAsStudent(){
|
||||
currentRole = new Student();
|
||||
}
|
||||
public void setLoggedInAsSysAdmin(){
|
||||
currentRole = new SysAdmin();
|
||||
}
|
||||
public void setLoggedInAsEmployee(){
|
||||
currentRole = new Employee();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getActiveProject(){
|
||||
return mockActiveProject;
|
||||
}
|
||||
@Override
|
||||
public void setActiveProject(Project project){
|
||||
mockActiveProject = project;
|
||||
}
|
||||
@Override
|
||||
public User getUser(){
|
||||
return mockUser;
|
||||
}
|
||||
@Override
|
||||
public void setUser(User user){
|
||||
mockUser = user;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,107 +1,169 @@
|
||||
package se.su.dsv.scipro.wicket;
|
||||
|
||||
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
|
||||
import org.apache.wicket.spring.test.ApplicationContextMock;
|
||||
import org.apache.wicket.util.tester.WicketTester;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
|
||||
import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;
|
||||
|
||||
import se.su.dsv.scipro.HomePage;
|
||||
import se.su.dsv.scipro.SciProApplication;
|
||||
import se.su.dsv.scipro.admin.pages.SystemMaintenancePage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.EventDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RoleDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.StringResourceDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.loginlogout.pages.LoginPage;
|
||||
import se.su.dsv.scipro.loginlogout.pages.LogoutPage;
|
||||
import se.su.dsv.scipro.project.pages.FinalSeminarProjectListPage;
|
||||
import se.su.dsv.scipro.project.pages.ProjectFilePage;
|
||||
import se.su.dsv.scipro.project.pages.ProjectOppositionPage;
|
||||
import se.su.dsv.scipro.project.pages.ProjectSchedulePlannerPage;
|
||||
import se.su.dsv.scipro.project.pages.ProjectStartPage;
|
||||
import se.su.dsv.scipro.repository.util.RepositoryManager;
|
||||
import se.su.dsv.scipro.supervisor.pages.SupervisorFinalSeminarListingPage;
|
||||
import se.su.dsv.scipro.supervisor.pages.SupervisorProjectDetailsPage;
|
||||
import se.su.dsv.scipro.supervisor.pages.SupervisorScheduleTemplatesPage;
|
||||
import se.su.dsv.scipro.supervisor.pages.SupervisorStartPage;
|
||||
|
||||
/**
|
||||
* @author Richard Wilkinson - richard.wilkinson@jweekend.com
|
||||
*
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class TestWicketPages {
|
||||
public class TestWicketPages extends BaseWicketTest {
|
||||
|
||||
User activeUser;
|
||||
ProjectClass bachelor;
|
||||
Project activeProject;
|
||||
|
||||
protected WicketTester tester;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
final ApplicationContextMock acm = new ApplicationContextMock();
|
||||
public void setup() {
|
||||
super.setup();
|
||||
|
||||
activeUser = new User();
|
||||
activeUser.setFirstName("Hugo");
|
||||
activeProject = new Project();
|
||||
activeProject.setProjectClass(bachelor);
|
||||
|
||||
EventDao eventDao = Mockito.mock(EventDao.class);
|
||||
UserDao userDao = Mockito.mock(UserDao.class);
|
||||
RoleDao roleDao = Mockito.mock(RoleDao.class);
|
||||
ProjectDao projectDao = Mockito.mock(ProjectDao.class);
|
||||
UserSettingsDao userSettingsDao = Mockito.mock(UserSettingsDao.class);
|
||||
|
||||
EntityManagerFactoryInfo emf = Mockito.mock(LocalEntityManagerFactoryBean.class);
|
||||
RepositoryManager repositoryManager = Mockito.mock(RepositoryManager.class);
|
||||
StringResourceDao stringResourceDao = Mockito.mock(StringResourceDao.class);
|
||||
|
||||
acm.putBean("eventDao", eventDao);
|
||||
acm.putBean("userDao", userDao);
|
||||
acm.putBean("roleDao", roleDao);
|
||||
acm.putBean("projectDao", projectDao);
|
||||
acm.putBean("userSettingsDao", userSettingsDao);
|
||||
acm.putBean("repositoryManager", repositoryManager);
|
||||
acm.putBean("stringResourceDao", stringResourceDao);
|
||||
acm.putBean("entityManagerFactory", emf);
|
||||
|
||||
tester = new WicketTester(new SciProApplication(){
|
||||
/* (non-Javadoc)
|
||||
* @see se.su.dsv.scipro.WicketApplication#getGuiceInjector()
|
||||
*/
|
||||
@Override
|
||||
protected SpringComponentInjector getSpringInjector() {
|
||||
return new SpringComponentInjector(this, acm, true);
|
||||
}
|
||||
});
|
||||
Mockito.when(projectDao.load(Mockito.eq(1L))).thenReturn(activeProject);
|
||||
Mockito.when(projectDao.isPartOf(activeUser, activeProject)).thenReturn(true);
|
||||
|
||||
this.setUser(activeUser);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Common pages
|
||||
*/
|
||||
@Test
|
||||
public void testStartPage() {
|
||||
public void testStartPage() throws Exception {
|
||||
|
||||
tester.startPage(HomePage.class);
|
||||
tester.assertRenderedPage(LoginPage.class);
|
||||
|
||||
this.setLoggedIn(true);
|
||||
|
||||
tester.startPage(HomePage.class);
|
||||
tester.assertRenderedPage(HomePage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoutPage() {
|
||||
tester.startPage(LogoutPage.class);
|
||||
tester.assertRenderedPage(LogoutPage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginPage() {
|
||||
tester.startPage(LoginPage.class);
|
||||
tester.assertRenderedPage(LoginPage.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* Project/author/student pages
|
||||
*/
|
||||
@Test
|
||||
public void testProjectStartPage() {
|
||||
//tester.startPage(ProjectStartPage.class);
|
||||
//tester.assertRenderedPage(NoActiveProjectPage.class);
|
||||
|
||||
//TODO: Set an active project so that the following test works
|
||||
|
||||
//tester.startPage(ProjectStartPage.class);
|
||||
//tester.assertRenderedPage(ProjectStartPage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectStartPage() {
|
||||
tester.startPage(ProjectStartPage.class);
|
||||
public void testfinalSeminarPages(){
|
||||
this.setActiveProject(activeProject);
|
||||
|
||||
tester.startPage(FinalSeminarProjectListPage.class);
|
||||
tester.assertRenderedPage(FinalSeminarProjectListPage.class);
|
||||
|
||||
Mockito.when(generalSystemSettingsDao.getGeneralSystemSettingsInstance()).thenReturn(new GeneralSystemSettings());
|
||||
Mockito.when(projectClassDao.getProjectClass(Mockito.anyString())).thenReturn(new ProjectClass());
|
||||
|
||||
tester.startPage(ProjectOppositionPage.class);
|
||||
tester.assertRenderedPage(ProjectOppositionPage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectSchedulePage() {
|
||||
MockSciProSession.currentSession.setLoggedInAsSysAdmin();
|
||||
|
||||
tester.startPage(ProjectSchedulePlannerPage.class);
|
||||
tester.assertRenderedPage(ProjectSchedulePlannerPage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectFilePage() {
|
||||
tester.startPage(ProjectFilePage.class);
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.add(Project.PP_PROJECT_ID, "1" );
|
||||
|
||||
Mockito.when(fileRepository.getProjectRootPath(1L)).thenReturn("/test/path/only");
|
||||
|
||||
tester.startPage(ProjectFilePage.class,pp);
|
||||
tester.assertRenderedPage(ProjectFilePage.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* Supervisor pages
|
||||
*/
|
||||
@Test
|
||||
public void testSupervisorStartPage(){
|
||||
MockSciProSession.currentSession.setLoggedInAsEmployee();
|
||||
tester.startPage(SupervisorStartPage.class);
|
||||
tester.assertRenderedPage(SupervisorStartPage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemSettingsPage() {
|
||||
tester.startPage(SystemMaintenancePage.class);
|
||||
public void testSupervisorFinalSeminarPage(){
|
||||
tester.startPage(SupervisorFinalSeminarListingPage.class);
|
||||
tester.assertRenderedPage(SupervisorFinalSeminarListingPage.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSupervisorProjectDetailsPage(){
|
||||
//TODO Hidden, remove this line when pages below are published
|
||||
MockSciProSession.currentSession.setLoggedInAsSysAdmin();
|
||||
|
||||
tester.startPage(SupervisorProjectDetailsPage.class);
|
||||
tester.assertRenderedPage(SupervisorProjectDetailsPage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupervisorScheduleTemplatesPage(){
|
||||
tester.startPage(SupervisorScheduleTemplatesPage.class);
|
||||
tester.assertRenderedPage(SupervisorScheduleTemplatesPage.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* Admin pages
|
||||
*/
|
||||
@Test
|
||||
public void testSystemSettingsPage() {
|
||||
MockSciProSession.currentSession.setLoggedInAsSysAdmin();
|
||||
|
||||
tester.startPage(SystemMaintenancePage.class);
|
||||
tester.assertRenderedPage(SystemMaintenancePage.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
171
src/test/java/se/su/dsv/scipro/wicket/TestWicketPeerPages.java
Normal file
171
src/test/java/se/su/dsv/scipro/wicket/TestWicketPeerPages.java
Normal file
@ -0,0 +1,171 @@
|
||||
package se.su.dsv.scipro.wicket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import se.su.dsv.scipro.basepages.errorpages.AccessDeniedPage;
|
||||
import se.su.dsv.scipro.data.dataobjects.CommentThread;
|
||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.interfaces.Commentable;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.PeerRequest;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.PeerReview;
|
||||
import se.su.dsv.scipro.peer.pages.PeerRequestSubmissionPage;
|
||||
import se.su.dsv.scipro.peer.pages.ProjectPeerPortalPage;
|
||||
import se.su.dsv.scipro.peer.pages.ProjectPeerReviewPage;
|
||||
import se.su.dsv.scipro.peer.pages.ProjectPeerStatsPage;
|
||||
import se.su.dsv.scipro.peer.pages.SupervisorPeerPortalPage;
|
||||
import se.su.dsv.scipro.peer.pages.SupervisorPeerReviewPage;
|
||||
import se.su.dsv.scipro.peer.pages.SupervisorPeerStatsPage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class TestWicketPeerPages extends BaseWicketTest {
|
||||
|
||||
User requester;
|
||||
Student requesterRole;
|
||||
User reviewer;
|
||||
Student reviewerRole;
|
||||
User supervisor;
|
||||
Employee supervisorRole;
|
||||
|
||||
Project activeProject;
|
||||
Project requestingProject;
|
||||
Project reviewingProject;
|
||||
|
||||
ProjectClass bachelor;
|
||||
User activeUser;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
super.setup();
|
||||
|
||||
/*
|
||||
* Initialize peer-stuff
|
||||
*/
|
||||
requestingProject = new Project();
|
||||
reviewingProject = new Project();
|
||||
activeProject = new Project();
|
||||
|
||||
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", null);
|
||||
activeProject.setProjectClass(bachelor);
|
||||
requestingProject.setProjectClass(bachelor);
|
||||
reviewingProject.setProjectClass(bachelor);
|
||||
|
||||
PeerReview review = new PeerReview();
|
||||
review.setProject(reviewingProject);
|
||||
review.setAborted(false);
|
||||
review.setDeleted(false);
|
||||
PeerRequest request = new PeerRequest();
|
||||
request.setProject(requestingProject);
|
||||
review.setPeerRequest(request);
|
||||
|
||||
requester = new User();
|
||||
requesterRole = new Student();
|
||||
requesterRole.setUser(requester);
|
||||
request.setRequester(requesterRole);
|
||||
|
||||
reviewer = new User();
|
||||
reviewerRole = new Student();
|
||||
reviewerRole.setUser(reviewer);
|
||||
review.setReviewer(reviewerRole);
|
||||
|
||||
supervisor = new User();
|
||||
supervisorRole = new Employee();
|
||||
supervisorRole.setUser(supervisor);
|
||||
|
||||
requestingProject.setHeadSupervisor(supervisorRole);
|
||||
reviewingProject.setHeadSupervisor(supervisorRole);
|
||||
|
||||
activeUser = new User();
|
||||
activeUser.setFirstName("Hugo");
|
||||
|
||||
Mockito.when(projectDao.load(Mockito.eq(1L))).thenReturn(activeProject);
|
||||
Mockito.when(projectDao.isPartOf(activeUser, activeProject)).thenReturn(true);
|
||||
Mockito.when(peerReviewDao.load(Mockito.eq(1L))).thenReturn(review);
|
||||
Mockito.when(commentThreadDao.getCommentThread(Mockito.any(Commentable.class))).thenReturn(new CommentThread());
|
||||
|
||||
this.setActiveProject(activeProject);
|
||||
this.setLoggedIn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStudentPeerPages() {
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.add(PeerReview.PP_PEER_REVIEW_ID, "1" );
|
||||
|
||||
MockSciProSession.currentSession.setUser(reviewer);
|
||||
|
||||
//TODO Remove this block when peer review functionality is enabled
|
||||
MockSciProSession.currentSession.setLoggedinAsStudent();
|
||||
tester.startPage(ProjectPeerReviewPage.class, pp);
|
||||
tester.assertRenderedPage(AccessDeniedPage.class);
|
||||
MockSciProSession.currentSession.setLoggedInAsSysAdmin();
|
||||
|
||||
tester.startPage(ProjectPeerReviewPage.class, pp);
|
||||
tester.assertRenderedPage(ProjectPeerReviewPage.class);
|
||||
|
||||
|
||||
Assert.assertNotNull(MockSciProSession.currentSession.getActiveProject().getProjectClass().getProjectClassSettings());
|
||||
tester.startPage(ProjectPeerPortalPage.class);
|
||||
tester.assertRenderedPage(ProjectPeerPortalPage.class);
|
||||
|
||||
activeProject.getProjectParticipants().add(reviewerRole);
|
||||
tester.startPage(PeerRequestSubmissionPage.class);
|
||||
tester.assertRenderedPage(PeerRequestSubmissionPage.class);
|
||||
|
||||
tester.startPage(ProjectPeerStatsPage.class);
|
||||
tester.assertRenderedPage(ProjectPeerStatsPage.class);
|
||||
|
||||
MockSciProSession.currentSession.setUser(activeUser);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Supervisor pages
|
||||
*/
|
||||
@Test
|
||||
public void testSupervisorPeerPages() {
|
||||
|
||||
Assert.assertNotNull(MockSciProSession.currentSession.getUser());
|
||||
|
||||
List<ProjectClass> resultList = new ArrayList<ProjectClass>();
|
||||
resultList.add(bachelor);
|
||||
Mockito.when(projectClassDao.findAll()).thenReturn(resultList);
|
||||
Mockito.when(projectClassDao.getProjectClass(ProjectClass.BACHELOR)).thenReturn(bachelor);
|
||||
|
||||
MockSciProSession.currentSession.setLoggedinAsStudent();
|
||||
tester.startPage(SupervisorPeerPortalPage.class);
|
||||
tester.assertRenderedPage(AccessDeniedPage.class);
|
||||
|
||||
MockSciProSession.currentSession.setLoggedInAsEmployee();
|
||||
tester.startPage(SupervisorPeerPortalPage.class);
|
||||
tester.assertRenderedPage(AccessDeniedPage.class);
|
||||
//TODO Fix these so proper behavior is ensured once peer functionality is enabled
|
||||
MockSciProSession.currentSession.setLoggedInAsSysAdmin();
|
||||
tester.startPage(SupervisorPeerPortalPage.class);
|
||||
tester.assertRenderedPage(SupervisorPeerPortalPage.class);
|
||||
|
||||
tester.startPage(SupervisorPeerStatsPage.class);
|
||||
tester.assertRenderedPage(SupervisorPeerStatsPage.class);
|
||||
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.add(PeerReview.PP_PEER_REVIEW_ID, "1" );
|
||||
tester.startPage(SupervisorPeerReviewPage.class,pp);
|
||||
tester.assertRenderedPage(SupervisorPeerReviewPage.class);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user