001package de.kiezatlas;
002
003import de.deepamehta.core.JSONEnabled;
004import de.deepamehta.plugins.geomaps.model.GeoCoordinate;
005import org.codehaus.jettison.json.JSONArray;
006
007import org.codehaus.jettison.json.JSONObject;
008
009
010
011/**
012 * A data transfer object as returned by the Kiezatlas Institution API and as used by Administrators.
013 */
014public class SocialInstitutionObject implements JSONEnabled {
015
016    // ---------------------------------------------------------------------------------------------- Instance Variables
017
018    private JSONObject json = new JSONObject();
019
020    // -------------------------------------------------------------------------------------------------- Public Methods
021
022    @Override
023    public JSONObject toJSON() {
024        return json;
025    }
026
027    // ----------------------------------------------------------------------------------------- Package Private Methods
028
029    void setName(String name) {
030        try {
031            json.put("name", name);
032        } catch (Exception e) {
033            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
034        }
035    }
036
037    void setBezirk(String bezirk) {
038        try {
039            json.put("bezirk", bezirk);
040        } catch (Exception e) {
041            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
042        }
043    }
044
045    void setGeoCoordinate(GeoCoordinate geoCoord) {
046        try {
047            JSONObject geolocation = new JSONObject();
048            geolocation.put("lon", geoCoord.lon);
049            geolocation.put("lat", geoCoord.lat);
050            //
051            json.put("geolocation", geolocation);
052        } catch (Exception e) {
053            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
054        }
055    }
056
057    void setDistanceInMeter(String meter) {
058        try {
059            json.put("distanz", meter);
060        } catch (Exception e) {
061            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
062        }
063    }
064
065    void setUri(String uri) {
066        try {
067            json.put("uri", uri);
068        } catch (Exception e) {
069            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
070        }
071    }
072    
073    void setAddress(String address) {
074        try {
075            json.put("anschrift", address);
076        } catch (Exception e) {
077            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
078        }
079    }
080
081    void setAddresses(JSONArray addresses) {
082        try {
083            json.put("anschriften", addresses);
084        } catch (Exception e) {
085            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
086        }
087    }
088    
089    void setOpeningHours(String openingHours) {
090        try {
091            json.put("oeffnungszeiten", openingHours);
092        } catch (Exception e) {
093            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
094        }
095    }
096
097    void setContact(String contact) {
098        try {
099            json.put("kontakt", contact);
100        } catch (Exception e) {
101            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
102        }
103    }
104
105    void setCreated(long timestamp) {
106        try {
107            json.put("created", timestamp);
108        } catch (Exception e) {
109            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
110        }
111    }
112
113    void setLastModified(long timestamp) {
114        try {
115            json.put("modified", timestamp);
116        } catch (Exception e) {
117            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
118        }
119    }
120
121    void addClassification(String className) {
122        try {
123            if (json.has("class")) {
124                json.put("class", json.get("class") + " " + className);
125            } else {
126                json.put("class", className);   
127            }
128        } catch (Exception e) {
129            throw new RuntimeException("Constructing a SocialInstitutionObject failed", e);
130        }
131    }
132
133}