package de.hsadmin.mods.qstat;

import java.util.List;

import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.user.UnixUser;

public class QTaskModuleImpl extends AbstractModuleImpl {

	private static final long serialVersionUID = 3942424688570077274L;

	public QTaskModuleImpl() {
	}

	@Override
	public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
		// do query and return result
		if (orderBy == null || orderBy.length() == 0) {
			orderBy = "ORDER BY obj.started DESC";
		}
		return super.search(entityClass, condition, orderBy);
	}

	// throws an AuthorisationException if the login user has no write acess
	// on the pac of the given UnixUser
	@SuppressWarnings("unused")
	private boolean hasAccessOnPacOf(UnixUser user) {
		// only pac admins (same name as pac) and the owner (customer) have
		// write access to the pac
		boolean isPacAdmin = getLoginUser().getName().equals(
				user.getPac().getName());
		boolean isCustomer = getLoginUser().getName().equals(
				user.getPac().getCustomer().getName());
		return isPacAdmin || isCustomer;
	}
}
