26
26
* #L%
27
27
*/
28
28
29
- import com .liferay .counter .kernel .service .CounterLocalServiceUtil ;
29
+ import com .liferay .exportimport .kernel .service .StagingLocalServiceUtil ;
30
+ import com .liferay .portal .kernel .dao .orm .QueryUtil ;
30
31
import com .liferay .portal .kernel .exception .PortalException ;
31
32
import com .liferay .portal .kernel .exception .SystemException ;
32
33
import com .liferay .portal .kernel .log .Log ;
33
34
import com .liferay .portal .kernel .log .LogFactoryUtil ;
34
- import com .liferay .portal .kernel .model .*;
35
+ import com .liferay .portal .kernel .model .Group ;
36
+ import com .liferay .portal .kernel .model .GroupConstants ;
37
+ import com .liferay .portal .kernel .model .User ;
38
+ import com .liferay .portal .kernel .security .auth .CompanyThreadLocal ;
35
39
import com .liferay .portal .kernel .service .GroupLocalServiceUtil ;
36
- import com .liferay .portal .kernel .service .OrganizationLocalServiceUtil ;
37
40
import com .liferay .portal .kernel .service .ServiceContext ;
38
41
import com .liferay .portal .kernel .service .UserLocalServiceUtil ;
39
42
import com .liferay .portal .kernel .util .PortalUtil ;
40
43
import com .mimacom .liferay .portal .setup .LiferaySetup ;
41
44
import com .mimacom .liferay .portal .setup .core .util .CustomFieldSettingUtil ;
45
+ import com .mimacom .liferay .portal .setup .core .util .PortletConstants ;
42
46
import com .mimacom .liferay .portal .setup .core .util .TitleMapUtil ;
43
47
import com .mimacom .liferay .portal .setup .domain .CustomFieldSetting ;
44
48
import com .mimacom .liferay .portal .setup .domain .Site ;
49
+ import com .mimacom .liferay .portal .setup .domain .Staging ;
45
50
46
51
import java .util .HashMap ;
47
52
import java .util .List ;
48
53
import java .util .Map ;
54
+ import java .util .Objects ;
49
55
50
56
/**
51
57
* Created by gustavnovotny on 28.08.17.
@@ -62,6 +68,8 @@ private SetupSites() {
62
68
63
69
public static void setupSites (final List <com .mimacom .liferay .portal .setup .domain .Site > groups , final Group parentGroup ) {
64
70
71
+
72
+ CompanyThreadLocal .setCompanyId (COMPANY_ID );
65
73
for (com .mimacom .liferay .portal .setup .domain .Site site : groups ) {
66
74
try {
67
75
Group liferayGroup = null ;
@@ -92,7 +100,6 @@ public static void setupSites(final List<com.mimacom.liferay.portal.setup.domain
92
100
93
101
long defaultUserId = UserLocalServiceUtil .getDefaultUserId (COMPANY_ID );
94
102
95
- long newGroupId = CounterLocalServiceUtil .increment ();
96
103
ServiceContext serviceContext = new ServiceContext ();
97
104
98
105
com .liferay .portal .kernel .model .Group newGroup = GroupLocalServiceUtil .addGroup (
@@ -103,20 +110,6 @@ public static void setupSites(final List<com.mimacom.liferay.portal.setup.domain
103
110
LOG .info ("New Organization created. Group ID: " + groupId );
104
111
}
105
112
106
- // if (liferayGroup != null && site.getSiteName() != null
107
- // && !site.getSiteName().equals("")) {
108
- // liferayGroup.setName(site.getSiteName());
109
- // liferayGroup = GroupLocalServiceUtil.updateGroup(liferayGroup);
110
- // }
111
- //
112
- // if (liferayGroup != null && site.getSiteFriendlyUrl() != null
113
- // && !site.getSiteFriendlyUrl().equals("")) {
114
- // liferayGroup.setFriendlyURL(site.getSiteFriendlyUrl());
115
- // GroupLocalServiceUtil.updateGroup(liferayGroup);
116
- // liferayGroup = liferayOrg.getGroup();
117
- // }
118
-
119
-
120
113
if (parentGroup != null && liferayGroup != null
121
114
&& site .isMaintainSiteHierarchy ()) {
122
115
liferayGroup .setParentGroupId (parentGroup .getGroupId ());
@@ -128,14 +121,15 @@ public static void setupSites(final List<com.mimacom.liferay.portal.setup.domain
128
121
129
122
LOG .info ("Setting site content..." );
130
123
124
+ long userId = LiferaySetup .getRunAsUserId ();
125
+
131
126
SetupDocumentFolders .setupDocumentFolders (site , groupId , COMPANY_ID );
132
127
LOG .info ("Document Folders setting finished." );
133
128
134
129
SetupDocuments .setupSiteDocuments (site , groupId , COMPANY_ID );
135
130
LOG .info ("Documents setting finished." );
136
131
137
- SetupPages .setupSitePages (site , groupId , COMPANY_ID ,
138
- LiferaySetup .getRunAsUserId ());
132
+ SetupPages .setupSitePages (site , groupId , COMPANY_ID , userId );
139
133
LOG .info ("Organization Pages setting finished." );
140
134
141
135
SetupWebFolders .setupWebFolders (site , groupId , COMPANY_ID );
@@ -147,9 +141,11 @@ public static void setupSites(final List<com.mimacom.liferay.portal.setup.domain
147
141
SetupArticles .setupSiteArticles (site , groupId , COMPANY_ID );
148
142
LOG .info ("Organization Articles setting finished." );
149
143
150
- setCustomFields (LiferaySetup . getRunAsUserId () , groupId , COMPANY_ID , site );
144
+ setCustomFields (userId , groupId , COMPANY_ID , site );
151
145
LOG .info ("Organization custom fields set up." );
152
146
147
+ setStaging (userId , liferayGroup , site .getStaging ());
148
+
153
149
List <com .mimacom .liferay .portal .setup .domain .Site > sites = site
154
150
.getSite ();
155
151
setupSites (sites , liferayGroup );
@@ -160,9 +156,58 @@ public static void setupSites(final List<com.mimacom.liferay.portal.setup.domain
160
156
}
161
157
}
162
158
159
+ static void setStaging (long userId , Group liveGroup , Staging staging ) {
160
+ if (Objects .isNull (staging )) {
161
+ LOG .info ("No staging configuration present for site." );
162
+ return ;
163
+ }
164
+
165
+ // only local staging supported, yet
166
+ LOG .info ("Setting up staging for site: " + liveGroup .getName ());
167
+ try {
168
+ if (staging .getType ().equals ("local" )) {
169
+ ServiceContext serviceContext = new ServiceContext ();
170
+ serviceContext .setAttribute (PortletConstants .STAGING_PARAM_TEMPLATE .replace ("#" , "com_liferay_dynamic_data_mapping_web_portlet_PortletDisplayTemplatePortlet" ), staging .isStageAdt ());
171
+
172
+ setStagingParam (staging .isStageAdt (), PortletConstants .STAGING_PORTLET_ID_ADT , serviceContext );
173
+ setStagingParam (staging .isStageBlogs (), PortletConstants .STAGING_PORTLET_ID_BLOGS , serviceContext );
174
+ setStagingParam (staging .isStageBookmarks (), PortletConstants .STAGING_PORTLET_ID_BOOKMARKS , serviceContext );
175
+ setStagingParam (staging .isStageCalendar (), PortletConstants .STAGING_PORTLET_ID_CALENDAR , serviceContext );
176
+ setStagingParam (staging .isStageDdl (), PortletConstants .STAGING_PORTLET_ID_DDL , serviceContext );
177
+ setStagingParam (staging .isStageDocumentLibrary (), PortletConstants .STAGING_PORTLET_ID_DL , serviceContext );
178
+ setStagingParam (staging .isStageForms (), PortletConstants .STAGING_PORTLET_ID_FORMS , serviceContext );
179
+ setStagingParam (staging .isStageMessageBoards (), PortletConstants .STAGING_PORTLET_ID_MB , serviceContext );
180
+ setStagingParam (staging .isStageMobileRules (), PortletConstants .STAGING_PORTLET_ID_MDR , serviceContext );
181
+ setStagingParam (staging .isStagePolls (), PortletConstants .STAGING_PORTLET_ID_POLLS , serviceContext );
182
+ setStagingParam (staging .isStageWebContent (), PortletConstants .STAGING_PORTLET_ID_WEB_CONTENT , serviceContext );
183
+ setStagingParam (staging .isStageWiki (), PortletConstants .STAGING_PORTLET_ID_WIKI , serviceContext );
184
+
185
+ StagingLocalServiceUtil .enableLocalStaging (userId , liveGroup , staging .isBranchingPublic (), staging .isBranchingPrivate (), serviceContext );
186
+ LOG .info ("Local staging switched on." );
187
+ }
188
+ if (staging .getType ().equals ("remote" )) {
189
+ LOG .error ("Remote staging setup is not supported, yet. Staging not set up." );
190
+ }
191
+ if (staging .getType ().equals ("none" ) && liveGroup .hasLocalOrRemoteStagingGroup ()) {
192
+ ServiceContext serviceContext = new ServiceContext ();
193
+ serviceContext .setUserId (userId );
194
+ serviceContext .setAttribute ("forceDisable" , true );
195
+ StagingLocalServiceUtil .disableStaging (liveGroup , serviceContext );
196
+ LOG .info ("Staging switched off." );
197
+ }
198
+
199
+ } catch (PortalException e ) {
200
+ LOG .error ("Error while setting up staging." , e );
201
+ }
202
+ }
203
+
204
+ private static void setStagingParam (boolean isParamOn , String portletId , ServiceContext serviceContext ) {
205
+ serviceContext .setAttribute (PortletConstants .STAGING_PARAM_TEMPLATE .replace ("#" , portletId ), String .valueOf (isParamOn ));
206
+ }
207
+
163
208
static void setCustomFields (final long runAsUserId , final long groupId ,
164
209
final long company , final Site site ) {
165
- if (site .getCustomFieldSetting () == null || site .getCustomFieldSetting ().size () == 0 ) {
210
+ if (site .getCustomFieldSetting () == null || site .getCustomFieldSetting ().isEmpty () ) {
166
211
LOG .error ("Site does has no Expando field settings." );
167
212
} else {
168
213
Class clazz = com .liferay .portal .kernel .model .Group .class ;
@@ -187,20 +232,14 @@ public static void deleteSite(
187
232
Map <String , Site > toBeDeletedOrganisations = convertSiteListToHashMap (
188
233
sites );
189
234
try {
190
- for (com .liferay .portal .kernel .model .Organization organisation : OrganizationLocalServiceUtil
191
- .getOrganizations (-1 , -1 )) {
192
- if (!toBeDeletedOrganisations .containsKey (organisation .getName ())) {
193
- try {
194
- OrganizationLocalServiceUtil
195
- .deleteOrganization (organisation .getOrganizationId ());
196
- LOG .info ("Deleting Organisation" + organisation .getName ());
197
- } catch (Exception e ) {
198
- LOG .error ("Error by deleting Organisation !" , e );
199
- }
235
+ for (com .liferay .portal .kernel .model .Group siteGroup : GroupLocalServiceUtil
236
+ .getGroups (QueryUtil .ALL_POS , QueryUtil .ALL_POS )) {
237
+ if (!toBeDeletedOrganisations .containsKey (siteGroup .getName ())) {
238
+ deleteLiferayGroup (siteGroup );
200
239
}
201
240
}
202
241
} catch (SystemException e ) {
203
- LOG .error ("Error by retrieving organisations !" , e );
242
+ LOG .error ("Error by retrieving sites !" , e );
204
243
}
205
244
break ;
206
245
@@ -211,9 +250,9 @@ public static void deleteSite(
211
250
com .liferay .portal .kernel .model .Group o = GroupLocalServiceUtil .getGroup (COMPANY_ID , name );
212
251
GroupLocalServiceUtil .deleteGroup (o );
213
252
} catch (Exception e ) {
214
- LOG .error ("Error by deleting Organisation !" , e );
253
+ LOG .error ("Error by deleting Site !" , e );
215
254
}
216
- LOG .info ("Deleting Organisation " + name );
255
+ LOG .info ("Deleting Site " + name );
217
256
}
218
257
219
258
break ;
@@ -224,6 +263,15 @@ public static void deleteSite(
224
263
}
225
264
}
226
265
266
+ private static void deleteLiferayGroup (Group siteGroup ) {
267
+ try {
268
+ GroupLocalServiceUtil .deleteGroup (siteGroup .getGroupId ());
269
+ LOG .info ("Deleting Site" + siteGroup .getName ());
270
+ } catch (Exception e ) {
271
+ LOG .error ("Error by deleting Site !" , e );
272
+ }
273
+ }
274
+
227
275
public static void addSiteUser (com .liferay .portal .kernel .model .Group group , User user ) {
228
276
LOG .info ("Adding user with screenName: " + user .getScreenName () + "to group with name: " + group .getName ());
229
277
GroupLocalServiceUtil .addUserGroup (user .getUserId (), group );
0 commit comments