001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.NoSuchPasswordPolicyRelException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.model.PasswordPolicyRel;
021    import com.liferay.portal.service.base.PasswordPolicyRelLocalServiceBaseImpl;
022    import com.liferay.portal.util.PortalUtil;
023    
024    /**
025     * @author Scott Lee
026     */
027    public class PasswordPolicyRelLocalServiceImpl
028            extends PasswordPolicyRelLocalServiceBaseImpl {
029    
030            public PasswordPolicyRel addPasswordPolicyRel(
031                            long passwordPolicyId, String className, long classPK)
032                    throws SystemException {
033    
034                    long classNameId = PortalUtil.getClassNameId(className);
035    
036                    PasswordPolicyRel passwordPolicyRel =
037                            passwordPolicyRelPersistence.fetchByP_C_C(
038                                    passwordPolicyId, classNameId, classPK);
039    
040                    if (passwordPolicyRel != null) {
041                            return null;
042                    }
043    
044                    try {
045    
046                            // Ensure that models only have one password policy
047    
048                            passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
049                    }
050                    catch (NoSuchPasswordPolicyRelException nsppre) {
051                    }
052    
053                    long passwordPolicyRelId = counterLocalService.increment();
054    
055                    passwordPolicyRel = passwordPolicyRelPersistence.create(
056                            passwordPolicyRelId);
057    
058                    passwordPolicyRel.setPasswordPolicyId(passwordPolicyId);
059                    passwordPolicyRel.setClassNameId(classNameId);
060                    passwordPolicyRel.setClassPK(classPK);
061    
062                    passwordPolicyRelPersistence.update(passwordPolicyRel, false);
063    
064                    return passwordPolicyRel;
065            }
066    
067            public void addPasswordPolicyRels(
068                            long passwordPolicyId, String className, long[] classPKs)
069                    throws SystemException {
070    
071                    for (int i = 0; i < classPKs.length; i++) {
072                            addPasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
073                    }
074            }
075    
076            public void deletePasswordPolicyRel(String className, long classPK)
077                    throws SystemException {
078    
079                    try {
080                            long classNameId = PortalUtil.getClassNameId(className);
081    
082                            passwordPolicyRelPersistence.removeByC_C(classNameId, classPK);
083                    }
084                    catch (NoSuchPasswordPolicyRelException nsppre) {
085                    }
086            }
087    
088            public void deletePasswordPolicyRel(
089                            long passwordPolicyId, String className, long classPK)
090                    throws SystemException {
091    
092                    try {
093                            long classNameId = PortalUtil.getClassNameId(className);
094    
095                            passwordPolicyRelPersistence.removeByP_C_C(
096                                    passwordPolicyId, classNameId, classPK);
097                    }
098                    catch (NoSuchPasswordPolicyRelException nsppre) {
099                    }
100            }
101    
102            public void deletePasswordPolicyRels(long passwordPolicyId)
103                    throws SystemException {
104    
105                    passwordPolicyRelPersistence.removeByPasswordPolicyId(passwordPolicyId);
106            }
107    
108            public void deletePasswordPolicyRels(
109                            long passwordPolicyId, String className, long[] classPKs)
110                    throws SystemException {
111    
112                    for (int i = 0; i < classPKs.length; i++) {
113                            deletePasswordPolicyRel(passwordPolicyId, className, classPKs[i]);
114                    }
115            }
116    
117            public PasswordPolicyRel getPasswordPolicyRel(
118                            String className, long classPK)
119                    throws PortalException, SystemException {
120    
121                    long classNameId = PortalUtil.getClassNameId(className);
122    
123                    return passwordPolicyRelPersistence.findByC_C(classNameId, classPK);
124            }
125    
126            public PasswordPolicyRel getPasswordPolicyRel(
127                            long passwordPolicyId, String className, long classPK)
128                    throws PortalException, SystemException {
129    
130                    long classNameId = PortalUtil.getClassNameId(className);
131    
132                    return passwordPolicyRelPersistence.findByP_C_C(
133                            passwordPolicyId, classNameId, classPK);
134            }
135    
136            public boolean hasPasswordPolicyRel(
137                            long passwordPolicyId, String className, long classPK)
138                    throws SystemException {
139    
140                    long classNameId = PortalUtil.getClassNameId(className);
141    
142                    PasswordPolicyRel passwordPolicyRel =
143                            passwordPolicyRelPersistence.fetchByP_C_C(
144                                    passwordPolicyId, classNameId, classPK);
145    
146                    if (passwordPolicyRel != null) {
147                            return true;
148                    }
149                    else {
150                            return false;
151                    }
152            }
153    
154    }