@Test @Ignore public void testUpdate() { String newLocation = "Shangri-la"; JsonObject args = new JsonObject(); EngagementStore store = new EngagementStore(args, "engagements"); Engagement tempObj = new Engagement( "TestObj2", "Valhalla",new Date()); tempObj = store.persist(tempObj); Engagement engagement = store.findById(tempObj.get_id()); assertEquals("TestObj2", engagement.getName()); args.addProperty("id", engagement.get_id()); args.addProperty("location", newLocation); JsonObject response = UpdateEngagement.main(args); System.out.println(response); assertEquals("OK", response.getAsJsonPrimitive("result").getAsString()); engagement = store.findById(tempObj.get_id()); assertEquals(newLocation, engagement.getLocation()); store.delete(engagement); }
public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); JsonPrimitive idArg = args.getAsJsonPrimitive("id"); if (idArg == null) { response.addProperty("result", "id not provided"); } else { EngagementStore store = new EngagementStore(args, "engagements"); Engagement engagement = store.findById(idArg.getAsString()); if (engagement != null) { Engagement newEngagement = store.cloneObject(engagement); JsonPrimitive nameArg = args.getAsJsonPrimitive("name"); if (nameArg != null) { newEngagement.setName(nameArg.getAsString()); } JsonPrimitive locationArg = args.getAsJsonPrimitive("location"); if (locationArg != null) { newEngagement.setLocation(locationArg.getAsString()); } JsonPrimitive dateArg = args.getAsJsonPrimitive("date"); if (dateArg != null) { DateFormat df = DateFormat.getDateInstance(); Date date; try { date = df.parse(dateArg.getAsString()); newEngagement.setDate(date); } catch ( ParseException e) { response.addProperty("warning", "Unable to parse date"); } } store.update(engagement.get_id(),newEngagement); response.addProperty("result", "OK"); } else { response.addProperty("result", "object not found"); } } return response; }
UpdateEngagement { public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); JsonPrimitive idArg = args.getAsJsonPrimitive("id"); if (idArg == null) { response.addProperty("result", "id not provided"); } else { EngagementStore store = new EngagementStore(args, "engagements"); Engagement engagement = store.findById(idArg.getAsString()); if (engagement != null) { Engagement newEngagement = store.cloneObject(engagement); JsonPrimitive nameArg = args.getAsJsonPrimitive("name"); if (nameArg != null) { newEngagement.setName(nameArg.getAsString()); } JsonPrimitive locationArg = args.getAsJsonPrimitive("location"); if (locationArg != null) { newEngagement.setLocation(locationArg.getAsString()); } JsonPrimitive dateArg = args.getAsJsonPrimitive("date"); if (dateArg != null) { DateFormat df = DateFormat.getDateInstance(); Date date; try { date = df.parse(dateArg.getAsString()); newEngagement.setDate(date); } catch ( ParseException e) { response.addProperty("warning", "Unable to parse date"); } } store.update(engagement.get_id(),newEngagement); response.addProperty("result", "OK"); } else { response.addProperty("result", "object not found"); } } return response; } }
UpdateEngagement { public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); JsonPrimitive idArg = args.getAsJsonPrimitive("id"); if (idArg == null) { response.addProperty("result", "id not provided"); } else { EngagementStore store = new EngagementStore(args, "engagements"); Engagement engagement = store.findById(idArg.getAsString()); if (engagement != null) { Engagement newEngagement = store.cloneObject(engagement); JsonPrimitive nameArg = args.getAsJsonPrimitive("name"); if (nameArg != null) { newEngagement.setName(nameArg.getAsString()); } JsonPrimitive locationArg = args.getAsJsonPrimitive("location"); if (locationArg != null) { newEngagement.setLocation(locationArg.getAsString()); } JsonPrimitive dateArg = args.getAsJsonPrimitive("date"); if (dateArg != null) { DateFormat df = DateFormat.getDateInstance(); Date date; try { date = df.parse(dateArg.getAsString()); newEngagement.setDate(date); } catch ( ParseException e) { response.addProperty("warning", "Unable to parse date"); } } store.update(engagement.get_id(),newEngagement); response.addProperty("result", "OK"); } else { response.addProperty("result", "object not found"); } } return response; }  }
UpdateEngagement { public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); JsonPrimitive idArg = args.getAsJsonPrimitive("id"); if (idArg == null) { response.addProperty("result", "id not provided"); } else { EngagementStore store = new EngagementStore(args, "engagements"); Engagement engagement = store.findById(idArg.getAsString()); if (engagement != null) { Engagement newEngagement = store.cloneObject(engagement); JsonPrimitive nameArg = args.getAsJsonPrimitive("name"); if (nameArg != null) { newEngagement.setName(nameArg.getAsString()); } JsonPrimitive locationArg = args.getAsJsonPrimitive("location"); if (locationArg != null) { newEngagement.setLocation(locationArg.getAsString()); } JsonPrimitive dateArg = args.getAsJsonPrimitive("date"); if (dateArg != null) { DateFormat df = DateFormat.getDateInstance(); Date date; try { date = df.parse(dateArg.getAsString()); newEngagement.setDate(date); } catch ( ParseException e) { response.addProperty("warning", "Unable to parse date"); } } store.update(engagement.get_id(),newEngagement); response.addProperty("result", "OK"); } else { response.addProperty("result", "object not found"); } } return response; }  static JsonObject main(JsonObject args); }
UpdateEngagement { public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); JsonPrimitive idArg = args.getAsJsonPrimitive("id"); if (idArg == null) { response.addProperty("result", "id not provided"); } else { EngagementStore store = new EngagementStore(args, "engagements"); Engagement engagement = store.findById(idArg.getAsString()); if (engagement != null) { Engagement newEngagement = store.cloneObject(engagement); JsonPrimitive nameArg = args.getAsJsonPrimitive("name"); if (nameArg != null) { newEngagement.setName(nameArg.getAsString()); } JsonPrimitive locationArg = args.getAsJsonPrimitive("location"); if (locationArg != null) { newEngagement.setLocation(locationArg.getAsString()); } JsonPrimitive dateArg = args.getAsJsonPrimitive("date"); if (dateArg != null) { DateFormat df = DateFormat.getDateInstance(); Date date; try { date = df.parse(dateArg.getAsString()); newEngagement.setDate(date); } catch ( ParseException e) { response.addProperty("warning", "Unable to parse date"); } } store.update(engagement.get_id(),newEngagement); response.addProperty("result", "OK"); } else { response.addProperty("result", "object not found"); } } return response; }  static JsonObject main(JsonObject args);  }