[AAI-168 Amsterdam] Check in source
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / serialization / queryformats / Resource.java
index c30b871..9a090a4 100644 (file)
@@ -25,7 +25,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.tinkerpop.gremlin.structure.Vertex;
-
 import org.openecomp.aai.db.props.AAIProperties;
 import org.openecomp.aai.exceptions.AAIException;
 import org.openecomp.aai.introspection.Introspector;
@@ -33,7 +32,10 @@ import org.openecomp.aai.introspection.Loader;
 import org.openecomp.aai.introspection.exceptions.AAIUnknownObjectException;
 import org.openecomp.aai.serialization.db.DBSerializer;
 import org.openecomp.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
+import org.openecomp.aai.serialization.queryformats.params.Depth;
+import org.openecomp.aai.serialization.queryformats.params.NodesOnly;
 import org.openecomp.aai.serialization.queryformats.utils.UrlBuilder;
+
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 
@@ -44,13 +46,16 @@ public class Resource implements FormatMapper {
        private final JsonParser parser;
        private final UrlBuilder urlBuilder;
        private final boolean includeUrl;
-       
+       private final boolean nodesOnly;
+       private final int depth;
        private Resource (Builder builder) {
                this.parser = new JsonParser();
                this.loader = builder.getLoader();
                this.serializer = builder.getSerializer();
                this.urlBuilder = builder.getUrlBuilder();
                this.includeUrl = builder.isIncludeUrl();
+               this.nodesOnly = builder.isNodesOnly();
+               this.depth = builder.getDepth();
        }
 
        @Override
@@ -79,7 +84,7 @@ public class Resource implements FormatMapper {
                        wrapper.add(v);
 
                        try {
-                               getSerializer().dbToObject(wrapper, obj, 1, false, "false");
+                               getSerializer().dbToObject(wrapper, obj, this.depth, this.nodesOnly, "false");
                        } catch (AAIException | UnsupportedEncodingException  e) {
                                throw new AAIFormatVertexException("Failed to format vertex - error while serializing: " + e.getMessage(), e);
                        }
@@ -101,13 +106,14 @@ public class Resource implements FormatMapper {
        private DBSerializer getSerializer() { return serializer; }
        private JsonParser getParser() { return parser; }
        
-       public static class Builder {
+       public static class Builder implements NodesOnly<Builder>, Depth<Builder> {
                
                private final Loader loader;
                private final DBSerializer serializer;
                private final UrlBuilder urlBuilder;
                private boolean includeUrl = false;
-               
+               private boolean nodesOnly = false;
+               private int depth = 1;
                public Builder(Loader loader, DBSerializer serializer, UrlBuilder urlBuilder) {
                        this.loader = loader;
                        this.serializer = serializer;
@@ -130,8 +136,22 @@ public class Resource implements FormatMapper {
                        this.includeUrl = true;
                        return this;
                }
-
-               protected boolean isIncludeUrl() {
+               
+               public Builder nodesOnly(Boolean nodesOnly) {
+                       this.nodesOnly = nodesOnly;
+                       return this;
+               }
+               public boolean isNodesOnly() {
+                       return this.nodesOnly;
+               }
+               public Builder depth(Integer depth) {
+                       this.depth = depth;
+                       return this;
+               }
+               public int getDepth() {
+                       return this.depth;
+               }
+               public boolean isIncludeUrl() {
                        return this.includeUrl;
                }