package at.ac.tuwien.inso.service.impl;

import at.ac.tuwien.inso.dto.SemesterDto;
import at.ac.tuwien.inso.entity.*;
import at.ac.tuwien.inso.repository.*;
import at.ac.tuwien.inso.service.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;
import org.springframework.transaction.annotation.*;

import java.util.*;

@Service
public class SemesterServiceImpl implements SemesterService {

    @Autowired
    private SemesterRepository semesterRepository;

    @Override
    @Transactional
    public SemesterDto create(SemesterDto semester) {
        return semesterRepository.save(semester.toEntity()).toDto();
    }

    @Override
    @Transactional(readOnly = true)
    public SemesterDto getCurrentSemester() {
        Semester s = semesterRepository.findFirstByOrderByIdDesc();
        if(s!=null){
        	return s.toDto();
        }else{
        	return null;
        }
    }

    @Override
    @Transactional(readOnly = true)
    public List<SemesterDto> findAll() {
        return convertSemesterListToSemesterDtoList(semesterRepository.findAllByOrderByIdDesc());
    }

    @Override
    @Transactional(readOnly = true)
    public List<SemesterDto> findAllSince(SemesterDto semester) {
        return convertSemesterListToSemesterDtoList(semesterRepository.findAllSince(semester.toEntity()));
    }
    
    private List<SemesterDto> convertSemesterListToSemesterDtoList(List<Semester> semesters){
    	List<SemesterDto> toReturn = new ArrayList<SemesterDto>();
        for(Semester s : semesters){
        	toReturn.add(s.toDto());
        }
        return toReturn;
    }
}

@@ -34,16 +34,58 @@
 .impl;%0A%0A
+import com.sun.istack.internal.Nullable;%0A%0A
 import a
@@ -959,32 +959,772 @@
        %7D%0A    %7D%0A%0A
+    @Override%0A    public SemesterDto getOrCreateCurrentSemester() %7B%0A        Calendar now = new GregorianCalendar();%0A        return getOrCreateCurrentSemester(now);%0A    %7D%0A%0A    /**%0A     * If now is still in the current semester, we return the semester%0A     *%0A     * Otherwise all semesters until now are created and the newest one returned.%0A     *%0A     * @param now date to compare with%0A     */%0A    public SemesterDto getOrCreateCurrentSemester(Calendar now) %7B%0A        SemesterDto current = getCurrentSemester();%0A%0A        // Recursion, to create all missing semesters%0A        if (!current.isCurrent(now)) %7B%0A            create(current.nextSemester());%0A            return getOrCreateCurrentSemester();%0A        %7D%0A%0A        return current;%0A    %7D%0A%0A
     @Override%0A  

Implement getOrCreateCurrentSemester