001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.impl;
022:
023: import com.liferay.portal.NoSuchPasswordPolicyRelException;
024: import com.liferay.portal.PortalException;
025: import com.liferay.portal.SystemException;
026: import com.liferay.portal.model.PasswordPolicyRel;
027: import com.liferay.portal.service.base.PasswordPolicyRelLocalServiceBaseImpl;
028: import com.liferay.portal.util.PortalUtil;
029:
030: /**
031: * <a href="PasswordPolicyRelLocalServiceImpl.java.html"><b><i>View Source</i>
032: * </b></a>
033: *
034: * @author Scott Lee
035: *
036: */
037: public class PasswordPolicyRelLocalServiceImpl extends
038: PasswordPolicyRelLocalServiceBaseImpl {
039:
040: public PasswordPolicyRel addPasswordPolicyRel(
041: long passwordPolicyId, String className, long classPK)
042: throws PortalException, SystemException {
043:
044: long classNameId = PortalUtil.getClassNameId(className);
045:
046: PasswordPolicyRel passwordPolicyRel = passwordPolicyRelPersistence
047: .fetchByP_C_C(passwordPolicyId, classNameId, classPK);
048:
049: if (passwordPolicyRel != null) {
050: return null;
051: }
052:
053: try {
054:
055: // Ensure that models only have one password policy
056:
057: passwordPolicyRelPersistence.removeByC_C(classNameId,
058: classPK);
059: } catch (NoSuchPasswordPolicyRelException nsppre) {
060: }
061:
062: long passwordPolicyRelId = counterLocalService.increment();
063:
064: passwordPolicyRel = passwordPolicyRelPersistence
065: .create(passwordPolicyRelId);
066:
067: passwordPolicyRel.setPasswordPolicyId(passwordPolicyId);
068: passwordPolicyRel.setClassNameId(classNameId);
069: passwordPolicyRel.setClassPK(classPK);
070:
071: passwordPolicyRelPersistence.update(passwordPolicyRel);
072:
073: return passwordPolicyRel;
074: }
075:
076: public void addPasswordPolicyRels(long passwordPolicyId,
077: String className, long[] classPKs) throws PortalException,
078: SystemException {
079:
080: for (int i = 0; i < classPKs.length; i++) {
081: addPasswordPolicyRel(passwordPolicyId, className,
082: classPKs[i]);
083: }
084: }
085:
086: public void deletePasswordPolicyRel(String className, long classPK)
087: throws PortalException, SystemException {
088:
089: try {
090: long classNameId = PortalUtil.getClassNameId(className);
091:
092: passwordPolicyRelPersistence.removeByC_C(classNameId,
093: classPK);
094: } catch (NoSuchPasswordPolicyRelException nsppre) {
095: }
096: }
097:
098: public void deletePasswordPolicyRel(long passwordPolicyId,
099: String className, long classPK) throws PortalException,
100: SystemException {
101:
102: try {
103: long classNameId = PortalUtil.getClassNameId(className);
104:
105: passwordPolicyRelPersistence.removeByP_C_C(
106: passwordPolicyId, classNameId, classPK);
107: } catch (NoSuchPasswordPolicyRelException nsppre) {
108: }
109: }
110:
111: public void deletePasswordPolicyRels(long passwordPolicyId,
112: String className, long[] classPKs) throws PortalException,
113: SystemException {
114:
115: for (int i = 0; i < classPKs.length; i++) {
116: deletePasswordPolicyRel(passwordPolicyId, className,
117: classPKs[i]);
118: }
119: }
120:
121: public PasswordPolicyRel getPasswordPolicyRel(String className,
122: long classPK) throws PortalException, SystemException {
123:
124: long classNameId = PortalUtil.getClassNameId(className);
125:
126: return passwordPolicyRelPersistence.findByC_C(classNameId,
127: classPK);
128: }
129:
130: public PasswordPolicyRel getPasswordPolicyRel(
131: long passwordPolicyId, String className, long classPK)
132: throws PortalException, SystemException {
133:
134: long classNameId = PortalUtil.getClassNameId(className);
135:
136: return passwordPolicyRelPersistence.findByP_C_C(
137: passwordPolicyId, classNameId, classPK);
138: }
139:
140: public boolean hasPasswordPolicyRel(long passwordPolicyId,
141: String className, long classPK) throws PortalException,
142: SystemException {
143:
144: long classNameId = PortalUtil.getClassNameId(className);
145:
146: PasswordPolicyRel passwordPolicyRel = passwordPolicyRelPersistence
147: .fetchByP_C_C(passwordPolicyId, classNameId, classPK);
148:
149: if (passwordPolicyRel != null) {
150: return true;
151: } else {
152: return false;
153: }
154: }
155:
156: }
|