1   /**
2    * Copyright (c) 2000-2009 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.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   */
39  public class PasswordPolicyRelLocalServiceImpl
40      extends PasswordPolicyRelLocalServiceBaseImpl {
41  
42      public PasswordPolicyRel addPasswordPolicyRel(
43              long passwordPolicyId, String className, long classPK)
44          throws SystemException {
45  
46          long classNameId = PortalUtil.getClassNameId(className);
47  
48          PasswordPolicyRel passwordPolicyRel =
49              passwordPolicyRelPersistence.fetchByP_C_C(
50                  passwordPolicyId, classNameId, classPK);
51  
52          if (passwordPolicyRel != null) {
53              return null;
54          }
55  
56          try {
57  
58              // Ensure that models only have one password policy
59  
60              passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
61          }
62          catch (NoSuchPasswordPolicyRelException nsppre) {
63          }
64  
65          long passwordPolicyRelId = counterLocalService.increment();
66  
67          passwordPolicyRel = passwordPolicyRelPersistence.create(
68              passwordPolicyRelId);
69  
70          passwordPolicyRel.setPasswordPolicyId(passwordPolicyId);
71          passwordPolicyRel.setClassNameId(classNameId);
72          passwordPolicyRel.setClassPK(classPK);
73  
74          passwordPolicyRelPersistence.update(passwordPolicyRel, false);
75  
76          return passwordPolicyRel;
77      }
78  
79      public void addPasswordPolicyRels(
80              long passwordPolicyId, String className, long[] classPKs)
81          throws SystemException {
82  
83          for (int i = 0; i < classPKs.length; i++) {
84              addPasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
85          }
86      }
87  
88      public void deletePasswordPolicyRel(String className, long classPK)
89          throws SystemException {
90  
91          try {
92              long classNameId = PortalUtil.getClassNameId(className);
93  
94              passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
95          }
96          catch (NoSuchPasswordPolicyRelException nsppre) {
97          }
98      }
99  
100     public void deletePasswordPolicyRel(
101             long passwordPolicyId, String className, long classPK)
102         throws SystemException {
103 
104         try {
105             long classNameId = PortalUtil.getClassNameId(className);
106 
107             passwordPolicyRelPersistence.removeByP_C_C(
108                 passwordPolicyId, classNameId, classPK);
109         }
110         catch (NoSuchPasswordPolicyRelException nsppre) {
111         }
112     }
113 
114     public void deletePasswordPolicyRels(
115             long passwordPolicyId, String className, long[] classPKs)
116         throws SystemException {
117 
118         for (int i = 0; i < classPKs.length; i++) {
119             deletePasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
120         }
121     }
122 
123     public PasswordPolicyRel getPasswordPolicyRel(
124             String className, long classPK)
125         throws PortalException, SystemException {
126 
127         long classNameId = PortalUtil.getClassNameId(className);
128 
129         return passwordPolicyRelPersistence.findByC_C(classNameId, classPK);
130     }
131 
132     public PasswordPolicyRel getPasswordPolicyRel(
133             long passwordPolicyId, String className, long classPK)
134         throws PortalException, SystemException {
135 
136         long classNameId = PortalUtil.getClassNameId(className);
137 
138         return passwordPolicyRelPersistence.findByP_C_C(
139             passwordPolicyId, classNameId, classPK);
140     }
141 
142     public boolean hasPasswordPolicyRel(
143             long passwordPolicyId, String className, long classPK)
144         throws SystemException {
145 
146         long classNameId = PortalUtil.getClassNameId(className);
147 
148         PasswordPolicyRel passwordPolicyRel =
149             passwordPolicyRelPersistence.fetchByP_C_C(
150                 passwordPolicyId, classNameId, classPK);
151 
152         if (passwordPolicyRel != null) {
153             return true;
154         }
155         else {
156             return false;
157         }
158     }
159 
160 }