com.portal.service.SimplePortalService.java Source code

Java tutorial

Introduction

Here is the source code for com.portal.service.SimplePortalService.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 com.portal.service;

import java.io.File;
import java.io.IOException;
import java.util.List;
import com.portal.dao.DepartmentDAO;
import com.portal.dao.EmployeeDAO;
import com.portal.dao.PositionDAO;
import com.portal.entity.Department;
import com.portal.entity.Employee;
import com.portal.entity.Position;
import com.portal.exception.PortalException;
import org.apache.commons.io.FileUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * @author Evgen
 */
public class SimplePortalService implements PortalService {

    DepartmentDAO departments;
    PositionDAO positions;
    EmployeeDAO employes;

    public SimplePortalService(DepartmentDAO departments, PositionDAO positions, EmployeeDAO employes) {
        this.departments = departments;
        this.positions = positions;
        this.employes = employes;
    }

    @Override
    public List<Department> getAllDepartments() {
        return departments.loadDepartments();
    }

    @Override
    public void saveDepartment(Department department) {
        departments.saveDepartment(department);
    }

    @Override
    public Department getDepartment(int id) {
        return departments.loadDepartment(id);
    }

    @Override
    public void deleteDepartment(int id) throws Exception {
        departments.deleteDepartment(id);
    }

    @Override
    public List<Position> getAllPositions() {
        return positions.loadPositions();
    }

    @Override
    public void savePosition(Position position) {
        positions.savePosition(position);
    }

    @Override
    public Position getPosition(int id) {
        return positions.loadPosition(id);
    }

    @Override
    public void deletePosition(int id) throws Exception {
        positions.deletePosition(id);
    }

    @Override
    public List<Employee> getAllEmployes() {
        return employes.loadEmployes();
    }

    @Override
    public void saveEmployee(Employee employee) {
        employes.saveEmployee(employee);
    }

    @Override
    public Employee getEmployee(int id) {
        return employes.loadEmployee(id);
    }

    @Override
    public void deleteEmployee(int id) {
        employes.deleteEmployee(id);
    }

    @Override
    public void saveFile(String fileName, MultipartFile file) throws Exception {
        try {
            FileUtils.writeByteArrayToFile(new File(fileName), file.getBytes());
        } catch (IOException ex) {
            throw new PortalException("? ? ? ");
        }
    }

}