git_sitools_idoc / solar / asynchronous_download_public / Asynchronous_Download_java_sitools2 / PublicOrderResourceFacade.java @ master
1 | 20ff13ec | shye0000 | /*******************************************************************************
|
---|---|---|---|
2 | * Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
|
||
3 | *
|
||
4 | * This file is part of SITools2.
|
||
5 | *
|
||
6 | * SITools2 is free software: you can redistribute it and/or modify
|
||
7 | * it under the terms of the GNU General Public License as published by
|
||
8 | * the Free Software Foundation, either version 3 of the License, or
|
||
9 | * (at your option) any later version.
|
||
10 | *
|
||
11 | * SITools2 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 SITools2. If not, see <http://www.gnu.org/licenses/>.
|
||
18 | ******************************************************************************/
|
||
19 | package fr.cnes.sitools.resources.order; |
||
20 | |||
21 | import org.restlet.data.Form; |
||
22 | import org.restlet.ext.wadl.MethodInfo; |
||
23 | import org.restlet.representation.Representation; |
||
24 | import org.restlet.representation.Variant; |
||
25 | |||
26 | import fr.cnes.sitools.common.resource.SitoolsParameterizedResource; |
||
27 | import fr.cnes.sitools.dataset.DataSetApplication; |
||
28 | import fr.cnes.sitools.dataset.database.common.DataSetExplorerUtil; |
||
29 | import fr.cnes.sitools.tasks.TaskUtils; |
||
30 | |||
31 | /**
|
||
32 | * Facade for PublicOrderResource
|
||
33 | *
|
||
34 | *
|
||
35 | * @author m.gond
|
||
36 | */
|
||
37 | public class PublicOrderResourceFacade extends SitoolsParameterizedResource implements IOrderResource { |
||
38 | /**
|
||
39 | * Description de la ressource
|
||
40 | */
|
||
41 | @Override
|
||
42 | public void sitoolsDescribe() { |
||
43 | setName("PublicOrderResourceFacade");
|
||
44 | setDescription("Resource to order data");
|
||
45 | } |
||
46 | |||
47 | /**
|
||
48 | * Description WADL de la methode POST
|
||
49 | *
|
||
50 | * @param info
|
||
51 | * The method description to update.
|
||
52 | */
|
||
53 | @Override
|
||
54 | public void describePost(MethodInfo info) { |
||
55 | info.setDocumentation("Method to order data from a dataset");
|
||
56 | info.setIdentifier("order");
|
||
57 | addStandardPostOrPutRequestInfo(info); |
||
58 | DataSetExplorerUtil.addDatasetExplorerGetRequestInfo(info); |
||
59 | DataSetApplication application = (DataSetApplication) getApplication(); |
||
60 | DataSetExplorerUtil.addDatasetExplorerGetFilterInfo(info, application.getFilterChained()); |
||
61 | addStandardResponseInfo(info); |
||
62 | addStandardInternalServerErrorInfo(info); |
||
63 | this.addInfo(info);
|
||
64 | } |
||
65 | |||
66 | /**
|
||
67 | * Create the order
|
||
68 | *
|
||
69 | * @param represent
|
||
70 | * the {@link Representation} entity
|
||
71 | * @param variant
|
||
72 | * The {@link Variant} needed
|
||
73 | * @return a representation
|
||
74 | */
|
||
75 | public Representation orderPost(Representation represent, Variant variant) {
|
||
76 | processBody(); |
||
77 | return TaskUtils.execute(this, variant); |
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | * Create the order
|
||
82 | *
|
||
83 | * @param variant
|
||
84 | * The {@link Variant} needed
|
||
85 | * @return a representation
|
||
86 | */
|
||
87 | public Representation orderGet(Variant variant) {
|
||
88 | return TaskUtils.execute(this, variant); |
||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * process the body and save the request entity {@link Representation}
|
||
93 | */
|
||
94 | public void processBody() { |
||
95 | Representation body = this.getRequest().getEntity();
|
||
96 | if (body != null && body.isAvailable() && body.getSize() > 0) { |
||
97 | Form bodyForm = new Form(body);
|
||
98 | getContext().getAttributes().put(TaskUtils.BODY_CONTENT, bodyForm); |
||
99 | } |
||
100 | else {
|
||
101 | getContext().getAttributes().remove(TaskUtils.BODY_CONTENT); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | } |