public static CategorySurveyProxy create(Station station, String[] canopyNames) { CategorySurveyProxy proxy = new CategorySurveyProxy(); proxy.setModel(station); if (station.getId() == null || station.getId() < 1) proxy.setCanopies(generateCategories(canopyNames)); else proxy.setCanopies(findCanopies(station, canopyNames)); return proxy; }
public static boolean saveOrUpdate(CategorySurveyProxy proxy) { boolean result = false; DaoSession session = SageApplication.getInstance().getDaoSession(); SurveyService surveyService = new SurveyService(session); ElementService elementService = new ElementService(session); SageApplication.getInstance().getDatabase().beginTransaction(); try { // main survey must already be saved (this will be the case) for (VegetationSurveyProxy survey : proxy.getCanopies()) { if (survey.getStationElements() != null && survey.getStationElements().size() > 0) { // Save the survey survey.setRoot(proxy); surveyService.saveOrUpdate(survey); // save the elements elementService.saveOrUpdate(survey.getStationElements(), survey.getModel()); } else { new ElementService(session).delete(survey.getModel()); } } SageApplication.getInstance().getDatabase().setTransactionSuccessful(); result = true; } catch (Exception e) { result = false; } finally { SageApplication.getInstance().getDatabase().endTransaction(); } return result; }