co.com.soinsoftware.altablero.controller.YearController.java Source code

Java tutorial

Introduction

Here is the source code for co.com.soinsoftware.altablero.controller.YearController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.soinsoftware.altablero.controller;

import co.com.soinsoftware.altablero.bll.YearBLL;
import co.com.soinsoftware.altablero.entity.YearBO;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Carlos Rodriguez
 * @since 03/02/2016
 * @version 1.0
 */
@Service
public class YearController {

    @Autowired
    private YearBLL yearBLL;

    public YearBO findCurrentYear() throws IOException {
        return yearBLL.findCurrentYear();
    }

    public String getCurrentYearString() {
        Calendar date = Calendar.getInstance();
        return String.valueOf(date.get(Calendar.YEAR));
    }

    public String getLastYearString() {
        Calendar date = Calendar.getInstance();
        return String.valueOf(date.get(Calendar.YEAR) - 1);
    }

    public List<YearBO> findAll() throws IOException {
        final Set<YearBO> yearSet = yearBLL.findAll();
        final List<YearBO> yearList = (yearSet != null) ? new ArrayList<>(yearSet) : new ArrayList<>();
        Collections.sort(yearList);
        return yearList;
    }
}