View Javadoc
1   package fr.ifremer.quadrige3.core.dao.administration.program;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Client Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  import fr.ifremer.quadrige3.core.dao.referential.monitoringLocation.MonitoringLocationImpl;
26  import fr.ifremer.quadrige3.core.vo.administration.program.MonLocProgVO;
27  import org.hibernate.SessionFactory;
28  import org.springframework.beans.factory.annotation.Autowired;
29  import org.springframework.context.annotation.Lazy;
30  import org.springframework.stereotype.Repository;
31  
32  /**
33   * <p>
34   * MonLocProgDaoImpl class.
35   * </p>
36   * 
37   * @see MonLocProg
38   */
39  @Repository("monLocProgDao")
40  @Lazy
41  public class MonLocProgDaoImpl
42  		extends MonLocProgDaoBase
43  {
44  	/**
45  	 * Constructor used by Spring
46  	 * 
47  	 * @param sessionFactory
48  	 *            a {@link org.hibernate.SessionFactory} object.
49  	 */
50  	@Autowired
51  	public MonLocProgDaoImpl(SessionFactory sessionFactory) {
52  		super();
53  		setSessionFactory(sessionFactory);
54  	}
55  
56  	/** {@inheritDoc} */
57  	public void toMonLocProgVO(
58  			MonLocProg source,
59  			MonLocProgVO target)
60  	{
61  		super.toMonLocProgVO(source, target);
62  
63  		// Monitoring location
64  		if (source.getMonitoringLocation() != null) {
65  			target.setMonLocId(source.getMonitoringLocation().getMonLocId());
66  		}
67  	}
68  
69  	/**
70  	 * Retrieves the entity object that is associated with the specified value object
71  	 * from the object store. If no such entity object exists in the object store,
72  	 * a new, blank entity is created
73  	 */
74  	private MonLocProg loadMonLocProgFromMonLocProgVO(MonLocProgVO monLocProgVO)
75  	{
76  		MonLocProg monLocProg = this.get(monLocProgVO.getMonLocProgId());
77  		if (monLocProg == null)
78  		{
79  			monLocProg = MonLocProg.Factory.newInstance();
80  		}
81  		return monLocProg;
82  	}
83  
84  	/** {@inheritDoc} */
85  	public MonLocProg monLocProgVOToEntity(MonLocProgVO monLocProgVO)
86  	{
87  		MonLocProg entity = this.loadMonLocProgFromMonLocProgVO(monLocProgVO);
88  		this.monLocProgVOToEntity(monLocProgVO, entity, true);
89  		return entity;
90  	}
91  
92  	/** {@inheritDoc} */
93  	@Override
94  	public void monLocProgVOToEntity(
95  			MonLocProgVO source,
96  			MonLocProg target,
97  			boolean copyIfNull)
98  	{
99  		super.monLocProgVOToEntity(source, target, copyIfNull);
100 
101 		// Monitoring location
102 		if (copyIfNull || source.getMonLocId() != null) {
103 			if (source.getMonLocId() == null) {
104 				target.setMonitoringLocation(null);
105 			}
106 			else {
107 				target.setMonitoringLocation(load(MonitoringLocationImpl.class, source.getMonLocId()));
108 			}
109 		}
110 
111 		// Program
112 		if (copyIfNull || source.getProgCd() != null) {
113 			if (source.getProgCd() == null) {
114 				target.setProgram(null);
115 			}
116 			else {
117 				target.setProgram(load(ProgramImpl.class, source.getProgCd()));
118 			}
119 		}
120 	}
121 }