<commit_before>/**
 * <p>Title: StorageContainerHDAO Class>
 * <p>Description:	StorageContainerHDAO is used to add Storage Container information into the database using Hibernate.</p>
 * Copyright:    Copyright (c) year
 * Company: Washington University, School of Medicine, St. Louis.
 * @author <NAME>
 * @version 1.00
 * Created on Jul 23, 2005
 */

package edu.wustl.catissuecore.dao;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import net.sf.hibernate.HibernateException;
import edu.wustl.catissuecore.domain.CollectionProtocol;
import edu.wustl.catissuecore.domain.CollectionProtocolEvent;
import edu.wustl.catissuecore.domain.SpecimenRequirement;
import edu.wustl.catissuecore.domain.User;
import edu.wustl.catissuecore.util.global.Constants;
import edu.wustl.common.util.dbManager.DAOException;
import edu.wustl.common.util.logger.Logger;

/**
 * StorageContainerHDAO is used to add Storage Container information into the database using Hibernate.
 * @author aniruddha_phadnis
 */
public class CollectionProtocolBizLogic extends DefaultBizLogic
{
	/**
     * Saves the storageContainer object in the database.
     * @param session The session in which the object is saved.
     * @param obj The storageType object to be saved.
     * @throws HibernateException Exception thrown during hibernate operations.
     * @throws DAOException 
     */
	public void insert(Object obj) throws DAOException 
	{
		AbstractDAO dao = DAOFactory.getDAO(Constants.HIBERNATE_DAO);
		try
		{
			CollectionProtocol collectionProtocol = (CollectionProtocol)obj;
	        
//			AbstractDAO dao = DAOFactory.getDAO(Constants.HIBERNATE_DAO);
			dao.openSession();
			
			List list = dao.retrieve(User.class.getName(), "systemIdentifier", collectionProtocol.getPrincipalInvestigator().getSystemIdentifier());
			if (list.size() != 0)
			{
				User pi = (User) list.get(0);
				collectionProtocol.setPrincipalInvestigator(pi);
			}
			
			Collection coordinatorColl = new HashSet();
			Iterator it = collectionProtocol.getUserCollection().iterator();
			while(it.hasNext())
			{
				User aUser  =(User)it.next();
				list = dao.retrieve(User.class.getName(), "systemIdentifier", aUser.getSystemIdentifier());
				if (list.size() != 0)
				{
					User coordinator = (User) list.get(0);
					System.out.println("coordinator "+coordinator.getSystemIdentifier());
					coordinatorColl.add(coordinator);
					coordinator.getCollectionProtocolCollection().add(coordinator);
					dao.update(coordinator);
				}
			}
			collectionProtocol.setUserCollection(coordinatorColl);
			
//			SpecimenProtocol p = new SpecimenProtocol();
//			p.setTitle("AAABBBA");
//			dao.insert(p);
			
			dao.insert(collectionProtocol);
			it = collectionProtocol.getCollectionProtocolEventCollection().iterator();
			while(it.hasNext())
			{
				CollectionProtocolEvent collectionProtocolEvent = (CollectionProtocolEvent)it.next();
				collectionProtocolEvent.setCollectionProtocol(collectionProtocol);
				dao.insert(collectionProtocolEvent);
				
				Iterator srIt = collectionProtocolEvent.getSpecimenRequirementCollection().iterator();
				while(srIt.hasNext())
				{
					SpecimenRequirement specimenRequirement = (SpecimenRequirement)srIt.next();
					specimenRequirement.getCollectionProtocolEventCollection().add(collectionProtocolEvent);
					dao.insert(specimenRequirement);
				}
			}
		}
		catch(DAOException ex)
		{
			Logger.out.error("",ex);
		}
		finally
		{
			dao.closeSession();
		}
	}
	
