diff options
Diffstat (limited to 'src/main/java/org/onap/dcae/common')
6 files changed, 396 insertions, 74 deletions
diff --git a/src/main/java/org/onap/dcae/common/ConfigProcessors.java b/src/main/java/org/onap/dcae/common/ConfigProcessors.java index c459bb1c..d1c5e5a0 100644 --- a/src/main/java/org/onap/dcae/common/ConfigProcessors.java +++ b/src/main/java/org/onap/dcae/common/ConfigProcessors.java @@ -54,8 +54,9 @@ public class ConfigProcessors { if (filter == null || isFilterMet(filter)) { getEventObjectVal(field); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -65,8 +66,9 @@ public class ConfigProcessors { final JSONObject filter = jsonObject.optJSONObject(FILTER); if (filter == null || isFilterMet(filter)) { setEventObjectVal(field, value); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -85,8 +87,9 @@ public class ConfigProcessors { if (filter == null || isFilterMet(filter)) { setEventObjectVal("suppressEvent", "true"); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -99,8 +102,9 @@ public class ConfigProcessors { if (filter == null || isFilterMet(filter)) { setEventObjectVal(field, value, fieldType); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -111,8 +115,9 @@ public class ConfigProcessors { final JSONObject filter = jsonObject.optJSONObject(FILTER); if (filter == null || isFilterMet(filter)) { setEventObjectVal(field, value); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -123,8 +128,9 @@ public class ConfigProcessors { if (filter == null || isFilterMet(filter)) { removeEventKey(field); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -152,8 +158,9 @@ public class ConfigProcessors { removeEventKey(oldfsplit[0]); setEventObjectVal(fsplit[0], ja); } - } else + } else { log.info(FILTER_NOT_MET); + } } private void renameObject(JSONObject jsonObject) // map @@ -170,29 +177,30 @@ public class ConfigProcessors { setEventObjectVal(field, oldValue); removeEventKey(oldField); } - } else + } else { log.info(FILTER_NOT_MET); + } } - + public void map(JSONObject jsonObject) { final String field = jsonObject.getString(FIELD); final String mapType = jsonObject.optString(MAP_TYPE, ""); if (field.contains("[]")) { - if (field.matches(".*\\[\\]\\..*\\[\\]")) + if (field.matches(".*\\[\\]\\..*\\[\\]")) { renameArrayInArray(jsonObject); - else + } else { mapToJArray(jsonObject); + } + } else if ("hashmapToNameValueArray".equals(mapType)) { + mapHashmapToNameValueArray(jsonObject); + } else if ("nameValueArrayToHashmap".equals(mapType)) { + mapNameValueArrayToHashmap(jsonObject); + } else if ("renameObject".equals(mapType)) { + renameObject(jsonObject); + } else { + mapAttribute(jsonObject); } - else if (mapType.equals("hashmapToNameValueArray")) - mapHashmapToNameValueArray(jsonObject); - else if (mapType.equals("nameValueArrayToHashmap")) - mapNameValueArrayToHashmap(jsonObject); - else if (mapType.equals("renameObject")) - renameObject(jsonObject); - - else - mapAttribute(jsonObject); } private String performOperation(String operation, String value) { @@ -216,15 +224,17 @@ public class ConfigProcessors { value = getEventObjectVal(oldField).toString(); if (!value.equals(OBJECT_NOT_FOUND)) { - if (operation != null && !operation.isEmpty()) + if (operation != null && !operation.isEmpty()) { value = performOperation(operation, value); + } setEventObjectVal(field, value); removeEventKey(oldField); } - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -270,16 +280,21 @@ public class ConfigProcessors { setEventObjectVal(field, ja); } } else // if new array + { setEventObjectVal(field + "[0]", new JSONObject(value), "JArray"); + } } else // oldfield is jsonArray + { setEventObjectVal(field, new JSONArray(value)); + } removeEventKey(oldField); } - } else + } else { log.info(FILTER_NOT_MET); + } } - + // this method is to support the mapping 5.x to VES7.x format for additionalInformation field private void mapNameValueArrayToHashmap(JSONObject jsonObject) { log.info("mapNameValueArrayToHashmap"); @@ -288,17 +303,17 @@ public class ConfigProcessors { final JSONObject filter = jsonObject.optJSONObject(FILTER); if (filter == null || isFilterMet(filter)) { - JSONObject newHashMap = new JSONObject(); // this will hold the newly mapped hashmap elements + JSONObject newHashMap = new JSONObject(); // this will hold the newly mapped hashmap elements JSONArray arrayValue = (JSONArray) getEventObjectVal(oldField); // old Array structure value - JSONObject tempJObj = null; - String tempName = ""; - String tempValue = ""; + JSONObject tempJObj; + String tempName; + String tempValue; if (!arrayValue.toString().equals(OBJECT_NOT_FOUND)) { log.info("old value ==" + arrayValue.toString()); // Loop thru the JSONArray, get the name:value pair and write to new JSONObject as hashmap elements for (int i = 0; i < arrayValue.length(); i++) { - tempJObj = arrayValue.getJSONObject(i); + tempJObj = arrayValue.getJSONObject(i); if (tempJObj != null) { tempName = tempJObj.get("name").toString(); tempValue = tempJObj.get(VALUE).toString(); @@ -310,11 +325,12 @@ public class ConfigProcessors { //Add the new Hashmap setEventObjectVal(field, newHashMap); } - } else + } else { log.info(FILTER_NOT_MET); + } } - - // this method is to support the mapping 7.x to VES5.x format for additionalInformation field + + // this method is to support the mapping 7.x to VES5.x format for additionalInformation field private void mapHashmapToNameValueArray(JSONObject jsonObject) { log.info("mapHashmapToNameValueArray"); System.out.println("mapHashmapToNameValueArray"); @@ -323,29 +339,30 @@ public class ConfigProcessors { final JSONObject filter = jsonObject.optJSONObject(FILTER); if (filter == null || isFilterMet(filter)) { - JSONArray newArray = new JSONArray(); // this will hold the new name:value JSONObject - JSONObject nameValJObj; - System.out.println("object ==" + getEventObjectVal(oldField).toString()); - if (!getEventObjectVal(oldField).toString().equals(OBJECT_NOT_FOUND)) { - - JSONObject hashMap = (JSONObject) getEventObjectVal(oldField); // old hashmap structure value - if (hashMap != null) { - log.info("old value ==" + hashMap.toString()); - // Loop thru the hashMap JSONObject, get the hashmap elements add them as name:value JsonObject into the newArray - for (String key : hashMap.keySet()) { - nameValJObj = new JSONObject(); //create new object so not to overwrite in memory for Array insertion - nameValJObj.put("name", key); - nameValJObj.put("value", hashMap.get(key)); - newArray.put(nameValJObj); - } - // remove the old hashMap structure - removeEventKey(oldField); - //Add the newArray containing the name:value Object - setEventObjectVal(field, newArray); - } - } - } else + JSONArray newArray = new JSONArray(); // this will hold the new name:value JSONObject + JSONObject nameValJObj; + System.out.println("object ==" + getEventObjectVal(oldField).toString()); + if (!getEventObjectVal(oldField).toString().equals(OBJECT_NOT_FOUND)) { + + JSONObject hashMap = (JSONObject) getEventObjectVal(oldField); // old hashmap structure value + if (hashMap != null) { + log.info("old value ==" + hashMap.toString()); + // Loop thru the hashMap JSONObject, get the hashmap elements add them as name:value JsonObject into the newArray + for (String key : hashMap.keySet()) { + nameValJObj = new JSONObject(); //create new object so not to overwrite in memory for Array insertion + nameValJObj.put("name", key); + nameValJObj.put("value", hashMap.get(key)); + newArray.put(nameValJObj); + } + // remove the old hashMap structure + removeEventKey(oldField); + //Add the newArray containing the name:value Object + setEventObjectVal(field, newArray); + } + } + } else { log.info(FILTER_NOT_MET); + } } /** @@ -367,16 +384,18 @@ public class ConfigProcessors { String tempVal = evaluate(values.getString(i)); if (!tempVal.equals(OBJECT_NOT_FOUND)) { - if (i == 0) + if (i == 0) { value.append(tempVal); - else + } else { value.append(delimiter).append(tempVal); + } } } setEventObjectVal(field, value.toString()); - } else + } else { log.info(FILTER_NOT_MET); + } } public void subtractValue(JSONObject jsonObject) { @@ -391,16 +410,18 @@ public class ConfigProcessors { String tempVal = evaluate(values.getString(i)); log.info("tempVal==" + tempVal); if (!tempVal.equals(OBJECT_NOT_FOUND)) { - if (i == 0) - value = value + Float.valueOf(tempVal); - else - value = value - Float.valueOf(tempVal); + if (i == 0) { + value = value + Float.parseFloat(tempVal); + } else { + value = value - Float.parseFloat(tempVal); + } } } log.info("value ==" + value); setEventObjectVal(field, value, "number"); - } else + } else { log.info(FILTER_NOT_MET); + } } @@ -470,12 +491,14 @@ public class ConfigProcessors { if ("not".equals(key)) { JSONObject njo = jo.getJSONObject(key); for (String njoKey : njo.keySet()) { - if (!checkFilter(njo, njoKey, key)) + if (!checkFilter(njo, njoKey, key)) { return false; + } } } else { - if (!checkFilter(jo, key, key)) + if (!checkFilter(jo, key, key)) { return false; + } } } return true; @@ -491,8 +514,9 @@ public class ConfigProcessors { keySeriesStr = keySeriesStr.replaceAll("\\.\\.", "."); } - if (keySeriesStr.lastIndexOf(".") == keySeriesStr.length() - 1) + if (keySeriesStr.lastIndexOf(".") == keySeriesStr.length() - 1) { keySeriesStr = keySeriesStr.substring(0, keySeriesStr.length() - 1); + } String[] keySet = keySeriesStr.split("\\.", keySeriesStr.length()); Object keySeriesObj = event; for (String aKeySet : keySet) { @@ -512,8 +536,9 @@ public class ConfigProcessors { } } - if (keySeriesObj == null) + if (keySeriesObj == null) { return OBJECT_NOT_FOUND; + } return keySeriesObj; } @@ -532,8 +557,9 @@ public class ConfigProcessors { } log.info("fieldType==" + fieldType); - if (keySeriesStr.lastIndexOf(".") == keySeriesStr.length() - 1) + if (keySeriesStr.lastIndexOf(".") == keySeriesStr.length() - 1) { keySeriesStr = keySeriesStr.substring(0, keySeriesStr.length() - 1); + } String[] keySet = keySeriesStr.split("\\.", keySeriesStr.length()); Object keySeriesObj = event; for (int i = 0; i < (keySet.length - 1); i++) { @@ -552,9 +578,11 @@ public class ConfigProcessors { { log.info("Object is null, must add it"); if (keySet[i + 1].matches("[0-9]*")) // if index then array + { ((JSONArray) keySeriesObj).put(Integer.parseInt(keySet[i]), new JSONArray()); - else + } else { ((JSONArray) keySeriesObj).put(Integer.parseInt(keySet[i]), new JSONObject()); + } } keySeriesObj = ((JSONArray) keySeriesObj).optJSONObject(Integer.parseInt(keySet[i])); @@ -570,9 +598,11 @@ public class ConfigProcessors { // it { if (keySet[i + 1].matches("[0-9]*")) // if index then array + { ((JSONObject) keySeriesObj).put(keySet[i], new JSONArray()); - else + } else { ((JSONObject) keySeriesObj).put(keySet[i], new JSONObject()); + } log.info("Object is null, must add it"); } keySeriesObj = ((JSONObject) keySeriesObj).opt(keySet[i]); @@ -582,17 +612,20 @@ public class ConfigProcessors { } if ("number".equals(fieldType)) { DecimalFormat df = new DecimalFormat("#.0"); - if (value instanceof String) + if (value instanceof String) { ((JSONObject) keySeriesObj).put(keySet[keySet.length - 1], Float.valueOf(df.format(Float.valueOf((String) value)))); - else + } else { ((JSONObject) keySeriesObj).put(keySet[keySet.length - 1], Float.valueOf(df.format(value))); - } else if ("integer".equals(fieldType) && value instanceof String) + } + } else if ("integer".equals(fieldType) && value instanceof String) { ((JSONObject) keySeriesObj).put(keySet[keySet.length - 1], Integer.valueOf((String) value)); - else if ("JArray".equals(fieldType)) + } else if ("JArray".equals(fieldType)) { + assert keySeriesObj instanceof JSONArray; ((JSONArray) keySeriesObj).put(value); - else + } else { ((JSONObject) keySeriesObj).put(keySet[keySet.length - 1], value); + } } } diff --git a/src/main/java/org/onap/dcae/common/model/VesEvent.java b/src/main/java/org/onap/dcae/common/model/VesEvent.java index ce709d1c..6c9a8ee2 100644 --- a/src/main/java/org/onap/dcae/common/model/VesEvent.java +++ b/src/main/java/org/onap/dcae/common/model/VesEvent.java @@ -19,6 +19,9 @@ */ package org.onap.dcae.common.model; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONObject; /** @@ -35,6 +38,8 @@ public class VesEvent { private static final String DOMAIN = "domain"; private static final String STND_DEFINED_NAMESPACE = "stndDefinedNamespace"; private static final String STND_DEFINED_DOMAIN = "stndDefined"; + private static final String STND_DEFINED_FIELDS = "stndDefinedFields"; + private static final String SCHEMA_REFERENCE = "schemaReference"; private final JSONObject event; @@ -66,6 +71,16 @@ public class VesEvent { return getEventHeader().getString(DOMAIN); } + public String getSchemaReference() { + return getStndDefinedFields().getString(SCHEMA_REFERENCE); + } + + private JSONObject getStndDefinedFields() { + return event + .getJSONObject(EVENT_LITERAL) + .getJSONObject(STND_DEFINED_FIELDS); + } + private String resolveDomainForStndDefinedEvent() { final JSONObject eventHeader = getEventHeader(); if(eventHeader.has(STND_DEFINED_NAMESPACE)) { @@ -108,6 +123,11 @@ public class VesEvent { return new JSONObject(event.toString()); } + public JsonNode asJsonNode() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readTree(event.toString()); + } + /** * Checks if type of event is same as given in paramaters. * diff --git a/src/main/java/org/onap/dcae/common/validator/GeneralEventValidator.java b/src/main/java/org/onap/dcae/common/validator/GeneralEventValidator.java new file mode 100644 index 00000000..5cd5dc25 --- /dev/null +++ b/src/main/java/org/onap/dcae/common/validator/GeneralEventValidator.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020 Nokia. 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.onap.dcae.common.validator; + +import com.networknt.schema.JsonSchema; +import org.onap.dcae.ApplicationSettings; +import org.onap.dcae.common.model.VesEvent; +import org.onap.dcae.restapi.ApiException; +import org.onap.dcae.restapi.EventValidatorException; + +/** + * This class is using ApplicationSetting and SchemaValidator to validate VES event. + * + * @author Zebek + */ +public class GeneralEventValidator { + + private final SchemaValidator schemaValidator; + private final ApplicationSettings applicationSettings; + + public GeneralEventValidator(ApplicationSettings applicationSettings) { + this(applicationSettings, new SchemaValidator()); + } + + GeneralEventValidator(ApplicationSettings applicationSettings, SchemaValidator schemaValidator) { + this.applicationSettings = applicationSettings; + this.schemaValidator = schemaValidator; + } + + /** + * This method is validating given event using schema adn throws exception if event is not valid + * + * @param vesEvent event that will be validate + * @param type expected type of event + * @param version json schema version that will be used + * @throws EventValidatorException when event is not valid or have wrong type + */ + public void validate(VesEvent vesEvent, String type, String version) throws EventValidatorException { + if (applicationSettings.eventSchemaValidationEnabled()) { + doValidation(vesEvent, type, version); + } + } + + private void doValidation(VesEvent vesEvent, String type, String version) throws EventValidatorException { + if (vesEvent.hasType(type)) { + if (!isEventMatchToSchema(vesEvent, applicationSettings.jsonSchema(version))) { + throw new EventValidatorException(ApiException.SCHEMA_VALIDATION_FAILED); + } + } else { + throw new EventValidatorException(ApiException.INVALID_JSON_INPUT); + } + } + + private boolean isEventMatchToSchema(VesEvent vesEvent, JsonSchema schema) { + return schemaValidator.conformsToSchema(vesEvent.asJsonObject(), schema); + } +} diff --git a/src/main/java/org/onap/dcae/common/validator/SchemaValidator.java b/src/main/java/org/onap/dcae/common/validator/SchemaValidator.java new file mode 100644 index 00000000..80c8f6e7 --- /dev/null +++ b/src/main/java/org/onap/dcae/common/validator/SchemaValidator.java @@ -0,0 +1,58 @@ +/*
+ * ============LICENSE_START=======================================================
+ * PROJECT
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 Nokia. All rights reserved.s
+ * ================================================================================
+ * 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.onap.dcae.common.validator;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.networknt.schema.JsonSchema;
+import com.networknt.schema.ValidationMessage;
+import org.json.JSONObject;
+import org.onap.dcae.ApplicationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+class SchemaValidator {
+ public static final Logger log = LoggerFactory.getLogger(SchemaValidator.class);
+
+ public boolean conformsToSchema(JSONObject payload, JsonSchema schema) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+
+ String content = payload.toString();
+ JsonNode node = mapper.readTree(content);
+ Set<ValidationMessage> messageSet = schema.validate(node);
+
+ if (messageSet.isEmpty()) {
+ return true;
+ }
+
+ log.warn("Schema validation failed for event: {}", payload);
+ messageSet.forEach(it->log.warn(it.getMessage()) );
+
+ return false;
+ } catch (Exception e) {
+ throw new ApplicationException("Unable to validate against schema", e);
+ }
+ }
+}
diff --git a/src/main/java/org/onap/dcae/common/validator/StndDefinedDataValidator.java b/src/main/java/org/onap/dcae/common/validator/StndDefinedDataValidator.java new file mode 100644 index 00000000..d936f272 --- /dev/null +++ b/src/main/java/org/onap/dcae/common/validator/StndDefinedDataValidator.java @@ -0,0 +1,83 @@ +/* + * ============LICENSE_START======================================================= + * VES + * ================================================================================ + * Copyright (C) 2020 Nokia. 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.onap.dcae.common.validator; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import org.json.JSONException; +import org.onap.dcae.common.model.VesEvent; +import org.onap.dcae.restapi.ApiException; +import org.onap.dcae.restapi.EventValidatorException; +import org.onap.dcaegen2.services.sdk.services.external.schema.manager.exception.IncorrectInternalFileReferenceException; +import org.onap.dcaegen2.services.sdk.services.external.schema.manager.exception.NoLocalReferenceException; +import org.onap.dcaegen2.services.sdk.services.external.schema.manager.service.StndDefinedValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class StndDefinedDataValidator { + + private static final String STND_DEFINED_DOMAIN = "stndDefined"; + + private final StndDefinedValidator stndDefinedValidator; + + @Autowired + public StndDefinedDataValidator(StndDefinedValidator validator) { + this.stndDefinedValidator = validator; + } + + /** + * Validates incoming event + * + * @param event as JsonNode + * @throws EventValidatorException exceptions related to failing StndDefined validation + */ + public void validate(VesEvent event) throws EventValidatorException { + try { + if (shouldBeValidated(event) && !doValidation(event.asJsonNode())) { + throw new EventValidatorException(ApiException.STND_DEFINED_VALIDATION_FAILED); + } + } catch (JsonProcessingException ex) { + throw new EventValidatorException(ApiException.INVALID_JSON_INPUT); + } + } + + private boolean doValidation(JsonNode event) throws EventValidatorException { + try { + return stndDefinedValidator.validate(event); + } catch (NoLocalReferenceException e) { + throw new EventValidatorException(ApiException.NO_LOCAL_SCHEMA_REFERENCE); + } catch (IncorrectInternalFileReferenceException e) { + throw new EventValidatorException(ApiException.INCORRECT_INTERNAL_FILE_REFERENCE); + } + } + + private boolean shouldBeValidated(VesEvent event) { + boolean shouldBeValidated; + try { + shouldBeValidated = STND_DEFINED_DOMAIN.equals(event.getDomain()) + && !event.getSchemaReference().isEmpty(); + } catch (JSONException e) { + shouldBeValidated = false; + } + return shouldBeValidated; + } +} diff --git a/src/main/java/org/onap/dcae/common/validator/StndDefinedValidatorResolver.java b/src/main/java/org/onap/dcae/common/validator/StndDefinedValidatorResolver.java new file mode 100644 index 00000000..3f06d0ae --- /dev/null +++ b/src/main/java/org/onap/dcae/common/validator/StndDefinedValidatorResolver.java @@ -0,0 +1,53 @@ +/* + * ============LICENSE_START======================================================= + * VES + * ================================================================================ + * Copyright (C) 2020 Nokia. 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.onap.dcae.common.validator; + +import org.onap.dcae.ApplicationSettings; +import org.onap.dcaegen2.services.sdk.services.external.schema.manager.service.StndDefinedValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class StndDefinedValidatorResolver { + + private final ApplicationSettings settings; + + @Autowired + public StndDefinedValidatorResolver(ApplicationSettings settings) { + this.settings = settings; + } + + /** + * Creates StndDefinedValidator using settings defined in collector.properties + * + * @return StndDefinedValidator object for validation of configured fields of event + */ + public StndDefinedValidator resolve() { + return new StndDefinedValidator.ValidatorBuilder() + .mappingFilePath(settings.getExternalSchemaMappingFileLocation()) + .schemaRefPath(settings.getExternalSchemaSchemaRefPath()) + .schemasPath(settings.getExternalSchemaSchemasLocation()) + .stndDefinedDataPath(settings.getExternalSchemaStndDefinedDataPath()) + .build(); + } +} + + |