PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/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 */
14package org.ala.spatial.util;
15
16import org.ala.layers.client.Client;
17import org.ala.layers.dto.Field;
18
19/**
20 * Util function for returning a fieldId from a layer short name.
21 *
22 * @author Adam
23 */
24public class Layers {
25
26    /**
27     * Get fieldId from a layer short name.
28     *
29     * @param layerShortName layer short name as String.
30     * @return fieldId as String, or the input parameter if unsuccessful.
31     */
32    public static String getFieldId(String layerShortName) {
33        String field = layerShortName;
34        // layer short name -> layer id -> field id
35        try {
36            String id = String.valueOf(Client.getLayerDao().getLayerByName(layerShortName).getId());
37            for (Field f : Client.getFieldDao().getFields()) {
38                if (f.getSpid() != null && f.getSpid().equals(id)) {
39                    field = f.getId();
40                    break;
41                }
42            }
43        } catch (Exception e) {
44            //don't care if unsuccessful.  May already be a fieldId.
45        }
46        return field;
47    }
48}