49
49
import org .springframework .stereotype .Component ;
50
50
51
51
import java .util .*;
52
+ import java .util .stream .Collectors ;
52
53
53
54
import static com .viglet .turing .connector .aem .commons .TurAemConstants .*;
54
55
@@ -108,20 +109,20 @@ public void sentToIndexStandaloneAsync(String name, TurAemPathList turAemPathLis
108
109
log .error ("Payload is empty" );
109
110
return ;
110
111
}
111
- log .info ("Receiving Async payload to {} source with paths {}" , name , turAemPathList );
112
+ log .debug ("Receiving Async payload to {} source with paths {}" , name , turAemPathList );
112
113
turAemSourceRepository .findByName (name ).ifPresentOrElse (turAemSource -> {
113
114
TurConnectorSession turConnectorSession = TurAemPluginProcess .getTurConnectorSession (turAemSource );
114
115
turAemPathList .getPaths ().forEach (path ->
115
116
indexContentId (turConnectorSession , turAemSource , path , true ));
116
117
finished (turConnectorSession , true );
117
118
},
118
- () -> log .info ("{} Source not found" , name ));
119
+ () -> log .error ("{} Source not found" , name ));
119
120
}
120
121
121
122
122
123
public void indexAll (TurAemSource turAemSource ) {
123
124
if (runningSources .contains (turAemSource .getName ())) {
124
- log .info ("Skipping. There are already source process running. {}" , turAemSource .getName ());
125
+ log .warn ("Skipping. There are already source process running. {}" , turAemSource .getName ());
125
126
return ;
126
127
}
127
128
runningSources .add (turAemSource .getName ());
@@ -142,37 +143,56 @@ public void indexAll(TurAemSource turAemSource) {
142
143
}
143
144
144
145
public void finished (TurConnectorSession turConnectorSession , boolean standalone ) {
145
- if (!standalone ) {
146
- runningSources .remove (turConnectorSession .getSource ());
147
- }
146
+ if (!standalone ) runningSources .remove (turConnectorSession .getSource ());
148
147
turConnectorContext .finishIndexing (turConnectorSession , standalone );
149
148
}
150
149
151
-
152
150
private @ NotNull TurAemContentMapping getTurAemContentMapping (TurAemSource turAemSource ) {
153
- List <TurAemModel > turAemModels = new ArrayList <>();
154
- turAemPluginModelRepository .findByTurAemSource (turAemSource ).forEach (pluginModel -> {
155
- List <TurAemTargetAttr > targetAttrs = new ArrayList <>();
156
- pluginModel .getTargetAttrs ().forEach (targetAttr -> {
157
- List <TurAemSourceAttr > sourceAttrs = new ArrayList <>();
158
- targetAttr .getSourceAttrs ().forEach (sourceAttr ->
159
- sourceAttrs .add (TurAemSourceAttr .builder ()
151
+ return TurAemContentMapping .builder ()
152
+ .deltaClassName (turAemSource .getDeltaClass ())
153
+ .models (getTurAemModels (turAemSource ))
154
+ .targetAttrDefinitions (getTurSNAttributeSpecs (turAemSource ))
155
+ .build ();
156
+ }
157
+
158
+ private @ NotNull List <TurAemModel > getTurAemModels (TurAemSource turAemSource ) {
159
+ return turAemPluginModelRepository .findByTurAemSource (turAemSource )
160
+ .stream ()
161
+ .map (pluginModel ->
162
+ TurAemModel .builder ()
163
+ .className (pluginModel .getClassName ())
164
+ .type (pluginModel .getType ())
165
+ .targetAttrs (getTurAemTargetAttrs (pluginModel ))
166
+ .build ()
167
+ )
168
+ .collect (Collectors .toList ());
169
+ }
170
+
171
+ private static @ NotNull List <TurAemTargetAttr > getTurAemTargetAttrs (TurAemPluginModel pluginModel ) {
172
+ return pluginModel .getTargetAttrs ()
173
+ .stream ()
174
+ .map (targetAttr ->
175
+ TurAemTargetAttr .builder ()
176
+ .name (targetAttr .getName ())
177
+ .sourceAttrs (getTurAemSourceAttrs (targetAttr ))
178
+ .build ()
179
+ ).collect (Collectors .toList ());
180
+ }
181
+
182
+ private static @ NotNull List <TurAemSourceAttr > getTurAemSourceAttrs (TurAemTargetAttribute targetAttr ) {
183
+ return targetAttr .getSourceAttrs ()
184
+ .stream ()
185
+ .map (sourceAttr ->
186
+ TurAemSourceAttr .builder ()
160
187
.className (sourceAttr .getClassName ())
161
188
.name (sourceAttr .getName ())
162
189
.convertHtmlToText (false )
163
190
.uniqueValues (false )
164
- .build ()));
165
- targetAttrs .add (TurAemTargetAttr .builder ()
166
- .name (targetAttr .getName ())
167
- .sourceAttrs (sourceAttrs )
168
- .build ());
169
- });
170
- turAemModels .add (TurAemModel .builder ()
171
- .className (pluginModel .getClassName ())
172
- .type (pluginModel .getType ())
173
- .targetAttrs (targetAttrs )
174
- .build ());
175
- });
191
+ .build ()
192
+ ).collect (Collectors .toList ());
193
+ }
194
+
195
+ private @ NotNull List <TurSNAttributeSpec > getTurSNAttributeSpecs (TurAemSource turAemSource ) {
176
196
List <TurSNAttributeSpec > targetAttrDefinitions = new ArrayList <>();
177
197
turAemAttributeSpecificationRepository .findByTurAemSource (turAemSource )
178
198
.ifPresent (attributeSpecifications ->
@@ -188,12 +208,7 @@ public void finished(TurConnectorSession turConnectorSession, boolean standalone
188
208
.facet (attributeSpec .isFacet ())
189
209
.build ()
190
210
)));
191
-
192
- TurAemContentMapping turAemContentMapping = new TurAemContentMapping ();
193
- turAemContentMapping .setDeltaClassName (turAemSource .getDeltaClass ());
194
- turAemContentMapping .setModels (turAemModels );
195
- turAemContentMapping .setTargetAttrDefinitions (targetAttrDefinitions );
196
- return turAemContentMapping ;
211
+ return targetAttrDefinitions ;
197
212
}
198
213
199
214
private TurAemSourceContext getTurAemSourceContext (IAemConfiguration config ) {
@@ -227,10 +242,9 @@ private void getNodesFromJson(TurAemSourceContext turAemSourceContext,
227
242
TurConnectorSession turConnectorSession ,
228
243
TurAemSource turAemSource ,
229
244
TurAemContentDefinitionProcess turAemContentDefinitionProcess ) {
230
- if (TurAemCommonsUtils .usingContentTypeParameter (turAemSourceContext )) {
231
- byContentTypeList (turAemSourceContext , turConnectorSession , turAemSource ,
232
- turAemContentDefinitionProcess );
233
- }
245
+ if (!TurAemCommonsUtils .usingContentTypeParameter (turAemSourceContext )) return ;
246
+ byContentTypeList (turAemSourceContext , turConnectorSession , turAemSource ,
247
+ turAemContentDefinitionProcess );
234
248
}
235
249
236
250
public void indexContentId (TurConnectorSession session , TurAemSource turAemSource , String contentId ,
@@ -268,7 +282,7 @@ private void byContentTypeList(TurAemSourceContext turAemSourceContext,
268
282
.ifPresentOrElse (turAemModel ->
269
283
byContentType (turAemSourceContext , turConnectorSession , turAemSource ,
270
284
turAemContentDefinitionProcess ),
271
- () -> log .info ("{} type is not configured in CTD Mapping file." ,
285
+ () -> log .debug ("{} type is not configured in CTD Mapping file." ,
272
286
turAemSourceContext .getContentType ()));
273
287
}
274
288
@@ -298,7 +312,7 @@ private void getNodeFromJson(String nodePath, JSONObject jsonObject,
298
312
turAemSourceContext , session , turAemSource ,
299
313
turAemContentDefinitionProcess , standalone ));
300
314
}
301
- }, () -> log .info ("AEM object ({}) is null transactionId = {}" ,
315
+ }, () -> log .debug ("AEM object ({}) is null transactionId = {}" ,
302
316
turAemSourceContext .getId (), session .getTransactionId ()));
303
317
getChildrenFromJson (nodePath , jsonObject , turAemSourceContext , session , turAemSource ,
304
318
turAemContentDefinitionProcess , standalone );
@@ -398,7 +412,7 @@ private void indexObjectByPublication(@NotNull TurAemObject aemObject, TurAemMod
398
412
TurAemCommonsUtils .getLocaleFromAemObject (turAemSourceContext , aemObject ),
399
413
turAemSourceContext , turConnectorSession , turAemContentDefinitionProcess , standalone );
400
414
} else {
401
- log .info ("Ignoring because {} object ({}) is not publishing. transactionId = {}" ,
415
+ log .debug ("Ignoring because {} object ({}) is not publishing. transactionId = {}" ,
402
416
aemObject .getPath (), turAemSourceContext .getId (), turConnectorSession .getTransactionId ());
403
417
}
404
418
}
0 commit comments