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