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 package com.buckosoft.BuckoVidLib.web;
83
84 import java.io.IOException;
85 import java.net.URISyntaxException;
86 import java.nio.charset.Charset;
87 import java.nio.file.Files;
88 import java.nio.file.Paths;
89 import java.util.List;
90
91 import javax.jws.WebService;
92 import javax.ws.rs.GET;
93 import javax.ws.rs.NotFoundException;
94 import javax.ws.rs.Path;
95 import javax.ws.rs.PathParam;
96 import javax.ws.rs.Produces;
97
98 import org.springframework.beans.factory.annotation.Autowired;
99 import org.springframework.stereotype.Service;
100
101 import com.buckosoft.BuckoVidLib.business.BuckoVidLib;
102 import com.buckosoft.BuckoVidLib.db.Database;
103 import com.buckosoft.BuckoVidLib.domain.FailedToRip;
104 import com.buckosoft.BuckoVidLib.domain.VideoBase;
105 import com.buckosoft.BuckoVidLib.domain.WishList;
106 import com.buckosoft.BuckoVidLib.util.ConfigManager;
107 import com.buckosoft.BuckoVidLib.util.DomainConverter;
108
109
110
111
112
113
114 @WebService(endpointInterface = "com.buckosoft.BuckoVidLib.web.BVLRestService")
115 @Service("bvlService")
116 @Path("/")
117 @Produces("text/xml")
118 public class BVLRestServiceImpl implements BVLRestService {
119
120 @Autowired
121 private BuckoVidLib bvl;
122
123 @Autowired
124 private Database db;
125
126
127 @Override
128 @GET
129 @Path("/failedToRip")
130 public List<FailedToRip> failedToRip() {
131 return(bvl.getFailedToRip());
132 }
133
134
135
136
137 @Override
138 @GET
139 @Path("/wishList")
140 public List<WishList> wishList() {
141 return(bvl.getWishList());
142 }
143
144
145
146
147
148
149
150
151 @Override
152 @GET
153 @Path("/about")
154 @Produces("text/plain")
155 public String about() {
156 return(readAllLines("/BuckoVidLib-about.html"));
157 }
158
159
160
161
162
163 @Override
164 @GET
165 @Path("/statistics/mia")
166 @Produces("text/plain")
167 public String missingInAction() {
168 return(readAllLines("/BuckoVidLib-MIA.html"));
169 }
170
171 private String readAllLines(String fileName) {
172 List<String> ss;
173 try {
174 ss = Files.readAllLines(
175 Paths.get(this.getClass().getResource(fileName).toURI()), Charset.defaultCharset());
176 } catch (IOException e) {
177 return("<h2>failed to read about data</h2>");
178 } catch (URISyntaxException e) {
179 return("<h2>failed to determine about data</h2>");
180 }
181 String s = "";
182 for (String sx : ss)
183 s += sx + "\n";
184 return s;
185
186 }
187
188 @GET
189 @Path("/idToKey/{id}")
190 @Produces("text/plain")
191 public String idToKey(@PathParam("id") Integer id) {
192 if (!ConfigManager.getBoolean("BuckoVidLib.debugJS", false))
193 return("Not in production");
194 VideoBase v = db.getVideoBase(id);
195 if (v == null) {
196 return("Video " + id + " not found");
197 }
198 return(DomainConverter.intToKey(v.getHashKey()) + "\n");
199 }
200
201 @GET
202 @Path("/.*")
203 public void unhandled() {
204 throw new NotFoundException();
205 }
206
207 }