Refactored ApplicationPeriod out of StringUtil bacause StringUtil should only be aware of Strings.
This commit is contained in:
parent
ae2165955e
commit
083de84643
src/main/java/se/su/dsv/scipro
admin/pages/match
match
util
@ -115,9 +115,9 @@ public class AdminMatchPeriodsPanel extends Panel {
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
if(facade.removeApplicationPeriod(appPeriod)) {
|
||||
target.addComponent(container);
|
||||
Session.get().info("Removed : " + StringUtil.getApplicationPeriodData(appPeriod));
|
||||
Session.get().info("Removed : " + facade.getApplicationPeriodData(appPeriod));
|
||||
} else {
|
||||
Session.get().error("It was not possible to remove : " + StringUtil.getApplicationPeriodData(appPeriod));
|
||||
Session.get().error("It was not possible to remove : " + facade.getApplicationPeriodData(appPeriod));
|
||||
}
|
||||
target.addComponent(localFeedbackPanel);
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ 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.dataobject.ApplicationPeriod;
|
||||
import se.su.dsv.scipro.match.dataobject.ProjectIdea;
|
||||
//import se.su.dsv.scipro.util.DateUtils;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -89,6 +88,41 @@ public class ApplicationPeriodFacade {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get uniformity in the written output on the FeedbackPanels of the Classes that has done CRUD-operations on the period
|
||||
* @param appPeriod the period on which a CRUD operation was done
|
||||
* @return String the formatted output sent to a FeedbackPanel
|
||||
*/
|
||||
public String getApplicationPeriodData(final ApplicationPeriod appPeriod) {
|
||||
StringBuilder projectClasses = new StringBuilder();
|
||||
Iterator<ProjectClass> projectClassIterator = appPeriod.getProjectClass().iterator();
|
||||
while(projectClassIterator.hasNext()) {
|
||||
projectClasses.append(projectClassIterator.next().getName());
|
||||
if(projectClassIterator.hasNext()) {
|
||||
projectClasses.append(", ");
|
||||
}
|
||||
}
|
||||
return new StringBuilder()
|
||||
.append("'").append(appPeriod.getName()).append("'")
|
||||
.append("\tStart date : '").append(new DateFormatter(DateFormatter.FORMAT.DEFAULT).createFormattedString(appPeriod.getStartDate())).append("'")
|
||||
.append("\tEnd date : '").append(new DateFormatter(DateFormatter.FORMAT.DEFAULT).createFormattedString(appPeriod.getEndDate())).append("'")
|
||||
.append("\tLevels: '").append(projectClasses.toString()).append("'").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that is used to initialize constructors
|
||||
* @return ApplicationPeriod the object that is returned
|
||||
*/
|
||||
public static ApplicationPeriod createDummyApplicationPeriod(){
|
||||
ApplicationPeriod appPeriod = new ApplicationPeriod();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
appPeriod.setStartDate(cal.getTime());
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
appPeriod.setEndDate(cal.getTime());
|
||||
appPeriod.setName("...");
|
||||
return appPeriod;
|
||||
}
|
||||
|
||||
// a helper method, to avoid NPEs when using faulty test data
|
||||
private boolean testForInvalidData(final ApplicationPeriod applicationPeriod) {
|
||||
return (applicationPeriod.getProjectClass() == null || applicationPeriod.getProjectClass().isEmpty() ||
|
||||
|
@ -32,42 +32,34 @@ import se.su.dsv.scipro.util.StringUtil;
|
||||
|
||||
public class MatchPeriodEditPanel extends Panel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Form<ApplicationPeriod> formWrapper;
|
||||
private Component feedbackPanel;
|
||||
|
||||
@SpringBean
|
||||
private ApplicationPeriodFacade facade;
|
||||
|
||||
@SpringBean
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
private WebMarkupContainer containerForUpdate;
|
||||
private Component feedbackPanel;
|
||||
|
||||
public MatchPeriodEditPanel(final String id, final WebMarkupContainer container) {
|
||||
this(id, new Model<ApplicationPeriod>(createDummyApplicationPeriod()), container);
|
||||
this(id, new Model<ApplicationPeriod>(ApplicationPeriodFacade.createDummyApplicationPeriod()), container);
|
||||
}
|
||||
public MatchPeriodEditPanel(String id, IModel<ApplicationPeriod> model, final WebMarkupContainer container) {
|
||||
super(id);
|
||||
containerForUpdate = container;
|
||||
add(feedbackPanel = new FeedbackPanel("feedback").setOutputMarkupId(true));
|
||||
formWrapper = new ApplicationPeriodForm("applicationPeriodForm",model);
|
||||
Form<ApplicationPeriod> formWrapper = new ApplicationPeriodForm("applicationPeriodForm", model);
|
||||
formWrapper.setEnabled(isEditable());
|
||||
add(formWrapper);
|
||||
}
|
||||
/**
|
||||
* Override to provide a fast and simple "view application period" or "edit application period" functionality depending on preference.
|
||||
* @return
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEditable(){
|
||||
return false;
|
||||
}
|
||||
private static ApplicationPeriod createDummyApplicationPeriod(){
|
||||
ApplicationPeriod appPeriod = new ApplicationPeriod();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
appPeriod.setStartDate(cal.getTime());
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
appPeriod.setEndDate(cal.getTime());
|
||||
appPeriod.setName("...");
|
||||
return appPeriod;
|
||||
}
|
||||
|
||||
private class ApplicationPeriodForm extends Form<ApplicationPeriod> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -126,7 +118,7 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
} else {
|
||||
saveMsg.append(" Saved : ");
|
||||
}
|
||||
Session.get().info(saveMsg.toString() + StringUtil.getApplicationPeriodData(appPeriod));
|
||||
Session.get().info(saveMsg.toString() + facade.getApplicationPeriodData(appPeriod));
|
||||
if(isEditing) {
|
||||
setResponsePage(AdminManageMatchPeriodsPage.class); // to avoid HibernateOptimisticLockingFailureException when updating
|
||||
}
|
||||
@ -138,7 +130,7 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
} else {
|
||||
errorMsg.append(" Could not create new : ");
|
||||
}
|
||||
Session.get().error(errorMsg.toString() + StringUtil.getApplicationPeriodData(appPeriod) + " period already exists.");
|
||||
Session.get().error(errorMsg.toString() + facade.getApplicationPeriodData(appPeriod) + " period already exists.");
|
||||
}
|
||||
target.addComponent(containerForUpdate);
|
||||
target.addComponent(feedbackPanel);
|
||||
@ -153,7 +145,7 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
protected void onError(AjaxRequestTarget target, Form<?> form) {
|
||||
final ApplicationPeriod appPeriod = ((ApplicationPeriod)form.getModelObject());
|
||||
if(appPeriod.getProjectClass().size() > 0 && !appPeriod.getEndDate().before(appPeriod.getStartDate())) {
|
||||
Session.get().error(" Could not add application period : " + StringUtil.getApplicationPeriodData(appPeriod));
|
||||
Session.get().error(" Could not add application period : " + facade.getApplicationPeriodData(appPeriod));
|
||||
target.addComponent(feedbackPanel);
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,9 @@ public class StringUtil {
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static String getAuthorsFormated(List<Student> authors) {
|
||||
|
||||
// TODO : this should be refactored, the StringUtil class should not be aware of Student
|
||||
public static String getAuthorsFormated(List<Student> authors) {
|
||||
if (authors == null) {
|
||||
return null;
|
||||
}
|
||||
@ -47,7 +48,8 @@ public class StringUtil {
|
||||
|
||||
return getFormatedString(stringList);
|
||||
}
|
||||
|
||||
|
||||
// TODO : this should be refactored, the StringUtil class should not be aware of Keywords
|
||||
public static String getKeywordsFormated(Keywords keywords) {
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
for (Keyword keyword : keywords.getAll()) {
|
||||
@ -56,21 +58,4 @@ public class StringUtil {
|
||||
|
||||
return getFormatedString(stringList);
|
||||
}
|
||||
|
||||
// TODO : this should be refactored, the StringUtil class should not be aware of ApplicationPeriods
|
||||
public static String getApplicationPeriodData(final ApplicationPeriod appPeriod) {
|
||||
StringBuilder projectClasses = new StringBuilder();
|
||||
Iterator<ProjectClass> projectClassIterator = appPeriod.getProjectClass().iterator();
|
||||
while(projectClassIterator.hasNext()) {
|
||||
projectClasses.append(projectClassIterator.next().getName());
|
||||
if(projectClassIterator.hasNext()) {
|
||||
projectClasses.append(", ");
|
||||
}
|
||||
}
|
||||
return new StringBuilder()
|
||||
.append("'").append(appPeriod.getName()).append("'")
|
||||
.append("\tStart date : '").append(new DateFormatter(DateFormatter.FORMAT.DEFAULT).createFormattedString(appPeriod.getStartDate())).append("'")
|
||||
.append("\tEnd date : '").append(new DateFormatter(DateFormatter.FORMAT.DEFAULT).createFormattedString(appPeriod.getEndDate())).append("'")
|
||||
.append("\tLevels: '").append(projectClasses.toString()).append("'").toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user