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.NoSuchWebDAVPropsException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.webdav.WebDAVException;
021    import com.liferay.portal.model.WebDAVProps;
022    import com.liferay.portal.service.base.WebDAVPropsLocalServiceBaseImpl;
023    import com.liferay.portal.util.PortalUtil;
024    
025    import java.util.Date;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class WebDAVPropsLocalServiceImpl
031            extends WebDAVPropsLocalServiceBaseImpl {
032    
033            public void deleteWebDAVProps(String className, long classPK)
034                    throws SystemException {
035    
036                    long classNameId = PortalUtil.getClassNameId(className);
037    
038                    try {
039                            webDAVPropsPersistence.removeByC_C(classNameId, classPK);
040                    }
041                    catch (NoSuchWebDAVPropsException nswdavpe) {
042                    }
043            }
044    
045            public WebDAVProps getWebDAVProps(
046                            long companyId, String className, long classPK)
047                    throws SystemException {
048    
049                    long classNameId = PortalUtil.getClassNameId(className);
050    
051                    WebDAVProps webDavProps = webDAVPropsPersistence.fetchByC_C(
052                            classNameId, classPK);
053    
054                    if (webDavProps == null) {
055                            webDavProps = webDAVPropsPersistence.create(
056                                    counterLocalService.increment());
057    
058                            Date now = new Date();
059    
060                            webDavProps.setCompanyId(companyId);
061                            webDavProps.setCreateDate(now);
062                            webDavProps.setModifiedDate(now);
063                            webDavProps.setClassNameId(classNameId);
064                            webDavProps.setClassPK(classPK);
065    
066                            webDAVPropsPersistence.update(webDavProps, false);
067                    }
068    
069                    return webDavProps;
070            }
071    
072            public void storeWebDAVProps(WebDAVProps webDavProps)
073                    throws PortalException, SystemException {
074    
075                    try {
076                            webDavProps.store();
077                    }
078                    catch (Exception e) {
079                            throw new WebDAVException("Problem trying to store WebDAVProps", e);
080                    }
081    
082                    webDAVPropsPersistence.update(webDavProps, true);
083            }
084    
085    }