summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/crud/service/BulkPayload.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/crud/service/BulkPayload.java')
-rw-r--r--src/main/java/org/openecomp/crud/service/BulkPayload.java166
1 files changed, 81 insertions, 85 deletions
diff --git a/src/main/java/org/openecomp/crud/service/BulkPayload.java b/src/main/java/org/openecomp/crud/service/BulkPayload.java
index 28cf420..619c53b 100644
--- a/src/main/java/org/openecomp/crud/service/BulkPayload.java
+++ b/src/main/java/org/openecomp/crud/service/BulkPayload.java
@@ -39,90 +39,86 @@ import java.util.Set;
import javax.ws.rs.core.Response.Status;
public class BulkPayload {
- public enum OperationType {
- CREATE, UPDATE, DELETE
- }
-
-
-
- private List<JsonElement> objects = new ArrayList<JsonElement>();
- private List<JsonElement> relationships = new ArrayList<JsonElement>();
-
- private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
-
- public String toJson() {
- return gson.toJson(this);
- }
-
- public static BulkPayload fromJson(String payload) throws CrudException {
- try {
- if (payload == null || payload.isEmpty()) {
- throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
- }
- return gson.fromJson(payload, BulkPayload.class);
- } catch (Exception ex) {
- throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
- }
- }
-
- public List<JsonElement> getObjects() {
- return objects;
- }
-
- public void setObjects(List<JsonElement> objects) {
- this.objects = objects;
- }
-
- public List<JsonElement> getRelationships() {
- return relationships;
- }
-
- public void setRelationships(List<JsonElement> relationships) {
- this.relationships = relationships;
- }
-
- @Override
- public String toString() {
- return "BulkPayload [objects=" + objects + ", relationships=" + relationships + "]";
- }
-
- public static void main(String[] args) throws Exception {
- BulkPayload p = new BulkPayload();
- JsonObject root = new JsonObject();
- JsonArray vertices = new JsonArray();
- JsonObject v1 = new JsonObject();
- JsonObject v2 = new JsonObject();
- JsonObject prop = new JsonObject();
-
- prop.addProperty("p1","value1");
- prop.addProperty("p2","value2");
- v1.add("v1", prop);
- v2.add("v2",prop);
-
- vertices.add(v1);
- vertices.add(v2);
-
-
- root.add("objects", vertices);
-
- String s = "{\"objects\":[{\"v1\":{\"p1\":\"value1\",\"p2\":\"value2\"}},{\"v2\":{\"p1\":\"value1\",\"p2\":\"value2\"}}]}";
-
- p = BulkPayload.fromJson(s);
-
- List<JsonElement> po = p.getObjects();
- List<String> ids = new ArrayList<String>();
- for (JsonElement e : po){
- Set<Map.Entry<String, JsonElement>> entries = e.getAsJsonObject().entrySet();
-
- for (Map.Entry<String, JsonElement> entry : entries) {
- ids.add(entry.getKey());
- }
- }
-
-
- System.out.println("root: " + root.toString());
- System.out.println("payload ids: " + ids.toString());
-
- }
+ public enum OperationType {
+ CREATE, UPDATE, DELETE
+ }
+
+ private List<JsonElement> objects = new ArrayList<JsonElement>();
+ private List<JsonElement> relationships = new ArrayList<JsonElement>();
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static BulkPayload fromJson(String payload) throws CrudException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ return gson.fromJson(payload, BulkPayload.class);
+ } catch (Exception ex) {
+ throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
+ }
+ }
+
+ public List<JsonElement> getObjects() {
+ return objects;
+ }
+
+ public void setObjects(List<JsonElement> objects) {
+ this.objects = objects;
+ }
+
+ public List<JsonElement> getRelationships() {
+ return relationships;
+ }
+
+ public void setRelationships(List<JsonElement> relationships) {
+ this.relationships = relationships;
+ }
+
+ @Override
+ public String toString() {
+ return "BulkPayload [objects=" + objects + ", relationships=" + relationships + "]";
+ }
+
+ public static void main(String[] args) throws Exception {
+ BulkPayload p = new BulkPayload();
+ JsonObject root = new JsonObject();
+ JsonArray vertices = new JsonArray();
+ JsonObject v1 = new JsonObject();
+ JsonObject v2 = new JsonObject();
+ JsonObject prop = new JsonObject();
+
+ prop.addProperty("p1", "value1");
+ prop.addProperty("p2", "value2");
+ v1.add("v1", prop);
+ v2.add("v2", prop);
+
+ vertices.add(v1);
+ vertices.add(v2);
+
+ root.add("objects", vertices);
+
+ String s = "{\"objects\":[{\"v1\":{\"p1\":\"value1\",\"p2\":\"value2\"}},{\"v2\":{\"p1\":\"value1\",\"p2\":\"value2\"}}]}";
+
+ p = BulkPayload.fromJson(s);
+
+ List<JsonElement> po = p.getObjects();
+ List<String> ids = new ArrayList<String>();
+ for (JsonElement e : po) {
+ Set<Map.Entry<String, JsonElement>> entries = e.getAsJsonObject().entrySet();
+
+ for (Map.Entry<String, JsonElement> entry : entries) {
+ ids.add(entry.getKey());
+ }
+ }
+
+ System.out.println("root: " + root.toString());
+ System.out.println("payload ids: " + ids.toString());
+
+ }
} \ No newline at end of file