aboutsummaryrefslogtreecommitdiffstats
path: root/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools
diff options
context:
space:
mode:
Diffstat (limited to 'ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools')
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/CreateUUID.java48
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/DefaultFields.java48
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Error.java25
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/InjectKeysFromURI.java70
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IntrospectorValidator.java278
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Issue.java144
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IssueResolver.java33
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Severity.java27
8 files changed, 673 insertions, 0 deletions
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/CreateUUID.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/CreateUUID.java
new file mode 100644
index 0000000..366c854
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/CreateUUID.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.openecomp.aai.introspection.Introspector;
+
+public class CreateUUID implements IssueResolver {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean resolveIssue(Issue issue) {
+
+ Introspector obj = issue.getIntrospector();
+ if (issue.getError().equals(Error.MISSING_KEY_PROP)) {
+ Map<String, String> metadata = obj.getPropertyMetadata(issue.getPropName());
+ if (metadata.containsKey("autoGenerateUuid") && metadata.get("autoGenerateUuid").equals("true")) {
+ obj.setValue(issue.getPropName(), UUID.randomUUID().toString());
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/DefaultFields.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/DefaultFields.java
new file mode 100644
index 0000000..05c78b6
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/DefaultFields.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.openecomp.aai.introspection.Introspector;
+
+public class DefaultFields implements IssueResolver {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean resolveIssue(Issue issue) {
+
+ Introspector obj = issue.getIntrospector();
+ if (issue.getError().equals(Error.MISSING_REQUIRED_PROP)) {
+ Map<String, String> metadata = obj.getPropertyMetadata(issue.getPropName());
+ if (metadata.containsKey("defaultValue")) {
+ obj.setValue(issue.getPropName(), metadata.get("defaultValue"));
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Error.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Error.java
new file mode 100644
index 0000000..044820f
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Error.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+public enum Error {
+ MISSING_REQUIRED_PROP, MISSING_KEY_PROP
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/InjectKeysFromURI.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/InjectKeysFromURI.java
new file mode 100644
index 0000000..2c12f82
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/InjectKeysFromURI.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+import java.net.URI;
+
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.Loader;
+import org.openecomp.aai.logging.LogLineBuilder;
+import org.openecomp.aai.parsers.uri.URIToObject;
+
+public class InjectKeysFromURI implements IssueResolver {
+
+ private URI uri = null;
+ private Loader loader = null;
+
+ /**
+ * Instantiates a new inject keys from URI.
+ *
+ * @param loader the loader
+ * @param uri the uri
+ */
+ public InjectKeysFromURI(Loader loader, URI uri) {
+ this.loader = loader;
+ this.uri = uri;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean resolveIssue(Issue issue) {
+ boolean result = false;
+ Introspector obj = issue.getIntrospector();
+ if (issue.getError().equals(Error.MISSING_KEY_PROP)) {
+ try {
+ URIToObject toObject = new URIToObject(loader, uri);
+ Introspector minimumObj = toObject.getEntity();
+ if (toObject.getEntityName().equals(obj.getDbName())) {
+ obj.setValue(issue.getPropName(), minimumObj.getValue(issue.getPropName()));
+ result = true;
+ }
+ } catch (Exception e) {
+ //log something probably
+ result = false;
+ }
+ }
+
+ return result;
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IntrospectorValidator.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IntrospectorValidator.java
new file mode 100644
index 0000000..89771df
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IntrospectorValidator.java
@@ -0,0 +1,278 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.IntrospectorWalker;
+import org.openecomp.aai.introspection.Wanderer;
+import org.openecomp.aai.logging.LogLineBuilder;
+
+public class IntrospectorValidator implements Wanderer {
+
+
+ private List<Issue> issues = null;
+ private List<IssueResolver> issueResolvers = null;
+ private boolean validateRequired = true;
+ private final LogLineBuilder llBuilder;
+
+ /**
+ * Instantiates a new introspector validator.
+ *
+ * @param builder the builder
+ */
+ private IntrospectorValidator(IntrospectorValidator.Builder builder) {
+ this.llBuilder = builder.getLogLineBuilder();
+ this.validateRequired = builder.getValidateRequired();
+ this.issueResolvers = builder.getResolvers();
+ issues = new ArrayList<>();
+ }
+
+ /**
+ * Validate.
+ *
+ * @param obj the obj
+ * @return true, if successful
+ */
+ public boolean validate(Introspector obj) {
+ IntrospectorWalker walker = new IntrospectorWalker(this, llBuilder);
+ walker.walk(obj);
+
+ for (Issue m : issues) {
+ if (!m.getSeverity().equals(Severity.WARNING)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Gets the issues.
+ *
+ * @return the issues
+ */
+ public List<Issue> getIssues() {
+ return this.issues;
+ }
+
+ /**
+ * Sets the issue resolvers.
+ *
+ * @param resolvers the new issue resolvers
+ */
+ public void setIssueResolvers(List<IssueResolver> resolvers) {
+ issueResolvers = new ArrayList<>();
+ for (IssueResolver resolver : resolvers) {
+ issueResolvers.add(resolver);
+ }
+ }
+
+ /**
+ * Resolve issues.
+ *
+ * @return true, if successful
+ */
+ public boolean resolveIssues() {
+ boolean result = true;
+ for (Issue issue : issues) {
+ for (IssueResolver resolver : issueResolvers) {
+ if (resolver.resolveIssue(issue)) {
+ issue.setResolved(true);
+ }
+ }
+ if (!issue.isResolved()) {
+ result = false;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processComplexObj(Introspector obj) {
+ List<String> requiredProps = obj.getRequiredProperties();
+ List<String> keys = obj.getKeys();
+
+ requiredProps.removeAll(keys);
+ if (validateRequired) {
+ for (String prop : requiredProps) {
+ Object value = obj.getValue(prop);
+ if (value == null) {
+ Issue message =
+ this.buildMessage(Severity.CRITICAL, Error.MISSING_REQUIRED_PROP, "Missing required property: " + prop);
+ message.setIntrospector(obj);
+ message.setPropName(prop);
+ issues.add(message);
+ }
+ }
+ }
+ for (String prop : keys) {
+ Object value = obj.getValue(prop);
+ if (value == null) {
+ Issue message =
+ this.buildMessage(Severity.CRITICAL, Error.MISSING_KEY_PROP, "Missing key property: " + prop);
+ message.setIntrospector(obj);
+ message.setPropName(prop);
+ issues.add(message);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitive(String propName, Introspector obj) {
+ //NO OP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitiveList(String propName, Introspector obj) {
+ //NO OP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void modifyComplexList(List<Object> list, Introspector parent, Introspector child) {
+ //NO OP
+ }
+
+
+ /**
+ * Builds the message.
+ *
+ * @param severity the severity
+ * @param error the error
+ * @param detail the detail
+ * @return the issue
+ */
+ private Issue buildMessage(Severity severity, Error error, String detail) {
+ Issue message = new Issue();
+ message.setSeverity(severity);
+ message.setError(error);
+ message.setDetail(detail);
+
+ return message;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean createComplexObjIfNull() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int createComplexListSize(Introspector parent, Introspector child) {
+ return 0;
+ }
+
+ public static class Builder {
+
+ private boolean validateRequired = true;
+ private List<IssueResolver> issueResolvers = null;
+ private final LogLineBuilder llBuilder;
+
+ /**
+ * Instantiates a new builder.
+ *
+ * @param llBuilder the ll builder
+ */
+ public Builder(LogLineBuilder llBuilder) {
+ this.llBuilder = llBuilder;
+ issueResolvers = new ArrayList<IssueResolver>();
+ }
+
+ /**
+ * Validate required.
+ *
+ * @param validateRequired the validate required
+ * @return the builder
+ */
+ public Builder validateRequired(boolean validateRequired) {
+ this.validateRequired = validateRequired;
+ return this;
+ }
+
+ /**
+ * Adds the resolver.
+ *
+ * @param resolver the resolver
+ * @return the builder
+ */
+ public Builder addResolver(IssueResolver resolver) {
+ issueResolvers.add(resolver);
+ return this;
+ }
+
+ /**
+ * Builds the.
+ *
+ * @return the introspector validator
+ */
+ public IntrospectorValidator build() {
+ return new IntrospectorValidator(this);
+ }
+
+ /**
+ * Gets the validate required.
+ *
+ * @return the validate required
+ */
+ public boolean getValidateRequired() {
+ return this.validateRequired;
+ }
+
+ /**
+ * Gets the resolvers.
+ *
+ * @return the resolvers
+ */
+ public List<IssueResolver> getResolvers() {
+ return this.issueResolvers;
+ }
+
+ /**
+ * Gets the log line builder.
+ *
+ * @return the log line builder
+ */
+ public LogLineBuilder getLogLineBuilder() {
+ return this.llBuilder;
+ }
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Issue.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Issue.java
new file mode 100644
index 0000000..2aa9761
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Issue.java
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+import org.openecomp.aai.introspection.Introspector;
+
+public class Issue {
+
+ private Severity severity;
+ private Error error;
+ private String detail;
+ private Introspector obj;
+ private String propName;
+ private boolean resolved = false;
+
+ /**
+ * Sets the severity.
+ *
+ * @param severity the new severity
+ */
+ public void setSeverity(Severity severity) {
+
+ this.severity = severity;
+ }
+
+ /**
+ * Sets the error.
+ *
+ * @param error the new error
+ */
+ public void setError(Error error) {
+ this.error = error;
+ }
+
+ /**
+ * Sets the detail.
+ *
+ * @param detail the new detail
+ */
+ public void setDetail(String detail) {
+ this.detail = detail;
+ }
+
+ /**
+ * Gets the severity.
+ *
+ * @return the severity
+ */
+ public Object getSeverity() {
+ return this.severity;
+ }
+
+ /**
+ * Sets the introspector.
+ *
+ * @param obj the new introspector
+ */
+ public void setIntrospector(Introspector obj) {
+ this.obj = obj;
+ }
+
+ /**
+ * Gets the introspector.
+ *
+ * @return the introspector
+ */
+ public Introspector getIntrospector() {
+ return this.obj;
+ }
+
+ /**
+ * Gets the detail.
+ *
+ * @return the detail
+ */
+ public String getDetail() {
+ return this.detail;
+ }
+
+ /**
+ * Gets the error.
+ *
+ * @return the error
+ */
+ public Error getError() {
+ return this.error;
+ }
+
+ /**
+ * Sets the prop name.
+ *
+ * @param prop the new prop name
+ */
+ public void setPropName(String prop) {
+ this.propName= prop;
+ }
+
+ /**
+ * Gets the prop name.
+ *
+ * @return the prop name
+ */
+ public String getPropName() {
+ return this.propName;
+ }
+
+ /**
+ * Checks if is resolved.
+ *
+ * @return true, if is resolved
+ */
+ public boolean isResolved() {
+ return resolved;
+ }
+
+ /**
+ * Sets the resolved.
+ *
+ * @param resolved the new resolved
+ */
+ public void setResolved(boolean resolved) {
+ this.resolved = resolved;
+ }
+
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IssueResolver.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IssueResolver.java
new file mode 100644
index 0000000..e62e9b7
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/IssueResolver.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+public interface IssueResolver {
+
+
+ /**
+ * Resolve issue.
+ *
+ * @param issue the issue
+ * @return true, if successful
+ */
+ public boolean resolveIssue(Issue issue);
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Severity.java b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Severity.java
new file mode 100644
index 0000000..1450179
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/introspection/tools/Severity.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.aai.introspection.tools;
+
+public enum Severity {
+ WARNING,
+ ERROR,
+ CRITICAL
+}