moved new checklist template stuff into service method

This commit is contained in:
fred-fri 2012-05-11 13:37:43 +09:00
parent 967c8c2f46
commit a8dbb0a675
3 changed files with 24 additions and 7 deletions
src/main/java/se/su/dsv/scipro

@ -53,13 +53,7 @@ public abstract class CheckListTemplateDataPanel extends Panel {
newLink = new AjaxLink<Void>("newLink") {
@Override
public void onClick(AjaxRequestTarget target) {
CheckListTemplate clt = new CheckListTemplate("New checklist template (change this to real name)", SciProSession.get().getUser());
clt.setCategories(new ArrayList<ChecklistCategory>());
ArrayList<String> questionList = new ArrayList<String>();
questionList.add(new String("Example question (remove this and add relevant questions)"));
clt.setQuestions(questionList);
clt.setTemplateNumber(safeLongToInt(checklistTemplateService.count() + 1));
cltdp.onClick(new Model<CheckListTemplate>(clt), target);
cltdp.onClick(new Model<CheckListTemplate>(checklistTemplateService.prepareNewTemplate()), target);
}
};
newLink.setVisible(adminPrivileges);

@ -7,13 +7,16 @@ 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.SciProSession;
import se.su.dsv.scipro.data.dataobjects.CheckListTemplate;
import se.su.dsv.scipro.data.dataobjects.ChecklistCategory;
import se.su.dsv.scipro.data.dataobjects.QCheckListTemplate;
import se.su.dsv.scipro.springdata.repos.ChecklistTemplateRepo;
import se.su.dsv.scipro.springdata.services.ChecklistTemplateService;
import javax.annotation.Resource;
import java.util.ArrayList;
/**
* @author: fred-fri
@ -93,6 +96,17 @@ public class ChecklistTemplateServiceImpl extends AbstractQueryService<CheckList
}
}
@Override
public CheckListTemplate prepareNewTemplate() {
CheckListTemplate clt = new CheckListTemplate("New checklist template (change this to real name)", SciProSession.get().getUser());
clt.setCategories(new ArrayList<ChecklistCategory>());
ArrayList<String> questionList = new ArrayList<String>();
questionList.add(new String("Example question (remove this and add relevant questions)"));
clt.setQuestions(questionList);
clt.setTemplateNumber(safeLongToInt(checklistTemplateRepo.count() + 1));
return clt;
}
private BooleanExpression filterStringIsCreatorName(String filterString){
return QCheckListTemplate.checkListTemplate.creator.firstName.contains(filterString).or(QCheckListTemplate.checkListTemplate.creator.lastName.contains(filterString));
}
@ -100,4 +114,12 @@ public class ChecklistTemplateServiceImpl extends AbstractQueryService<CheckList
private BooleanExpression filterStringIsChecklistTemplateName(String filterString){
return QCheckListTemplate.checkListTemplate.name.contains(filterString);
}
public static int safeLongToInt(long l) {
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw new IllegalArgumentException
(l + " cannot be cast to int without changing its value.");
}
return (int) l;
}
}

@ -15,4 +15,5 @@ public interface ChecklistTemplateService extends CrudService<CheckListTemplate,
Long count(String filterString);
void upChecklistTemplate(CheckListTemplate checkListTemplate);
void downChecklistTemplate(CheckListTemplate checkListTemplate);
CheckListTemplate prepareNewTemplate();
}