removed exemptions and settingsmodel
This commit is contained in:
parent
9620846131
commit
9d766ad68f
resources/db_update_scripts
src
main/java/se/su/dsv/scipro
SciProApplication.java
admin
data/dataobjects
match
dao
dataobject
springdata
test/java/se/su/dsv/scipro
@ -34,4 +34,10 @@ DELETE FROM supervisor_message_board;
|
||||
DROP TABLE supervisor_board_message_supervisor_board_message;
|
||||
DROP TABLE supervisor_message_board_supervisor_board_message;
|
||||
DROP TABLE supervisor_board_message;
|
||||
DROP TABLE supervisor_message_board;
|
||||
DROP TABLE supervisor_message_board;
|
||||
|
||||
DELETE FROM Student_Exemption;
|
||||
DELETE FROM Exemption;
|
||||
|
||||
DROP TABLE Student_Exemption;
|
||||
DROP TABLE Exemption;
|
@ -184,7 +184,6 @@ public class SciProApplication extends RepositoryApplication implements IThemabl
|
||||
mountBookmarkablePage("admin/match/projectideas", AdminManageIdeaPage.class);
|
||||
mountBookmarkablePage("admin/match/ideapopup", AdminNewIdeaPopupPage.class);
|
||||
mountBookmarkablePage("admin/match/keywords", AdminKeywordPage.class);
|
||||
mountBookmarkablePage("admin/match/exemptions", AdminExemptionPage.class);
|
||||
mountBookmarkablePage("admin/match/applicationperiods", AdminManageMatchPeriodsPage.class);
|
||||
mountBookmarkablePage("admin/match/applicationperiods/targets", AdminManageTargetsPage.class);
|
||||
mountBookmarkablePage("admin/mail", AdminMailPage.class);
|
||||
|
@ -1,124 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.admin.models;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class SettingsModel implements IClusterable {
|
||||
|
||||
|
||||
private int maxActiveParticipation;
|
||||
private int maxActiveForMaster;
|
||||
private int maxActiveForBachelor;
|
||||
private int maxOppositionsForMaster;
|
||||
private int maxOppositionsForBachelor;
|
||||
private int maxOpponentForBachelor;
|
||||
private int maxOpponentForMaster;
|
||||
private int registerAsActive;
|
||||
private int registerAsOpponent;
|
||||
private boolean finalSeminarThesisMustBeAPDF;
|
||||
private ProjectClass projectClass;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the finalSeminarThesisMustBeAPDF
|
||||
*/
|
||||
public boolean isFinalSeminarThesisMustBeAPDF() {
|
||||
return finalSeminarThesisMustBeAPDF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param finalSeminarThesisMustBeAPDF the finalSeminarThesisMustBeAPDF to set
|
||||
*/
|
||||
public void setFinalSeminarThesisMustBeAPDF(boolean finalSeminarThesisMustBeAPDF) {
|
||||
this.finalSeminarThesisMustBeAPDF = finalSeminarThesisMustBeAPDF;
|
||||
}
|
||||
|
||||
public int getMaxOppositionsForMaster() {
|
||||
return maxOppositionsForMaster;
|
||||
}
|
||||
|
||||
public void setMaxOppositionsForMaster(int maxOppositionsForMaster) {
|
||||
this.maxOppositionsForMaster = maxOppositionsForMaster;
|
||||
}
|
||||
|
||||
public int getMaxOppositionsForBachelor() {
|
||||
return maxOppositionsForBachelor;
|
||||
}
|
||||
|
||||
public void setMaxOppositionsForBachelor(int maxOppositionsForBachelor) {
|
||||
this.maxOppositionsForBachelor = maxOppositionsForBachelor;
|
||||
}
|
||||
|
||||
public int getMaxOpponentForBachelor() {
|
||||
return maxOpponentForBachelor;
|
||||
}
|
||||
|
||||
public void setMaxOpponentForBachelor(int maxOpponentForBachelor) {
|
||||
this.maxOpponentForBachelor = maxOpponentForBachelor;
|
||||
}
|
||||
|
||||
public int getMaxOpponentForMaster() {
|
||||
return maxOpponentForMaster;
|
||||
}
|
||||
|
||||
public void setMaxOpponentForMaster(int maxOpponentForMaster) {
|
||||
this.maxOpponentForMaster = maxOpponentForMaster;
|
||||
}
|
||||
|
||||
public ProjectClass getProjectClass() {
|
||||
return projectClass;
|
||||
}
|
||||
|
||||
public void setProjectClass(ProjectClass projectClass) {
|
||||
this.projectClass = projectClass;
|
||||
}
|
||||
|
||||
public void setMaxActiveParticipation(int maxActiveParticipation) {
|
||||
this.maxActiveParticipation = maxActiveParticipation;
|
||||
}
|
||||
|
||||
public int getMaxActiveParticipation() {
|
||||
return maxActiveParticipation;
|
||||
}
|
||||
|
||||
public int getMaxActiveForMaster() {
|
||||
return maxActiveForMaster;
|
||||
}
|
||||
|
||||
public void setMaxActiveForMaster(int maxActiveForMaster) {
|
||||
this.maxActiveForMaster = maxActiveForMaster;
|
||||
}
|
||||
|
||||
public int getMaxActiveForBachelor() {
|
||||
return maxActiveForBachelor;
|
||||
}
|
||||
|
||||
public void setMaxActiveForBachelor(int maxActiveForBachelor) {
|
||||
this.maxActiveForBachelor = maxActiveForBachelor;
|
||||
}
|
||||
|
||||
public int getRegisterAsActive() {
|
||||
return registerAsActive;
|
||||
}
|
||||
|
||||
public void setRegisterAsActive(int registerAsActive) {
|
||||
this.registerAsActive = registerAsActive;
|
||||
}
|
||||
|
||||
public int getRegisterAsOpponent() {
|
||||
return registerAsOpponent;
|
||||
}
|
||||
|
||||
public void setRegisterAsOpponent(int registerAsOpponent) {
|
||||
this.registerAsOpponent = registerAsOpponent;
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@ public abstract class AbstractAdminMatchPage extends AbstractAdminPage {
|
||||
final List<MenuItem> items = new ArrayList<MenuItem>();
|
||||
items.add(new MenuItem("Ideas", AdminManageIdeaPage.class));
|
||||
items.add(new MenuItem("Keywords and research areas", AdminKeywordPage.class));
|
||||
items.add(new MenuItem("Student exemptions", AdminExemptionPage.class));
|
||||
items.add(new MenuItem("Application periods", AdminManageMatchPeriodsPage.class, MenuHighlightAdminApplicationPeriod.class));
|
||||
return items;
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<form wicket:id="exemptionForm">
|
||||
|
||||
<!-- Fix max lengths -->
|
||||
<table>
|
||||
<tr>
|
||||
<td>Level: <select wicket:id="selectProjectClass"></select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Author: <div wicket:id="selectAuthor"></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Comment: <div><textarea wicket:id="comment"></textarea></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Expiration date: <div><input wicket:id="dateField"/></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input wicket:id="createButton" type="submit" value="Save" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
@ -1,98 +0,0 @@
|
||||
package se.su.dsv.scipro.admin.pages.match;
|
||||
|
||||
import org.apache.wicket.extensions.markup.html.form.DateTextField;
|
||||
import org.apache.wicket.extensions.yui.calendar.DatePicker;
|
||||
import org.apache.wicket.markup.html.form.Button;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.TextArea;
|
||||
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 org.joda.time.DateTime;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.components.ProjectClassSelector;
|
||||
import se.su.dsv.scipro.components.StudentSelector;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.AuthorDao;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
import se.su.dsv.scipro.springdata.services.DateService;
|
||||
import se.su.dsv.scipro.springdata.services.ExemptionService;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class AdminExemptionCreatePanel extends Panel {
|
||||
|
||||
@SpringBean
|
||||
private ExemptionService exemptionService;
|
||||
|
||||
@SpringBean
|
||||
AuthorDao authorDao;
|
||||
@SpringBean
|
||||
DateService dateService;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AdminExemptionCreatePanel(final String id) {
|
||||
this(id, new Model<Exemption>(new Exemption()));
|
||||
}
|
||||
|
||||
public AdminExemptionCreatePanel(String id, IModel<Exemption> model) {
|
||||
super(id);
|
||||
|
||||
add(new ExemptionForm("exemptionForm", model));
|
||||
}
|
||||
|
||||
private class ExemptionForm extends Form<Exemption> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private ProjectClassSelector projectClassSelect;
|
||||
private StudentSelector studentSelector;
|
||||
private TextArea<String> comment;
|
||||
private DateTextField dateField;
|
||||
|
||||
public ExemptionForm(String id, final IModel<Exemption> model) {
|
||||
super(id, model);
|
||||
projectClassSelect = new ProjectClassSelector("selectProjectClass");
|
||||
add(projectClassSelect);
|
||||
studentSelector = new StudentSelector("selectAuthor");
|
||||
studentSelector.getSelector().setRequired(true);
|
||||
add(studentSelector);
|
||||
|
||||
comment = new TextArea<String>("comment",
|
||||
new PropertyModel<String>(model, "comment"));
|
||||
add(comment);
|
||||
|
||||
DateTime expirationDate = new DateTime();
|
||||
expirationDate = expirationDate.plusMonths(6);
|
||||
dateField = new DateTextField("dateField", new Model<Date>(expirationDate.toDate()), dateService.getFormat(DateStyle.DATE));
|
||||
DatePicker datePicker = new DatePicker();
|
||||
datePicker.setShowOnFieldClick(true);
|
||||
dateField.add(datePicker);
|
||||
dateField.setRequired(true);
|
||||
add(dateField);
|
||||
|
||||
Button createButton = new Button("createButton");
|
||||
add(createButton);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSubmit() {
|
||||
Exemption exemption = getModelObject();
|
||||
exemption.setProjectClass(projectClassSelect.getModelObject());
|
||||
exemption.setGrantedBy(SciProSession.get().getUser());
|
||||
exemption.setAuthor(authorDao.getOrCreate(studentSelector.getModelObject().getUser()));
|
||||
exemption.setExpirationDate(dateField.getModelObject());
|
||||
try {
|
||||
exemption = exemptionService.save(exemption);
|
||||
info("Exemption created.");
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
error("Only one exemption per author and project class allowed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:extend>
|
||||
<div wicket:id="adminExemptionsPanel"></div>
|
||||
</wicket:extend>
|
||||
</body>
|
||||
</html>
|
@ -1,17 +0,0 @@
|
||||
package se.su.dsv.scipro.admin.pages.match;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import se.su.dsv.scipro.admin.pages.AbstractAdminMatchPage;
|
||||
import se.su.dsv.scipro.admin.panels.match.AdminStudentExemptionPanel;
|
||||
import se.su.dsv.scipro.security.auth.Authorization;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
|
||||
@Authorization(authorizedRoles={Roles.ADMIN})
|
||||
public class AdminExemptionPage extends AbstractAdminMatchPage {
|
||||
|
||||
public AdminExemptionPage(PageParameters pp) {
|
||||
super(pp);
|
||||
add(new AdminStudentExemptionPanel("adminExemptionsPanel"));
|
||||
}
|
||||
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
dateField.Required=You may not grant an exemption without an expiration date
|
||||
selector.Required=You need to select a student to be able to grant exemption
|
@ -1,29 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<div wicket:id="dialog">
|
||||
<div wicket:id="dialogPanel"></div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="info-box span12">
|
||||
Use this page to grant and remove exemptions to Bachelor level students to write their thesis alone.
|
||||
Don't forget to write a comment describing the reason why the exemption was granted.
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span3" wicket:id="levelFilter"></div>
|
||||
<div class="span3">
|
||||
<b>Filter by student:</b><br />
|
||||
|
||||
<input wicket:id="studentFilter"/>
|
||||
</div>
|
||||
<div class="span6"></div>
|
||||
</div>
|
||||
<br/>
|
||||
<a href=# wicket:id="createLink"><img wicket:id="addIcon" alt="" /> Grant new exemption</a>
|
||||
<div wicket:id="dataTable"></div>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
@ -1,205 +0,0 @@
|
||||
package se.su.dsv.scipro.admin.panels.match;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
|
||||
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
|
||||
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
|
||||
import org.apache.wicket.markup.html.panel.EmptyPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.markup.repeater.Item;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import se.su.dsv.scipro.admin.pages.match.AdminExemptionCreatePanel;
|
||||
import se.su.dsv.scipro.components.DialogPlus;
|
||||
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.datatables.ClickableIconColumn;
|
||||
import se.su.dsv.scipro.datatables.DateColumn;
|
||||
import se.su.dsv.scipro.datatables.GenericDataPanel;
|
||||
import se.su.dsv.scipro.icons.ImageIcon;
|
||||
import se.su.dsv.scipro.icons.ImageObject;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
import se.su.dsv.scipro.match.panel.FilterFormCheckBoxPanel;
|
||||
import se.su.dsv.scipro.profile.UserLinkPanel;
|
||||
import se.su.dsv.scipro.reusable.AuthorAutoComplete;
|
||||
import se.su.dsv.scipro.reusable.SciProUtilities;
|
||||
import se.su.dsv.scipro.springdata.services.ExemptionService;
|
||||
import se.su.dsv.scipro.springdata.services.ExemptionService.FilterParams;
|
||||
import se.su.dsv.scipro.springdata.services.GenericService;
|
||||
import se.su.dsv.scipro.springdata.services.ProjectClassService;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Panel for administration of author exemptions.
|
||||
* With an exemption, a bachelor student may write his/her thesis alone
|
||||
*
|
||||
*/
|
||||
public class AdminStudentExemptionPanel extends Panel {
|
||||
|
||||
private static final long serialVersionUID = -5020119685494141444L;
|
||||
|
||||
@SpringBean
|
||||
private ExemptionService exemptionService;
|
||||
@SpringBean
|
||||
private ProjectClassService projectClassService;
|
||||
|
||||
private Dialog dialog;
|
||||
private FilterParams params;
|
||||
private GenericDataPanel<Exemption> dataTable;
|
||||
|
||||
public AdminStudentExemptionPanel(String id) {
|
||||
super(id);
|
||||
addDialog();
|
||||
addCreateLink();
|
||||
addFilteringControls();
|
||||
addDataTable();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Pop up dialog that contains the Create new exemption panel
|
||||
*
|
||||
*/
|
||||
private void addDialog() {
|
||||
dialog = new DialogPlus("dialog");
|
||||
dialog.setModal(true);
|
||||
dialog.setAutoOpen(false);
|
||||
dialog.setWidth(500);
|
||||
dialog.setHeight(520);
|
||||
add(dialog);
|
||||
dialog.add(new EmptyPanel("dialogPanel"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Adds a link to dialog where administrators may create new student exemptions
|
||||
*
|
||||
*/
|
||||
private void addCreateLink() {
|
||||
AjaxLink<Void> createLink = new AjaxLink<Void>("createLink"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
dialog.replace(new AdminExemptionCreatePanel("dialogPanel"));
|
||||
target.addComponent(dialog);
|
||||
dialog.setTitle("Grant exemption...");
|
||||
dialog.open(target);
|
||||
}
|
||||
};
|
||||
add(createLink);
|
||||
createLink.add(new ImageObject("addIcon", ImageObject.SIXTEEN + ImageObject.ADD));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Artifacts used to filter the datatable on project class and specified Student
|
||||
*
|
||||
*/
|
||||
private void addFilteringControls() {
|
||||
params = new FilterParams();
|
||||
|
||||
// LEVEL FILTER
|
||||
final FilterFormCheckBoxPanel<ProjectClass> levelFilter = new FilterFormCheckBoxPanel<ProjectClass>("levelFilter", "level:") {
|
||||
private static final long serialVersionUID = -3198696681822582264L;
|
||||
|
||||
@Override
|
||||
public void ajaxUpdate(AjaxRequestTarget target) {
|
||||
if(!getSelection().isEmpty()){
|
||||
params.setLevels(getSelection());
|
||||
}
|
||||
target.addComponent(dataTable.getWMC());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ProjectClass> choices() {
|
||||
return projectClassService.findAllActive();
|
||||
}
|
||||
};
|
||||
params.setLevels(levelFilter.getSelection());
|
||||
add(levelFilter);
|
||||
|
||||
// AUTHOR FILTER
|
||||
add(new AuthorAutoComplete("studentFilter") {
|
||||
private static final long serialVersionUID = -5155064219647834987L;
|
||||
|
||||
@Override
|
||||
protected void action(AjaxRequestTarget pTarget, Student newSelection) {
|
||||
params.setAuthor(newSelection);
|
||||
pTarget.addComponent(dataTable.getWMC());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* The data table that holds all the information about current exemptions.
|
||||
*
|
||||
*/
|
||||
private void addDataTable() {
|
||||
add(dataTable = new GenericDataPanel<Exemption>("dataTable") {
|
||||
private static final long serialVersionUID = 3470508297052300548L;
|
||||
|
||||
@Override
|
||||
public GenericService<Exemption, Long> getService() {
|
||||
return exemptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Exemption> getIterator() {
|
||||
return exemptionService.findAll(params, new PageRequest(getTable().getCurrentPage(), getTable().getRowsPerPage(), getSort())).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return SciProUtilities.safeLongToInt(exemptionService.countAll(params));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSortString() {
|
||||
return "dateCreated";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumns() {
|
||||
getColumns().add(new AbstractColumn<Exemption>(Model.of("Granted exemptions"), "author.user.firstName"){
|
||||
private static final long serialVersionUID = 3591460296758864594L;
|
||||
@Override
|
||||
public void populateItem(Item<ICellPopulator<Exemption>> item, String id, IModel<Exemption> model) {
|
||||
User exemptionUser = model.getObject().getAuthor().getUser();
|
||||
// item.add(new Label(id, exemptionUser.getFullName() + " ("+exemptionUser.getEmailAddress()+")"));
|
||||
item.add(new UserLinkPanel(id, new Model<User>(exemptionUser)));
|
||||
}
|
||||
});
|
||||
getColumns().add(new PropertyColumn<Exemption>(Model.of("Comment"), "comment"));
|
||||
getColumns().add(new PropertyColumn<Exemption>(Model.of("Level"), "projectClass", "projectClass"));
|
||||
getColumns().add(new PropertyColumn<Exemption>(Model.of("Granted by"), "grantedBy.firstName", "grantedBy"));
|
||||
getColumns().add(new DateColumn<Exemption>(Model.of("Date of granting"), "dateCreated", "dateCreated"));
|
||||
getColumns().add(new DateColumn<Exemption>(Model.of("Expiration date"), "expirationDate", "expirationDate"));
|
||||
getColumns().add(new ClickableIconColumn<Exemption>(Model.of("Revoke exemption"), null, null, ImageIcon.ICON_DELETE, "Are you sure you want to revoke this exemption?") {
|
||||
private static final long serialVersionUID = -8513790808581469089L;
|
||||
@Override
|
||||
protected void onClick(IModel<Exemption> model, AjaxRequestTarget target) {
|
||||
exemptionService.delete(model.getObject().getId());
|
||||
info("Exemption revoked");
|
||||
target.addComponent(getWMC());
|
||||
target.addComponent(getPage().get("feedbackPanel"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSortDirection() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ package se.su.dsv.scipro.data.dataobjects;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import se.su.dsv.scipro.match.dataobject.ApplicationPeriodExemption;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
import se.su.dsv.scipro.match.dataobject.NewIdeaParticipation;
|
||||
|
||||
import javax.persistence.*;
|
||||
@ -22,11 +21,7 @@ import java.util.Set;
|
||||
public class Student extends Role {
|
||||
|
||||
private static final long serialVersionUID = 7672230173163740687L;
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
@MapKey(name = "projectClass")
|
||||
@JoinTable(name = "Student_Exemption")
|
||||
private Map<ProjectClass, Exemption> exemptions = new HashMap<ProjectClass, Exemption>();
|
||||
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "student", cascade=CascadeType.ALL, orphanRemoval=true)
|
||||
private Set<NewIdeaParticipation> newIdeaParticipations = new HashSet<NewIdeaParticipation>();
|
||||
|
||||
@ -75,32 +70,6 @@ public class Student extends Role {
|
||||
|
||||
}
|
||||
|
||||
public int getMinAuthors(ProjectClass projectClass) {
|
||||
Exemption exemption = getExemptions().get(projectClass);
|
||||
if (exemption != null) {
|
||||
return 1;
|
||||
} else {
|
||||
return projectClass.getProjectClassSettings().getMinAuthors();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ProjectClass, Exemption> getExemptions() {
|
||||
return exemptions;
|
||||
}
|
||||
|
||||
public void setExemptions(Map<ProjectClass, Exemption> exemptions) {
|
||||
this.exemptions = exemptions;
|
||||
}
|
||||
|
||||
public int getMaxAuthors(ProjectClass projectClass) {
|
||||
Exemption exemption = getExemptions().get(projectClass);
|
||||
if (exemption != null) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else {
|
||||
return projectClass.getProjectClassSettings().getMaxAuthors();
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewIdeaParticipations(Set<NewIdeaParticipation> newIdeaParticipations) {
|
||||
this.newIdeaParticipations = newIdeaParticipations;
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
package se.su.dsv.scipro.match.dao.interfaces;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.QueryableDao;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
|
||||
public interface ExemptionDao extends QueryableDao<Exemption, ExemptionDaoParams>{
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package se.su.dsv.scipro.match.dao.interfaces;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.Dao.SortableParams;
|
||||
|
||||
public class ExemptionDaoParams extends SortableParams {
|
||||
|
||||
private String authorNameLike;
|
||||
|
||||
public void setAuthorNameLike(String authorNameLike) {
|
||||
this.authorNameLike = authorNameLike;
|
||||
}
|
||||
|
||||
public String getAuthorNameLike() {
|
||||
return authorNameLike;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package se.su.dsv.scipro.match.dao.jpa;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import se.su.dsv.scipro.data.dao.jpa.AbstractSortableQuerySet;
|
||||
import se.su.dsv.scipro.data.dao.jpa.Query;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ExemptionDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ExemptionDaoParams;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
|
||||
@Repository("ExcemptionDao")
|
||||
public class ExemptionDaoJPAImp extends QueryableDaoJPAImp<Exemption, ExemptionDaoParams> implements
|
||||
ExemptionDao {
|
||||
|
||||
public ExemptionDaoJPAImp() {
|
||||
super(Exemption.class);
|
||||
}
|
||||
|
||||
public AbstractSortableQuerySet<Exemption> createQuerySet(ExemptionDaoParams exemptionDaoParams) {
|
||||
return new QuerySet().authorNameLike(exemptionDaoParams.getAuthorNameLike()).sort(exemptionDaoParams);
|
||||
}
|
||||
|
||||
public static class QuerySet extends AbstractSortableQuerySet<Exemption> {
|
||||
public QuerySet() {
|
||||
super(Exemption.class);
|
||||
}
|
||||
|
||||
public QuerySet authorNameLike(String authorNameLike) {
|
||||
if (authorNameLike != null) {
|
||||
getQuery().combine(
|
||||
new Query().where("(_.author.user.firstName LIKE (:authorName) OR _.author.user.lastName LIKE (:authorName))")
|
||||
.parameter("authorName", authorNameLike + "%"));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query initQuery() {
|
||||
return new Query().select("e").from("Exemption e");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package se.su.dsv.scipro.match.dataobject;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import se.su.dsv.scipro.data.dataobjects.DomainObject;
|
||||
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.dataproviders.SortableField;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Cacheable(true)
|
||||
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
|
||||
// Hibernate specific
|
||||
@Table(uniqueConstraints=@UniqueConstraint(columnNames = { "author_id", "projectClass_id" }))
|
||||
public class Exemption extends DomainObject {
|
||||
|
||||
private static final long serialVersionUID = 2329496528014255128L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@SortableField
|
||||
private ProjectClass projectClass;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@SortableField
|
||||
private Student author;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@SortableField
|
||||
private User grantedBy;
|
||||
|
||||
private String comment;
|
||||
|
||||
@NotNull
|
||||
private Date expirationDate;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public ProjectClass getProjectClass() {
|
||||
return projectClass;
|
||||
}
|
||||
|
||||
public void setProjectClass(ProjectClass projectClass) {
|
||||
this.projectClass = projectClass;
|
||||
}
|
||||
|
||||
public Student getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(Student author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public User getGrantedBy() {
|
||||
return grantedBy;
|
||||
}
|
||||
|
||||
public void setGrantedBy(User grantedBy) {
|
||||
this.grantedBy = grantedBy;
|
||||
}
|
||||
|
||||
public void setExpirationDate(Date expirationDate) {
|
||||
this.expirationDate = expirationDate;
|
||||
}
|
||||
|
||||
public Date getExpirationDate() {
|
||||
return expirationDate;
|
||||
}
|
||||
|
||||
}
|
@ -30,8 +30,6 @@ public class BeansManager {
|
||||
@Autowired
|
||||
ExaminerService examinerService;
|
||||
@Autowired
|
||||
ExemptionService exemptionService;
|
||||
@Autowired
|
||||
FileDescriptionService fileDescriptionService;
|
||||
@Autowired
|
||||
FinalSeminarActiveParticipationService finalSeminarActiveParticipationService;
|
||||
@ -183,14 +181,6 @@ public class BeansManager {
|
||||
this.examinerService = examinerService;
|
||||
}
|
||||
|
||||
public ExemptionService getExemptionService() {
|
||||
return exemptionService;
|
||||
}
|
||||
|
||||
public void setExemptionService(ExemptionService exemptionService) {
|
||||
this.exemptionService = exemptionService;
|
||||
}
|
||||
|
||||
public FileDescriptionService getFileDescriptionService() {
|
||||
return fileDescriptionService;
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package se.su.dsv.scipro.springdata.repos;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public interface ExemptionRepo extends JpaRepository<Exemption, Long>, QueryDslPredicateExecutor<Exemption> {
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package se.su.dsv.scipro.springdata.serviceimpls;
|
||||
|
||||
import com.mysema.query.BooleanBuilder;
|
||||
import com.mysema.query.types.expr.BooleanExpression;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
import se.su.dsv.scipro.match.dataobject.QExemption;
|
||||
import se.su.dsv.scipro.springdata.repos.ExemptionRepo;
|
||||
import se.su.dsv.scipro.springdata.services.ExemptionService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Service ( "exemptionService" )
|
||||
@Transactional ( readOnly = true )
|
||||
public class ExemptionServiceImpl extends AbstractQueryService<Exemption, Long> implements ExemptionService {
|
||||
|
||||
@Resource
|
||||
private ExemptionRepo exemptionRepo;
|
||||
|
||||
@Autowired
|
||||
public ExemptionServiceImpl(
|
||||
@Qualifier("exemptionRepo")
|
||||
ExemptionRepo exemptionRepo) {
|
||||
super(exemptionRepo, exemptionRepo);
|
||||
System.out.println("ExemptionServiceImpl instantiating...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Exemption> findAll(FilterParams params, Pageable pageable) {
|
||||
if(params!=null)
|
||||
return exemptionRepo.findAll(fromParams(params), pageable);
|
||||
else
|
||||
return exemptionRepo.findAll(pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countAll(FilterParams params) {
|
||||
return exemptionRepo.count(fromParams(params));
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Exemption getActiveExemption(Student author, ProjectClass projectClass) {
|
||||
// return exemptionRepo.findOne(byAuthor(author).and(byLevel(projectClass)).and(isActive()));
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public boolean isExemptionGranted(Student author, ProjectClass projectClass) {
|
||||
// return getActiveExemption(author, projectClass)!=null;
|
||||
// }
|
||||
|
||||
private BooleanBuilder fromParams(FilterParams params) {
|
||||
BooleanBuilder bb = new BooleanBuilder();
|
||||
if(params.getLevels()!=null)
|
||||
bb.and(levelFilter(params.getLevels()));
|
||||
if(params.getAuthor()!=null)
|
||||
bb.and(byAuthor(params.getAuthor()));
|
||||
return bb;
|
||||
}
|
||||
|
||||
private BooleanBuilder levelFilter(Collection<ProjectClass> levels) {
|
||||
BooleanBuilder e = new BooleanBuilder();
|
||||
if (levels != null && !levels.isEmpty()) {
|
||||
for (ProjectClass level : levels) {
|
||||
e.or(byLevel(level));
|
||||
}
|
||||
return e;
|
||||
} else {
|
||||
e.and(QExemption.exemption.projectClass.isNull());
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
private BooleanExpression byAuthor(Student author) {
|
||||
return QExemption.exemption.author.eq(author);
|
||||
}
|
||||
|
||||
private BooleanExpression byLevel(ProjectClass pc) {
|
||||
return QExemption.exemption.projectClass.eq(pc);
|
||||
}
|
||||
|
||||
private BooleanExpression isActive() {
|
||||
return QExemption.exemption.expirationDate.after(new Date());
|
||||
}
|
||||
|
||||
}
|
@ -39,8 +39,6 @@ public class NewIdeaServiceImpl extends AbstractQueryService<NewIdea, Long> impl
|
||||
@Resource
|
||||
NewIdeaRepo newIdeaRepo;
|
||||
@Resource
|
||||
ExemptionService exemptionService;
|
||||
@Resource
|
||||
ApplicationPeriodService applicationPeriodService;
|
||||
@Resource
|
||||
StudentService studentService;
|
||||
|
@ -1,42 +0,0 @@
|
||||
package se.su.dsv.scipro.springdata.services;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public interface ExemptionService extends GenericService<Exemption, Long>, QueryService<Exemption, Long> {
|
||||
|
||||
Page<Exemption> findAll(FilterParams params, Pageable pageable);
|
||||
|
||||
Long countAll(FilterParams params);
|
||||
|
||||
// Exemption getActiveExemption(Student author, ProjectClass projectClass);
|
||||
|
||||
// boolean isExemptionGranted(Student author, ProjectClass projectClass);
|
||||
|
||||
public static class FilterParams implements Serializable {
|
||||
private static final long serialVersionUID = -6302602492932432321L;
|
||||
|
||||
private Collection<ProjectClass> levels;
|
||||
private Student author;
|
||||
|
||||
public void setLevels(Collection<ProjectClass> levels) {
|
||||
this.levels = levels;
|
||||
}
|
||||
public Collection<ProjectClass> getLevels() {
|
||||
return levels;
|
||||
}
|
||||
public void setAuthor(Student author) {
|
||||
this.author = author;
|
||||
}
|
||||
public Student getAuthor() {
|
||||
return author;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,6 @@ import se.su.dsv.scipro.io.ExcelExportService;
|
||||
import se.su.dsv.scipro.io.ExternalImporter;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ApplicationPeriodDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.AuthorDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ExemptionDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.SupervisorDao;
|
||||
import se.su.dsv.scipro.milestones.service.MileStoneActivityService;
|
||||
import se.su.dsv.scipro.milestones.service.MileStonePhaseService;
|
||||
@ -56,7 +55,6 @@ public abstract class SciProTest {
|
||||
*/
|
||||
@Mock protected ApplicationPeriodDao applicationPeriodDao;
|
||||
@Mock protected AuthorDao authorDao;
|
||||
@Mock protected ExemptionDao exemptionDao;
|
||||
@Mock protected SupervisorDao supervisorDao;
|
||||
|
||||
@Mock protected CheckListAnswerDao checkListAnswerDao;
|
||||
@ -114,7 +112,6 @@ public abstract class SciProTest {
|
||||
@Mock protected ChecklistTemplateService checklistTemplateService;
|
||||
@Mock protected DateService dateService;
|
||||
@Mock protected DaysService daysService;
|
||||
@Mock protected ExemptionService exemptionService;
|
||||
@Mock protected FileDescriptionService fileDescriptionService;
|
||||
@Mock protected FinalSeminarActiveParticipationService finalSeminarActiveParticipationService;
|
||||
@Mock protected FinalSeminarOppositionService finalSeminarOppositionService;
|
||||
|
@ -17,8 +17,6 @@ import se.su.dsv.scipro.data.dataobjects.ProjectClassSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.AuthorDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ExemptionDao;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -36,9 +34,6 @@ public class TestAuthorDao {
|
||||
|
||||
@Autowired
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
@Autowired
|
||||
private ExemptionDao exemptionDao;
|
||||
|
||||
private AuthorDao target;
|
||||
|
||||
@ -94,63 +89,4 @@ public class TestAuthorDao {
|
||||
Assert.assertEquals(studentNoAuthor, author.getUser());
|
||||
Assert.assertTrue(oldAuthor.getId() == author.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldReturnProjectClassMinLimitIfNotExemptionForClass() {
|
||||
Student author = target.getOrCreate(student1);
|
||||
int minAuthors = author.getMinAuthors(bachelor);
|
||||
Assert.assertEquals(2, minAuthors);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldReturnOneIfHasExemptionForProjectClass() {
|
||||
Student author = target.getOrCreate(student1);
|
||||
|
||||
Exemption exemption = new Exemption();
|
||||
exemption.setProjectClass(bachelor);
|
||||
exemption.setAuthor(author);
|
||||
exemption.setGrantedBy(student1);
|
||||
exemption.setExpirationDate(futureDate);
|
||||
exemption = exemptionDao.save(exemption);
|
||||
author.getExemptions().put(bachelor, exemption);
|
||||
|
||||
int minAuthors = author.getMinAuthors(bachelor);
|
||||
Assert.assertEquals(1, minAuthors);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldReturnProjectClassMaxLimitIfNoExemptionForClass() {
|
||||
|
||||
Student author = target.getOrCreate(student1);
|
||||
int maxAuthors = author.getMaxAuthors(bachelor);
|
||||
Assert.assertEquals(4, maxAuthors);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldReturnMaxIntIfHasExemptionForProjectClass() {
|
||||
Student author = target.getOrCreate(student1);
|
||||
Exemption exemption = new Exemption();
|
||||
exemption.setProjectClass(bachelor);
|
||||
exemption.setAuthor(author);
|
||||
exemption.setGrantedBy(student1);
|
||||
exemption.setExpirationDate(futureDate);
|
||||
exemption = exemptionDao.save(exemption);
|
||||
|
||||
author.getExemptions().put(bachelor, exemption);
|
||||
|
||||
int maxAuthors = author.getMaxAuthors(bachelor);
|
||||
Assert.assertEquals(Integer.MAX_VALUE, maxAuthors);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,197 +0,0 @@
|
||||
package se.su.dsv.scipro.match.dao;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
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.match.dao.interfaces.AuthorDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ExemptionDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ExemptionDaoParams;
|
||||
import se.su.dsv.scipro.match.dataobject.Exemption;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(inheritLocations = false, locations = {
|
||||
"classpath:test-applicationContext.xml"
|
||||
})
|
||||
public class TestExemptionDao {
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Autowired
|
||||
private AuthorDao authorDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
@Autowired
|
||||
private ExemptionDao exemptionDao;
|
||||
|
||||
private ExemptionDao target;
|
||||
|
||||
private ProjectClass bachelor;
|
||||
|
||||
private Exemption student1Exemption;
|
||||
|
||||
private Exemption student2Exemption;
|
||||
|
||||
private ExemptionDaoParams exemptionDaoParams;
|
||||
|
||||
private Student student3Author;
|
||||
|
||||
private Exemption student3Exemption;
|
||||
|
||||
private User admin;
|
||||
|
||||
private ProjectClass master;
|
||||
|
||||
private Date futureDate;
|
||||
|
||||
@Before
|
||||
public void startTransaction() {
|
||||
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree");
|
||||
bachelor = projectClassDao.save(bachelor);
|
||||
|
||||
master = new ProjectClass(ProjectClass.MASTER, "Master", "Master degree");
|
||||
master = projectClassDao.save(master);
|
||||
|
||||
admin = new User();
|
||||
admin.setFirstName("Admin 1");
|
||||
admin = userDao.save(admin);
|
||||
|
||||
|
||||
DateTime dt = new DateTime();
|
||||
dt = dt.plusMonths(1);
|
||||
futureDate = dt.toDate();
|
||||
|
||||
User student1 = new User();
|
||||
student1.setFirstName("User 1");
|
||||
student1.setLastName("Last 1");
|
||||
student1 = userDao.save(student1);
|
||||
Student student1Author = authorDao.getOrCreate(student1);
|
||||
|
||||
student1Exemption = new Exemption();
|
||||
student1Exemption.setProjectClass(bachelor);
|
||||
student1Exemption.setAuthor(student1Author);
|
||||
student1Exemption.setGrantedBy(admin);
|
||||
student1Exemption.setExpirationDate(futureDate);
|
||||
student1Exemption = exemptionDao.save(student1Exemption);
|
||||
|
||||
|
||||
User student2 = new User();
|
||||
student2.setFirstName("User 2");
|
||||
student2.setLastName("Lst 1");
|
||||
student2 = userDao.save(student2);
|
||||
Student student2Author = authorDao.getOrCreate(student2);
|
||||
|
||||
student2Exemption = new Exemption();
|
||||
student2Exemption.setProjectClass(bachelor);
|
||||
student2Exemption.setAuthor(student2Author);
|
||||
student2Exemption.setGrantedBy(admin);
|
||||
student2Exemption.setExpirationDate(futureDate);
|
||||
student2Exemption = exemptionDao.save(student2Exemption);
|
||||
|
||||
|
||||
User student3 = new User();
|
||||
student3.setFirstName("Usr 3");
|
||||
student3.setLastName("Last 3");
|
||||
student3 = userDao.save(student3);
|
||||
student3Author = authorDao.getOrCreate(student3);
|
||||
|
||||
student3Exemption = new Exemption();
|
||||
student3Exemption.setProjectClass(bachelor);
|
||||
student3Exemption.setAuthor(student3Author);
|
||||
student3Exemption.setGrantedBy(admin);
|
||||
student3Exemption.setExpirationDate(futureDate);
|
||||
student3Exemption = exemptionDao.save(student3Exemption);
|
||||
|
||||
target = exemptionDao;
|
||||
|
||||
exemptionDaoParams = new ExemptionDaoParams();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldFindAllExemptions() {
|
||||
List<Exemption> exemptions = target.find(exemptionDaoParams);
|
||||
Assert.assertEquals(
|
||||
Arrays.asList(new Exemption[]{student1Exemption, student2Exemption, student3Exemption}), exemptions);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldFindAllExemptionsWithAuthorsFirstNamesStartingWithName() {
|
||||
exemptionDaoParams.setAuthorNameLike("Use");
|
||||
List<Exemption> exemptions = target.find(exemptionDaoParams);
|
||||
Assert.assertEquals(
|
||||
Arrays.asList(new Exemption[] { student1Exemption, student2Exemption}), exemptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldFindAllExemptionsWithAuthorsLastNamesStartingWithName() {
|
||||
exemptionDaoParams.setAuthorNameLike("Las");
|
||||
List<Exemption> exemptions = target.find(exemptionDaoParams);
|
||||
Assert.assertEquals(
|
||||
Arrays.asList(new Exemption[] { student1Exemption, student3Exemption}), exemptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldCountExemptionsWithAuthorsLastNamesStartingWithName() {
|
||||
exemptionDaoParams.setAuthorNameLike("Las");
|
||||
long count = target.count(exemptionDaoParams);
|
||||
Assert.assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldBeAbleToHaveExemptionsForDifferentClasses() {
|
||||
|
||||
Exemption student3Exemption = new Exemption();
|
||||
student3Exemption.setProjectClass(master);
|
||||
student3Exemption.setAuthor(student3Author);
|
||||
student3Exemption.setGrantedBy(admin);
|
||||
student3Exemption.setExpirationDate(futureDate);
|
||||
student3Exemption = exemptionDao.save(student3Exemption);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldNotBeAbleToHaveMultipleExemptionsForSameClass() {
|
||||
|
||||
Exemption student3Exemption = new Exemption();
|
||||
student3Exemption.setProjectClass(bachelor);
|
||||
student3Exemption.setAuthor(student3Author);
|
||||
student3Exemption.setGrantedBy(admin);
|
||||
try {
|
||||
student3Exemption = exemptionDao.save(student3Exemption);
|
||||
Assert.fail();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
package se.su.dsv.scipro.springdata;
|
||||
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
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.match.dataobject.Exemption;
|
||||
import se.su.dsv.scipro.springdata.services.ExemptionService;
|
||||
import se.su.dsv.scipro.springdata.services.ExemptionService.FilterParams;
|
||||
import se.su.dsv.scipro.springdata.services.ProjectClassService;
|
||||
import se.su.dsv.scipro.springdata.services.StudentService;
|
||||
import se.su.dsv.scipro.springdata.services.UserService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(inheritLocations = false, locations = {
|
||||
"classpath:test-applicationContext.xml"
|
||||
})
|
||||
|
||||
public class TestExemption {
|
||||
|
||||
@Autowired
|
||||
private ProjectClassService projectClassService;
|
||||
@Autowired
|
||||
private ExemptionService exemptionService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private StudentService studentService;
|
||||
|
||||
private ProjectClass bachelor, master;
|
||||
private User authorUser1, authorUser2, granter;
|
||||
private Student author1, author2;
|
||||
private Exemption exemptionExpired, exemptionBachelor, exemptionMaster;
|
||||
|
||||
@Before
|
||||
public void startTransaction() throws Exception {
|
||||
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
|
||||
bachelor = projectClassService.save(bachelor);
|
||||
master = new ProjectClass(ProjectClass.MASTER, "Master", "Master degree thesis project");
|
||||
master = projectClassService.save(master);
|
||||
|
||||
authorUser1 = newUser();
|
||||
authorUser2 = newUser();
|
||||
granter = newUser();
|
||||
|
||||
author1 = newStudent(authorUser1);
|
||||
author2 = newStudent(authorUser2);
|
||||
|
||||
exemptionExpired = newExemption(author1, bachelor, granter, "expired exemption", expiredDate(2));
|
||||
exemptionBachelor = newExemption(author2, bachelor, granter, "current bachelor", futureDate(2));
|
||||
exemptionMaster = newExemption(author1, master, granter, "current master", futureDate(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindAllExemptions() {
|
||||
//Test with null params
|
||||
List<Exemption> allExemptions = exemptionService.findAll(null, new PageRequest(0, 10)).getContent();
|
||||
List<Exemption> testExemptions = Arrays.asList(new Exemption[]{exemptionExpired, exemptionBachelor, exemptionMaster});
|
||||
Assert.assertEquals(testExemptions, allExemptions);
|
||||
|
||||
//Test with empty params
|
||||
FilterParams params = new FilterParams();
|
||||
List<Exemption> allWithParams = exemptionService.findAll(params, new PageRequest(0, 10)).getContent();
|
||||
Assert.assertEquals(testExemptions, allWithParams);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindAllWithParams() {
|
||||
FilterParams params = new FilterParams();
|
||||
List<ProjectClass> levels = new ArrayList<ProjectClass>();
|
||||
levels.add(bachelor);
|
||||
params.setLevels(levels);
|
||||
|
||||
//Should only find bachelors
|
||||
List<Exemption> allWithParams = exemptionService.findAll(params, new PageRequest(0, 10)).getContent();
|
||||
List<Exemption> expectedBachelors = Arrays.asList(new Exemption[]{exemptionExpired, exemptionBachelor});
|
||||
Assert.assertEquals(expectedBachelors, allWithParams);
|
||||
|
||||
levels.add(master);
|
||||
params.setLevels(levels);
|
||||
|
||||
//Should find all
|
||||
allWithParams = exemptionService.findAll(params, new PageRequest(0, 10)).getContent();
|
||||
List<Exemption> expectedAll = Arrays.asList(new Exemption[]{exemptionExpired, exemptionBachelor, exemptionMaster});
|
||||
Assert.assertEquals(expectedAll, allWithParams);
|
||||
|
||||
params.setAuthor(author1);
|
||||
|
||||
//Should only find author1 exemptions
|
||||
allWithParams = exemptionService.findAll(params, new PageRequest(0, 10)).getContent();
|
||||
List<Exemption> expectedAuthor1 = Arrays.asList(new Exemption[]{exemptionExpired, exemptionMaster});
|
||||
Assert.assertEquals(expectedAuthor1, allWithParams);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// @Transactional
|
||||
// @Rollback
|
||||
// public void testIsExemptionGranted() {
|
||||
//
|
||||
// // This should be false, author1 has a bachelor exemption, but the date's expired.
|
||||
// Assert.assertFalse(exemptionService.isExemptionGranted(author1, bachelor));
|
||||
//
|
||||
// // This should be true, author1 has a current master exemption.
|
||||
// Assert.assertTrue(exemptionService.isExemptionGranted(author1, master));
|
||||
//
|
||||
// // This should be true, author2 has a current bachelor exemption.
|
||||
// Assert.assertTrue(exemptionService.isExemptionGranted(author2, bachelor));
|
||||
//
|
||||
// }
|
||||
|
||||
private User newUser() {
|
||||
User user = new User();
|
||||
return userService.save(user);
|
||||
}
|
||||
|
||||
private Student newStudent(final User user) {
|
||||
Student student = new Student();
|
||||
student.setUser(user);
|
||||
return studentService.save(student);
|
||||
}
|
||||
|
||||
private Exemption newExemption(Student author, ProjectClass pc, User granter, String comment, Date expirationDate) {
|
||||
Exemption exemption = new Exemption();
|
||||
exemption.setAuthor(author);
|
||||
exemption.setProjectClass(pc);
|
||||
exemption.setGrantedBy(granter);
|
||||
exemption.setComment(comment);
|
||||
exemption.setExpirationDate(expirationDate);
|
||||
return exemptionService.save(exemption);
|
||||
}
|
||||
|
||||
private Date expiredDate(int minusMonths) {
|
||||
DateTime dt = new DateTime();
|
||||
dt = dt.minusMonths(minusMonths);
|
||||
return dt.toDate();
|
||||
}
|
||||
|
||||
private Date futureDate(int plusMonths) {
|
||||
DateTime dt = new DateTime();
|
||||
dt = dt.plusMonths(plusMonths);
|
||||
return dt.toDate();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user