001    /**
002     * Copyright (c) 2000-2012 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.portlet.documentlibrary.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portlet.documentlibrary.model.DLSync;
021    import com.liferay.portlet.documentlibrary.model.DLSyncConstants;
022    import com.liferay.portlet.documentlibrary.service.base.DLSyncLocalServiceBaseImpl;
023    
024    import java.util.Date;
025    
026    /**
027     * @author Michael Young
028     */
029    public class DLSyncLocalServiceImpl extends DLSyncLocalServiceBaseImpl {
030    
031            /**
032             * @deprecated {@link #addSync(long, String, long, long, long, String,
033             *             String, String, String)}
034             */
035            public DLSync addSync(
036                            long fileId, String fileUuid, long companyId, long repositoryId,
037                            long parentFolderId, String name, String type, String version)
038                    throws SystemException {
039    
040                    return addSync(
041                            fileId, fileUuid, companyId, repositoryId, parentFolderId, name,
042                            StringPool.BLANK, type, version);
043            }
044    
045            public DLSync addSync(
046                            long fileId, String fileUuid, long companyId, long repositoryId,
047                            long parentFolderId, String name, String description,
048                            String type, String version)
049                    throws SystemException {
050    
051                    Date now = new Date();
052    
053                    long syncId = counterLocalService.increment();
054    
055                    DLSync dlSync = dlSyncPersistence.create(syncId);
056    
057                    dlSync.setCompanyId(companyId);
058                    dlSync.setCreateDate(now);
059                    dlSync.setDescription(description);
060                    dlSync.setModifiedDate(now);
061                    dlSync.setFileId(fileId);
062                    dlSync.setFileUuid(fileUuid);
063                    dlSync.setRepositoryId(repositoryId);
064                    dlSync.setParentFolderId(parentFolderId);
065                    dlSync.setEvent(DLSyncConstants.EVENT_ADD);
066                    dlSync.setType(type);
067                    dlSync.setName(name);
068                    dlSync.setVersion(version);
069    
070                    dlSyncPersistence.update(dlSync, false);
071    
072                    return dlSync;
073            }
074    
075            /**
076             * @deprecated {@link #updateSync(long, long, String, String, String,
077             *             String)}
078             */
079            public DLSync updateSync(
080                            long fileId, long parentFolderId, String name, String event,
081                            String version)
082                    throws PortalException, SystemException {
083    
084                    return updateSync(
085                            fileId, parentFolderId, name, StringPool.BLANK, event, version);
086            }
087    
088            public DLSync updateSync(
089                            long fileId, long parentFolderId, String name, String description,
090                            String event, String version)
091                    throws PortalException, SystemException {
092    
093                    DLSync dlSync = null;
094    
095                    if (event == DLSyncConstants.EVENT_DELETE) {
096                            dlSync = dlSyncPersistence.fetchByFileId(fileId);
097    
098                            if (dlSync == null) {
099                                    return null;
100                            }
101                    }
102                    else {
103                            dlSync = dlSyncPersistence.findByFileId(fileId);
104                    }
105    
106                    dlSync.setModifiedDate(new Date());
107                    dlSync.setParentFolderId(parentFolderId);
108                    dlSync.setName(name);
109                    dlSync.setDescription(description);
110                    dlSync.setEvent(event);
111                    dlSync.setVersion(version);
112    
113                    dlSyncPersistence.update(dlSync, false);
114    
115                    return dlSync;
116            }
117    
118    }