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.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.portlet.documentlibrary.model.DLSync;
020    import com.liferay.portlet.documentlibrary.model.DLSyncConstants;
021    import com.liferay.portlet.documentlibrary.service.base.DLSyncLocalServiceBaseImpl;
022    
023    import java.util.Date;
024    
025    /**
026     * @author Michael Young
027     */
028    public class DLSyncLocalServiceImpl extends DLSyncLocalServiceBaseImpl {
029    
030            public DLSync addSync(
031                            long fileId, String fileUuid, long companyId, long repositoryId,
032                            long parentFolderId, String name, String type, String version)
033                    throws SystemException {
034    
035                    Date now = new Date();
036    
037                    long syncId = counterLocalService.increment();
038    
039                    DLSync dlSync = dlSyncPersistence.create(syncId);
040    
041                    dlSync.setCompanyId(companyId);
042                    dlSync.setCreateDate(now);
043                    dlSync.setModifiedDate(now);
044                    dlSync.setFileId(fileId);
045                    dlSync.setFileUuid(fileUuid);
046                    dlSync.setRepositoryId(repositoryId);
047                    dlSync.setParentFolderId(parentFolderId);
048                    dlSync.setEvent(DLSyncConstants.EVENT_ADD);
049                    dlSync.setType(type);
050                    dlSync.setName(name);
051                    dlSync.setVersion(version);
052    
053                    dlSyncPersistence.update(dlSync, false);
054    
055                    return dlSync;
056            }
057    
058            public DLSync updateSync(
059                            long fileId, long parentFolderId, String name, String event,
060                            String version)
061                    throws PortalException, SystemException {
062    
063                    DLSync dlSync = null;
064    
065                    if (event == DLSyncConstants.EVENT_DELETE) {
066                            dlSync = dlSyncPersistence.fetchByFileId(fileId);
067    
068                            if (dlSync == null) {
069                                    return null;
070                            }
071                    }
072                    else {
073                            dlSync = dlSyncPersistence.findByFileId(fileId);
074                    }
075    
076                    dlSync.setModifiedDate(new Date());
077                    dlSync.setParentFolderId(parentFolderId);
078                    dlSync.setEvent(event);
079                    dlSync.setName(name);
080                    dlSync.setVersion(version);
081    
082                    dlSyncPersistence.update(dlSync, false);
083    
084                    return dlSync;
085            }
086    
087    }