47
47
import org .apache .commons .collections4 .CollectionUtils ;
48
48
import org .apache .commons .io .FileUtils ;
49
49
import org .apache .commons .lang3 .StringUtils ;
50
+ import org .apache .commons .lang3 .tuple .Pair ;
50
51
import org .exoplatform .portal .config .model .Page ;
51
52
import org .exoplatform .portal .config .model .PortalConfig ;
52
53
import org .exoplatform .portal .mop .SiteKey ;
53
- import org .exoplatform .portal .mop .State ;
54
54
import org .exoplatform .portal .mop .Utils ;
55
55
import org .exoplatform .portal .mop .Visibility ;
56
56
import org .exoplatform .portal .mop .navigation .*;
@@ -100,7 +100,7 @@ public class SiteTemplateDatabindPlugin implements DatabindPlugin {
100
100
private SiteTemplateService siteTemplateService ;
101
101
102
102
@ Autowired
103
- LayoutService layoutService ;
103
+ private LayoutService layoutService ;
104
104
105
105
@ Autowired
106
106
private DatabindService databindService ;
@@ -132,10 +132,10 @@ public class SiteTemplateDatabindPlugin implements DatabindPlugin {
132
132
private NavigationLayoutService navigationLayoutService ;
133
133
134
134
@ Autowired
135
- DescriptionService descriptionService ;
135
+ private DescriptionService descriptionService ;
136
136
137
137
@ Autowired
138
- PageLayoutService pageLayoutService ;
138
+ private PageLayoutService pageLayoutService ;
139
139
140
140
@ PostConstruct
141
141
public void init () {
@@ -216,7 +216,7 @@ public void serialize(String objectId, ZipOutputStream zipOutputStream, String u
216
216
if (CollectionUtils .isNotEmpty (pageContexts )) {
217
217
pages = pageContexts .stream ().map (this ::toPage ).toList ();
218
218
}
219
- List <NodeDefinition > nodeDefinitions = buildNodeDefinitions (siteKey );
219
+ List <NodeDefinition > nodeDefinitions = buildNodeDefinitions (siteKey , username );
220
220
221
221
String navigationJsonData = JsonUtils .toJsonString (nodeDefinitions );
222
222
@@ -235,12 +235,12 @@ public void serialize(String objectId, ZipOutputStream zipOutputStream, String u
235
235
writeToZip (zipOutputStream , folderPath + "/" + NAVIGATION_JSON , navigationJsonData );
236
236
}
237
237
238
- public CompletableFuture <DatabindReport > deserialize (File zipFile , Map <String , String > params , String username ) {
238
+ public CompletableFuture <Pair < DatabindReport , File > > deserialize (File zipFile , Map <String , String > params , String username ) {
239
239
return CompletableFuture .supplyAsync (() -> importSiteTemplates (zipFile , username )).thenApply (processedTemplates -> {
240
240
DatabindReport report = new DatabindReport ();
241
241
report .setSuccess (!processedTemplates .isEmpty ());
242
242
report .setProcessedItems (processedTemplates );
243
- return report ;
243
+ return Pair . of ( report , zipFile ) ;
244
244
});
245
245
246
246
}
@@ -289,8 +289,7 @@ private Map<String, SiteTemplateDatabind> extractTemplates(File zipFile) {
289
289
}
290
290
templateDatabindMap .put (key , databindFromJson );
291
291
}
292
- }
293
- else if (entryName .endsWith (NAVIGATION_JSON )) {
292
+ } else if (entryName .endsWith (NAVIGATION_JSON )) {
294
293
List <NodeDefinition > nodeDefinitions = JsonUtils .fromJsonString (jsonContent , new TypeReference <>() {
295
294
});
296
295
if (nodeDefinitions != null ) {
@@ -302,8 +301,7 @@ else if (entryName.endsWith(NAVIGATION_JSON)) {
302
301
});
303
302
databind .setNodeDefinitions (nodeDefinitions );
304
303
}
305
- }
306
- else if (entryName .matches (".+/pages/.+\\ .json$" )) {
304
+ } else if (entryName .matches (".+/pages/.+\\ .json$" )) {
307
305
LayoutModel page = JsonUtils .fromJsonString (jsonContent , LayoutModel .class );
308
306
if (page != null ) {
309
307
String key = entryName .substring (0 , entryName .indexOf ("/pages/" ));
@@ -428,17 +426,16 @@ private void processSiteTemplate(SiteTemplateDatabind siteTemplateDatabind, Stri
428
426
List <NodeDefinition > nodeDefinitions = siteTemplateDatabind .getNodeDefinitions ();
429
427
if (CollectionUtils .isNotEmpty (nodeDefinitions )) {
430
428
NodeDefinition targetParentNode = nodeDefinitions .getFirst ();
431
- NavigationUpdateModel navigationUpdateModel = new NavigationUpdateModel (targetParentNode .getName (),
432
- getPageKey (portalConfig .getSiteKey (),
433
- targetParentNode ),
434
- null ,
435
- targetParentNode .getVisibility ()
436
- .equals (Visibility .DISPLAYED ),
437
- false ,
438
- null ,
439
- null ,
440
- targetParentNode .getIcon (),
441
- targetParentNode .getLabels ());
429
+
430
+ NavigationUpdateModel navigationUpdateModel = new NavigationUpdateModel ();
431
+ navigationUpdateModel .setNodeLabel (targetParentNode .getName ());
432
+ navigationUpdateModel .setPageRef (getPageKey (portalConfig .getSiteKey (), targetParentNode ));
433
+ navigationUpdateModel .setVisible (targetParentNode .getVisibility ()
434
+ .equals (Visibility .DISPLAYED ));
435
+ navigationUpdateModel .setScheduled (false );
436
+ navigationUpdateModel .setIcon (targetParentNode .getIcon ());
437
+ targetParentNode .setLabels (targetParentNode .getLabels ());
438
+
442
439
navigationLayoutService .updateNode (Long .parseLong (parentNode .getId ()), navigationUpdateModel , username );
443
440
parentNode .getNodes ().forEach (node -> navigationLayoutService .deleteNode (Long .parseLong (node .getId ())));
444
441
createNodesRecursively (nodeDefinitions , parentNode .getId (), portalConfig .getSiteKey (), username );
@@ -491,7 +488,7 @@ private Page toPage(PageContext pageContext) {
491
488
return page ;
492
489
}
493
490
494
- private List <NodeDefinition > buildNodeDefinitions (SiteKey siteKey ) {
491
+ private List <NodeDefinition > buildNodeDefinitions (SiteKey siteKey , String username ) {
495
492
NavigationContext navigationContext = navigationService .loadNavigation (siteKey );
496
493
497
494
NodeContext <?> rootNode = navigationService .loadNode (NodeModel .SELF_MODEL , navigationContext , Scope .ALL , null );
@@ -504,34 +501,28 @@ private List<NodeDefinition> buildNodeDefinitions(SiteKey siteKey) {
504
501
505
502
Collection <NodeContext <?>> children = getChildren (rootNode );
506
503
for (NodeContext <?> child : children ) {
507
- nodeDefinitions .add (buildNodeDefinitionRecursively (child ));
504
+ nodeDefinitions .add (buildNodeDefinitionRecursively (child , username ));
508
505
}
509
506
return nodeDefinitions ;
510
507
}
511
508
512
- private NodeDefinition buildNodeDefinitionRecursively (NodeContext <?> nodeContext ) {
509
+ @ SneakyThrows
510
+ private NodeDefinition buildNodeDefinitionRecursively (NodeContext <?> nodeContext , String username ) {
513
511
NodeState state = nodeContext .getData ().getState ();
514
512
515
513
NodeDefinition def = new NodeDefinition ();
516
514
def .setName (nodeContext .getName ());
517
515
def .setIcon (state .getIcon ());
518
516
def .setVisibility (state .getVisibility ());
519
- def .setPageReference (state .getPageRef ().format ());
520
-
521
- Map <Locale , State > descriptions = descriptionService .getDescriptions (nodeContext .getId ());
517
+ def .setPageReference (state .getPageRef () != null ? state .getPageRef ().format () : null );
522
518
523
- Map <String , String > labels = new HashMap <>();
524
- if (descriptions != null ) {
525
- for (Map .Entry <Locale , State > entry : descriptions .entrySet ()) {
526
- labels .put (entry .getKey ().toLanguageTag (), entry .getValue ().getName ());
527
- }
528
- }
519
+ NodeLabel nodeLabel = navigationLayoutService .getNodeLabels (Long .parseLong (nodeContext .getId ()), username );
529
520
530
- def .setLabels (labels );
521
+ def .setLabels (nodeLabel . getLabels () );
531
522
532
523
Collection <NodeContext <?>> children = getChildren (nodeContext );
533
524
for (NodeContext <?> child : children ) {
534
- def .getChildren ().add (buildNodeDefinitionRecursively (child ));
525
+ def .getChildren ().add (buildNodeDefinitionRecursively (child , username ));
535
526
}
536
527
return def ;
537
528
}
0 commit comments