Not possible to edit dates for application periods that are connected to project ideas.
This commit is contained in:
parent
20cbbe3f4f
commit
c78992f69e
src
main/java/se/su/dsv/scipro/match
test/java/se/su/dsv/scipro/match/dao
@ -6,7 +6,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ApplicationPeriodDao;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ProjectIdeaDao;
|
||||
import se.su.dsv.scipro.match.dataobject.ApplicationPeriod;
|
||||
import se.su.dsv.scipro.match.dataobject.ProjectIdea;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
|
||||
import java.util.*;
|
||||
@ -17,6 +19,9 @@ public class ApplicationPeriodFacade {
|
||||
@Autowired
|
||||
private ApplicationPeriodDao applicationPeriodDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectIdeaDao projectIdeaDao;
|
||||
|
||||
@Transactional
|
||||
public void saveApplicationPeriod(final ApplicationPeriod period){
|
||||
applicationPeriodDao.save(period);
|
||||
@ -24,15 +29,14 @@ public class ApplicationPeriodFacade {
|
||||
|
||||
/**
|
||||
* Returns true when the application period has been removed successfully,
|
||||
* it should only be allowed to remove a period if the start date NOT IS BEFORE present date,
|
||||
* ie. the same prerequisites as for editing the start date of a period.
|
||||
* It is only allowed to remove an application period if not any project ideas exists.
|
||||
* @param appPeriod the period that should be removed
|
||||
* @return boolean the value is true if success false if failure
|
||||
*/
|
||||
@Transactional
|
||||
public boolean removeApplicationPeriod(ApplicationPeriod appPeriod){
|
||||
appPeriod = applicationPeriodDao.reLoad(appPeriod);
|
||||
if(editStartDatePeriod(appPeriod)) {
|
||||
if(!projectIdeasExists(appPeriod)) {
|
||||
applicationPeriodDao.delete(appPeriod);
|
||||
return true;
|
||||
} else {
|
||||
@ -41,24 +45,25 @@ public class ApplicationPeriodFacade {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it is allowed to edit the application period. ,
|
||||
* It should be allowed to edit the start date a period only if the start date NOT IS BEFORE present date,
|
||||
* @param editedAppPeriod the period that should be edited
|
||||
* @return boolean true if success false if failure
|
||||
* It is only allowed to edit an application period if not any project ideas exists.
|
||||
* @param applicationPeriod the application period that should be tested
|
||||
* @return boolean true if possible to edit
|
||||
*/
|
||||
@Transactional
|
||||
public boolean editStartDatePeriod(final ApplicationPeriod editedAppPeriod){
|
||||
return !editedAppPeriod.getStartDate().before(Calendar.getInstance().getTime());
|
||||
}
|
||||
public boolean projectIdeasExists(final ApplicationPeriod applicationPeriod) {
|
||||
ApplicationPeriod savedApplicationPeriod = applicationPeriod.getId() != null ? applicationPeriodDao.reLoad(applicationPeriod): null;
|
||||
if(savedApplicationPeriod == null) {
|
||||
return false;
|
||||
}
|
||||
List<ProjectIdea> projectIdeaList = new ArrayList<ProjectIdea>();
|
||||
projectIdeaList.addAll(projectIdeaDao.findAll());
|
||||
for(ProjectIdea projectIdea : projectIdeaList) {
|
||||
if(projectIdea.getApplicationPeriod().equals(savedApplicationPeriod)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it is allowed to edit the end date of the application period.
|
||||
* It should be allowed to edit the end date of a period only if the end date NOT IS BEFORE present date,
|
||||
* @param editedAppPeriod the period which end date should be edited
|
||||
* @return boolean true if success false if failure
|
||||
*/
|
||||
public boolean editEndDatePeriod(final ApplicationPeriod editedAppPeriod){
|
||||
return !editedAppPeriod.getEndDate().before(Calendar.getInstance().getTime());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,9 +26,10 @@ import se.su.dsv.scipro.admin.pages.match.AdminManageMatchPeriodsPage;
|
||||
import se.su.dsv.scipro.components.CustomDateTimeField;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ApplicationPeriodDao;
|
||||
import se.su.dsv.scipro.match.dataobject.ApplicationPeriod;
|
||||
import se.su.dsv.scipro.match.facade.ApplicationPeriodFacade;
|
||||
import se.su.dsv.scipro.util.StringUtil;
|
||||
|
||||
|
||||
public class MatchPeriodEditPanel extends Panel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -39,6 +40,11 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
@SpringBean
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
@SpringBean
|
||||
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||
|
||||
|
||||
|
||||
private WebMarkupContainer containerForUpdate;
|
||||
private Component feedbackPanel;
|
||||
|
||||
@ -102,10 +108,17 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
}
|
||||
|
||||
if(appPeriod.getEndDate().before(appPeriod.getStartDate())) {
|
||||
error("The end date can not be before the start date.");
|
||||
error("The end date cannot be before the start date.");
|
||||
target.addComponent(feedbackPanel);
|
||||
return;
|
||||
}
|
||||
|
||||
if(applicationPeriodFacade.projectIdeasExists(appPeriod)) {
|
||||
error("It is not possible to edit dates when an application period has connected project ideas.");
|
||||
target.addComponent(feedbackPanel);
|
||||
return;
|
||||
}
|
||||
|
||||
appPeriod.setProjectClass(pClassesToSet);
|
||||
boolean isEditing = appPeriod.getId() != null;
|
||||
|
||||
|
@ -190,8 +190,8 @@ public class TestApplicationPeriodDao {
|
||||
applicationPeriodDao.delete(applicationPeriod2);
|
||||
}
|
||||
|
||||
/* create an application period with the start date before TODAY
|
||||
but the end date is irrelevant, it should NOT be possible to remove the application period, */
|
||||
/* create an application period and a new project idea which is connected to this period
|
||||
it should NOT be possible to remove the application period, */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
@ -205,12 +205,14 @@ public class TestApplicationPeriodDao {
|
||||
cal.add(Calendar.MONDAY, 3);
|
||||
final Date endDate1 = cal.getTime();
|
||||
ApplicationPeriod applicationPeriod = applicationPeriodFacade.createApplicationPeriodDates(myBachelorSet, startDate1, endDate1, "name1");
|
||||
ProjectIdea projectIdea = createProjectIdea(applicationPeriod, bachelor);
|
||||
boolean periodRemoved = applicationPeriodFacade.removeApplicationPeriod(applicationPeriod);
|
||||
assertFalse(periodRemoved); // should be false
|
||||
assertNotNull(applicationPeriod);
|
||||
}
|
||||
|
||||
|
||||
/* create an application period with the the start-date after TODAY,
|
||||
/* create an application period with no connected project ideas,
|
||||
it should be possible to remove the period */
|
||||
@Test
|
||||
@Transactional
|
||||
@ -227,51 +229,33 @@ public class TestApplicationPeriodDao {
|
||||
ApplicationPeriod applicationPeriod = applicationPeriodFacade.createApplicationPeriodDates(myBachelorSet, startDate1, endDate1, "name1");
|
||||
boolean periodRemoved = applicationPeriodFacade.removeApplicationPeriod(applicationPeriod);
|
||||
assertTrue(periodRemoved); // should be true
|
||||
applicationPeriod = applicationPeriodDao.reLoad(applicationPeriod);
|
||||
assertNull(applicationPeriod); // should be null
|
||||
}
|
||||
|
||||
/* create an application period, then try to edit the start date of the period to a date before TODAY
|
||||
but the end date is irrelevant, it should NOT be possible to edit the start date of the application period, */
|
||||
/* create an application period, and add the period to a new project idea,
|
||||
try to find this connected project idea => it should NOT be possible to edit a connected application period, */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testEditStartDate() {
|
||||
public void testProjIdeasExists() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_WEEK, 1);
|
||||
final Date startDate1 = cal.getTime();
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
final Date endDate1 = cal.getTime();
|
||||
ApplicationPeriod applicationPeriod = applicationPeriodFacade.createApplicationPeriodDates(myBachelorSet, startDate1, endDate1, "name1");
|
||||
cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
applicationPeriod.setStartDate(cal.getTime());
|
||||
boolean allowedToEdit = applicationPeriodFacade.editStartDatePeriod(applicationPeriod);
|
||||
assertFalse(allowedToEdit); // allowedToEdit should be false
|
||||
ProjectIdea projectIdea = createProjectIdea(applicationPeriod, bachelor);
|
||||
boolean projIdeasExist = applicationPeriodFacade.projectIdeasExists(applicationPeriod);
|
||||
if(!projIdeasExist) {
|
||||
applicationPeriod.setStartDate(cal.getTime());
|
||||
}
|
||||
assertTrue(projIdeasExist); // projIdeasExist should be true
|
||||
}
|
||||
|
||||
/* create an application period, then try to edit the end date of the period to a date before TODAY
|
||||
but the start date is irrelevant, it should NOT be possible to edit end date of the application period, */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testEditEndDate() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
final Date startDate1 = cal.getTime();
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
final Date endDate1 = cal.getTime();
|
||||
ApplicationPeriod applicationPeriod = applicationPeriodFacade.createApplicationPeriodDates(myBachelorSet, startDate1, endDate1, "name1");
|
||||
cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
applicationPeriod.setEndDate(cal.getTime());
|
||||
boolean allowedToEdit = applicationPeriodFacade.editEndDatePeriod(applicationPeriod);
|
||||
assertFalse(allowedToEdit); // allowedToEdit should be false
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* create a "bachelor" application period from TODAY and a month forward,,
|
||||
there should exist an OPEN "bachelor"application period */
|
||||
|
Loading…
x
Reference in New Issue
Block a user