summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java22
-rw-r--r--openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java6
-rw-r--r--openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java22
3 files changed, 15 insertions, 35 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java
index 199d11da98..dac9eae9ad 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java
@@ -16,21 +16,6 @@
package org.openecomp.sdc.enrichment.impl.external.artifact;
-import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME;
-import static org.openecomp.sdc.tosca.services.ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME;
-
-import java.io.File;
-import java.io.IOException;
-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.Optional;
-import java.util.Set;
-
import org.onap.sdc.tosca.datatypes.model.Directive;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
@@ -60,6 +45,13 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity;
import org.openecomp.sdc.versioning.dao.types.Version;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+
+import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME;
+import static org.openecomp.sdc.tosca.services.ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME;
+
public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface {
private EnrichedServiceModelDao enrichedServiceModelDao;
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java
index a3f0c4a931..8f3c57f432 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java
@@ -42,11 +42,7 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
/**
* Created by Talio on 11/24/2016
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
index 669fb1c0ee..266d1346e4 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
@@ -16,23 +16,8 @@
package org.openecomp.sdc.enrichment.impl.tosca;
-import static org.openecomp.sdc.tosca.services.DataModelUtil.getClonedObject;
-import static org.openecomp.sdc.tosca.services.ToscaConstants.PORT_MIRRORING_CAPABILITY_CP_PROPERTY_NAME;
-import static org.openecomp.sdc.tosca.services.ToscaConstants.PORT_MIRRORING_CAPABILITY_ID;
-
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.Import;
@@ -50,6 +35,13 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.tosca.services.DataModelUtil.getClonedObject;
+import static org.openecomp.sdc.tosca.services.ToscaConstants.PORT_MIRRORING_CAPABILITY_CP_PROPERTY_NAME;
+import static org.openecomp.sdc.tosca.services.ToscaConstants.PORT_MIRRORING_CAPABILITY_ID;
+
public class PortMirroringEnricher {
private static final String ABSTRACT_LINK_REQUIREMENT_ID_PREFIX = ToscaConstants.LINK_REQUIREMENT_ID + "_";
private static final int ABSTRACT_LINK_REQUIREMENT_ID_PREFIX_LENGTH = ABSTRACT_LINK_REQUIREMENT_ID_PREFIX.length();
al.Number.Integer.Long */ }
/*-
 * ============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=========================================================
 */

import * as _ from "lodash";

class basePattern {
    pattern:RegExp;
    base:number;

    constructor(pattern:RegExp, base:number) {
        this.pattern = pattern;
        this.base = base;
    }
}

export interface IMapRegex {
    integer:RegExp;
    boolean:RegExp;
    float:RegExp;
    string:RegExp;
}

export class ValidationUtils {

    static '$inject' = [
        'IntegerNoLeadingZeroValidationPattern',
        'FloatValidationPattern',
        'CommentValidationPattern',
        'BooleanValidationPattern',
        'NumberValidationPattern',
        'LabelValidationPattern',
    ];
    private trueRegex:string = '[t][r][u][e]|[t]|[o][n]|[y]|[y][e][s]|[1]';
    private falseRegex:string = '[f][a][l][s][e]|[f]|[o][f][f]|[n]|[n][o]|[0]';
    private heatBooleanValidationPattern:RegExp = new RegExp('^(' + this.trueRegex + '|' + this.falseRegex + ')$');


    constructor(private IntegerNoLeadingZeroValidationPattern:RegExp,
                private FloatValidationPattern:RegExp,
                private CommentValidationPattern:RegExp,
                private BooleanValidationPattern:RegExp,
                private NumberValidationPattern:RegExp,
                private LabelValidationPattern:RegExp) {
    }

    public stripAndSanitize(text:string):string {
        if (!text) {
            return null;
        }
        return text.replace(/\s+/g, ' ').replace(/%[A-Fa-f0-9]{2}/g, '').trim();
    }

    public getValidationPattern = (validationType:string, parameterType?:string):RegExp => {
        switch (validationType) {
            case 'integer':
                return this.IntegerNoLeadingZeroValidationPattern;
            case 'float':
                return this.FloatValidationPattern;
            case 'number':
                return this.NumberValidationPattern;
            case 'string':
                return this.CommentValidationPattern;
            case 'boolean':
            {
                //Bug Fix DE197437 [Patch]Mismatch between BE to FE regarding supported characters in Boolean filed
                if (parameterType && parameterType === 'heat') {
                    return this.heatBooleanValidationPattern;
                }
                else {
                    return this.BooleanValidationPattern;
                }
            }

            case 'label':
                return this.LabelValidationPattern;
            case 'category':
                return this.LabelValidationPattern;
            default :
                return null;
        }
    };

    public getPropertyListPatterns():IMapRegex {
        return {
            integer: /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)(,?(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+))*$/,
            string: /^"[\u0000-\u0021\u0023-\u00BF]+"(\s*,?\s*"[\u0000-\u0021\u0023-\u00BF]+")*$/,
            boolean: /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])(,?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]))*$/,
            float: /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?(,?[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?)*$/
        };
    }

    public getPropertyMapPatterns():IMapRegex {
        return {
            integer: /^"\w+"\s*:\s?(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)+(\s*,?\s*"\w+"\s?:\s?(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)+)*$/,
            string: /^"\w+"\s?:\s?"[\u0000-\u0021\u0023-\u00BF]*"(\s*,?\s*"\w+"\s?:\s?"[\u0000-\u0021\u0023-\u00BF]*")*$/,
            boolean: /^"\w+"\s?:\s?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])(\s*,?\s*"\w+"\s?:\s?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]))*$/,
            float: /^"\w+"\s?:\s?[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?(\s*,?\s*"\w+"\s?:\s?[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?)*$/
        };
    }

    public validateUniqueKeys(viewValue:string):boolean {
        if (!viewValue) {
            return true; //allow empty value
        }

        let json:string = "{" + viewValue.replace(/\s\s+/g, ' ') + "}";
        try {
            let obj:any = JSON.parse(json);
            /*
             //Method #1 : check json string length before & after parsing
             let newJson:string = JSON.stringify(obj);
             if (newJson.length < json.length) {
             return false;
             }*/

            //Method #2 : check how many times we can find "KEY": in json string
            let result:boolean = true;
            Object.keys(obj).forEach((key:string) => {
                result = result && json.split('"' + key + '":').length === 2;
            });
            return result;

        } catch (e) {
            return false; //not a valid JSON
        }

        //return true;
    }

    public validateJson = (json:string):boolean => {
        try {
            JSON.parse(json);
            return true;
        } catch (err) {
            console.log('invalid json');
            return false;
        }
    };

    public validateIntRange = (value:string):boolean => {

        let base8 = new basePattern(/^([-+]?0o[0-7]+)$/, 8);
        let base10 = new basePattern(/^(0|[-+]?[1-9][0-9]*)$/, 10);
        let base16 = new basePattern(/^([-+]?0x[0-9a-fA-F]+)$/, 16);

        let min:number = -0x80000000;
        let max:number = 0x7fffffff;
        let intPatterns:Array<basePattern> = [base8, base10, base16];
        let matchedBase = _.find(intPatterns, (item)=> {
            return item.pattern.test(value);
        });

        let parsed:number = parseInt(value.replace('o', ''), matchedBase.base);
        if (parsed) {
            return min <= parsed && max >= parsed;
        }
    }
}