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);
     }
   }
 }
 public static List<StationElementProxy> convertStationElementsToProxies(
     List<StationElement> stationElements) {
   List<StationElementProxy> proxies = new ArrayList<StationElementProxy>();
   if (stationElements != null) {
     for (StationElement se : stationElements) {
       StationElementProxy proxy = new StationElementProxy();
       proxy.setModel(se);
       proxies.add(proxy);
     }
   }
   return proxies;
 }
 public static void updateFromViewModels(
     ArrayList<CategoryElementsListAdapter.ViewModel> viewModels,
     List<StationElementProxy> proxies) {
   StationElementProxy.StationElementProxyByRowGuidComparator comparator =
       new StationElementProxy.StationElementProxyByRowGuidComparator();
   List<StationElementProxy> fromVM = CategorySurveyService.convertToProxies(viewModels);
   List<StationElementProxy> forDelete = CollectionOperations.except(proxies, fromVM, comparator);
   if (forDelete != null && forDelete.size() > 0)
     CollectionOperations.removeAll(proxies, forDelete, comparator);
   // PhotoService photoService = new PhotoService(SageApplication.getInstance().getDaoSession());
   for (StationElementProxy proxy : proxies) { // TODO: investigate moving to ElementService
     StationElementProxy temp = CollectionOperations.find(fromVM, proxy, comparator);
     proxy.getModel().setCount(temp.getModel().getCount());
     MetaDataService.MetaSupportExtensionMethods.replace(proxy.getModel(), temp.getModel());
     updateLocationProxy(proxy, temp);
     // TODO: deal with photos
     temp.setPhotos(proxy.getPhotos());
     // List<Photo> photos = photoService.find(proxy.getModel());
     // if(photos != null && photos.size() > 0) proxy.setPhotos(PhotoService.convertToProxy(photos,
     // proxy.getModel()));
   }
 }
 public static StationElementProxy convertToProxy(
     CategoryElementsListAdapter.ViewModel viewModel) {
   StationElementProxy proxy = new StationElementProxy();
   StationElement se = new StationElement();
   Element element = new Element();
   DescriptorServices.setByFieldDescriptor(viewModel, element);
   DescriptorServices.setByFieldDescriptor(viewModel, se);
   List<StationElementMeta> metaElements = MetaDataService.fromAnnotations(viewModel, true);
   if (metaElements != null && metaElements.size() > 0) se.setMetaData(metaElements);
   se.setElement(element);
   proxy.setModel(se);
   if (viewModel.location != null) {
     Location l = new Location();
     if (proxy.getModel().getRowGuid() == null) proxy.getModel().setRowGuid();
     l.setName(proxy.getModel().getRowGuid());
     LocationProxy lp = LocationService.createPointFromLocation(viewModel.location, l);
     proxy.setLocation(lp);
   }
   return proxy;
 }
 private static void updateLocationProxy(
     StationElementProxy destination, StationElementProxy source) {
   if (destination.getLocation() == null && source.getLocation() == null) return;
   else if (destination.getLocation() == null) {
     destination.setLocation(source.getLocation());
     if (destination.getModel().getRowGuid() == null) destination.getModel().setRowGuid();
     destination.getLocation().getModel().setName(destination.getModel().getRowGuid());
   } else if (source.getLocation() == null) {
     destination.setLocation(null);
   } else {
     destination.getLocation().setCoordinates(source.getLocation().getCoordinates());
   }
 }
 /**
  * Builds a ViewModel from the provided proxy note: uses the first location in the proxy's
  * locations as the location
  *
  * @param proxy
  * @return the generated ViewModel or null if the proxy, or the proxy's model's element is null
  */
 public static CategoryElementsListAdapter.ViewModel convertToViewModel(
     StationElementProxy proxy) {
   if (proxy == null || proxy.getModel() == null) return null;
   CategoryElementsListAdapter.ViewModel vm = convertToViewModel(proxy.getModel().getElement());
   if (vm == null) return null;
   DescriptorServices.getByFieldDescriptor(vm, proxy.getModel());
   if (proxy.getModel().hasMetaData())
     MetaDataService.updateAnnotations(vm, proxy.getModel().getMetaData());
   if (proxy.getLocation() != null && proxy.getLocation().getLocations().size() > 0)
     vm.location = proxy.getLocation().getLocations().get(0);
   if (proxy.getPhotos() != null && proxy.getPhotos().size() > 0)
     vm.photos = PhotoService.convertProxiesToFilePathArray(proxy.getPhotos());
   return vm;
 }