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