View Javadoc
1   package fr.ifremer.quadrige2.core.dao.administration.program;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 Server 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.quadrige2.core.dao.referential.monitoringLocation.MonitoringLocationImpl;
26  import fr.ifremer.quadrige2.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  		// Program
69  		if (source.getProgram() != null) {
70  			target.setProgCd(source.getProgram().getProgCd());
71  		}
72  	}
73  
74  	/**
75  	 * Retrieves the entity object that is associated with the specified value object
76  	 * from the object store. If no such entity object exists in the object store,
77  	 * a new, blank entity is created
78  	 */
79  	private MonLocProg loadMonLocProgFromMonLocProgVO(MonLocProgVO monLocProgVO)
80  	{
81  		MonLocProg monLocProg = this.get(monLocProgVO.getMonLocProgId());
82  		if (monLocProg == null)
83  		{
84  			monLocProg = MonLocProg.Factory.newInstance();
85  		}
86  		return monLocProg;
87  	}
88  
89  	/** {@inheritDoc} */
90  	public MonLocProg monLocProgVOToEntity(MonLocProgVO monLocProgVO)
91  	{
92  		MonLocProg entity = this.loadMonLocProgFromMonLocProgVO(monLocProgVO);
93  		this.monLocProgVOToEntity(monLocProgVO, entity, true);
94  		return entity;
95  	}
96  
97  	/** {@inheritDoc} */
98  	@Override
99  	public void monLocProgVOToEntity(
100 			MonLocProgVO source,
101 			MonLocProg target,
102 			boolean copyIfNull)
103 	{
104 		super.monLocProgVOToEntity(source, target, copyIfNull);
105 
106 		// Monitoring location
107 		if (copyIfNull || source.getMonLocId() != null) {
108 			if (source.getMonLocId() == null) {
109 				target.setMonitoringLocation(null);
110 			}
111 			else {
112 				target.setMonitoringLocation(load(MonitoringLocationImpl.class, source.getMonLocId()));
113 			}
114 		}
115 
116 		// Program
117 		if (copyIfNull || source.getProgCd() != null) {
118 			if (source.getProgCd() == null) {
119 				target.setProgram(null);
120 			}
121 			else {
122 				target.setProgram(load(ProgramImpl.class, source.getProgCd()));
123 			}
124 		}
125 	}
126 }