001
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.repository.model.Folder;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
022 import com.liferay.portlet.documentlibrary.model.DLSync;
023 import com.liferay.portlet.documentlibrary.model.DLSyncConstants;
024 import com.liferay.portlet.documentlibrary.service.base.DLSyncLocalServiceBaseImpl;
025
026 import java.util.Date;
027
028
031 public class DLSyncLocalServiceImpl extends DLSyncLocalServiceBaseImpl {
032
033
037 public DLSync addSync(
038 long fileId, String fileUuid, long companyId, long repositoryId,
039 long parentFolderId, String name, String type, String version)
040 throws PortalException, SystemException {
041
042 return addSync(
043 fileId, fileUuid, companyId, repositoryId, parentFolderId, name,
044 StringPool.BLANK, type, version);
045 }
046
047 public DLSync addSync(
048 long fileId, String fileUuid, long companyId, long repositoryId,
049 long parentFolderId, String name, String description, String type,
050 String version)
051 throws PortalException, SystemException {
052
053 if (!isDefaultRepository(parentFolderId)) {
054 return null;
055 }
056
057 Date now = new Date();
058
059 long syncId = counterLocalService.increment();
060
061 DLSync dlSync = dlSyncPersistence.create(syncId);
062
063 dlSync.setCompanyId(companyId);
064 dlSync.setCreateDate(now);
065 dlSync.setDescription(description);
066 dlSync.setModifiedDate(now);
067 dlSync.setFileId(fileId);
068 dlSync.setFileUuid(fileUuid);
069 dlSync.setRepositoryId(repositoryId);
070 dlSync.setParentFolderId(parentFolderId);
071 dlSync.setEvent(DLSyncConstants.EVENT_ADD);
072 dlSync.setType(type);
073 dlSync.setName(name);
074 dlSync.setVersion(version);
075
076 dlSyncPersistence.update(dlSync, false);
077
078 return dlSync;
079 }
080
081
085 public DLSync updateSync(
086 long fileId, long parentFolderId, String name, String event,
087 String version)
088 throws PortalException, SystemException {
089
090 return updateSync(
091 fileId, parentFolderId, name, StringPool.BLANK, event, version);
092 }
093
094 public DLSync updateSync(
095 long fileId, long parentFolderId, String name, String description,
096 String event, String version)
097 throws PortalException, SystemException {
098
099 if (!isDefaultRepository(parentFolderId)) {
100 return null;
101 }
102
103 DLSync dlSync = null;
104
105 if (event == DLSyncConstants.EVENT_DELETE) {
106 dlSync = dlSyncPersistence.fetchByFileId(fileId);
107
108 if (dlSync == null) {
109 return null;
110 }
111 }
112 else {
113 dlSync = dlSyncPersistence.findByFileId(fileId);
114 }
115
116 dlSync.setModifiedDate(new Date());
117 dlSync.setParentFolderId(parentFolderId);
118 dlSync.setName(name);
119 dlSync.setDescription(description);
120 dlSync.setEvent(event);
121 dlSync.setVersion(version);
122
123 dlSyncPersistence.update(dlSync, false);
124
125 return dlSync;
126 }
127
128 protected boolean isDefaultRepository(long folderId)
129 throws PortalException, SystemException {
130
131 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
132 return true;
133 }
134
135 Folder folder = dlAppLocalService.getFolder(folderId);
136
137 return folder.isDefaultRepository();
138 }
139
140 }