View Javadoc
1   package net.sumaris.core.service.administration.programStrategy;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
6    * %%
7    * Copyright (C) 2018 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  
26  import com.google.common.base.Preconditions;
27  import net.sumaris.core.dao.administration.programStrategy.ProgramDao;
28  import net.sumaris.core.dao.technical.SortDirection;
29  import net.sumaris.core.vo.administration.programStrategy.ProgramVO;
30  import net.sumaris.core.vo.administration.programStrategy.StrategyVO;
31  import net.sumaris.core.vo.filter.ProgramFilterVO;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.stereotype.Service;
36  
37  import java.util.List;
38  
39  @Service("programService")
40  public class ProgramServiceImpl implements ProgramService {
41  
42  	private static final Logger log = LoggerFactory.getLogger(ProgramServiceImpl.class);
43  
44  	@Autowired
45  	protected ProgramDao  programDao;
46  
47  	@Autowired
48  	protected StrategyService strategyService;
49  
50  	@Override
51  	public List<ProgramVO> getAll() {
52  		return programDao.getAll();
53  	}
54  
55  	@Override
56  	public List<ProgramVO> findByFilter(ProgramFilterVO filter, int offset, int size, String sortAttribute, SortDirection sortDirection) {
57  		return programDao.findByFilter(filter, offset, size, sortAttribute, sortDirection);
58  	}
59  
60  	@Override
61  	public ProgramVO get(int id) {
62  		return programDao.get(id);
63  	}
64  
65  	@Override
66  	public ProgramVO getByLabel(String label) {
67  		Preconditions.checkNotNull(label);
68  		return programDao.getByLabel(label);
69  	}
70  
71  	@Override
72  	public ProgramVO="../../../../../../net/sumaris/core/vo/administration/programStrategy/ProgramVO.html#ProgramVO">ProgramVO save(ProgramVO source) {
73  		Preconditions.checkNotNull(source);
74  		ProgramVO savedProgram = programDao.save(source);
75  
76  		// Save strategies
77  		if (savedProgram.getStrategies() != null) {
78  			List<StrategyVO> savedStrategies = strategyService.saveByProgramId(savedProgram.getId(), source.getStrategies());
79  			savedProgram.setStrategies(savedStrategies);
80  		}
81  
82  		return savedProgram;
83  	}
84  
85  	@Override
86  	public void delete(int id) {
87  		programDao.delete(id);
88  	}
89  }
90