RecommendationTemplateImpl.java
1.93 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.cq.targetrecommendations.impl.model;
import com.adobe.cq.targetrecommendations.api.TargetRecommendationsException;
import com.adobe.cq.targetrecommendations.api.model.RecommendationTemplate;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class RecommendationTemplateImpl
implements RecommendationTemplate {
private int id;
private String name;
private String script;
public RecommendationTemplateImpl(int id, String name, String script) {
this.id = id;
this.name = name;
this.script = script;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return this.name;
}
@Override
public String getScript() {
return this.script;
}
public static RecommendationTemplate fromJson(JSONObject recTemplateJson) throws JSONException {
int id = -1;
if (recTemplateJson.has("id")) {
id = recTemplateJson.getInt("id");
}
String name = recTemplateJson.getString("name");
String script = recTemplateJson.getString("script");
return new RecommendationTemplateImpl(id, name, script);
}
@Override
public String toJson() throws TargetRecommendationsException {
try {
JSONObject templateJson = new JSONObject();
if (this.getId() > 0) {
templateJson.put("id", this.getId());
}
templateJson.put("name", (Object)this.getName());
templateJson.put("script", (Object)this.getScript());
return templateJson.toString();
}
catch (Exception e) {
throw new TargetRecommendationsException(e);
}
}
}