summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/RuleEditorController.java
blob: 3f5ff1a72d11a869e0323dbfae61e1685e6b6358 (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
package org.onap.sdc.dcae.composition.controller;

import com.google.gson.JsonParseException;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact;
import org.onap.sdc.dcae.composition.restmodels.sdc.Asset;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.onap.sdc.dcae.composition.CompositionConfig;
import org.onap.sdc.dcae.utils.Normalizers;
import org.onap.sdc.dcae.composition.restmodels.ruleeditor.*;
import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
import org.onap.sdc.dcae.enums.ArtifactType;
import org.onap.sdc.dcae.enums.AssetType;
import org.onap.sdc.dcae.errormng.ActionStatus;
import org.onap.sdc.dcae.errormng.ErrConfMgr;
import org.onap.sdc.dcae.errormng.ErrConfMgr.ApiType;
import org.onap.sdc.dcae.errormng.ServiceException;
import org.onap.sdc.dcae.rule.editor.impl.RulesBusinessLogic;
import org.onap.sdc.dcae.rule.editor.utils.RulesPayloadUtils;
import org.onap.sdc.dcae.utils.SdcRestClientUtils;
import org.onap.sdc.dcae.ves.VesDataItemsDefinition;
import org.onap.sdc.dcae.ves.VesDataTypeDefinition;
import org.onap.sdc.dcae.ves.VesSimpleTypesEnum;
import org.onap.sdc.dcae.ves.VesStructureLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Base64Utils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController 
@EnableAutoConfiguration 
@CrossOrigin 
@RequestMapping("/rule-editor") 
public class RuleEditorController extends BaseController {

    private static final String EXCEPTION = "Exception {}";
    @Autowired
    private CompositionConfig compositionConfig;

    @Autowired
    private RulesBusinessLogic rulesBusinessLogic;

    @RequestMapping(value = "/list-events-by-versions", method = RequestMethod.GET)
    public ResponseEntity getEventsByVersion() {
        try {

            Map<String, Set<String>> eventsByVersions = VesStructureLoader.getAvailableVersionsAndEventTypes();

            List<EventTypesByVersionUI> resBody = eventsByVersions.entrySet().stream().map(entry -> {
                Set<String> events = entry.getValue().stream().filter(event -> !EventTypesByVersionUI.DEFAULT_EVENTS.contains(event)).collect(Collectors.toSet());
                return new EventTypesByVersionUI(entry.getKey(), events);
            }).collect(Collectors.toList());

            debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Got a request to return all ves event types by versions {}", eventsByVersions);
            return new ResponseEntity<>(resBody, HttpStatus.OK);

        } catch (Exception e) {
            errLogger.log(LogLevel.ERROR, this.getClass().getName(), EXCEPTION, e);
            return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.VES_SCHEMA_NOT_FOUND);
        }
    }

    @RequestMapping(value = { "/definition/{version:.*}/{eventType}" }, method = { RequestMethod.GET }, produces = { "application/json" })
    public ResponseEntity getDefinition(@PathVariable("version") String version,
            @PathVariable("eventType") String eventType) {

        try {
            List<EventTypeDefinitionUI> result = getEventTypeDefinitionUIs(version, eventType);

            return new ResponseEntity<>(result, HttpStatus.OK);

        } catch (Exception e) {
            errLogger.log(LogLevel.ERROR, this.getClass().getName(), EXCEPTION, e);
            return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.VES_SCHEMA_NOT_FOUND);
        }
    }

    /**
     * This endpoint functions as a 'create/update' service for the rule editor UI
     *
     * @param json          - json representing the saved rule
     * @param vfcmtUuid     - VFCMT that the rule editor ui is saved in
     * @param dcaeCompLabel - the name of the DCAE Component which the rule is applied to
     * @param nid           - A unique id of the DCAE Component which the rule is applied to - exists also in the cdump
     * @param configParam   - the name of the DCAE Component configuration property the rule is linked to
     * @return json representing the rule editor UI
     * Validations:
     * 1. That the user is able to edit the VFCMT
     * 2. That the cdump holds a dcae component with such nid (to avoid orphan rules)
     * 3. Check that the fetched VFCMT is actually a VFCMT and not a regular VF
     */
    @RequestMapping(value = "/rule/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam}", method = { RequestMethod.POST }, produces = "application/json")
    public ResponseEntity saveRule(@RequestBody String json, @ModelAttribute("requestId") String requestId,
                                                    @RequestHeader("USER_ID") String userId,
                                                    @PathVariable("vfcmtUuid") String vfcmtUuid,
                                                    @PathVariable("dcaeCompLabel") String dcaeCompLabel,
                                                    @PathVariable("nid") String nid,
                                                    @PathVariable("configParam") String configParam) {
        try {
            Rule rule = RulesPayloadUtils.parsePayloadToRule(json);
            if (null == rule) {
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.INVALID_RULE_FORMAT);
            }

            List<ServiceException> errors = rulesBusinessLogic.validateRule(rule);
            if(!errors.isEmpty()){
                return ErrConfMgr.INSTANCE.buildErrorArrayResponse(errors);
            }

            ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(vfcmtUuid, requestId);
            checkVfcmtType(vfcmt);

            if (CollectionUtils.isEmpty(vfcmt.getArtifacts())) {
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.SAVE_RULE_FAILED);
            }

            String artifactLabel = Normalizers.normalizeArtifactLabel(dcaeCompLabel + nid + configParam);

             // check for MappingRules artifact in existing artifacts
            Artifact artifactFound = vfcmt.getArtifacts().stream()
                        .filter(a -> artifactLabel.equals(Normalizers.normalizeArtifactLabel(a.getArtifactLabel())))
                        .findAny().orElse(null);

            // exception thrown if vfcmt is checked out and current user is not its owner
            // performs vfcmt checkout if required
            String vfcmtId = assertOwnershipOfVfcmtId(userId, vfcmt, requestId);
            // new mappingRules artifact, validate nid exists in composition before creating new artifact
            if (null == artifactFound) {
                if(cdumpContainsNid(vfcmt, nid, requestId)) {
                    return saveNewRulesArtifact(rule, vfcmtId, generateMappingRulesFileName(dcaeCompLabel, nid, configParam), artifactLabel , userId, requestId);
                }
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.NODE_NOT_FOUND, "", dcaeCompLabel);
            }

            //update artifact flow - append new rule or edit existing rule
            return addOrEditRuleInArtifact(rule, vfcmtId, userId, artifactFound, requestId);

        } catch (JsonParseException je) {
            errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error: Rule format is invalid: {}", je);
            return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.INVALID_RULE_FORMAT, "", je.getMessage());
        } catch (Exception e) {
            return handleException(e, ErrConfMgr.ApiType.SAVE_RULE_ARTIFACT);
        }

    }


    /**
     * This endpoint functions as a 'fetch' service for the rule editor UI
     *
     * @param vfcmtUuid     - VFCMT that the rule editor ui is saved in
     * @param dcaeCompLabel - the name of the DCAE Component which the rule is applied to
     * @param nid           - A unique id of the DCAE Component which the rule is applied to - exists also in the cdump
     * @param configParam   - the name of the DCAE Component configuration property the rule is linked to
     * @return json representing the rule editor UI
     */
    @RequestMapping(value = "/rule/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam}", method = { RequestMethod.GET }, produces = "application/json")
    public ResponseEntity getRules(
            @PathVariable("vfcmtUuid") String vfcmtUuid,
            @PathVariable("dcaeCompLabel") String dcaeCompLabel,
            @PathVariable("nid") String nid,
            @PathVariable("configParam") String configParam,
            @ModelAttribute("requestId") String requestId) {

        try {
            ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(vfcmtUuid, requestId);
            if (CollectionUtils.isEmpty(vfcmt.getArtifacts())) {
                return new ResponseEntity<>("{}", HttpStatus.OK);
            }
            String artifactLabel = Normalizers.normalizeArtifactLabel(dcaeCompLabel + nid + configParam);

            // check for MappingRules artifact in existing artifacts
            Artifact artifactListed = vfcmt.getArtifacts().stream().filter(a -> artifactLabel.equals(Normalizers.normalizeArtifactLabel(a.getArtifactLabel()))).findAny().orElse(null);
            if (null == artifactListed) {
                return new ResponseEntity<>("{}", HttpStatus.OK);
            }
            String ruleFile = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmtUuid, artifactListed.getArtifactUUID(), requestId);

            // To avoid opening the file for reading we search for the eventType and SchemaVer from the artifact metadata's description
            SchemaInfo schemainfo = RulesPayloadUtils.extractInfoFromDescription(artifactListed);
            List<EventTypeDefinitionUI> schema = null == schemainfo? new ArrayList<>() : getEventTypeDefinitionUIs(schemainfo.getVersion(), schemainfo.getEventType());
            return new ResponseEntity<>(RulesPayloadUtils.buildSchemaAndRulesResponse(ruleFile, schema), HttpStatus.OK);
        } catch (Exception e) {
            return handleException(e, ApiType.GET_RULE_ARTIFACT);
        }

    }

    /**
     * This endpoint functions as a 'delete' service for the rule editor UI
     *
     * @param vfcmtUuid     - VFCMT that the rule editor ui is saved in
     * @param dcaeCompLabel - the name of the DCAE Component which the rule is applied to
     * @param nid           - A unique id of the DCAE Component which the rule is applied to - exists also in the cdump
     * @param configParam   - the name of the DCAE Component configuration property the rule is linked to
     * @param ruleUid   	- the unique id of the rule to delete
     * @return operation result
     */
    @RequestMapping(value = "/rule/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam}/{ruleUid}", method = { RequestMethod.DELETE }, produces = "application/json")
    public ResponseEntity deleteRule(
            @RequestHeader("USER_ID") String userId,
            @PathVariable("vfcmtUuid") String vfcmtUuid,
            @PathVariable("dcaeCompLabel") String dcaeCompLabel,
            @PathVariable("nid") String nid,
            @PathVariable("configParam") String configParam,
            @PathVariable("ruleUid") String ruleUid,
            @ModelAttribute("requestId") String requestId){

        try {
            ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(vfcmtUuid, requestId);
            if (null == vfcmt.getArtifacts()) {
                errLogger.log(LogLevel.ERROR, this.getClass().getName(), "VFCMT {} doesn't have artifacts", vfcmtUuid);
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.DELETE_RULE_FAILED);
            }
            String artifactLabel = Normalizers.normalizeArtifactLabel(dcaeCompLabel + nid + configParam);

            // check for MappingRules artifact in existing artifacts
            Artifact mappingRuleFile = vfcmt.getArtifacts().stream()
                    .filter(a -> artifactLabel.equals(Normalizers.normalizeArtifactLabel(a.getArtifactLabel())))
                    .findAny().orElse(null);

            if (null == mappingRuleFile) {
                errLogger.log(LogLevel.ERROR, this.getClass().getName(), "{} doesn't exist for VFCMT {}", artifactLabel, vfcmtUuid);
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.DELETE_RULE_FAILED);
            }

            String vfcmtId = assertOwnershipOfVfcmtId(userId, vfcmt, requestId);
            String payload = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmtId, mappingRuleFile.getArtifactUUID(), requestId);
            MappingRules rules = RulesPayloadUtils.parseMappingRulesArtifactPayload(payload);
            Rule removedRule = rulesBusinessLogic.deleteRule(rules, ruleUid);
            if(null == removedRule){
                errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Rule {} not found.", ruleUid);
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.DELETE_RULE_FAILED);
            }
            if(rules.isEmpty()){ // if file doesn't contain any rules after last deletion -> let's delete the file
                baseBusinessLogic.getSdcRestClient().deleteResourceArtifact(userId, vfcmtId, mappingRuleFile.getArtifactUUID(), requestId);
            } else {
                updateRulesArtifact(vfcmtId, userId, mappingRuleFile, rules, requestId);
            }
            return checkInAndReturnSaveArtifactResult(removedRule, vfcmtId, userId, requestId);
        } catch (Exception e) {
            return handleException(e, ApiType.SAVE_RULE_ARTIFACT);
        }

    }

    /**
     * This endpoint functions as a 'translate' service for the rule editor UI
     *
     * @param vfcmtUuid     - VFCMT that the rule editor ui is saved in
     * @param dcaeCompLabel - the name of the DCAE Component which the rule is applied to
     * @param nid           - A unique id of the DCAE Component which the rule is applied to - exists also in the cdump
     * @param configParam   - the name of the DCAE Component configuration property the rule is linked to
     * @param flowType		- the mapping rules flow type (SNMP,Syslog,FOI)
     * @return translateJson representing the translated Rules
     * Validations:
     * 1. That the user is able to edit the VFCMT
     * 2. That the cdump holds a dcae component with such nid (to avoid orphan rules)
     * 3. Check that the fetched VFCMT is actually a VFCMT and not a regular VF
     * @throws Exception
     */
    @RequestMapping(value = "/rule/translate/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam}", method = { RequestMethod.GET }, produces = "application/json")
    public ResponseEntity translateRules(@PathVariable("vfcmtUuid") String vfcmtUuid, @ModelAttribute("requestId") String requestId,
                                                 @PathVariable("dcaeCompLabel") String dcaeCompLabel,
                                                 @PathVariable("nid") String nid,
                                                 @PathVariable("configParam") String configParam,
                                                 @RequestParam("flowType") String flowType) throws Exception {

        try {

            if (StringUtils.isBlank(flowType) || MapUtils.isEmpty(compositionConfig.getFlowTypesMap()) || null == compositionConfig.getFlowTypesMap().get(flowType)) {
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.TRANSLATE_FAILED, "", "Flow type " + flowType + " not found");
            }

            // extract entry phase name and last phase name from configuration:
            String entryPointPhaseName = compositionConfig.getFlowTypesMap().get(flowType).getEntryPointPhaseName();
            String lastPhaseName = compositionConfig.getFlowTypesMap().get(flowType).getLastPhaseName();

            ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(vfcmtUuid, requestId);
            checkVfcmtType(vfcmt);

            if (CollectionUtils.isEmpty(vfcmt.getArtifacts())) {
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.TRANSLATE_FAILED, "", "No rules found on VFCMT " + vfcmtUuid);
            }
            String artifactLabel = Normalizers.normalizeArtifactLabel(dcaeCompLabel + nid + configParam);

            // check for MappingRules artifact in existing artifacts
            Artifact rulesArtifact = vfcmt.getArtifacts().stream().filter(a -> artifactLabel.equals(Normalizers.normalizeArtifactLabel(a.getArtifactLabel()))).findAny().orElse(null);

            if (rulesArtifact == null) {
                return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.TRANSLATE_FAILED, "", artifactLabel + " doesn't exist on VFCMT " + vfcmtUuid);
            }

            String payload = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmtUuid, rulesArtifact.getArtifactUUID(), requestId);
            debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Retrieved mapping rules artifact {}, start parsing rules...", artifactLabel);
            MappingRules rules = RulesPayloadUtils.parseMappingRulesArtifactPayload(payload);
            debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Finished parsing rules, calling validator...");
            List<ServiceException> errors = rulesBusinessLogic.validateRules(rules);
            if (!errors.isEmpty()) {
                return ErrConfMgr.INSTANCE.buildErrorArrayResponse(errors);
            }

            debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Validation completed successfully, calling translator...");
            String translateJson = rulesBusinessLogic.translateRules(rules, entryPointPhaseName, lastPhaseName, vfcmt.getName());
            debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Translation completed successfully");
            return new ResponseEntity<>(translateJson, HttpStatus.OK);
        } catch (Exception e) {
            return handleException(e, ApiType.SAVE_RULE_ARTIFACT);
        }
    }


    ///////////////////PRIVATE METHODS////////////////////////////////////////////////////////////////////////

    private String assertOwnershipOfVfcmtId(String userId, ResourceDetailed vfcmt, String requestId) throws Exception {
        checkUserIfResourceCheckedOut(userId, vfcmt);
        String newVfcmtId = vfcmt.getUuid(); // may change after checking out a certified vfcmt
        if (isNeedToCheckOut(vfcmt.getLifecycleState())) {
            Asset result = checkout(userId, newVfcmtId, AssetType.RESOURCE, requestId);
            if (result != null) {
                newVfcmtId = result.getUuid();
                debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "New resource after checkout is: {}", newVfcmtId);
            }
        }
        return newVfcmtId;
    }



    // called after validating vfcmt.getArtifacts() is not null
    private boolean cdumpContainsNid(ResourceDetailed vfcmt, String nid, String requestId) {
        Artifact cdump = vfcmt.getArtifacts().stream()
                .filter(a -> DcaeBeConstants.Composition.fileNames.COMPOSITION_YML.equalsIgnoreCase(a.getArtifactName()))
                .findAny().orElse(null);
        if (null == cdump || null == cdump.getArtifactUUID()) {
            errLogger.log(LogLevel.ERROR, this.getClass().getName(), "No {} found on vfcmt {}", DcaeBeConstants.Composition.fileNames.COMPOSITION_YML, vfcmt.getUuid());
            return false;
        }
        try {
            String artifact = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmt.getUuid(), cdump.getArtifactUUID(), requestId);
            if (!artifact.contains("\"nid\":\""+nid)) {
                errLogger.log(LogLevel.ERROR, this.getClass().getName(), "{} doesn't contain nid {}. Cannot save mapping rule file", DcaeBeConstants.Composition.fileNames.COMPOSITION_YML, nid);
                return false;
            }
        } catch (Exception e) {
            errLogger.log(LogLevel.ERROR, this.getClass().getName(), EXCEPTION, e);
            return false;
        }
        return true;
    }

    private ResponseEntity<String> saveNewRulesArtifact(Rule rule, String vfcmtUuid, String artifactFileName, String artifactLabel, String userId, String requestId) throws Exception {
        MappingRules body = new MappingRules(rule);
        Artifact artifact = SdcRestClientUtils.generateDeploymentArtifact(body.describe(), artifactFileName, ArtifactType.OTHER.name(), artifactLabel, body.convertToPayload());
        baseBusinessLogic.getSdcRestClient().createResourceArtifact(userId, vfcmtUuid, artifact, requestId);
        return checkInAndReturnSaveArtifactResult(rule, vfcmtUuid, userId, requestId);
    }

    private ResponseEntity addOrEditRuleInArtifact(Rule rule, String vfcmtUuid, String userId, Artifact rulesArtifact, String requestId) throws Exception {
        String payload = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmtUuid, rulesArtifact.getArtifactUUID(), requestId);
        MappingRules rules = RulesPayloadUtils.parseMappingRulesArtifactPayload(payload);

        // in case the rule id is passed but the rule doesn't exist on the mapping rule file:
        if(!rulesBusinessLogic.addOrEditRule(rules, rule)) {
            return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.SAVE_RULE_FAILED);
        }
        updateRulesArtifact(vfcmtUuid, userId, rulesArtifact, rules, requestId);
        return checkInAndReturnSaveArtifactResult(rule, vfcmtUuid, userId, requestId);
    }

    // regardless of check in result, return save artifact success
    private ResponseEntity<String> checkInAndReturnSaveArtifactResult(Rule rule, String vfcmtUuid, String userId, String requestId) {
        try {
            checkin(userId, vfcmtUuid, AssetType.RESOURCE, requestId);
        } catch (Exception e) {
            // swallowing the exception intentionally since it is on the check in action
            errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error occurred while performing check in on VFCMT {}:{}", vfcmtUuid, e);
        }
        return new ResponseEntity<>(rule.toJson(), HttpStatus.OK);
    }

    private void updateRulesArtifact(String vfcmtUuid, String userId, Artifact artifactInfo, MappingRules rules, String requestId) throws Exception {
        artifactInfo.setPayloadData(Base64Utils.encodeToString(rules.convertToPayload()));
        // POST must contain 'description' while GET returns 'artifactDescription'
        artifactInfo.setDescription(artifactInfo.getArtifactDescription());
        baseBusinessLogic.getSdcRestClient().updateResourceArtifact(userId, vfcmtUuid, artifactInfo, requestId);
    }


    /**
     * @param eventMapStream
     * @param parent
     * @param path
     * @return
     */
    private List<EventTypeDefinitionUI> convertToEventTypeDefinition(Stream<Entry<String, VesDataTypeDefinition>> eventMapStream, VesDataTypeDefinition parent, String path) {

        return eventMapStream.map(entry -> {
            Map<String, VesDataTypeDefinition> properties = entry.getValue().getProperties();
            VesDataItemsDefinition items = entry.getValue().getItems();
            String newPath = path + "." + entry.getKey();
            List<EventTypeDefinitionUI> children = (properties == null) ? null : convertToEventTypeDefinition(properties.entrySet().stream(), entry.getValue(), newPath);
            if(VesSimpleTypesEnum.ARRAY.getType().equals(entry.getValue().getType())) {
                newPath += "[]";
                if(innerTypeIsComplex(items)) {
                    children = convertComplexArrayType(items, newPath);
                } else if(innerTypeIsArray(items)) {
                    newPath += "[]";
                }
            }

            boolean isRequired = (parent != null) ? parent.getRequired().contains(entry.getKey()) : false;
            return new EventTypeDefinitionUI(entry.getKey(), children, isRequired, newPath);
        }).collect(Collectors.toList());
    }

    private boolean innerTypeIsComplex(VesDataItemsDefinition items){
        return items != null && items.stream().anyMatch(p -> p.getProperties() != null);
    }

    private boolean innerTypeIsArray(VesDataItemsDefinition items){
        return items != null && items.stream().anyMatch(p -> p.getItems() != null);
    }

    private List<EventTypeDefinitionUI> convertComplexArrayType(VesDataItemsDefinition items, String path){
        return items.stream().map(item -> item.getProperties() != null ? convertToEventTypeDefinition(item.getProperties().entrySet().stream(), item, path) : new ArrayList<EventTypeDefinitionUI>())
                .flatMap(List::stream).collect(Collectors.toList());
    }


    private String generateMappingRulesFileName(String dcaeCompLabel, String nid, String configParam) {
        return dcaeCompLabel + "_" + nid + "_" + configParam + DcaeBeConstants.Composition.fileNames.MAPPING_RULE_POSTFIX;
    }

    private List<EventTypeDefinitionUI> getEventTypeDefinitionUIs(String version, String eventType) {
        List<String> eventNamesToReturn = ListUtils.union(EventTypesByVersionUI.DEFAULT_EVENTS, Arrays.asList(eventType));
        Map<String, VesDataTypeDefinition> eventDefs = VesStructureLoader.getEventListenerDefinitionByVersion(version);
        Stream<Entry<String, VesDataTypeDefinition>> filteredEvents = eventDefs.entrySet().stream().filter(entry -> eventNamesToReturn.contains(entry.getKey()));

        return convertToEventTypeDefinition(filteredEvents, null, "event");
    }
}