All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ars.module.people.service.AbstractGroupService Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package ars.module.people.service;

import java.util.Map;

import ars.invoke.request.Requester;
import ars.invoke.request.AccessDeniedException;
import ars.invoke.request.RequestHandleException;
import ars.invoke.request.ParameterInvalidException;
import ars.database.repository.Query;
import ars.database.repository.Repositories;
import ars.database.service.StandardGeneralService;
import ars.module.people.model.User;
import ars.module.people.model.Group;
import ars.module.people.service.GroupService;

/**
 * 部门业务操作抽象实现
 * 
 * @author yongqiangwu
 * 
 * @param 
 *            数据模型
 */
public abstract class AbstractGroupService extends StandardGeneralService
		implements GroupService {

	@Override
	public void initObject(Requester requester, T entity, Map parameters) {
		super.initObject(requester, entity, parameters);
		Group parent = entity.getParent();
		User owner = Repositories.getRepository(User.class).query().eq("code", requester.getUser()).single();
		if (!owner.getAdmin() && this.getRepository().get(owner.getGroup().getId()).getParent() != null
				&& (parent == null || !parent.getKey().startsWith(owner.getGroup().getKey()))) {
			throw new AccessDeniedException("Illegal operation");
		}
		Query query = this.getRepository().query().ne("id", entity.getId()).eq("name", entity.getName());
		if (parent == null) {
			query.empty("parent");
		} else {
			query.eq("parent", parent);
		}
		if (query.count() > 0) {
			throw new ParameterInvalidException("name", "exist");
		}
	}

	@Override
	public void deleteObject(Requester requester, T object) {
		User owner = Repositories.getRepository(User.class).query().eq("code", requester.getUser()).single();
		if (!owner.getAdmin() && !object.getKey().startsWith(owner.getGroup().getKey())) {
			throw new RequestHandleException("Unauthorized operation");
		}
		super.deleteObject(requester, object);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy