
ars.module.educate.service.AbstractChapterService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ars-module-educate Show documentation
Show all versions of ars-module-educate Show documentation
Ars framework module educate
package ars.module.educate.service;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import ars.util.SimpleTree;
import ars.invoke.request.Requester;
import ars.invoke.request.ParameterInvalidException;
import ars.module.educate.model.Course;
import ars.module.educate.model.Chapter;
import ars.module.educate.service.ChapterService;
import ars.database.repository.Query;
import ars.database.repository.Repositories;
import ars.database.service.StandardGeneralService;
/**
* 课程章节抽象实现
*
* @author yongqiangwu
*
* @param
* 数据模型
*/
public abstract class AbstractChapterService extends StandardGeneralService
implements ChapterService {
@Override
public void initObject(Requester requester, T entity, Map parameters) {
super.initObject(requester, entity, parameters);
Course course = entity.getCourse();
Chapter parent = entity.getParent();
Query query = this.getRepository().query().ne("id", entity.getId()).eq("course", course).eq("name",
entity.getName());
if (parent == null) {
query.empty("parent");
} else {
query.eq("parent", parent);
}
if (query.count() > 0) {
throw new ParameterInvalidException("name", "exist");
}
if (parent == null) {
if (course == null) {
throw new ParameterInvalidException("course", "required");
}
} else if (course == null) {
entity.setCourse(parent.getCourse());
} else if (!course.equals(parent.getCourse())) {
throw new ParameterInvalidException("course", "invalid");
}
}
@Override
public List ctrees(Requester requester, Map parameters) {
List trees = this.trees(requester, parameters);
List branchs = Repositories.getSimpleTrees(trees);
List roots = new ArrayList(trees.size());
Map temp = new HashMap(trees.size());
for (int i = 0; i < trees.size(); i++) {
Course course = trees.get(i).getCourse();
SimpleTree root = temp.get(course);
if (root == null) {
root = Repositories.getSimpleTree(course);
temp.put(course, root);
roots.add(root);
}
SimpleTree branch = branchs.get(i);
branch.setParent(root);
root.getChildren().add(branch);
}
return roots;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy