private static VegetationSurveyProxy buildCanopy(String canopy) {
   VegetationSurveyProxy result = new VegetationSurveyProxy();
   result.setModel(new Station());
   result.getModel().setStationType(VegetationGlobals.STATION_TYPE_VEGETATION_CANOPY);
   result.getModel().setName(canopy);
   result.getModel().setRowGuid();
   result.setStationElements(new ArrayList<StationElementProxy>());
   return result;
 }
 private static VegetationSurveyProxy buildCanopy(Station station) {
   VegetationSurveyProxy result = new VegetationSurveyProxy();
   result.setModel(station);
   ElementService es = new ElementService(SageApplication.getInstance().getDaoSession());
   List<StationElement> stationElements = es.findStationElements(station);
   if (stationElements != null)
     result.setStationElements(es.convertFromStationElements(stationElements));
   return result;
 }
 /**
  * Converts an element to a StationElementProxy and adds it to the proxy's station elements if an
  * matching element does not already exist.
  *
  * @param proxy the VegetationSurveyProxy (canopy) to add the elements to
  * @param elements the list of elements to add as proxies
  * @return the number of elements added
  */
 public static int addElements(VegetationSurveyProxy proxy, List<Element> elements) {
   if (elements == null || elements.size() < 1) return 0;
   List<StationElementProxy> proxies = proxy.getStationElements();
   if (proxies == null) {
     proxies = ElementService.convertFromElements(elements);
     return proxies.size();
   }
   return CollectionOperations.Merge(
       proxy.getStationElements(),
       ElementService.convertFromElements(elements),
       new StationElementProxy.StationElementProxyByElementRowGuidComparator());
 }
 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;
 }
 public static void addPhotoProxy(
     VegetationSurveyProxy proxy,
     PhotoProxy photoProxy,
     CategoryElementsListAdapter.ViewModel viewModel) {
   for (StationElementProxy seProxy : proxy.getStationElements()) {
     if (seProxy.getModel().getElement().getId() == viewModel.getElementId()) {
       if (seProxy.getPhotos() == null) seProxy.setPhotos(new ArrayList<PhotoProxy>());
       seProxy.getPhotos().add(photoProxy);
     }
   }
 }