<commit_before>package org.devilry.core.dao;

import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.Stateless;
import javax.persistence.*;

import org.devilry.core.daointerfaces.AssignmentNodeLocal;
import org.devilry.core.daointerfaces.AssignmentNodeRemote;
import org.devilry.core.entity.*;

@Stateless
public class AssignmentNodeImpl extends BaseNodeImpl implements
		AssignmentNodeRemote, AssignmentNodeLocal {

	
	private AssignmentNode getAssignmentNode(long nodeId) {
		return (AssignmentNode) getNode(nodeId);
	}

	@SuppressWarnings("unchecked")
	public List<Long> getDeliveries(long nodeId) {
		Query q = em
				.createQuery("SELECT d.id FROM Delivery d WHERE d.assignment.id = :id");
		q.setParameter("id", nodeId);
		return q.getResultList();
	}

	public List<Long> getChildren(long nodeId) {
		throw new UnsupportedOperationException(
				"AssignmentNode does not have any children. Did you mean getDeliveries?");
	}

	public Date getDeadline(long nodeId) {
		return getAssignmentNode(nodeId).getDeadline();
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void setDeadline(long nodeId, Date deadline) {
		AssignmentNode a = getAssignmentNode(nodeId);
		a.setDeadline(deadline);
		em.persist(a);
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public long create(String name, String displayName, Date deadline,
			long parentId) {<commit_msg>Added methods getDeliveriesWhereIsStudent and getDeliveriesWhereIsExaminer<commit_after>package org.devilry.core.dao;

import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.Stateless;
import javax.persistence.*;

import org.devilry.core.daointerfaces.AssignmentNodeLocal;
import org.devilry.core.daointerfaces.AssignmentNodeRemote;
import org.devilry.core.entity.*;

@Stateless
public class AssignmentNodeImpl extends BaseNodeImpl implements
		AssignmentNodeRemote, AssignmentNodeLocal {

	
	private AssignmentNode getAssignmentNode(long nodeId) {
		return (AssignmentNode) getNode(nodeId);
	}

	@SuppressWarnings("unchecked")
	public List<Long> getDeliveries(long nodeId) {
		Query q = em.createQuery("SELECT d.id FROM Delivery d WHERE d.assignment.id = :id");
		q.setParameter("id", nodeId);
		return q.getResultList();
	}

	
	public List<Long> getDeliveriesWhereIsStudent(long assignmentId) {
		long userId = userBean.getAuthenticatedUser();
		
		System.err.println("authenticated user:" + userId);
		//System.err.println("authenticated user:" + );
		
		Query q = em.createQuery("SELECT d.id FROM Delivery d INNER JOIN d.students user WHERE user.id = :userId AND d.assignment.id =:assignmentId");
		q.setParameter("assignmentId", assignmentId);
		q.setParameter("userId", userId);
		
		return q.getResultList();
	}
	
	public List<Long> getDeliveriesWhereIsExaminer(long assignmentId) {
		long userId = userBean.getAuthenticatedUser();
		
		Query q = em.createQuery("SELECT d.id FROM Delivery d INNER JOIN d.examiners user WHERE user.id = :userId AND d.assignment.id =:assignmentId");
		q.setParameter("assignmentId", userId);
		q.setParameter("userId", userId);
		
		return q.getResultList();
	}
		
	public List<Long> getChildren(long nodeId) {
		throw new UnsupportedOperationException(
				"AssignmentNode does not have any children. Did you mean getDeliveries?");
	}

	public Date getDeadline(long nodeId) {
		return getAssignmentNode(nodeId).getDeadline();
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void setDeadline(long nodeId, Date deadline) {
		AssignmentNode a = getAssignmentNode(nodeId);
		a.setDeadline(deadline);
		em.persist(a);
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public long create(String name, String displayName, Date deadline,
			long parentId) {
{'fraction_non_alphanumeric': 0.10111223458038422, 'fraction_numerical': 0.0, 'mean_word_length': 5.752559726962457, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3634644', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1240, 'n_words': 276}