1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.NoSuchPasswordPolicyRelException;
18  import com.liferay.portal.PortalException;
19  import com.liferay.portal.SystemException;
20  import com.liferay.portal.model.PasswordPolicyRel;
21  import com.liferay.portal.service.base.PasswordPolicyRelLocalServiceBaseImpl;
22  import com.liferay.portal.util.PortalUtil;
23  
24  /**
25   * <a href="PasswordPolicyRelLocalServiceImpl.java.html"><b><i>View Source</i>
26   * </b></a>
27   *
28   * @author Scott Lee
29   */
30  public class PasswordPolicyRelLocalServiceImpl
31      extends PasswordPolicyRelLocalServiceBaseImpl {
32  
33      public PasswordPolicyRel addPasswordPolicyRel(
34              long passwordPolicyId, String className, long classPK)
35          throws SystemException {
36  
37          long classNameId = PortalUtil.getClassNameId(className);
38  
39          PasswordPolicyRel passwordPolicyRel =
40              passwordPolicyRelPersistence.fetchByP_C_C(
41                  passwordPolicyId, classNameId, classPK);
42  
43          if (passwordPolicyRel != null) {
44              return null;
45          }
46  
47          try {
48  
49              // Ensure that models only have one password policy
50  
51              passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
52          }
53          catch (NoSuchPasswordPolicyRelException nsppre) {
54          }
55  
56          long passwordPolicyRelId = counterLocalService.increment();
57  
58          passwordPolicyRel = passwordPolicyRelPersistence.create(
59              passwordPolicyRelId);
60  
61          passwordPolicyRel.setPasswordPolicyId(passwordPolicyId);
62          passwordPolicyRel.setClassNameId(classNameId);
63          passwordPolicyRel.setClassPK(classPK);
64  
65          passwordPolicyRelPersistence.update(passwordPolicyRel, false);
66  
67          return passwordPolicyRel;
68      }
69  
70      public void addPasswordPolicyRels(
71              long passwordPolicyId, String className, long[] classPKs)
72          throws SystemException {
73  
74          for (int i = 0; i < classPKs.length; i++) {
75              addPasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
76          }
77      }
78  
79      public void deletePasswordPolicyRel(String className, long classPK)
80          throws SystemException {
81  
82          try {
83              long classNameId = PortalUtil.getClassNameId(className);
84  
85              passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
86          }
87          catch (NoSuchPasswordPolicyRelException nsppre) {
88          }
89      }
90  
91      public void deletePasswordPolicyRel(
92              long passwordPolicyId, String className, long classPK)
93          throws SystemException {
94  
95          try {
96              long classNameId = PortalUtil.getClassNameId(className);
97  
98              passwordPolicyRelPersistence.removeByP_C_C(
99                  passwordPolicyId, classNameId, classPK);
100         }
101         catch (NoSuchPasswordPolicyRelException nsppre) {
102         }
103     }
104 
105     public void deletePasswordPolicyRels(long passwordPolicyId)
106         throws SystemException {
107 
108         passwordPolicyRelPersistence.removeByPasswordPolicyId(passwordPolicyId);
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 }