<commit_before>/**  
   Copyright 2008 University of Rochester

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/  


package edu.ur.ir.handle.service;

import java.util.List;

import edu.ur.ir.handle.HandleInfo;
import edu.ur.ir.handle.HandleInfoDAO;
import edu.ur.ir.handle.HandleNameAuthority;
import edu.ur.ir.handle.HandleNameAuthorityDAO;
import edu.ur.ir.handle.HandleService;

/**
 * Service for dealing with handle information.
 * 
 * @author <NAME>
 *
 */
public class DefaultHandleService implements HandleService {
	
	/** Handle info data access */
	private HandleInfoDAO handleInfoDAO;
	

	/** Data access for handle name authority information */
	private HandleNameAuthorityDAO handleNameAuthorityDAO;

	public void delete(HandleNameAuthority handleNameAuthority) {
		handleNameAuthorityDAO.makeTransient(handleNameAuthority);
	}

	public void delete(HandleInfo handleInfo) {
		handleInfoDAO.makeTransient(handleInfo);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getHandleInfo(java.lang.Long, boolean)
	 */
	public HandleInfo getHandleInfo(Long id, boolean lock) {
		return handleInfoDAO.getById(id, lock);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getHandleInfo(java.lang.String)
	 */
	public HandleInfo getHandleInfo(String fullHandle) {
		HandleInfo info = null;
		if( fullHandle != null )
		{
		    String[] parts = fullHandle.split("/");
		    if( parts.length == 2)
		    {
		    	String prefix = parts[0];
		    	String localName = parts[1];
		    	System.out.println("prefix = " + prefix + " localName = " + localName);
		    	info =handleInfoDAO.get(prefix, localName);
		    }
		}
		return info;
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getNameAuthority(java.lang.String)
	 */
	public HandleNameAuthority getNameAuthority(String nameAuthority) {
		return handleNameAuthorityDAO.findByUniqueName(nameAuthority);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getNameAuthority(java.lang.Long, boolean)
	 */
	public HandleNameAuthority getNameAuthority(Long id, boolean lock) {
		return handleNameAuthorityDAO.getById(id, lock);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#save(edu.ur.ir.handle.HandleNameAuthority)<commit_msg>removed System.out call<commit_after>/**  
   Copyright 2008 University of Rochester

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/  


package edu.ur.ir.handle.service;

import java.util.List;

import org.apache.log4j.Logger;

import edu.ur.ir.handle.HandleInfo;
import edu.ur.ir.handle.HandleInfoDAO;
import edu.ur.ir.handle.HandleNameAuthority;
import edu.ur.ir.handle.HandleNameAuthorityDAO;
import edu.ur.ir.handle.HandleService;

/**
 * Service for dealing with handle information.
 * 
 * @author <NAME>
 *
 */
public class DefaultHandleService implements HandleService {
	
	/** Handle info data access */
	private HandleInfoDAO handleInfoDAO;
	

	/** Data access for handle name authority information */
	private HandleNameAuthorityDAO handleNameAuthorityDAO;
	
	/**  Get the logger for this class */
	private static final Logger log = Logger.getLogger(DefaultHandleService.class);

	/**
	 * Delete the Handle name authority.
	 * 
	 * @see edu.ur.ir.handle.HandleService#delete(edu.ur.ir.handle.HandleNameAuthority)
	 */
	public void delete(HandleNameAuthority handleNameAuthority) {
		handleNameAuthorityDAO.makeTransient(handleNameAuthority);
	}

	/**
	 * Delete the handle info object
	 * 
	 * @see edu.ur.ir.handle.HandleService#delete(edu.ur.ir.handle.HandleInfo)
	 */
	public void delete(HandleInfo handleInfo) {
		handleInfoDAO.makeTransient(handleInfo);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getHandleInfo(java.lang.Long, boolean)
	 */
	public HandleInfo getHandleInfo(Long id, boolean lock) {
		return handleInfoDAO.getById(id, lock);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getHandleInfo(java.lang.String)
	 */
	public HandleInfo getHandleInfo(String fullHandle) {
		HandleInfo info = null;
		if( fullHandle != null )
		{
		    String[] parts = fullHandle.split("/");
		    if( parts.length == 2)
		    {
		    	String prefix = parts[0];
		    	String localName = parts[1];
		    	log.debug("prefix = " + prefix + " localName = " + localName);
		    	info =handleInfoDAO.get(prefix, localName);
		    }
		}
		return info;
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getNameAuthority(java.lang.String)
	 */
	public HandleNameAuthority getNameAuthority(String nameAuthority) {
		return handleNameAuthorityDAO.findByUniqueName(nameAuthority);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#getNameAuthority(java.lang.Long, boolean)
	 */
	public HandleNameAuthority getNameAuthority(Long id, boolean lock) {
		return handleNameAuthorityDAO.getById(id, lock);
	}

	/**
	 * @see edu.ur.ir.handle.HandleService#save(edu.ur.ir.handle.HandleNameAuthority)
{'fraction_non_alphanumeric': 0.10489873636835728, 'fraction_numerical': 0.003981305175696728, 'mean_word_length': 3.9469178082191783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3956041', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1750, 'n_words': 439}