Commit e4d54817 by Shwetha G S

Merge pull request #60 from hortonworks/issue57

ISSUE 57 - throw exception if type created with invalid JSON
parents db8ac80d 8cac97e5
......@@ -43,6 +43,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.tools.cmd.Meta;
import javax.inject.Inject;
import javax.inject.Singleton;
......@@ -90,9 +91,14 @@ public class DefaultMetadataService implements MetadataService {
public JSONObject createType(String typeDefinition) throws MetadataException {
try {
Preconditions.checkNotNull(typeDefinition, "type definition cannot be null");
Preconditions.checkArgument(!typeDefinition.equals(""), "type definition cannot be an empty string");
TypesDef typesDef = TypesSerialization.fromJson(typeDefinition);
if(typesDef.isEmpty())
throw new MetadataException("Invalid type definition");
Map<String, IDataType> typesAdded = typeSystem.defineTypes(typesDef);
//TODO how do we handle transaction - store failure??
typeStore.store(typeSystem, ImmutableList.copyOf(typesAdded.keySet()));
......
......@@ -58,4 +58,8 @@ case class TypesDef(enumTypes: Seq[EnumTypeDefinition],
import scala.collection.JavaConverters._
classTypes.asJava
}
def isEmpty() = {
enumTypes.isEmpty & structTypes.isEmpty & traitTypes.isEmpty & classTypes.isEmpty
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment