summaryrefslogtreecommitdiff
path: root/src/main/groovy/org/xapek/yvesf/classifieds/Model.groovy
blob: 6cbdc6e7b7b240ff6bbb9d5af333eb69767fa43f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.xapek.yvesf.classifieds

import groovy.transform.CompileStatic

import java.text.SimpleDateFormat

@CompileStatic
class Model {
  static class Classified {
    //0 = available" -> "Flexible"
    //1 = city" -> "France"
    //2 = column_headings" -> "0"
    //3 = contact" -> "0795354458"
    //4 = currency" -> "CHF"
    //5 = date" -> "Jan 25, 16"
    //6 = description" -> "Fully furnished house of 270 sqm in total. <br />\r\n<br />\r\nVery nice and big house of 270sqm (included 90 sqm2 of basement) with 5 bedrooms, 2 showerooms,1 bathroom and a guest toilet. 70 sqm of closed garage. Wine cellar. Lots of storage.<br />\r\n<br />\r\nBig living/dining room with fireplace.  Big kitchen all equipped.<br />\r\n<br />\r\nLaundry area and storage room.<br />\r\n<br />\r\n1000 sqm of land.<br />\r\n<br />\r\nLocated in Valleiry 20 minutes from Geneva.<br />\r\n<br />\r\n3'000 €<br />\r\n<br />\r\nCan be rent unfurnished TBD<br />\r\n<br />\r\nNo agencies, thanks!"
    //7 = expired" -> "0"
    //8 = id" -> "67199"
    //9 = location" -> "Valleiry"
    //10 ="mark" -> "<a href="javascript:mark(67199)" id="classified_mark_67199">Mark / Save Ad</a>"
    //11 ="mem_first_name" -> "petitemanga"
    //12 ="mem_id" -> "16088"
    //13 ="mem_link" -> "javascript:open_login_popup();"
    //14 ="mem_name" -> "petitemanga"
    //15 ="mem_name_js" -> "petitemanga"
    //16 ="mem_photo" -> "http://cdn.glocals.com/sites/glocals/_static_media/public/members/empty54.gif"
    //17 ="network" -> "Geneva"
    //18 ="photo1" -> "/_media/board_flat1/67/67199_bl_photo_eedba.jpg"
    //19 ="photo2" -> "/_media/board_flat1/67/67199_bl_photo2_58cc1.jpg"
    //20 ="photo3" -> "/_media/board_flat1/67/67199_bl_photo3_a5502.jpg"
    //21 ="photo4" -> "/_media/board_flat1/67/67199_bl_photo4_63653.jpg"
    //22 ="photos" -> "1"
    //23 ="price" -> "3000"
    //24 ="rooms" -> "7"
    //25 ="status" -> "null"
    //26 ="title" -> "Fully furnished house of 270 sqm and huge terrace of 90 sqm"
    //27 ="title_js" -> "Fully furnished house of 270 sqm and huge terrace of 90 sqm"
    //28 ="type" -> "Apts / Housing for rent"
    //29 ="views" -> "8"
    String available
    String rooms
    String location
    String city
    String type
    String price
    String currency
    String views
    String title
    String id
    String mem_name
    String mem_id
    String description
    String date
    Object photo1
    Object photo2
    Object photo3
    Object photo4

    Classified(Map map) {
      metaClass.properties.grep { it instanceof MetaBeanProperty }.each { MetaProperty property ->
        if (!(property as MetaBeanProperty).field) return // ignore setters/getters
        if (property.modifiers != 1) return // only public fields

        if (map.containsKey(property.name)) {
          final value = map.get(property.name)
          if (property.type.isAssignableFrom(value.getClass())) {
            property.setProperty(this, value)
          } else {
            throw new IllegalArgumentException("Cannot set field ${property.name} with object of type ${value.getClass()}")
          }
        } else {
          throw new IllegalArgumentException("Missing data for field ${property.name}")
        }
      }
    }

    final static SimpleDateFormat dateParser = new SimpleDateFormat('MMM dd, yy', Locale.ENGLISH)
    final static SimpleDateFormat dateFormatter = new SimpleDateFormat('EEE, dd MMM yyyy HH:mm:ss Z', Locale.ROOT)
    String getFormattedDate() {
      return dateFormatter.format(dateParser.parse(date))
    }
    String getLink() {
      return "http://www.glocals.com/classifieds/housing-and-real-estate/${id}.htm"
    }

    String getComposedLocation() {
      return location + (city != location ? ', ' + city : '')
    }

    Collection<String> getImages() {
      return [photo1,photo2,photo3,photo4]
          .grep { it instanceof String }
          .collect { "http://www.glocals.com/sites/glocals${it}" }
    }

    String getMemberProfileLink() {
      return "http://www.glocals.com/members/member_profile/${id}"
    }
  }

  static class ClassifiedsList extends ArrayList<Classified> {
    long totalCount

    @Override
    String toString() {
      return "Classified List: totalCount=${totalCount} actualCount=${size()}"
    }
  }
}