	/**
     * Updates the persistent object in the database.
     * @param session The session in which the object is saved.
     * @param obj The object to be updated.
     * @throws HibernateException Exception thrown during hibernate operations.
     * @throws DAOException 
     */
    public void update(Object obj) throws DAOException
    {
    }<commit_msg>Collection protocol<commit_after>/**
 * <p>Title: StorageContainerHDAO Class>
 * <p>Description:	StorageContainerHDAO is used to add Storage Container information into the database using Hibernate.</p>
 * Copyright:    Copyright (c) year
 * Company: Washington University, School of Medicine, St. Louis.
 * @author <NAME>
 * @version 1.00
 * Created on Jul 23, 2005
 */

package edu.wustl.catissuecore.dao;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import net.sf.hibernate.HibernateException;
import edu.wustl.catissuecore.domain.CollectionProtocol;
import edu.wustl.catissuecore.domain.CollectionProtocolEvent;
import edu.wustl.catissuecore.domain.SpecimenRequirement;
import edu.wustl.catissuecore.domain.User;
import edu.wustl.catissuecore.util.global.Constants;
import edu.wustl.common.util.dbManager.DAOException;
import edu.wustl.common.util.logger.Logger;

/**
 * StorageContainerHDAO is used to add Storage Container information into the database using Hibernate.
 * @author aniruddha_phadnis
 */
public class CollectionProtocolBizLogic extends DefaultBizLogic
{
	/**
     * Saves the storageContainer object in the database.
     * @param session The session in which the object is saved.
     * @param obj The storageType object to be saved.
     * @throws HibernateException Exception thrown during hibernate operations.
     * @throws DAOException 
     */
	public void insert(Object obj) throws DAOException 
	{
		AbstractDAO dao = DAOFactory.getDAO(Constants.HIBERNATE_DAO);
		try
		{
			CollectionProtocol collectionProtocol = (CollectionProtocol)obj;
			dao.openSession();
			
			List list = dao.retrieve(User.class.getName(), "systemIdentifier", collectionProtocol.getPrincipalInvestigator().getSystemIdentifier());
			if (list.size() != 0)
			{
				User pi = (User) list.get(0);
				collectionProtocol.setPrincipalInvestigator(pi);
			}
			
			Collection coordinatorColl = new HashSet();
			Iterator it = collectionProtocol.getUserCollection().iterator();
			while(it.hasNext())
			{
				User aUser  =(User)it.next();
				list = dao.retrieve(User.class.getName(), "systemIdentifier", aUser.getSystemIdentifier());
				if (list.size() != 0)
				{
					User coordinator = (User) list.get(0);
					System.out.println("coordinator "+coordinator.getSystemIdentifier());
					coordinatorColl.add(coordinator);
					coordinator.getCollectionProtocolCollection().add(collectionProtocol);
					dao.update(coordinator);
				}
			}
			collectionProtocol.setUserCollection(coordinatorColl);
			
			dao.insert(collectionProtocol);
			it = collectionProtocol.getCollectionProtocolEventCollection().iterator();
			while(it.hasNext())
			{
				CollectionProtocolEvent collectionProtocolEvent = (CollectionProtocolEvent)it.next();
				collectionProtocolEvent.setCollectionProtocol(collectionProtocol);
				dao.insert(collectionProtocolEvent);
				
				Iterator srIt = collectionProtocolEvent.getSpecimenRequirementCollection().iterator();
				while(srIt.hasNext())
				{
					SpecimenRequirement specimenRequirement = (SpecimenRequirement)srIt.next();
					specimenRequirement.getCollectionProtocolEventCollection().add(collectionProtocolEvent);
					dao.insert(specimenRequirement);
				}
			}
		}
		catch(Exception ex)
		{
			Logger.out.error("",ex);
		}
		finally
		{
			dao.closeSession();
		}
	}
	
	/**
     * Updates the persistent object in the database.
     * @param session The session in which the object is saved.
     * @param obj The object to be updated.
     * @throws HibernateException Exception thrown during hibernate operations.
     * @throws DAOException 
     */
    public void update(Object obj) throws DAOException
    {
    }
{'fraction_non_alphanumeric': 0.10358879978966741, 'fraction_numerical': 0.003417904561588011, 'mean_word_length': 4.24328049620951, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7392865', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2174, 'n_words': 482}