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
|
/*
* Copyright (C) 2008-2022, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.juick.www.api.activity.model;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.juick.www.api.activity.helpers.ActivityIdDeserializer;
import com.juick.www.api.activity.helpers.ContextTypeFilter;
import com.juick.www.api.activity.helpers.LinkValueDeserializer;
import com.juick.www.api.activity.model.activities.*;
import com.juick.www.api.activity.model.objects.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property="type", defaultImpl = Context.class)
@JsonSubTypes({
@JsonSubTypes.Type(value = Create.class, name = "Create"),
@JsonSubTypes.Type(value = Update.class, name = "Update"),
@JsonSubTypes.Type(value = Delete.class, name = "Delete"),
@JsonSubTypes.Type(value = Flag.class, name = "Flag"),
@JsonSubTypes.Type(value = Follow.class, name = "Follow"),
@JsonSubTypes.Type(value = Accept.class, name = "Accept"),
@JsonSubTypes.Type(value = Undo.class, name = "Undo"),
@JsonSubTypes.Type(value = Like.class, name = "Like"),
@JsonSubTypes.Type(value = Block.class, name = "Block"),
@JsonSubTypes.Type(value = Announce.class, name = "Announce"),
@JsonSubTypes.Type(value = Activity.class, name = "Activity"),
@JsonSubTypes.Type(value = Image.class, name = "Image"),
@JsonSubTypes.Type(value = Key.class, name = "Key"),
@JsonSubTypes.Type(value = Link.class, name = "Link"),
@JsonSubTypes.Type(value = Hashtag.class, name = "Hashtag"),
@JsonSubTypes.Type(value = Mention.class, name = "Mention"),
@JsonSubTypes.Type(value = Emoji.class, name = "Emoji"),
@JsonSubTypes.Type(value = Note.class, name = "Note"),
@JsonSubTypes.Type(value = OrderedCollection.class, name = "OrderedCollection"),
@JsonSubTypes.Type(value = OrderedCollectionPage.class, name = "OrderedCollectionPage"),
@JsonSubTypes.Type(value = Person.class, name = "Person"),
@JsonSubTypes.Type(value = Application.class, name = "Application"),
@JsonSubTypes.Type(value = Service.class, name = "Service"),
@JsonSubTypes.Type(value = Group.class, name = "Group"),
@JsonSubTypes.Type(value = Organization.class, name = "Organization")
})
public class Context implements Serializable {
private List<Object> context;
private String id;
private String name;
private Image icon;
private Instant published;
private String content;
@JsonDeserialize(using = LinkValueDeserializer.class)
private String url;
private List<String> to;
private List<String> cc;
private List<Context> tags;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = ContextTypeFilter.class)
public String getType() {
return getClass().getSimpleName();
}
@JsonProperty("@context")
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
public List<Object> getContext() {
return context;
}
public final static String ACTIVITY_STREAMS_URI = "https://www.w3.org/ns/activitystreams";
public final static String SECURITY_URI = "https://w3id.org/security/v1";
public final static String LD_JSON_MEDIA_TYPE = "application/ld+json";
public final static String ACTIVITY_MEDIA_TYPE = "application/activity+json";
public final static String ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE = LD_JSON_MEDIA_TYPE + "; profile=\"https://www.w3.org/ns/activitystreams\"";
public final static String ACTIVITYSTREAMS_PUBLIC = "https://www.w3.org/ns/activitystreams#Public";
public Instant getPublished() {
return published;
}
public void setPublished(Instant published) {
this.published = published;
}
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
@JsonDeserialize(contentUsing = ActivityIdDeserializer.class)
public List<String> getTo() {
return to;
}
public void setTo(List<String> to) {
this.to = to;
}
public static Context build(Context response) {
response.context = new ArrayList<>(Arrays.asList(ACTIVITY_STREAMS_URI, SECURITY_URI));
response.context.add(Map.of("Hashtag", "as:Hashtag", "sensitive", "as:sensitive"));
return response;
}
public Context() {}
public Context(String id) {
setId(id);
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@JsonProperty("tag")
public List<Context> getTags() {
return tags;
}
public void setTags(List<Context> tags) {
this.tags = tags;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
public Image getIcon() {
return icon;
}
public void setIcon(Image icon) {
this.icon = icon;
}
public List<String> getCc() {
return cc;
}
public void setCc(List<String> cc) {
this.cc = cc;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
|