gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / main / java / org / gvsig / vcsgis / lib / server / handlers / RowUpdateHandler.java @ 3375
History | View | Annotate | Download (4.78 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.vcsgis.lib.server.handlers; |
24 |
|
25 |
import java.io.IOException; |
26 |
import java.io.InputStream; |
27 |
import java.io.Writer; |
28 |
import java.util.Map; |
29 |
import javax.json.JsonObject; |
30 |
import javax.json.JsonReader; |
31 |
import org.apache.commons.io.IOUtils; |
32 |
import org.apache.commons.lang3.mutable.MutableObject; |
33 |
import org.gvsig.json.Json; |
34 |
import org.gvsig.json.JsonObjectBuilder; |
35 |
import static org.gvsig.vcsgis.lib.VCSGisUtils.ENTITY_CODE; |
36 |
import static org.gvsig.vcsgis.lib.VCSGisUtils.ENTITY_NAME; |
37 |
import static org.gvsig.vcsgis.lib.VCSGisUtils.ENTITY_REVISIONCODE; |
38 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
39 |
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRequest; |
40 |
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRowUpdateRequest; |
41 |
import static org.gvsig.vcsgis.lib.server.handlers.AbstractVCSGisServertHandler.LOGGER; |
42 |
|
43 |
/**
|
44 |
*
|
45 |
* @author gvSIG Team
|
46 |
*/
|
47 |
@SuppressWarnings("UseSpecificCatch") |
48 |
public class RowUpdateHandler extends AbstractVCSGisServertHandler { |
49 |
|
50 |
private static final String REQUEST_NAME = "RowUpdate"; |
51 |
|
52 |
public RowUpdateHandler(VCSGisRepository repository) {
|
53 |
super(repository, REQUEST_NAME);
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
protected void requestProducer(MutableObject<VCSGisRequest>req,Map<String,String> params, InputStream request_contents) throws IOException { |
58 |
LOGGER.debug("===: ["+this.getName()+"] requestProducer 1"); |
59 |
JsonReader reader = Json.createReader(request_contents); |
60 |
JsonObject jsonRequest = reader.readObject(); |
61 |
|
62 |
String entityName = jsonRequest.getString("EntityName"); |
63 |
String localRevisionCode = jsonRequest.getString("LocalRevisionCode"); |
64 |
|
65 |
VCSGisRowUpdateRequest request = this.getRepository().createRowUpdateRequest(entityName, localRevisionCode);
|
66 |
request.setAuthenticationTokenAndUser(params); |
67 |
|
68 |
request.setEfectiveDate(jsonRequest.getString("EfectiveDate", null)); |
69 |
request.setComment(jsonRequest.getString("Comment", null)); |
70 |
request.setData(jsonRequest.getString("Data", null)); |
71 |
|
72 |
req.setValue(request); |
73 |
|
74 |
LOGGER.debug("===: ["+this.getName()+"] requestProducer 2 notifyRequestConsumers"); |
75 |
notifyRequestConsumers(); |
76 |
|
77 |
LOGGER.debug("===: ["+this.getName()+"] requestProducer 3 return"); |
78 |
} |
79 |
|
80 |
@Override
|
81 |
protected void responseProducer(VCSGisRequest req, Writer response_contents) throws IOException { |
82 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 1"); |
83 |
final VCSGisRowUpdateRequest request = (VCSGisRowUpdateRequest) req;
|
84 |
try {
|
85 |
JsonObjectBuilder jsonbuilder = Json.createObjectBuilder(); |
86 |
jsonbuilder.add("StatusCode", request.getLastErrorCode());
|
87 |
jsonbuilder.add("StatusMessage", request.getLastErrorMessage());
|
88 |
|
89 |
jsonbuilder.add(ENTITY_NAME, request.getEntityName()); |
90 |
jsonbuilder.add(ENTITY_CODE, request.getEntityCode()); |
91 |
jsonbuilder.add(ENTITY_REVISIONCODE, request.getEntityRevisionCode()); |
92 |
|
93 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 2 notifyResponseConsumers"); |
94 |
notifyResponseConsumers(); |
95 |
|
96 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 3 write json to response"); |
97 |
IOUtils.write(jsonbuilder.toString(), response_contents); |
98 |
|
99 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 4 flush"); |
100 |
response_contents.flush(); |
101 |
|
102 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 5 return"); |
103 |
|
104 |
|
105 |
} catch (Exception ex) { |
106 |
LOGGER.warn("Can't produce Json data for "+this.getName()+" response.",ex); |
107 |
|
108 |
} finally {
|
109 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 6 close response_contents"); |
110 |
IOUtils.closeQuietly(response_contents); |
111 |
LOGGER.debug("===: ["+this.getName()+"] responseProducer 7"); |
112 |
} |
113 |
} |
114 |
|
115 |
} |