-
Notifications
You must be signed in to change notification settings - Fork 3
/
Constants.java
330 lines (278 loc) · 8.93 KB
/
Constants.java
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/**
* "First, solve the problem. Then, write the code. -John Johnson"
* "Or use Vangav M"
* www.vangav.com
* */
/**
* MIT License
*
* Copyright (c) 2016 Vangav
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
* */
/**
* Community
* Facebook Group: Vangav Open Source - Backend
* fb.com/groups/575834775932682/
* Facebook Page: Vangav
* fb.com/vangav.f
*
* Third party communities for Vangav Backend
* - play framework
* - cassandra
* - datastax
*
* Tag your question online (e.g.: stack overflow, etc ...) with
* #vangav_backend
* to easier find questions/answers online
* */
package com.vangav.vos_instagram.common;
import com.vangav.backend.exceptions.CodeException;
import com.vangav.backend.exceptions.VangavException;
import com.vangav.backend.exceptions.VangavException.ExceptionClass;
import com.vangav.backend.geo.geo_grids.GeoGridsConfig;
import com.vangav.backend.metrics.distance.Distance;
import com.vangav.backend.metrics.distance.DistanceUnitType;
import com.vangav.backend.metrics.time.Period;
import com.vangav.backend.metrics.time.TimeUnitType;
import com.vangav.backend.play_framework.request.RequestState;
import com.vangav.vos_instagram.common.properties.ConstantsProperties;
/**
* @author mustapha
* fb.com/mustapha.abdallah
*/
/**
* Constants has vos_instagram's constants
*/
public class Constants {
/**
* kAuthCodeLifeTime represents the life time of an authorization code
* before it expires
*/
public static final Period kAuthCodeLifeTime;
static {
try {
kAuthCodeLifeTime =
new Period(
ConstantsProperties.i().getDoubleProperty(
ConstantsProperties.kAuthCodeLifeTimeValue),
TimeUnitType.valueOf(
ConstantsProperties.i().getStringPropterty(
ConstantsProperties.kAuthCodeLifeTimeUnit) ) );
} catch (Exception e) {
throw new CodeException(
300,
1,
"Couldn't initialize kAuthCodeLifeTime: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kAccessTokenLifeTime represents the life time of an access token before
* it expires and has to be refreshed
*/
public static final Period kAccessTokenLifeTime;
static {
try {
kAccessTokenLifeTime =
new Period(
ConstantsProperties.i().getDoubleProperty(
ConstantsProperties.kAccessTokenLifeTimeValue),
TimeUnitType.valueOf(
ConstantsProperties.i().getStringPropterty(
ConstantsProperties.kAccessTokenLifeTimeUnit) ) );
} catch (Exception e) {
throw new CodeException(
300,
2,
"Couldn't initialize kAccessTokenLifeTime: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kFacebookAppId represents facebook's app id, used for facebook-related
* operations
* Only need to be set to a valid value to be able to use facebook-related
* functionalities like facebook login
*/
public static final String kFacebookAppId;
static {
try {
kFacebookAppId =
ConstantsProperties.i().getStringPropterty(
ConstantsProperties.kFacebookAppId);
} catch (Exception e) {
throw new CodeException(
300,
3,
"Couldn't initialize kFacebookAppId: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kCassandraIdConcat is the String used to concat multi-part IDs
* e.g.: year_month_day
*/
public static final String kCassandraIdConcat = "_";
/**
* kDefaultUuid is used when the needed UUID can't be determined
*/
public static final String kDefaultUuid =
"00000000-0000-1000-0000-000000000000";
/**
* kDefaultRegion is used when the needed region can't be determined
*/
public static final String kDefaultRegion;
static {
try {
kDefaultRegion =
ConstantsProperties.i().getStringPropterty(
ConstantsProperties.kDefaultRegion);
} catch (Exception e) {
throw new CodeException(
300,
4,
"Couldn't initialize kDefaultRegion: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kWorldRegion is used to represent the whole world's region
*/
public static final String kWorldRegion;
static {
try {
kWorldRegion =
ConstantsProperties.i().getStringPropterty(
ConstantsProperties.kWorldRegion);
} catch (Exception e) {
throw new CodeException(
300,
5,
"Couldn't initialize kWorldRegion: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kDefaultGridId is used when the needed grid id can't be determined
*/
public static final long kDefaultGridId;
static {
try {
kDefaultGridId =
ConstantsProperties.i().getLongProperty(
ConstantsProperties.kDefaultGridId);
} catch (Exception e) {
throw new CodeException(
300,
6,
"Couldn't initialize kDefaultGridId: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kGeoGridDimensionMetres defines the dimension of geo grids
*/
public static final double kGeoGridDimensionMetres;
static {
try {
kGeoGridDimensionMetres =
ConstantsProperties.i().getDoubleProperty(
ConstantsProperties.kGeoGridDimensionMetres);
} catch (Exception e) {
throw new CodeException(
300,
7,
"Couldn't initialize kGeoGridDimensionMetres: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kGeoGridsConfig defines the geo grids config
*/
public static final GeoGridsConfig kGeoGridsConfig;
static {
try {
kGeoGridsConfig =
new GeoGridsConfig(
"vos_instagram",
new Distance(
kGeoGridDimensionMetres,
DistanceUnitType.METRE) );
} catch (Exception e) {
throw new CodeException(
300,
8,
"Couldn't initialize kGeoGridsConfig: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
public static final String kImagesType = "png";
/**
* kThumbnailDimension represents a thumbnail's dimension in pixels
*/
public static final int kThumbnailDimension;
static {
try {
kThumbnailDimension =
ConstantsProperties.i().getIntProperty(
ConstantsProperties.kThumbnailDimension);
} catch (Exception e) {
throw new CodeException(
300,
9,
"Couldn't initialize kThumbnailDimension: "
+ VangavException.getExceptionStackTrace(e),
ExceptionClass.INITIALIZATION);
}
}
/**
* kFacebookProfilePictureDimension used to query Facebook Graph API
* for users' profile pictures
*/
public static final int kFacebookProfilePictureDimension = 400;
/**
* getHttpStatusCode
* @param requestState
* @return the HTTP status code int corresponding to param requestState
* @throws Exception
*/
public static int getHttpStatusCode (
RequestState requestState) throws Exception {
if (requestState == RequestState.OK) {
return 200;
} else if (requestState == RequestState.BAD_REQUEST) {
return 400;
}
return 500;
}
public static final String kAppleDeviceTypeName = "apple";
public static final String kAndroidDeviceTypeName = "android";
public static final int kDefaultGettersCountLimit = 30;
public static final int kMinGettersCountLimit = 1;
public static final int kMaxGettersCountLimit = 30;
}