001    /**
002     * Copyright (c) 2000-2013 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            @Override
034            public void deleteWebDAVProps(String className, long classPK)
035                    throws SystemException {
036    
037                    long classNameId = PortalUtil.getClassNameId(className);
038    
039                    try {
040                            webDAVPropsPersistence.removeByC_C(classNameId, classPK);
041                    }
042                    catch (NoSuchWebDAVPropsException nswdavpe) {
043                    }
044            }
045    
046            @Override
047            public WebDAVProps getWebDAVProps(
048                            long companyId, String className, long classPK)
049                    throws SystemException {
050    
051                    long classNameId = PortalUtil.getClassNameId(className);
052    
053                    WebDAVProps webDavProps = webDAVPropsPersistence.fetchByC_C(
054                            classNameId, classPK);
055    
056                    if (webDavProps == null) {
057                            webDavProps = webDAVPropsPersistence.create(
058                                    counterLocalService.increment());
059    
060                            Date now = new Date();
061    
062                            webDavProps.setCompanyId(companyId);
063                            webDavProps.setCreateDate(now);
064                            webDavProps.setModifiedDate(now);
065                            webDavProps.setClassNameId(classNameId);
066                            webDavProps.setClassPK(classPK);
067    
068                            webDAVPropsLocalService.updateWebDAVProps(webDavProps);
069                    }
070    
071                    return webDavProps;
072            }
073    
074            @Override
075            public void storeWebDAVProps(WebDAVProps webDavProps)
076                    throws PortalException, SystemException {
077    
078                    try {
079                            webDavProps.store();
080                    }
081                    catch (Exception e) {
082                            throw new WebDAVException("Problem trying to store WebDAVProps", e);
083                    }
084    
085                    webDAVPropsPersistence.update(webDavProps);
086            }
087    
088    }