1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portal.NoSuchPasswordPolicyRelException;
26  import com.liferay.portal.PortalException;
27  import com.liferay.portal.SystemException;
28  import com.liferay.portal.model.PasswordPolicyRel;
29  import com.liferay.portal.service.base.PasswordPolicyRelLocalServiceBaseImpl;
30  import com.liferay.portal.util.PortalUtil;
31  
32  /**
33   * <a href="PasswordPolicyRelLocalServiceImpl.java.html"><b><i>View Source</i>
34   * </b></a>
35   *
36   * @author Scott Lee
37   */
38  public class PasswordPolicyRelLocalServiceImpl
39      extends PasswordPolicyRelLocalServiceBaseImpl {
40  
41      public PasswordPolicyRel addPasswordPolicyRel(
42              long passwordPolicyId, String className, long classPK)
43          throws SystemException {
44  
45          long classNameId = PortalUtil.getClassNameId(className);
46  
47          PasswordPolicyRel passwordPolicyRel =
48              passwordPolicyRelPersistence.fetchByP_C_C(
49                  passwordPolicyId, classNameId, classPK);
50  
51          if (passwordPolicyRel != null) {
52              return null;
53          }
54  
55          try {
56  
57              // Ensure that models only have one password policy
58  
59              passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
60          }
61          catch (NoSuchPasswordPolicyRelException nsppre) {
62          }
63  
64          long passwordPolicyRelId = counterLocalService.increment();
65  
66          passwordPolicyRel = passwordPolicyRelPersistence.create(
67              passwordPolicyRelId);
68  
69          passwordPolicyRel.setPasswordPolicyId(passwordPolicyId);
70          passwordPolicyRel.setClassNameId(classNameId);
71          passwordPolicyRel.setClassPK(classPK);
72  
73          passwordPolicyRelPersistence.update(passwordPolicyRel, false);
74  
75          return passwordPolicyRel;
76      }
77  
78      public void addPasswordPolicyRels(
79              long passwordPolicyId, String className, long[] classPKs)
80          throws SystemException {
81  
82          for (int i = 0; i < classPKs.length; i++) {
83              addPasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
84          }
85      }
86  
87      public void deletePasswordPolicyRel(String className, long classPK)
88          throws SystemException {
89  
90          try {
91              long classNameId = PortalUtil.getClassNameId(className);
92  
93              passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
94          }
95          catch (NoSuchPasswordPolicyRelException nsppre) {
96          }
97      }
98  
99      public void deletePasswordPolicyRel(
100             long passwordPolicyId, String className, long classPK)
101         throws SystemException {
102 
103         try {
104             long classNameId = PortalUtil.getClassNameId(className);
105 
106             passwordPolicyRelPersistence.removeByP_C_C(
107                 passwordPolicyId, classNameId, classPK);
108         }
109         catch (NoSuchPasswordPolicyRelException nsppre) {
110         }
111     }
112 
113     public void deletePasswordPolicyRels(
114             long passwordPolicyId, String className, long[] classPKs)
115         throws SystemException {
116 
117         for (int i = 0; i < classPKs.length; i++) {
118             deletePasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
119         }
120     }
121 
122     public PasswordPolicyRel getPasswordPolicyRel(
123             String className, long classPK)
124         throws PortalException, SystemException {
125 
126         long classNameId = PortalUtil.getClassNameId(className);
127 
128         return passwordPolicyRelPersistence.findByC_C(classNameId, classPK);
129     }
130 
131     public PasswordPolicyRel getPasswordPolicyRel(
132             long passwordPolicyId, String className, long classPK)
133         throws PortalException, SystemException {
134 
135         long classNameId = PortalUtil.getClassNameId(className);
136 
137         return passwordPolicyRelPersistence.findByP_C_C(
138             passwordPolicyId, classNameId, classPK);
139     }
140 
141     public boolean hasPasswordPolicyRel(
142             long passwordPolicyId, String className, long classPK)
143         throws SystemException {
144 
145         long classNameId = PortalUtil.getClassNameId(className);
146 
147         PasswordPolicyRel passwordPolicyRel =
148             passwordPolicyRelPersistence.fetchByP_C_C(
149                 passwordPolicyId, classNameId, classPK);
150 
151         if (passwordPolicyRel != null) {
152             return true;
153         }
154         else {
155             return false;
156         }
157     }
158 
159 }