/app/models/Venue.java
Java | 228 lines | 202 code | 25 blank | 1 comment | 34 complexity | 03e1520cf1cde231fb83d51d7e1d39c2 MD5 | raw file
- package models;
- import com.google.gson.Gson;
- import models.Notifications.Publication;
- import org.bson.types.ObjectId;
- import play.Logger;
- import play.data.validation.Constraints.Required;
- import com.mongodb.BasicDBObject;
- import com.mongodb.DBObject;
- import org.apache.commons.lang3.text.WordUtils;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Venue {
- @Required
- public String name;
- public String searchName="";
- public ArrayList<String> types = new ArrayList<String>(3);
- public ArrayList<String> followers;
- @Override
- public String toString() {
- return "Venue{" +
- "name='" + name + '\'' +
- ", types=" + types +
- ", address=" + address +
- '}';
- }
- public ArrayList<Publication> publications;
- public String description = "";
- public String phone = "";
- public String photoURLs[]= {"http://toptasting.s3.amazonaws.com/sinImagenVenue.png","",""};
- public ArrayList<String> menuSections=new ArrayList<String>(Arrays.asList("Otros"));
- public double coordinates[] = new double[]{0.0,0.0};
- public ObjectId oid;
- public Address address=new Address();
- public String date="";
- public String insertedBy="";
- public String modified="";//date
- public String modifiedBy="";
- public Venue() {
- }
- public ArrayList<Publication> getPublications() {
- return publications;
- }
- public void setPublications(ArrayList<Publication> publications) {
- this.publications = publications;
- }
- @SuppressWarnings("unchecked")
- public Venue(DBObject object) {
- if (object.containsField("name")) {
- this.name = object.get("name").toString();
- }
- if (object.containsField("searchName")) {
- this.searchName = object.get("searchName").toString();
- }
- Object o=object.get("date");
- if (o!=null) {
- this.date = o.toString();
- }
- o=object.get("insertBy");
- if (o!=null) {
- this.insertedBy = o.toString();
- }
- o=object.get("modified");
- if (o!=null) {
- this.modified = o.toString();
- }
- o=object.get("modifiedBy");
- if (o!=null) {
- this.modifiedBy = o.toString();
- }
- if (object.containsField("description")) {
- this.description = object.get("description").toString();
- }
- if (object.containsField("phone")) {
- this.phone = object.get("phone").toString();
- }
- ArrayList<Object> al = (ArrayList<Object>) object.get("coordinates");
- if (al!=null) {
- coordinates[0]=Double.parseDouble(al.get(0).toString());
- coordinates[1]=Double.parseDouble(al.get(1).toString());
- }
- if (object.containsField("address")) {
- DBObject address = (DBObject) object.get("address");
- if (address.containsField("street")) {
- this.address.street = address.get("street").toString();
- }
- if (address.containsField("city")) {
- this.address.city = WordUtils.capitalize( address.get("city").toString());
- }
- if (address.containsField("province")) {
- this.address.province = WordUtils.capitalize(address.get("province").toString());
- }
- if (address.containsField("streetNumber")) {
- this.address.streetNumber = Integer.parseInt(address.get("streetNumber")
- .toString());
- }
- if (address.containsField("postalCode")) {
- this.address.postalCode = address.get("postalCode").toString();
- }
- }
- if (object.containsField("_id")) {
- oid = (ObjectId) object.get("_id");
- }
- al = (ArrayList<Object>) object.get("menuSections");
- if (al != null) {
- this.menuSections = new ArrayList<String>(al.size());
- for (Object obj : al) {
- this.menuSections.add(obj.toString());
- }
- }
- al = (ArrayList<Object>) object.get("publications");
- if (al != null) {
- this.publications = new ArrayList<Publication>(al.size());
- for (Object obj : al) {
- this.publications.add(new Gson().fromJson(obj.toString(),Publication.class));
- }
- }
- al = (ArrayList<Object>) object.get("followers");
- if (al != null) {
- this.followers = new ArrayList<String>(al.size());
- for (Object obj : al) {
- followers.add(obj.toString());
- }
- }
- al = (ArrayList<Object>) object.get("types");
- if (al != null) {
- for (Object obj : al) {
- this.types.add(obj.toString());
- }
- al = (ArrayList<Object>) object.get("photoURLs");
- if (al != null) {
- this.photoURLs = new String[al.size()];
- int i = 0;
- for (Object obj : al) {
- this.photoURLs[i] = obj.toString();
- i++;
- }
- }
- // menuSections=(String[])object.get("menuSections")).toArray();
- }
-
- }
- public BasicDBObject toDBO(){
-
- BasicDBObject doc = new BasicDBObject("name", name);
- doc.append("description",description);
- doc.append("phone", phone);
- for(String type:types){
- type=type.toLowerCase();
- }
- doc.append("searchName",searchName);
- doc.append("types", types);
- doc.append("coordinates", coordinates);
- doc.append("date",date);
- doc.append("insertedBy",insertedBy);
- doc.append("modified",modified);
- doc.append("modifiedBy",modifiedBy);
- if(photoURLs[0]==null||photoURLs[0].equalsIgnoreCase("")||photoURLs[0].equalsIgnoreCase("undefined")){
- photoURLs[0]="http://toptasting.s3.amazonaws.com/sinImagenVenue.png";
- }
- doc.append("photoURLs", photoURLs);
- doc.append("menuSections", menuSections);
- if(address!=null){
- doc.append("address", address.toDBO());
- }
- return doc;
- }
- public class Address{
- public String street="";
- @Required
- public int streetNumber=0;
- public String postalCode="";
- public String province="asturias";
- public String city="";
- public Address(){
- }
- public Address(String city,String street, int streetNumber, String postalCode,
- String province) {
- super();
- this.street = street;
- this.streetNumber = streetNumber;
- this.postalCode = postalCode;
- this.province = province;
- this.city=city;
- }
- @Override
- public String toString() {
- return "Address{" +
- "street='" + street + '\'' +
- ", postalCode='" + postalCode + '\'' +
- ", province='" + province + '\'' +
- ", city='" + city + '\'' +
- '}';
- }
- public BasicDBObject toDBO(){
- BasicDBObject add=new BasicDBObject();
- add.append("street", address.street);
- add.append("city", address.city.toLowerCase());
- add.append("postalCode", address.postalCode);
- add.append("streetNumber", address.streetNumber);
- add.append("province", address.province.toLowerCase());
- return add;
- }
- }
- }