/alaspatial/src/main/java/org/ala/spatial/util/Layers.java

http://alageospatialportal.googlecode.com/ · Java · 48 lines · 19 code · 3 blank · 26 comment · 4 complexity · 35fda91fe3920311a0a3ca46be3a9881 MD5 · raw file

  1. /**
  2. * ************************************************************************
  3. * Copyright (C) 2010 Atlas of Living Australia All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with the
  7. * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  11. * the specific language governing rights and limitations under the License.
  12. * *************************************************************************
  13. */
  14. package org.ala.spatial.util;
  15. import org.ala.layers.client.Client;
  16. import org.ala.layers.dto.Field;
  17. /**
  18. * Util function for returning a fieldId from a layer short name.
  19. *
  20. * @author Adam
  21. */
  22. public class Layers {
  23. /**
  24. * Get fieldId from a layer short name.
  25. *
  26. * @param layerShortName layer short name as String.
  27. * @return fieldId as String, or the input parameter if unsuccessful.
  28. */
  29. public static String getFieldId(String layerShortName) {
  30. String field = layerShortName;
  31. // layer short name -> layer id -> field id
  32. try {
  33. String id = String.valueOf(Client.getLayerDao().getLayerByName(layerShortName).getId());
  34. for (Field f : Client.getFieldDao().getFields()) {
  35. if (f.getSpid() != null && f.getSpid().equals(id)) {
  36. field = f.getId();
  37. break;
  38. }
  39. }
  40. } catch (Exception e) {
  41. //don't care if unsuccessful. May already be a fieldId.
  42. }
  43. return field;
  44. }
  45. }