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