@ApiMethod(name = "form.get") public Form getForm(@Named("groupId") Long groupId, @Named("formId") Long formId) throws EntityNotFoundException { // Get the key Key rootKey = KeyFactory.createKey("Root", 1); Key groupKey = KeyFactory.createKey(rootKey, "Group", groupId); Key key = KeyFactory.createKey(groupKey, "Form", formId); Entity entity = dataStore.get(key); return Form.fromEntity(dataStore, entity); }
@ApiMethod(name = "form.list") public List<Form> getForms(@Named("groupId") Long groupId) throws EntityNotFoundException { // Get the key Key rootKey = KeyFactory.createKey("Root", 1); Key groupKey = KeyFactory.createKey(rootKey, "Group", groupId); // Get or create the group Entity group; group = dataStore.get(groupKey); //noinspection unchecked List<Key> keys = (List<Key>) group.getProperty("forms"); keys = firstNonNull(keys, Collections.<Key>emptyList()); List<Form> forms = new ArrayList<>(); for (Key key : keys) { Form f = Form.fromEntity(dataStore, dataStore.get(key)); forms.add(f); } return forms; }