Fix arraylist cast
@@ -20,23 +20,8 @@ package org.openbaton.nfvo.core.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.regex.Pattern;
+import com.networknt.schema.ValidationMessage;
+
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
@@ -69,6 +54,7 @@ import org.openbaton.exceptions.PluginException;
import org.openbaton.exceptions.VNFPackageFormatException;
import org.openbaton.exceptions.VimException;
import org.openbaton.exceptions.WrongAction;
+import org.openbaton.nfvo.common.utils.schema.SchemaValidator;
import org.openbaton.nfvo.core.interfaces.VnfPlacementManagement;
import org.openbaton.nfvo.core.utils.CheckVNFDescriptor;
import org.openbaton.nfvo.core.utils.CheckVNFPackage;
@@ -95,6 +81,24 @@ import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserExc
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.error.YAMLException;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.regex.Pattern;
+
/** Created by lto on 22/07/15. */
@Service
@Scope
@@ -183,6 +187,15 @@ public class VNFPackageManagement
//and has to be onboarded in the catalogue
String json = new String(content);
log.trace("Content of json is: " + json);
+ Set<ValidationMessage> errors = SchemaValidator.validateSchema(VirtualNetworkFunctionDescriptor.class.getCanonicalName(), json);
+ if (errors.size() >0 ){
+ StringBuilder builder = new StringBuilder();
+ for (ValidationMessage s : errors) {
+ String message = s.getMessage();
+ builder.append(message).append(", ");
+ }
+ throw new BadFormatException(builder.toString());
+ }
try {
virtualNetworkFunctionDescriptor =
mapper.fromJson(json, VirtualNetworkFunctionDescriptor.class);
@@ -356,7 +369,9 @@ public class VNFPackageManagement
} else {
vnfPackageMetadata.setVimTypes(
new HashSet<String>((ArrayList) metadata.get("vim_types")));
- vnfPackage.setVimTypes((Set<String>) metadata.get("vim_types"));
+ LinkedHashSet<String> vimTypes = new LinkedHashSet<>();
+ vimTypes.addAll((ArrayList) metadata.get("vim_types"));
+ vnfPackage.setVimTypes(vimTypes);
}
vnfPackageMetadata.setDescription((String) metadata.get("description"));
