1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.NoSuchWebDAVPropsException;
18  import com.liferay.portal.kernel.exception.PortalException;
19  import com.liferay.portal.kernel.exception.SystemException;
20  import com.liferay.portal.model.WebDAVProps;
21  import com.liferay.portal.service.base.WebDAVPropsLocalServiceBaseImpl;
22  import com.liferay.portal.util.PortalUtil;
23  import com.liferay.portal.webdav.WebDAVException;
24  
25  import java.util.Date;
26  
27  /**
28   * <a href="WebDAVPropsLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Alexander Chow
31   */
32  public class WebDAVPropsLocalServiceImpl
33      extends WebDAVPropsLocalServiceBaseImpl {
34  
35      public void deleteWebDAVProps(String className, long classPK)
36          throws SystemException {
37  
38          long classNameId = PortalUtil.getClassNameId(className);
39  
40          try {
41              webDAVPropsPersistence.removeByC_C(classNameId, classPK);
42          }
43          catch (NoSuchWebDAVPropsException nswdavpe) {
44          }
45      }
46  
47      public WebDAVProps getWebDAVProps(
48              long companyId, String className, long classPK)
49          throws SystemException {
50  
51          long classNameId = PortalUtil.getClassNameId(className);
52  
53          WebDAVProps webDavProps = webDAVPropsPersistence.fetchByC_C(
54              classNameId, classPK);
55  
56          if (webDavProps == null) {
57              webDavProps = webDAVPropsPersistence.create(
58                  counterLocalService.increment());
59  
60              Date now = new Date();
61  
62              webDavProps.setCompanyId(companyId);
63              webDavProps.setCreateDate(now);
64              webDavProps.setModifiedDate(now);
65              webDavProps.setClassNameId(classNameId);
66              webDavProps.setClassPK(classPK);
67  
68              webDAVPropsPersistence.update(webDavProps, false);
69          }
70  
71          return webDavProps;
72      }
73  
74      public void storeWebDAVProps(WebDAVProps webDavProps)
75          throws PortalException, SystemException {
76  
77          try {
78              webDavProps.store();
79          }
80          catch (Exception e) {
81              throw new WebDAVException("Problem trying to store WebDAVProps", e);
82          }
83  
84          webDAVPropsPersistence.update(webDavProps, true);
85      }
86  
87  }