aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java
blob: 81cacf75ac6ddbc65a0841635d2d21e765098361 (plain)
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
import org.openecomp.sdc.versioning.dao.types.Version;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class CompositionEntityDataManagerImpl implements CompositionEntityDataManager {

  private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR =
      "COMPOSITION_ENTITY_DATA_MANAGER_ERR";
  private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG =
      "Invalid input: %s may not be null";

  private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();

  private Map<CompositionEntityId, CompositionEntityData> entities = new HashMap<>();
  private Map<CompositionEntityType, String> nonDynamicSchemas = new HashMap<>();
  private List<CompositionEntityValidationData> roots = new ArrayList<>();

  private VendorSoftwareProductInfoDao vspInfoDao;
  private ComponentDao componentDao;
  private NicDao nicDao;
  private NetworkDao networkDao;

  public CompositionEntityDataManagerImpl(VendorSoftwareProductInfoDao vspInfoDao,
                                          ComponentDao componentDao,
                                          NicDao nicDao, NetworkDao networkDao) {
    this.vspInfoDao = vspInfoDao;
    this.componentDao = componentDao;
    this.nicDao = nicDao;
    this.networkDao = networkDao;
  }

  /**
   * Validate entity composition entity validation data.
   *
   * @param entity                the entity
   * @param schemaTemplateContext the schema template context
   * @param schemaTemplateInput   the schema template input
   * @return the composition entity validation data
   */
  @Override
  public CompositionEntityValidationData validateEntity(CompositionEntity entity,
                                                        SchemaTemplateContext schemaTemplateContext,
                                                        SchemaTemplateInput schemaTemplateInput) {
    mdcDataDebugMessage.debugEntryMessage(null);

    if (entity == null) {
      throw new CoreException(
          new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
              .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
              String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity"))
              .build());
    }
    if (schemaTemplateContext == null) {
      throw new CoreException(
          new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
              .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
              String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context"))
              .build());
    }

    CompositionEntityValidationData validationData =
        new CompositionEntityValidationData(entity.getType(), entity.getId());
    String json =
        schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData()
            : entity.getQuestionnaireData();
    validationData.setErrors(JsonUtil.validate(
        json == null ? JsonUtil.object2Json(new Object()) : json,
        generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput)));

    mdcDataDebugMessage.debugExitMessage(null);
    return validationData;
  }

  /**
   * Add entity.
   *
   * @param entity              the entity
   * @param schemaTemplateInput the schema template input
   */
  @Override
  public void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) {
    if (entity == null) {
      throw new CoreException(
          new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
              .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
              String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity"))
              .build());
    }
    entities.put(entity.getCompositionEntityId(),
        new CompositionEntityData(entity, schemaTemplateInput));
  }

  /**
   * Validate entities questionnaire map.
   *
   * @return the map
   */
  @Override
  public Map<CompositionEntityId, Collection<String>> validateEntitiesQuestionnaire() {
    mdcDataDebugMessage.debugEntryMessage(null);

    Map<CompositionEntityId, Collection<String>> errorsByEntityId = new HashMap<>();
    entities.entrySet().forEach(entry -> {
      Collection<String> errors = validateQuestionnaire(entry.getValue());
      if (errors != null) {
        errorsByEntityId.put(entry.getKey(), errors);
      }
    });

    mdcDataDebugMessage.debugExitMessage(null);
    return errorsByEntityId;
  }

  /**
   * Build trees.
   */
  @Override
  public void buildTrees() {
    Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData =
        new HashMap<>();
    entities.entrySet().forEach(
        entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(),
            entry.getValue().entity));
  }

  public Collection<CompositionEntityValidationData> getTrees() {
    return roots;
  }

  @Override
  public void saveCompositionData(String vspId, Version version, CompositionData compositionData) {
    mdcDataDebugMessage.debugEntryMessage(null);

    if (Objects.isNull(compositionData)) {
      return;
    }

    Map<String, String> networkIdByName = saveNetworks(vspId, version, compositionData);
    saveComponents(vspId, version, compositionData, networkIdByName);

    mdcDataDebugMessage.debugExitMessage(null);
  }

  @Override
  public Set<CompositionEntityValidationData> getAllErrorsByVsp(String vspId) {
    CompositionEntityValidationData matchVsp = null;
    Set<CompositionEntityValidationData> entitiesWithErrors = new HashSet<>();
    for (CompositionEntityValidationData root : roots) {
      if (root.getEntityId().equals(vspId)) {
        matchVsp = root;
        break;
      }
    }

    getEntityListWithErrors(matchVsp, entitiesWithErrors);
    if (CollectionUtils.isNotEmpty(entitiesWithErrors)) {
      updateValidationCompositionEntityName(entitiesWithErrors);
      return entitiesWithErrors;
    }

    return null;
  }

  private boolean isThereErrorsInSubTree(CompositionEntityValidationData entity) {
    if (Objects.isNull(entity)) {
      return false;
    }

    if (CollectionUtils.isNotEmpty(entity.getErrors())) {
      return true;
    }

    Collection<CompositionEntityValidationData> subEntitiesValidationData =
        entity.getSubEntitiesValidationData();
    return !CollectionUtils.isEmpty(subEntitiesValidationData) &&
        checkForErrorsInChildren(subEntitiesValidationData);

  }

  private boolean checkForErrorsInChildren(
      Collection<CompositionEntityValidationData> subEntitiesValidationData) {
    boolean result = false;
    for (CompositionEntityValidationData subEntity : subEntitiesValidationData) {
      if (CollectionUtils.isNotEmpty(subEntity.getErrors())) {
        return true;
      }

      result = result || isThereErrorsInSubTree(subEntity);
      if (result) {
        return true;
      }
    }
    return false;
  }

  public void saveComponents(String vspId, Version version, CompositionData compositionData,
                             Map<String, String> networkIdByName) {


    mdcDataDebugMessage.debugEntryMessage(null);

    if (CollectionUtils.isNotEmpty(compositionData.getComponents())) {
      for (Component component : compositionData.getComponents()) {
        ComponentEntity componentEntity = new ComponentEntity(vspId, version, null);
        componentEntity.setComponentCompositionData(component.getData());

        String componentId = createComponent(componentEntity).getId();

        saveNicsByComponent(vspId, version, networkIdByName, component, componentId);
      }
    }

    mdcDataDebugMessage.debugExitMessage(null);
  }

  public void saveNicsByComponent(String vspId, Version version,
                                  Map<String, String> networkIdByName, Component component,
                                  String componentId) {
    if (CollectionUtils.isNotEmpty(component.getNics())) {
      for (Nic nic : component.getNics()) {
        if (nic.getNetworkName() != null && MapUtils.isNotEmpty(networkIdByName)) {
          nic.setNetworkId(networkIdByName.get(nic.getNetworkName()));
        }
        nic.setNetworkName(null);

        NicEntity nicEntity = new NicEntity(vspId, version, componentId, null);
        nicEntity.setNicCompositionData(nic);
        createNic(nicEntity);
      }
    }
  }

  public Map<String, String> saveNetworks(String vspId, Version version,
                                          CompositionData compositionData) {
    mdcDataDebugMessage.debugEntryMessage(null);

    Map<String, String> networkIdByName = new HashMap<>();
    if (CollectionUtils.isNotEmpty(compositionData.getNetworks())) {
      for (Network network : compositionData.getNetworks()) {

        NetworkEntity networkEntity = new NetworkEntity(vspId, version, null);
        networkEntity.setNetworkCompositionData(network);

        if (network.getName() != null) {
          networkIdByName.put(network.getName(), createNetwork(networkEntity).getId());
        }
      }
    }

    mdcDataDebugMessage.debugExitMessage(null);
    return networkIdByName;
  }

  @Override
  public NetworkEntity createNetwork(NetworkEntity network) {
    mdcDataDebugMessage.debugEntryMessage(null);

    //network.setId(CommonMethods.nextUuId()); will be set by the dao
    networkDao.create(network);
    mdcDataDebugMessage.debugExitMessage(null);
    return network;
  }

  @Override
  public ComponentEntity createComponent(ComponentEntity component) {
    mdcDataDebugMessage.debugEntryMessage(null);

    //component.setId(CommonMethods.nextUuId()); will be set by the dao
    component.setQuestionnaireData(
        new JsonSchemaDataGenerator(
            generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component,
                null))
            .generateData());

    componentDao.create(component);

    mdcDataDebugMessage.debugExitMessage(null);
    return component;
  }

  @Override
  public NicEntity createNic(NicEntity nic) {
    mdcDataDebugMessage.debugEntryMessage(null);

    //nic.setId(CommonMethods.nextUuId()); will be set by the dao
    nic.setQuestionnaireData(
        new JsonSchemaDataGenerator(
            generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null))
            .generateData());

    nicDao.create(nic);

    mdcDataDebugMessage.debugExitMessage(null);
    return nic;
  }


  public void addErrorsToTrees(Map<CompositionEntityId, Collection<String>> errors) {
    roots.forEach(root -> addErrorsToTree(root, null, errors));
  }

  /* *
  * get a flat list of all questionnaire entities that have validation errors
  * */
  public Set<CompositionEntityValidationData> getEntityListWithErrors() {
    mdcDataDebugMessage.debugEntryMessage(null);
    Set<CompositionEntityValidationData> treeAsList = new HashSet<>();

    for (CompositionEntityValidationData entity : roots) {
      if (CollectionUtils.isNotEmpty(entity.getErrors())) {
        addNodeWithErrors(entity, treeAsList);
      }
      getEntityListWithErrors(entity, treeAsList);
    }

    updateValidationCompositionEntityName(treeAsList);

    mdcDataDebugMessage.debugExitMessage(null);
    return treeAsList;
  }

  public void getEntityListWithErrors(CompositionEntityValidationData entity,
                                      Set<CompositionEntityValidationData> compositionSet) {
    Collection<CompositionEntityValidationData> childNodes =
        entity.getSubEntitiesValidationData();

    if (CollectionUtils.isEmpty(childNodes)) {
      return;
    }

    for (CompositionEntityValidationData child : childNodes) {
      if (CollectionUtils.isNotEmpty(child.getErrors())) {
        addNodeWithErrors(child, compositionSet);
      }
      getEntityListWithErrors(child, compositionSet);
    }
  }


  public void addNodeWithErrors(CompositionEntityValidationData node,
                                Set<CompositionEntityValidationData> entitiesWithErrors) {
    CompositionEntityValidationData compositionNodeToAdd = new CompositionEntityValidationData(node
        .getEntityType(), node.getEntityId());
    compositionNodeToAdd.setErrors(node.getErrors());
    compositionNodeToAdd.setSubEntitiesValidationData(null);

    entitiesWithErrors.add(compositionNodeToAdd);
  }

  public void removeNodesWithoutErrors() {
    roots.forEach(root -> removeNodesWithoutErrors(root, null));
  }


  private CompositionEntityData getCompositionEntityDataById(CompositionEntityValidationData
                                                                 entity) {
    for (Map.Entry<CompositionEntityId, CompositionEntityData> entityEntry : entities
        .entrySet()) {
      if (entityEntry.getKey().getId().equals(entity.getEntityId())) {
        return entityEntry.getValue();
      }
    }
    return null;
  }


  private void updateValidationCompositionEntityName(Set<CompositionEntityValidationData>
                                                         compositionSet) {
    for (CompositionEntityValidationData entity : compositionSet) {
      String compositionData = getCompositionDataAsString(entity);
      if (entity.getEntityType().equals(CompositionEntityType.vsp) ||
          Objects.nonNull(compositionData)) {
        entity.setEntityName(getEntityNameByEntityType(compositionData, entity));
      }
    }
  }

  private String getCompositionDataAsString(CompositionEntityValidationData entity) {
    CompositionEntityData compositionEntityData = getCompositionEntityDataById(entity);
    return compositionEntityData == null ? null : compositionEntityData.entity.getCompositionData();
  }


  private String getEntityNameByEntityType(String compositionData,
                                           CompositionEntityValidationData entity) {
    switch (entity.getEntityType()) {
      case component:
        ComponentData component = JsonUtil.json2Object(compositionData, ComponentData.class);
        return component.getDisplayName();

      case nic:
        Nic nic = JsonUtil.json2Object(compositionData, Nic.class);
        return nic.getName();

      case network:
        Network network = JsonUtil.json2Object(compositionData, Network.class);
        return network.getName();

      case vsp:
        CompositionEntityData vspEntity = getCompositionEntityDataById(entity);
        VspQuestionnaireEntity vspQuestionnaireEntity = (VspQuestionnaireEntity) vspEntity.entity;
        VspDetails vspDetails =
            vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(),
                    vspQuestionnaireEntity.getVersion()));
        return vspDetails.getName();
    }

    return null;
  }

  private void removeNodesWithoutErrors(CompositionEntityValidationData node,
                                        CompositionEntityValidationData parent) {

    if (Objects.isNull(node)) {
      return;
    }

    if (hasChildren(node)) {
      Collection<CompositionEntityValidationData> subNodes =
          new ArrayList<>(node.getSubEntitiesValidationData());
      subNodes.forEach(subNode -> removeNodesWithoutErrors(subNode, node));
      node.setSubEntitiesValidationData(subNodes);

      if (canNodeGetRemovedFromValidationDataTree(node)) {
        removeNodeFromChildren(parent, node);
      }
    } else if (canNodeGetRemovedFromValidationDataTree(node)) {
      removeNodeFromChildren(parent, node);
    }
  }

  private void removeNodeFromChildren(CompositionEntityValidationData parent,
                                      CompositionEntityValidationData childToRemove) {
    if (!Objects.isNull(parent)) {
      parent.getSubEntitiesValidationData().remove(childToRemove);
    }
  }

  private boolean hasChildren(CompositionEntityValidationData node) {
    return !CollectionUtils.isEmpty(node.getSubEntitiesValidationData());
  }

  private boolean canNodeGetRemovedFromValidationDataTree(CompositionEntityValidationData node) {
    return !hasChildren(node) && CollectionUtils.isEmpty(node.getErrors());
  }


  private void addValidationDataEntity(
      Map<CompositionEntityId, CompositionEntityValidationData> entitiesValidationData,
      CompositionEntityId entityId, CompositionEntity entity) {
    if (entitiesValidationData.containsKey(entityId)) {
      return;
    }

    CompositionEntityValidationData validationData =
        new CompositionEntityValidationData(entity.getType(), entity.getId());
    entitiesValidationData.put(entityId, validationData);

    CompositionEntityId parentEntityId = entityId.getParentId();
    if (parentEntityId == null) {
      roots.add(validationData);
    } else {
      CompositionEntityData parentEntity = entities.get(parentEntityId);
      if (parentEntity == null) {
        roots.add(validationData);
      } else {
        addValidationDataEntity(entitiesValidationData, parentEntityId, parentEntity.entity);
        entitiesValidationData.get(parentEntityId).addSubEntityValidationData(validationData);
      }
    }
  }

  private void addErrorsToTree(CompositionEntityValidationData node,
                               CompositionEntityId parentNodeId,
                               Map<CompositionEntityId, Collection<String>> errors) {
    if (node == null) {
      return;
    }
    CompositionEntityId nodeId = new CompositionEntityId(node.getEntityId(), parentNodeId);
    node.setErrors(errors.get(nodeId));

    if (node.getSubEntitiesValidationData() != null) {
      node.getSubEntitiesValidationData()
          .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors));
    }
  }

  private Collection<String> validateQuestionnaire(CompositionEntityData compositionEntityData) {
    return JsonUtil.validate(
        compositionEntityData.entity.getQuestionnaireData() == null
            ? JsonUtil.object2Json(new Object())
            : compositionEntityData.entity.getQuestionnaireData(),
        getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire,
            compositionEntityData.schemaTemplateInput));
  }

  private String getSchema(CompositionEntityType compositionEntityType,
                           SchemaTemplateContext schemaTemplateContext,
                           SchemaTemplateInput schemaTemplateInput) {
    return schemaTemplateInput == null
        ? nonDynamicSchemas.computeIfAbsent(compositionEntityType,
        k -> generateSchema(schemaTemplateContext, compositionEntityType, null))
        : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput);
  }

  private static class CompositionEntityData {
    private CompositionEntity entity;
    private SchemaTemplateInput schemaTemplateInput;

    CompositionEntityData(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) {
      this.entity = entity;
      this.schemaTemplateInput = schemaTemplateInput;
    }

  }

  // todo - make SchemaGenerator non static and mock it in UT instead of mocking this method (and
  // make the method private

  protected String generateSchema(SchemaTemplateContext schemaTemplateContext,
                                  CompositionEntityType compositionEntityType,
                                  SchemaTemplateInput schemaTemplateInput) {
    return SchemaGenerator
        .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput);
  }
}