public Data save(Data data) { ContentValues values = new ContentValues(); values.put("entity_name", data.getEntityName()); values.put("attribute_name", data.getAttributeName()); values.put("entity_id", data.getEntityId()); values.put("field_value", data.getFieldValue()); double num = 0; if (isNumeric(data.getFieldValue())) { try { num = Double.valueOf(data.getFieldValue()); } catch (Exception e) { } } values.put("field_value_num", num); if (data.getId() == 0) { long insertId = database.insert(TABLE_NAME, null, values); return getById(insertId); } else { int rows = database.update(TABLE_NAME, values, "_id = " + data.getId(), null); if (rows == 0) throw new RuntimeException("Invalid id " + data.getId()); return data; // if there were triggers, would need to re-read row here. } }
@OnAlias("selectedproject") public void select_story(TeamchatAPI api) { String[] Project = api.context().currentReply().getField("project_name").split("-"); pid = Long.valueOf(Project[Project.length - 1]); String URL = "https://www.pivotaltracker.com/services/v5/projects/" + pid + "/stories"; String URL_parameter = ""; SendGet sg = new SendGet(); Field field_story = null; try { String jsonData = sg.sendGet(URL, USER_AGENT, URL_parameter, pb.getAccess_token()); Gson gson = new Gson(); Data[] Story = gson.fromJson(jsonData, Data[].class); field_story = api.objects().select().name("story_name").label("Story"); for (Data story : Story) { field_story.addOption(story.getName() + "-" + story.getId()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestion("Select story to be deleted") .setReplyScreen(api.objects().form().addField(field_story)) .alias("deleteselectedstory"))); }
public void delete(Data data) { long id = data.getId(); database.delete(TABLE_NAME, "_id = " + id, null); }