<commit_before>package com.syzton.sunread.service.bookshelf;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.syzton.sunread.dto.bookshelf.BookInShelfDTO;
import com.syzton.sunread.exception.bookshelf.BookInShelfDuplicateVerifiedException;
import com.syzton.sunread.exception.common.DuplicateException;
import com.syzton.sunread.exception.common.NotFoundException;
import com.syzton.sunread.model.book.Book;
import com.syzton.sunread.model.bookshelf.BookInShelf;
import com.syzton.sunread.model.bookshelf.Bookshelf;
import com.syzton.sunread.repository.SemesterRepository;
import com.syzton.sunread.repository.book.BookRepository;
import com.syzton.sunread.repository.bookshelf.BookInShelfRepository;
import com.syzton.sunread.repository.bookshelf.BookshelfRepository;
import com.syzton.sunread.service.book.BookRepositoryService;

/*
 * @Date 2015/3/12
 * @author Morgan-Leon
 */
@Service
public class BookInShelfRepositoryService implements BookInShelfService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BookRepositoryService.class);
    @Autowired
    private BookInShelfRepository repository;
    private BookshelfRepository bookshelfRepository;
    private BookRepository bookRepository;
    private Book book;
	private Bookshelf bookshelf;

    
    @Autowired
    public BookInShelfRepositoryService(BookInShelfRepository repository,SemesterRepository semesterRepository
    		,BookshelfRepository bookshelfRepository,BookRepository bookRepository) {
        this.repository = repository;
        this.bookRepository = bookRepository;
        this.bookshelfRepository = bookshelfRepository;
    }
    
    @Transactional(rollbackFor = {NotFoundException.class})
	@Override
	public BookInShelf add(BookInShelfDTO added, Long id, Long bookId) {
		// TODO Auto-generated method stub
        LOGGER.debug("Adding a new Book entry with information: {}", added);
       
        book = bookRepository.findOne(bookId);
        bookshelf = bookshelfRepository.findOne(id);
        if (book == null) {
			throw new NotFoundException("no book found with isbn :"+ book.getIsbn());
		}
        if (bookshelf == null) {
			throw new NotFoundException("no bookshelf found with id :"+bookshelf.getId());
		}
        
        //If the Book has been added in student`s bookshelf
//		ArrayList<BookInShelf> bookArray = repository.findByBookShelf(bookshelf);
//		for (BookInShelf bookInShelf : bookArray) {
//			if(bookInShelf.getBookId() == bookId){<commit_msg>semester<commit_after>package com.syzton.sunread.service.bookshelf;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.syzton.sunread.dto.bookshelf.BookInShelfDTO;
import com.syzton.sunread.exception.bookshelf.BookInShelfDuplicateVerifiedException;
import com.syzton.sunread.exception.common.DuplicateException;
import com.syzton.sunread.exception.common.NotFoundException;
import com.syzton.sunread.model.book.Book;
import com.syzton.sunread.model.bookshelf.BookInShelf;
import com.syzton.sunread.model.bookshelf.Bookshelf;
import com.syzton.sunread.repository.SemesterRepository;
import com.syzton.sunread.repository.book.BookRepository;
import com.syzton.sunread.repository.bookshelf.BookInShelfRepository;
import com.syzton.sunread.repository.bookshelf.BookshelfRepository;
import com.syzton.sunread.service.book.BookRepositoryService;

/*
 * @Date 2015/3/12
 * @author Morgan-Leon
 */
@Service
public class BookInShelfRepositoryService implements BookInShelfService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BookRepositoryService.class);
    @Autowired
    private BookInShelfRepository repository;
    private BookshelfRepository bookshelfRepository;
    private BookRepository bookRepository;
    private Book book;
	private Bookshelf bookshelf;
//	private SemesterRepository semesterRepository;

    
    @Autowired
    public BookInShelfRepositoryService(BookInShelfRepository repository
    		,BookshelfRepository bookshelfRepository,BookRepository bookRepository) {
        this.repository = repository;
        this.bookRepository = bookRepository;
        this.bookshelfRepository = bookshelfRepository;
//        this.semesterRepository=semesterRepository;
    }
    
    @Transactional(rollbackFor = {NotFoundException.class})
	@Override
	public BookInShelf add(BookInShelfDTO added, Long id, Long bookId) {
		// TODO Auto-generated method stub
        LOGGER.debug("Adding a new Book entry with information: {}", added);
       
        book = bookRepository.findOne(bookId);
        bookshelf = bookshelfRepository.findOne(id);
        if (book == null) {
			throw new NotFoundException("no book found with isbn :"+ book.getIsbn());
		}
        if (bookshelf == null) {
			throw new NotFoundException("no bookshelf found with id :"+bookshelf.getId());
		}
        
        //If the Book has been added in student`s bookshelf
//		ArrayList<BookInShelf> bookArray = repository.findByBookShelf(bookshelf);
//		for (BookInShelf bookInShelf : bookArray) {
//			if(bookInShelf.getBookId() == bookId){
{'fraction_non_alphanumeric': 0.0911597449595037, 'fraction_numerical': 0.003101843873858349, 'mean_word_length': 4.839034205231388, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4632674', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1690, 'n_words': 324}