001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }