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.QuserImpl;
26  import fr.ifremer.quadrige2.core.vo.administration.program.ProgQuserProgPrivVO;
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   * ProgQuserProgPrivDaoImpl class.
36   * </p>
37   * 
38   * @see ProgQuserProgPriv
39   */
40  @Repository("progQuserProgPrivDao")
41  @Lazy
42  public class ProgQuserProgPrivDaoImpl
43  		extends ProgQuserProgPrivDaoBase
44  {
45  	/**
46  	 * Constructor used by Spring
47  	 * 
48  	 * @param sessionFactory
49  	 *            a {@link org.hibernate.SessionFactory} object.
50  	 */
51  	@Autowired
52  	public ProgQuserProgPrivDaoImpl(SessionFactory sessionFactory) {
53  		super();
54  		setSessionFactory(sessionFactory);
55  	}
56  
57  	/** {@inheritDoc} */
58  	public void toProgQuserProgPrivVO(
59  			ProgQuserProgPriv source,
60  			ProgQuserProgPrivVO target)
61  	{
62  		super.toProgQuserProgPrivVO(source, target);
63  
64  		// load Pk data
65  		ProgQuserProgPrivPK pk = source.getProgQuserProgPrivPk();
66  		if (pk != null) {
67  			target.setQuserId(pk.getQuser().getQuserId());
68  			target.setProgPrivId(pk.getProgramPrivilege().getProgPrivId());
69  			target.setProgCd(pk.getProgram().getProgCd());
70  		}
71  	}
72  
73  	/**
74  	 * Retrieves the entity object that is associated with the specified value object
75  	 * from the object store. If no such entity object exists in the object store,
76  	 * a new, blank entity is created
77  	 */
78  	private ProgQuserProgPriv loadProgQuserProgPrivFromProgQuserProgPrivVO(ProgQuserProgPrivVO source)
79  	{
80  		ProgQuserProgPrivPK pk = new ProgQuserProgPrivPK();
81  
82  		// Program
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  
89  		pk.setQuser(load(QuserImpl.class, source.getQuserId()));
90  		pk.setProgramPrivilege(load(ProgramPrivilegeImpl.class, source.getProgPrivId()));
91  
92  		ProgQuserProgPriv target = this.get(pk);
93  		if (target == null) {
94  			target = ProgQuserProgPriv.Factory.newInstance();
95  			target.setProgQuserProgPrivPk(pk);
96  		}
97  		return target;
98  	}
99  
100 	/** {@inheritDoc} */
101 	public ProgQuserProgPriv progQuserProgPrivVOToEntity(ProgQuserProgPrivVO progQuserProgPrivVO)
102 	{
103 		ProgQuserProgPriv entity = this.loadProgQuserProgPrivFromProgQuserProgPrivVO(progQuserProgPrivVO);
104 		this.progQuserProgPrivVOToEntity(progQuserProgPrivVO, entity, true);
105 		return entity;
106 	}
107 }