1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.impl;
24  
25  import com.liferay.counter.service.CounterLocalServiceUtil;
26  import com.liferay.portal.NoSuchPasswordPolicyRelException;
27  import com.liferay.portal.PortalException;
28  import com.liferay.portal.SystemException;
29  import com.liferay.portal.model.PasswordPolicyRel;
30  import com.liferay.portal.service.base.PasswordPolicyRelLocalServiceBaseImpl;
31  import com.liferay.portal.service.persistence.PasswordPolicyRelUtil;
32  import com.liferay.portal.util.PortalUtil;
33  
34  /**
35   * <a href="PasswordPolicyRelLocalServiceImpl.java.html"><b><i>View Source</i>
36   * </b></a>
37   *
38   * @author Scott Lee
39   *
40   */
41  public class PasswordPolicyRelLocalServiceImpl
42      extends PasswordPolicyRelLocalServiceBaseImpl {
43  
44      public PasswordPolicyRel addPasswordPolicyRel(
45              long passwordPolicyId, String className, long classPK)
46          throws PortalException, SystemException {
47  
48          long classNameId = PortalUtil.getClassNameId(className);
49  
50          PasswordPolicyRel passwordPolicyRel =
51              PasswordPolicyRelUtil.fetchByP_C_C(
52                  passwordPolicyId, classNameId, classPK);
53  
54          if (passwordPolicyRel != null) {
55              return null;
56          }
57  
58          try {
59  
60              // Ensure that models only have one password policy
61  
62              PasswordPolicyRelUtil.removeByC_C(classNameId, classPK);
63          }
64          catch (NoSuchPasswordPolicyRelException nsppre) {
65          }
66  
67          long passwordPolicyRelId = CounterLocalServiceUtil.increment();
68  
69          passwordPolicyRel = PasswordPolicyRelUtil.create(passwordPolicyRelId);
70  
71          passwordPolicyRel.setPasswordPolicyId(passwordPolicyId);
72          passwordPolicyRel.setClassNameId(classNameId);
73          passwordPolicyRel.setClassPK(classPK);
74  
75          PasswordPolicyRelUtil.update(passwordPolicyRel);
76  
77          return passwordPolicyRel;
78      }
79  
80      public void addPasswordPolicyRels(
81              long passwordPolicyId, String className, long[] classPKs)
82          throws PortalException, SystemException {
83  
84          for (int i = 0; i < classPKs.length; i++) {
85              addPasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
86          }
87      }
88  
89      public void deletePasswordPolicyRel(String className, long classPK)
90          throws PortalException, SystemException {
91  
92          try {
93              long classNameId = PortalUtil.getClassNameId(className);
94  
95              PasswordPolicyRelUtil.removeByC_C(classNameId, classPK);
96          }
97          catch (NoSuchPasswordPolicyRelException nsppre) {
98          }
99      }
100 
101     public void deletePasswordPolicyRel(
102             long passwordPolicyId, String className, long classPK)
103         throws PortalException, SystemException {
104 
105         try {
106             long classNameId = PortalUtil.getClassNameId(className);
107 
108             PasswordPolicyRelUtil.removeByP_C_C(
109                 passwordPolicyId, classNameId, classPK);
110         }
111         catch (NoSuchPasswordPolicyRelException nsppre) {
112         }
113     }
114 
115     public void deletePasswordPolicyRels(
116             long passwordPolicyId, String className, long[] classPKs)
117         throws PortalException, SystemException {
118 
119         for (int i = 0; i < classPKs.length; i++) {
120             deletePasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
121         }
122     }
123 
124     public PasswordPolicyRel getPasswordPolicyRel(
125             String className, long classPK)
126         throws PortalException, SystemException {
127 
128         long classNameId = PortalUtil.getClassNameId(className);
129 
130         return PasswordPolicyRelUtil.findByC_C(classNameId, classPK);
131     }
132 
133     public PasswordPolicyRel getPasswordPolicyRel(
134             long passwordPolicyId, String className, long classPK)
135         throws PortalException, SystemException {
136 
137         long classNameId = PortalUtil.getClassNameId(className);
138 
139         return PasswordPolicyRelUtil.findByP_C_C(
140             passwordPolicyId, classNameId, classPK);
141     }
142 
143     public boolean hasPasswordPolicyRel(
144             long passwordPolicyId, String className, long classPK)
145         throws PortalException, SystemException {
146 
147         long classNameId = PortalUtil.getClassNameId(className);
148 
149         if (PasswordPolicyRelUtil.fetchByP_C_C(
150                 passwordPolicyId, classNameId, classPK) != null) {
151 
152             return true;
153         }
154         else {
155             return false;
156         }
157     }
158 
159 }