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.administration.user.DepartmentImpl;
26  import fr.ifremer.quadrige2.core.vo.administration.program.ProgDepProgPrivVO;
27  import org.apache.commons.lang3.StringUtils;
28  import org.hibernate.SessionFactory;
29  import org.springframework.beans.factory.annotation.Autowired;
30  import org.springframework.context.annotation.Lazy;
31  import org.springframework.stereotype.Repository;
32  
33  /**
34   * <p>
35   * ProgDepProgPrivDaoImpl class.
36   * </p>
37   * 
38   * @see ProgDepProgPriv
39   */
40  @Repository("progDepProgPrivDao")
41  @Lazy
42  public class ProgDepProgPrivDaoImpl
43  		extends ProgDepProgPrivDaoBase
44  {
45  	/**
46  	 * Constructor used by Spring
47  	 * 
48  	 * @param sessionFactory
49  	 *            a {@link org.hibernate.SessionFactory} object.
50  	 */
51  	@Autowired
52  	public ProgDepProgPrivDaoImpl(SessionFactory sessionFactory) {
53  		super();
54  		setSessionFactory(sessionFactory);
55  	}
56  
57  	/** {@inheritDoc} */
58  	@Override
59  	public void toProgDepProgPrivVO(
60  			ProgDepProgPriv source,
61  			ProgDepProgPrivVO target)
62  	{
63  		super.toProgDepProgPrivVO(source, target);
64  
65  		// load Pk data
66  		ProgDepProgPrivPK pk = source.getProgDepProgPrivPk();
67  		if (pk != null) {
68  			target.setDepId(pk.getDepartment().getDepId());
69  			target.setProgPrivId(pk.getProgramPrivilege().getProgPrivId());
70  			target.setProgCd(pk.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 ProgDepProgPriv loadProgDepProgPrivFromProgDepProgPrivVO(ProgDepProgPrivVO source)
80  	{
81  		ProgDepProgPrivPK pk = new ProgDepProgPrivPK();
82  
83  		String progCd = source.getProgCd();
84  		if (StringUtils.isBlank(progCd) && source.getProgramVO() != null) {
85  			progCd = source.getProgramVO().getProgCd();
86  		}
87  		pk.setProgram(load(ProgramImpl.class, progCd));
88  		pk.setDepartment(load(DepartmentImpl.class, source.getDepId()));
89  		pk.setProgramPrivilege(load(ProgramPrivilegeImpl.class, source.getProgPrivId()));
90  
91  		ProgDepProgPriv target = this.get(pk);
92  		if (target == null)
93  		{
94  			target = ProgDepProgPriv.Factory.newInstance();
95  			target.setProgDepProgPrivPk(pk);
96  		}
97  		return target;
98  	}
99  
100 	/** {@inheritDoc} */
101 	public ProgDepProgPriv progDepProgPrivVOToEntity(ProgDepProgPrivVO progDepProgPrivVO)
102 	{
103 		ProgDepProgPriv entity = this.loadProgDepProgPrivFromProgDepProgPrivVO(progDepProgPrivVO);
104 		this.progDepProgPrivVOToEntity(progDepProgPrivVO, entity, true);
105 		return entity;
106 	}
107 }