ProjectUpgrade.java
31.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.projects.api.Project
* com.adobe.cq.projects.api.ProjectManager
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.Rendition
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Workspace
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.resource.collection.ResourceCollection
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.projects;
import com.adobe.cq.projects.api.Project;
import com.adobe.cq.projects.api.ProjectManager;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.resource.collection.ResourceCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProjectUpgrade {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectUpgrade.class);
static final String SITES_HTML = "/sites.html";
static final String AEM_PUBLICATIONS_HTML = "/aem/publications.html";
static final String AEM_APPS_HTML = "/aem/apps.html";
static final String PREVIOUSLY_MIGRATED = "migrated";
static final String ROLE_OWNER = "owner";
static final String PROJECT_TITLE = "jcr:title";
static final String PROJECT_DESCRIPTION = "jcr:description";
static final String SLING_RESOURCE_TYPE = "sling:resourceType";
static final String RESOURCE_TYPE_PROJECT_CONTENT = "cq/gui/components/projects/admin/card/projectcontent";
static final String RESOURCE_TYPE_ASSETLINK_CARD = "cq/gui/components/projects/admin/card/assetlinkcard";
static final String RESOURCE_TYPE_PROJECT_LINK = "cq/gui/components/projects/admin/card/linkcard";
static final String RESOURCE_TYPE_PROJECT_CARD = "cq/gui/components/projects/admin/card/projectcard";
static final String RESOURCE_TYPE_ASSET_POD = "cq/gui/components/projects/admin/pod/assetpod";
static final String RESOURCE_TYPE_COLLECTIONS_POD = "cq/gui/components/projects/admin/pod/collectionspod";
static final String RESOURCE_TYPE_CHANNEL_POD = "cq/gui/components/projects/admin/pod/channelpod";
static final String RESOURCE_TYPE_EXTERNALLINK_POD = "cq/gui/components/projects/admin/pod/externallinkspod";
static final String OLD_RESOURCE_TYPE_CQ_PROJECT_CARD = "cq/gui/components/projects/admin/projectcard";
static final String OLD_RESOURCE_TYPE_PROJECT_LINK = "cq/gui/components/projects/admin/projectlink";
static final String OLD_RESOURCE_TYPE_ASSETLINK_CARD = "cq/gui/components/projects/admin/assetlink";
static final String PROPERTY_DAM_FOLDER_PATH = "damFolderPath";
static final String PROJECT_ADMINISTRATORS_GROUP = "projects-administrators";
static final String PROJECT_USERS_GROUP = "projects-users";
static final String PUBLISHING_ADMIN = "/publishingadmin";
static final String PUBLICATIONS_HTML = "/publications.html";
static final String PROP_NAME = "name";
static final String PROP_CONSOLE_PATH = "consolePath";
static final String PROP_SUFFIX = "suffix";
static final String NN_DASHBOARD = "dashboard";
static final String NN_GADGETS = "gadgets";
static final String CONSOLE_MOBILEAPP = "mobileapp";
static final String CONSOLE_PUBLICATIONS = "publications";
static final String CONSOLE_WEBSITES = "websites";
static final String TITLE_ASSETS = "Assets";
static final String TEMPLATE_DEFAULT_PROJECT = "/libs/cq/core/content/projects/templates/default";
static final String COLLECTIONS_DETAILS_PATH = "/libs/dam/gui/content/collections/collectiondetails.html";
public static void upgradeProjects(Resource projectsFolder) {
Iterable iter = projectsFolder.getChildren();
if (iter != null) {
for (Resource resource : iter) {
if ("cq/gui/components/projects/admin/projectcard".equals(resource.getResourceType()) || "cq/gui/components/projects/admin/projectcard".equals(resource.getResourceSuperType())) {
ValueMap valueMap = resource.getValueMap();
Boolean previouslyMigrated = (Boolean)valueMap.get("migrated", Boolean.class);
if (previouslyMigrated != null && previouslyMigrated.booleanValue()) {
LOGGER.info("Found project at path which has already been migrated: '{}'", (Object)resource.getPath());
continue;
}
LOGGER.info("Found project to upgrade at path: '{}'", (Object)resource.getPath());
try {
ProjectUpgrade.upgradeProject(resource);
}
catch (PersistenceException e) {
LOGGER.error("Exception occured while upgrading project at {}", (Object)resource.getPath(), (Object)e);
}
catch (RepositoryException e) {
LOGGER.error("Exception occured while upgrading project at {}", (Object)resource.getPath(), (Object)e);
}
continue;
}
LOGGER.debug("Resource path '{}' does not point to a project.", (Object)resource.getPath());
ProjectUpgrade.upgradeProjects(resource);
}
}
}
private static void upgradeProject(Resource oldProjectResource) throws PersistenceException, RepositoryException {
String projPathEnd;
Resource oldLinks;
String oldProjPathEnd;
Resource content;
Resource projRes;
Resource imageFile;
LOGGER.info("Upgrading projects located at {}", (Object)oldProjectResource.getPath());
ModifiableValueMap modifiableValueMap = (ModifiableValueMap)oldProjectResource.adaptTo(ModifiableValueMap.class);
String imageMimeType = null;
InputStream imageInputStream = null;
Resource imageResource = oldProjectResource.getChild("image");
if (imageResource != null && (imageFile = imageResource.getChild("file")) != null && (content = imageFile.getChild("jcr:content")) != null) {
ValueMap imageProperties = content.getValueMap();
imageMimeType = (String)imageProperties.get("jcr:mimeType", String.class);
if ("application/octet-stream".equals(imageMimeType)) {
imageMimeType = "image/jpeg";
}
imageInputStream = (InputStream)imageProperties.get("jcr:data", InputStream.class);
}
String[] teamMemberUserIds = new String[]{"projects-administrators"};
String[] teamMemberRoleIds = new String[]{"owner"};
String projectTitle = (String)modifiableValueMap.get("jcr:title", String.class);
String projectDesc = (String)modifiableValueMap.get("jcr:description", String.class);
ProjectManager projMan = (ProjectManager)oldProjectResource.getResourceResolver().adaptTo(ProjectManager.class);
Project project = projMan.createProject(oldProjectResource.getName(), projectTitle, ProjectUpgrade.getProjectTemplate(oldProjectResource));
project.updateMembers(Arrays.asList(teamMemberUserIds), Arrays.asList(teamMemberRoleIds));
if (StringUtils.isNotBlank((CharSequence)projectDesc)) {
project.setDescription(projectDesc);
}
project.setProjectCover(imageMimeType, imageInputStream);
if (project != null && !StringUtils.equals((CharSequence)(projPathEnd = StringUtils.substringAfterLast((String)(projRes = (Resource)project.adaptTo(Resource.class)).getPath(), (String)"/")), (CharSequence)(oldProjPathEnd = StringUtils.substringAfterLast((String)oldProjectResource.getPath(), (String)"/")))) {
LOGGER.info("Making project {} at path {} inactive", (Object)projectTitle, (Object)projRes.getPath());
project.setActive(false);
}
if ((oldLinks = oldProjectResource.getChild("links")) != null) {
int assetPodCount = 0;
Session session = (Session)oldLinks.getResourceResolver().adaptTo(Session.class);
Iterable links = oldLinks.getChildren();
Resource newProjectResource = (Resource)project.adaptTo(Resource.class);
String newLinkPrefix = newProjectResource.getPath() + "/" + "jcr:content" + "/links/";
String experiencesPodPath = null;
Resource gadgetsResource = ProjectUpgrade.findGadgetsResource(newProjectResource);
Resource experiencesPod = ProjectUpgrade.findExperiencesPod(gadgetsResource);
if (experiencesPod == null) {
experiencesPod = ProjectUpgrade.createExperiencesPod(oldProjectResource.getResourceResolver(), gadgetsResource);
}
if (!(experiencesPodPath = experiencesPod.getPath()).endsWith("/")) {
experiencesPodPath = experiencesPodPath + "/";
}
for (Resource link : links) {
boolean isExperiencesEntry;
if (ProjectUpgrade.skipLink(oldProjectResource, link)) continue;
ValueMap linkMap = link.getValueMap();
if (ProjectUpgrade.isDamAssetFolder(link, linkMap)) {
String assetFolderPath = (String)linkMap.get("suffix", String.class);
if (StringUtils.equals((CharSequence)assetFolderPath, (CharSequence)project.getAssetFolder().getPath())) continue;
ResourceResolver resourceResolver = oldProjectResource.getResourceResolver();
String title = (String)linkMap.get("jcr:title", (Object)"Assets");
String description = (String)linkMap.get("jcr:description", (Object)"");
HashMap<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
props.put("jcr:title", title);
props.put("sling:resourceType", "cq/gui/components/projects/admin/pod/assetpod");
props.put("jcr:mixinTypes", (String)new String[]{"mix:lastModified"});
props.put("jcr:description", description);
props.put("cardWeight", "90");
props.put("assetPath", assetFolderPath);
resourceResolver.create(gadgetsResource, "asset" + assetPodCount, props);
++assetPodCount;
continue;
}
String newLinkPath = newLinkPrefix + link.getName();
boolean bl = isExperiencesEntry = ProjectUpgrade.isExperiencesLink(link) && experiencesPodPath != null;
if (isExperiencesEntry) {
newLinkPath = experiencesPodPath + link.getName();
}
session.getWorkspace().copy(link.getPath(), newLinkPath);
Resource resourceLink = oldProjectResource.getResourceResolver().getResource(newLinkPath);
ProjectUpgrade.updateLinkResourceType(resourceLink);
if (!isExperiencesEntry) continue;
ModifiableValueMap newProperties = (ModifiableValueMap)resourceLink.adaptTo(ModifiableValueMap.class);
newProperties.put((Object)"projectPath", (Object)newProjectResource.getPath());
String consolePath = (String)newProperties.get("consolePath", String.class);
if ("/aem/apps.html".equals(consolePath)) {
newProperties.put((Object)"name", (Object)"mobileapp");
newProperties.put((Object)"consolePath", (Object)"/aem/apps.html");
continue;
}
if ("/publishingadmin".equals(consolePath) || "/publications.html".equals(consolePath)) {
newProperties.put((Object)"name", (Object)"publications");
newProperties.put((Object)"consolePath", (Object)"/aem/publications.html");
String suffix = (String)newProperties.get("suffix", String.class);
if (StringUtils.isNotBlank((CharSequence)suffix)) {
suffix = StringUtils.removeStart((String)suffix, (String)"#");
}
newProperties.put((Object)"suffix", (Object)suffix);
continue;
}
if (!"/sites.html".equals(consolePath)) continue;
newProperties.put((Object)"name", (Object)"websites");
}
}
modifiableValueMap.put((Object)"migrated", (Object)Boolean.TRUE);
oldProjectResource.getResourceResolver().commit();
LOGGER.info("Done upgrading project.");
}
public static void upgrade561FP2Projects(Resource projectsFolder) {
Iterable iter = projectsFolder.getChildren();
if (iter != null) {
for (Resource resource : iter) {
Iterable dateBuckets = resource.getChildren();
for (Resource child : dateBuckets) {
if ("cq/gui/components/projects/admin/card/projectcard".equals(child.getResourceType())) {
ValueMap valueMap = child.getValueMap();
Boolean previouslyMigrated = (Boolean)valueMap.get("migrated", Boolean.class);
if (previouslyMigrated != null && previouslyMigrated.booleanValue()) {
LOGGER.debug("Found project at path which has already been migrated: '{}'", (Object)child.getPath());
continue;
}
if (ProjectUpgrade.shouldSkip(child)) continue;
LOGGER.debug("Found project to upgrade at path: '{}'", (Object)child.getPath());
try {
ProjectUpgrade.upgrade561FP2Project(child);
}
catch (PersistenceException e) {
LOGGER.error("Exception occured upgrading project at {}", (Object)child.getPath(), (Object)e);
continue;
}
catch (RepositoryException e) {
LOGGER.error("Exception occured upgrading project at {}", (Object)child.getPath(), (Object)e);
continue;
}
((ModifiableValueMap)child.adaptTo(ModifiableValueMap.class)).put((Object)"migrated", (Object)Boolean.TRUE);
continue;
}
LOGGER.debug("Resource path '{}' does not point to a project.", (Object)child.getPath());
}
}
}
}
private static boolean shouldSkip(Resource projectRes) {
boolean skip = false;
String path = projectRes.getPath();
if (StringUtils.startsWith((CharSequence)path, (CharSequence)"/content/projects/geometrixx")) {
return skip;
}
if (StringUtils.endsWithAny((CharSequence)path, (CharSequence[])new CharSequence[]{"outdoors", "media", "shapes", "gov"})) {
LOGGER.debug("Skipping upgrade of project at {} and marking as inactive", (Object)projectRes.getPath());
skip = true;
Project project = (Project)projectRes.adaptTo(Project.class);
if (project != null) {
project.setActive(false);
}
}
return skip;
}
private static void upgrade561FP2Project(Resource projectResource) throws PersistenceException, RepositoryException {
Asset imageAsset;
Resource links;
LOGGER.debug("Migrating " + projectResource.getPath());
ResourceResolver resourceResolver = projectResource.getResourceResolver();
Project project = (Project)projectResource.adaptTo(Project.class);
Resource contentResource = projectResource.getChild("jcr:content");
if (contentResource == null) {
LOGGER.debug("Did not migrate {} :: /jcr:content not found", (Object)projectResource.getPath());
return;
}
ModifiableValueMap modifiableValueMap = (ModifiableValueMap)contentResource.adaptTo(ModifiableValueMap.class);
if ("cq/gui/components/projects/admin/card/projectcontent".equals(modifiableValueMap.get("sling:resourceType", String.class))) {
return;
}
String title = (String)modifiableValueMap.get("jcr:title", String.class);
String desc = (String)modifiableValueMap.get("jcr:description", String.class);
project.setTitle(title == null ? "" : title);
project.setDescription(desc == null ? "" : desc);
project.setActive(true);
Resource imageResource = resourceResolver.getResource((String)modifiableValueMap.get("coverUrl", String.class));
if (imageResource != null && (imageAsset = (Asset)imageResource.adaptTo(Asset.class)) != null) {
String imageMimeType = imageAsset.getMimeType();
if ("application/octet-stream".equals(imageMimeType)) {
imageMimeType = "image/jpeg";
}
InputStream imageInputStream = imageAsset.getOriginal().getStream();
project.setProjectCover(imageMimeType, imageInputStream);
}
if ((links = contentResource.getChild("links")) != null) {
Resource experiencesPod;
String externalLinksPodPath;
Resource externalLinksPod;
String experiencesPodPath;
Resource gadgetsResource = ProjectUpgrade.findGadgetsResource(projectResource);
if (gadgetsResource == null) {
gadgetsResource = ProjectUpgrade.createGadgetsResource(resourceResolver, contentResource);
LOGGER.debug("Creating " + gadgetsResource.getPath());
}
if ((experiencesPod = ProjectUpgrade.findExperiencesPod(gadgetsResource)) == null) {
experiencesPod = ProjectUpgrade.createExperiencesPod(resourceResolver, gadgetsResource);
}
if (!(experiencesPodPath = experiencesPod.getPath()).endsWith("/")) {
experiencesPodPath = experiencesPodPath + "/";
}
if ((externalLinksPod = ProjectUpgrade.findExternalLinksPod(gadgetsResource)) == null) {
externalLinksPod = ProjectUpgrade.createExternalLinksPod(resourceResolver, gadgetsResource);
}
if (!(externalLinksPodPath = externalLinksPod.getPath()).endsWith("/")) {
externalLinksPodPath = externalLinksPodPath + "/";
}
Session session = (Session)resourceResolver.adaptTo(Session.class);
int assetPodCount = 0;
int assetCollectionPodCount = 0;
Iterable linksList = links.getChildren();
for (Resource link : linksList) {
Resource resourceLink;
ModifiableValueMap newProperties;
String newLinkPath;
if (link == null) continue;
ValueMap linkMap = link.getValueMap();
if (link.isResourceType("cq/gui/components/projects/admin/card/assetlinkcard")) {
String linkPath = (String)linkMap.get("suffix", String.class);
if (link.getName().equals("project_dam_folder")) {
LOGGER.debug("Migrating default project assets folder entry {}", (Object)link.getPath());
HashMap<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
props.put("jcr:title", "Assets");
props.put("sling:resourceType", "cq/gui/components/projects/admin/pod/assetpod");
props.put("cardWeight", "90");
resourceResolver.create(gadgetsResource, "asset", props);
} else {
Resource assetResource = resourceResolver.getResource(linkPath);
if (assetResource.adaptTo(ResourceCollection.class) != null) {
LOGGER.debug("Migrating collections entry {}", (Object)link.getPath());
HashMap<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
props.put("jcr:title", "Asset Collection");
props.put("sling:resourceType", "cq/gui/components/projects/admin/pod/collectionspod");
props.put("jcr:mixinTypes", (String)new String[]{"mix:lastModified"});
props.put("jcr:description", "Asset Collection Tile");
props.put("cardWeight", "90");
props.put("collectionPath", linkPath);
resourceResolver.create(gadgetsResource, "assetcollection" + assetCollectionPodCount, props);
++assetCollectionPodCount;
((ModifiableValueMap)link.adaptTo(ModifiableValueMap.class)).put((Object)"consolePath", (Object)"/libs/dam/gui/content/collections/collectiondetails.html");
} else {
ValueMap assetMap = assetResource.getValueMap();
String primaryType = (String)assetMap.get("jcr:primaryType", String.class);
if (StringUtils.equals((CharSequence)"sling:OrderedFolder", (CharSequence)primaryType) || StringUtils.equals((CharSequence)"nt:folder", (CharSequence)primaryType)) {
LOGGER.debug("Migrating assets entry {}", (Object)link.getPath());
String assetTitle = (String)linkMap.get("jcr:title", (Object)"Assets");
String description = (String)linkMap.get("jcr:description", (Object)"");
HashMap<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
props.put("jcr:title", assetTitle);
props.put("sling:resourceType", "cq/gui/components/projects/admin/pod/assetpod");
props.put("jcr:mixinTypes", (String)new String[]{"mix:lastModified"});
props.put("jcr:description", description);
props.put("cardWeight", "90");
props.put("assetPath", linkPath);
resourceResolver.create(gadgetsResource, "asset" + assetPodCount, props);
++assetPodCount;
}
}
}
resourceResolver.delete(link);
continue;
}
if (ProjectUpgrade.isExperiencesLink(link)) {
LOGGER.debug("Migrating experiences entry {}", (Object)link.getPath());
newLinkPath = experiencesPodPath + link.getName();
session.getWorkspace().copy(link.getPath(), newLinkPath);
resourceLink = resourceResolver.getResource(newLinkPath);
newProperties = (ModifiableValueMap)resourceLink.adaptTo(ModifiableValueMap.class);
newProperties.put((Object)"projectPath", (Object)projectResource.getPath());
String consolePath = (String)linkMap.get("consolePath", String.class);
if ("/aem/apps.html".equals(consolePath)) {
newProperties.put((Object)"name", (Object)"mobileapp");
newProperties.put((Object)"consolePath", (Object)"/aem/apps.html");
} else if ("/publishingadmin".equals(consolePath) || "/publications.html".equals(consolePath)) {
newProperties.put((Object)"name", (Object)"publications");
newProperties.put((Object)"consolePath", (Object)"/aem/publications.html");
String suffix = (String)newProperties.get("suffix", String.class);
if (StringUtils.isNotBlank((CharSequence)suffix)) {
suffix = StringUtils.removeStart((String)suffix, (String)"#");
}
newProperties.put((Object)"suffix", (Object)suffix);
} else if ("/sites.html".equals(consolePath)) {
newProperties.put((Object)"name", (Object)"websites");
}
resourceResolver.delete(link);
continue;
}
if (!link.isResourceType("cq/gui/components/projects/admin/card/linkcard") || !"External".equals(linkMap.get("name", String.class))) continue;
LOGGER.debug("Migrating external links entry {}", (Object)link.getPath());
newLinkPath = externalLinksPodPath + link.getName();
session.getWorkspace().copy(link.getPath(), newLinkPath);
resourceLink = resourceResolver.getResource(newLinkPath);
newProperties = (ModifiableValueMap)resourceLink.adaptTo(ModifiableValueMap.class);
newProperties.put((Object)"linkParent", (Object)externalLinksPodPath);
resourceResolver.delete(link);
}
}
modifiableValueMap.put((Object)"sling:resourceType", (Object)"cq/gui/components/projects/admin/card/projectcontent");
resourceResolver.commit();
}
private static boolean skipLink(Resource oldProjectResource, Resource link) {
if (oldProjectResource != null && link != null && "/etc/projects/geometrixx/outdoors".equals(oldProjectResource.getPath()) && "/etc/projects/geometrixx/outdoors/links/campaign".equals(link.getPath())) {
return true;
}
return false;
}
private static Resource createGadgetsResource(ResourceResolver resourceResolver, Resource projectContent) throws PersistenceException {
Resource gadgetResource;
Resource dashboardResource = projectContent.getChild("dashboard");
if (dashboardResource == null) {
Map dashboardResourceProps = Collections.emptyMap();
dashboardResource = resourceResolver.create(projectContent, "dashboard", dashboardResourceProps);
}
if ((gadgetResource = dashboardResource.getChild("gadgets")) == null) {
Map gadgetsResourceProps = Collections.emptyMap();
gadgetResource = resourceResolver.create(dashboardResource, "gadgets", gadgetsResourceProps);
}
return gadgetResource;
}
private static Resource createExperiencesPod(ResourceResolver resourceResolver, Resource gadgetsResource) throws PersistenceException {
HashMap<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
props.put("jcr:title", "Experiences");
props.put("sling:resourceType", "cq/gui/components/projects/admin/pod/channelpod");
props.put("cardWeight", "90");
Resource result = resourceResolver.create(gadgetsResource, "experiences", props);
resourceResolver.commit();
return result;
}
private static String getProjectTemplate(Resource oldProjectResource) {
return "/libs/cq/core/content/projects/templates/default";
}
private static boolean isDamAssetFolder(Resource link, ValueMap linkMap) {
String assetPath;
Resource assetResource;
String primaryType;
ValueMap assetMap;
if (link != null && link.isResourceType("cq/gui/components/projects/admin/assetlink") && linkMap != null && StringUtils.isNotBlank((CharSequence)(assetPath = (String)linkMap.get("suffix", String.class))) && (assetResource = link.getResourceResolver().getResource(assetPath)) != null && (StringUtils.equals((CharSequence)"sling:OrderedFolder", (CharSequence)(primaryType = (String)(assetMap = assetResource.getValueMap()).get("jcr:primaryType", String.class))) || StringUtils.equals((CharSequence)"nt:folder", (CharSequence)primaryType))) {
return true;
}
return false;
}
private static boolean isExperiencesLink(Resource link) {
if (link != null) {
ValueMap vmLink = link.getValueMap();
String consolePath = (String)vmLink.get("consolePath", String.class);
return "/sites.html".equals(consolePath) || "/aem/publications.html".equals(consolePath) || "/aem/apps.html".equals(consolePath) || "/publishingadmin".equals(consolePath) || "/publications.html".equals(consolePath);
}
return false;
}
private static Resource findExperiencesPod(Resource gadgetsResource) {
if (gadgetsResource != null) {
for (Resource child : gadgetsResource.getChildren()) {
if (!child.isResourceType("cq/gui/components/projects/admin/pod/channelpod")) continue;
return child;
}
}
return null;
}
private static Resource findExternalLinksPod(Resource gadgetsResource) {
if (gadgetsResource != null) {
for (Resource child : gadgetsResource.getChildren()) {
if (!child.isResourceType("cq/gui/components/projects/admin/pod/externallinkspod")) continue;
return child;
}
}
return null;
}
private static Resource createExternalLinksPod(ResourceResolver resourceResolver, Resource gadgetsResource) throws PersistenceException {
HashMap<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
props.put("jcr:title", "Links");
props.put("jcr:description", "Links Tile");
props.put("sling:resourceType", "cq/gui/components/projects/admin/pod/externallinkspod");
props.put("cardWeight", "90");
Resource result = resourceResolver.create(gadgetsResource, "externallinks", props);
resourceResolver.commit();
return result;
}
private static Resource findGadgetsResource(Resource projectResource) {
Resource jcrContent;
Resource dashboard;
if (projectResource != null && (jcrContent = projectResource.getChild("jcr:content")) != null && (dashboard = jcrContent.getChild("dashboard")) != null) {
return dashboard.getChild("gadgets");
}
return null;
}
private static void updateLinkResourceType(Resource resourceLink) {
ModifiableValueMap newProperties = (ModifiableValueMap)resourceLink.adaptTo(ModifiableValueMap.class);
String currentRT = (String)newProperties.get("sling:resourceType", String.class);
if ("cq/gui/components/projects/admin/projectlink".equals(currentRT)) {
newProperties.put((Object)"sling:resourceType", (Object)"cq/gui/components/projects/admin/card/linkcard");
} else if ("cq/gui/components/projects/admin/assetlink".equals(currentRT)) {
newProperties.put((Object)"sling:resourceType", (Object)"cq/gui/components/projects/admin/card/assetlinkcard");
}
}
}