Mercurial > hg > IndexMetaContextualizer
comparison src/main/java/de/mpiwg/indexmeta/web/servlet/methods/JSONSaveCtx.java @ 9:2bc783262919 default tip
Implementation of Servlet
author | Jorge Urzua <jurzua@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 24 Apr 2013 10:34:46 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
8:9ce7979fd037 | 9:2bc783262919 |
---|---|
1 package de.mpiwg.indexmeta.web.servlet.methods; | |
2 | |
3 import java.io.PrintWriter; | |
4 | |
5 import javax.servlet.http.HttpServletRequest; | |
6 import javax.servlet.http.HttpServletResponse; | |
7 | |
8 import org.apache.commons.lang.StringUtils; | |
9 import org.json.JSONObject; | |
10 | |
11 import de.mpiwg.indexmeta.bo.Contextualization; | |
12 import de.mpiwg.indexmeta.services.DataProvider; | |
13 | |
14 public class JSONSaveCtx extends AbstractServletMethod { | |
15 | |
16 public static void execute(DataProvider dp, | |
17 HttpServletRequest request, HttpServletResponse response) | |
18 throws Exception { | |
19 | |
20 JSONObject json = new JSONObject(); | |
21 | |
22 long startExecution = System.currentTimeMillis(); | |
23 | |
24 String indexMetaId = getString(request, p_indexMetaId); | |
25 String elementId = getString(request, p_elementId); | |
26 | |
27 String comment = getString(request, p_comment); | |
28 String content = getString(request, p_content); | |
29 String remoteId = getString(request, p_remoteId); | |
30 String state = getString(request, p_state); | |
31 String type = getString(request, p_type); | |
32 | |
33 if(StringUtils.isEmpty(indexMetaId) || | |
34 StringUtils.isEmpty(elementId) || | |
35 StringUtils.isEmpty(type)){ | |
36 | |
37 response.sendError(HttpServletResponse.SC_BAD_REQUEST, | |
38 "Parameters 'indexMetaId', 'elementId' and 'type' are null. " | |
39 + "At least one of them must be not null."); | |
40 return; | |
41 } | |
42 | |
43 Contextualization ctx = dp.getCtx(indexMetaId, elementId); | |
44 | |
45 if(ctx == null){ | |
46 ctx = new Contextualization(); | |
47 ctx.setIndexMetaId(indexMetaId); | |
48 ctx.setElementId(elementId); | |
49 } | |
50 | |
51 ctx.setComment(comment); | |
52 ctx.setContent(content); | |
53 ctx.setRemoteId(remoteId); | |
54 ctx.setState(state); | |
55 ctx.setType(type); | |
56 | |
57 json.put(RUNTIME, (System.currentTimeMillis() - startExecution)); | |
58 | |
59 PrintWriter out = response.getWriter(); | |
60 out.print(json.toString()); | |
61 | |
62 } | |
63 | |
64 } |