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(long passwordPolicyId)
114         throws SystemException {
115 
116         passwordPolicyRelPersistence.removeByPasswordPolicyId(passwordPolicyId);
117     }
118 
119     public void deletePasswordPolicyRels(
120             long passwordPolicyId, String className, long[] classPKs)
121         throws SystemException {
122 
123         for (int i = 0; i < classPKs.length; i++) {
124             deletePasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
125         }
126     }
127 
128     public PasswordPolicyRel getPasswordPolicyRel(
129             String className, long classPK)
130         throws PortalException, SystemException {
131 
132         long classNameId = PortalUtil.getClassNameId(className);
133 
134         return passwordPolicyRelPersistence.findByC_C(classNameId, classPK);
135     }
136 
137     public PasswordPolicyRel getPasswordPolicyRel(
138             long passwordPolicyId, String className, long classPK)
139         throws PortalException, SystemException {
140 
141         long classNameId = PortalUtil.getClassNameId(className);
142 
143         return passwordPolicyRelPersistence.findByP_C_C(
144             passwordPolicyId, classNameId, classPK);
145     }
146 
147     public boolean hasPasswordPolicyRel(
148             long passwordPolicyId, String className, long classPK)
149         throws SystemException {
150 
151         long classNameId = PortalUtil.getClassNameId(className);
152 
153         PasswordPolicyRel passwordPolicyRel =
154             passwordPolicyRelPersistence.fetchByP_C_C(
155                 passwordPolicyId, classNameId, classPK);
156 
157         if (passwordPolicyRel != null) {
158             return true;
159         }
160         else {
161             return false;
162         }
163     }
164 
165 }