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.administration.user.QuserImpl;
26  import fr.ifremer.quadrige3.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  		ProgQuserProgPrivPK pk = source.getProgQuserProgPrivPk();
65  		if (pk != null) {
66  			target.setQuserId(pk.getQuser().getQuserId());
67  			target.setProgPrivId(pk.getProgramPrivilege().getProgPrivId());
68  			target.setProgCd(pk.getProgram().getProgCd());
69  		}
70  	}
71  
72  	/**
73  	 * Retrieves the entity object that is associated with the specified value object
74  	 * from the object store. If no such entity object exists in the object store,
75  	 * a new, blank entity is created
76  	 */
77  	private ProgQuserProgPriv loadProgQuserProgPrivFromProgQuserProgPrivVO(ProgQuserProgPrivVO source)
78  	{
79  		ProgQuserProgPrivPK pk = new ProgQuserProgPrivPK();
80  
81  		String progCd = source.getProgCd();
82  		if (StringUtils.isBlank(progCd) && source.getProgramVO() != null) {
83  			progCd = source.getProgramVO().getProgCd();
84  		}
85  		pk.setProgram(load(ProgramImpl.class, progCd));
86  
87  		pk.setQuser(load(QuserImpl.class, source.getQuserId()));
88  		pk.setProgramPrivilege(load(ProgramPrivilegeImpl.class, source.getProgPrivId()));
89  
90  		ProgQuserProgPriv progQuserProgPriv = this.get(pk);
91  		if (progQuserProgPriv == null)
92  		{
93  			progQuserProgPriv = ProgQuserProgPriv.Factory.newInstance();
94  			progQuserProgPriv.setProgQuserProgPrivPk(pk);
95  		}
96  		return progQuserProgPriv;
97  	}
98  
99  	/** {@inheritDoc} */
100 	public ProgQuserProgPriv progQuserProgPrivVOToEntity(ProgQuserProgPrivVO progQuserProgPrivVO)
101 	{
102 		ProgQuserProgPriv entity = this.loadProgQuserProgPrivFromProgQuserProgPrivVO(progQuserProgPrivVO);
103 		this.progQuserProgPrivVOToEntity(progQuserProgPrivVO, entity, true);
104 		return entity;
105 	}
106 
107 }