001
014
015 package com.liferay.portal.verify;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.model.Role;
020 import com.liferay.portal.model.RoleConstants;
021 import com.liferay.portal.security.permission.ResourceActionsUtil;
022 import com.liferay.portal.service.ResourceBlockLocalServiceUtil;
023 import com.liferay.portal.service.RoleLocalServiceUtil;
024 import com.liferay.portal.util.PropsValues;
025 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
026 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
027 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
028 import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
029
030 import java.util.List;
031
032
036 public class VerifyBookmarks extends VerifyProcess {
037
038 @Override
039 protected void doVerify() throws Exception {
040 verifyAssets();
041
042 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
043 verifyResourceBlocksForEntries();
044 verifyResourceBlocksForFolders();
045 }
046 }
047
048 protected void verifyAssets() throws Exception {
049 List<BookmarksEntry> entries =
050 BookmarksEntryLocalServiceUtil.getNoAssetEntries();
051
052 if (_log.isDebugEnabled()) {
053 _log.debug(
054 "Processing " + entries.size() + " entries with no asset");
055 }
056
057 for (BookmarksEntry entry : entries) {
058 try {
059 BookmarksEntryLocalServiceUtil.updateAsset(
060 entry.getUserId(), entry, null, null, null);
061 }
062 catch (Exception e) {
063 if (_log.isWarnEnabled()) {
064 _log.warn(
065 "Unable to update asset for entry " +
066 entry.getEntryId() + ": " + e.getMessage());
067 }
068 }
069 }
070
071 if (_log.isDebugEnabled()) {
072 _log.debug("Assets verified for entries");
073 }
074 }
075
076 protected void verifyResourceBlocksForEntries() throws Exception {
077 List<BookmarksEntry> entries =
078 BookmarksEntryLocalServiceUtil.getNoResourceBlockEntries();
079
080 if (_log.isDebugEnabled()) {
081 _log.debug(
082 "Processing " + entries.size() +
083 " entries with no resource blocks");
084 }
085
086 if (!entries.isEmpty()) {
087 List<String> actionIds =
088 ResourceActionsUtil.getModelResourceActions(
089 BookmarksEntry.class.getName());
090
091 for (BookmarksEntry entry : entries) {
092 Role ownerRole = RoleLocalServiceUtil.getRole(
093 entry.getCompanyId(), RoleConstants.OWNER);
094
095 ResourceBlockLocalServiceUtil.setIndividualScopePermissions(
096 entry.getCompanyId(), entry.getGroupId(),
097 BookmarksEntry.class.getName(), entry,
098 ownerRole.getRoleId(), actionIds);
099 }
100 }
101
102 if (_log.isDebugEnabled()) {
103 _log.debug("Resource blocks verified for entries");
104 }
105 }
106
107 protected void verifyResourceBlocksForFolders() throws Exception {
108 List<BookmarksFolder> folders =
109 BookmarksFolderLocalServiceUtil.getNoResourceBlockFolders();
110
111 if (_log.isDebugEnabled()) {
112 _log.debug(
113 "Processing " + folders.size() +
114 " folders with no resource blocks");
115 }
116
117 if (!folders.isEmpty()) {
118 List<String> actionIds =
119 ResourceActionsUtil.getModelResourceActions(
120 BookmarksFolder.class.getName());
121
122 for (BookmarksFolder folder : folders) {
123 Role ownerRole = RoleLocalServiceUtil.getRole(
124 folder.getCompanyId(), RoleConstants.OWNER);
125
126 ResourceBlockLocalServiceUtil.setIndividualScopePermissions(
127 folder.getCompanyId(), folder.getGroupId(),
128 BookmarksFolder.class.getName(), folder,
129 ownerRole.getRoleId(), actionIds);
130 }
131 }
132
133 if (_log.isDebugEnabled()) {
134 _log.debug("Resource blocks verified for folders");
135 }
136 }
137
138 private static Log _log = LogFactoryUtil.getLog(VerifyBookmarks.class);
139
140 }