1 | package com.ether; |
---|
2 | |
---|
3 | import com.ether.annotation.ControllerMethod; |
---|
4 | import com.ether.annotation.Mandatory; |
---|
5 | import com.ether.annotation.ParamName; |
---|
6 | import com.ether.annotation.UseJSON; |
---|
7 | import com.ether.tapas.Observatory; |
---|
8 | import com.ether.tapas.Tapas; |
---|
9 | import com.ether.user.UserRole; |
---|
10 | import net.sf.json.JSONObject; |
---|
11 | import org.apache.commons.logging.Log; |
---|
12 | import org.apache.commons.logging.LogFactory; |
---|
13 | |
---|
14 | import java.util.ArrayList; |
---|
15 | import java.util.HashMap; |
---|
16 | import java.util.List; |
---|
17 | import java.util.Map; |
---|
18 | |
---|
19 | /** |
---|
20 | * @author vmipsl |
---|
21 | * @date 02 march 2012 |
---|
22 | */ |
---|
23 | public class Controller |
---|
24 | extends ControllerEther |
---|
25 | { |
---|
26 | |
---|
27 | /** *********************************************************** **/ |
---|
28 | /** *********************** VIEWS ***************************** **/ |
---|
29 | /** *********************************************************** **/ |
---|
30 | @ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = true, defaultView = VIEW_INDEX) |
---|
31 | public JSONObject viewForm() |
---|
32 | throws WebException |
---|
33 | { |
---|
34 | |
---|
35 | try |
---|
36 | { |
---|
37 | final List<Observatory> allObservatories = getTapasService().getAllObservatories(); |
---|
38 | |
---|
39 | final JSONObject jsonObject = new JSONObject(); |
---|
40 | jsonObject.put( "jSonFileFormats", getJSONFileFormat() ); |
---|
41 | jsonObject.put( "jSonYesNos", getJSONYesNo() ); |
---|
42 | jsonObject.put( "jSonObservatories", allObservatories ); |
---|
43 | return jsonObject; |
---|
44 | } |
---|
45 | catch( ServiceException e ) |
---|
46 | { |
---|
47 | throw new WebException( WebException.WebCode.ERROR_NO_OBSERVATORY_FOUND, e ); |
---|
48 | } |
---|
49 | |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | /** *********************************************************** **/ |
---|
57 | /** *********************** CALLS ***************************** **/ |
---|
58 | /** *********************************************************** **/ |
---|
59 | @ControllerMethod(jsonResult = true) |
---|
60 | public JSONObject createUserRequest( @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas javaTapas ) |
---|
61 | throws WebException |
---|
62 | { |
---|
63 | if( null == javaTapas ) |
---|
64 | throw new WebException( WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL, "Serialization error : jsonTapas is null", WebException.getExceptionThrowable() ); |
---|
65 | |
---|
66 | //appel a createxml |
---|
67 | getTapasService().createXMLRequest( javaTapas ); |
---|
68 | |
---|
69 | final JSONObject result = new JSONObject(); |
---|
70 | result.put( "result", "SUCCESS" ); |
---|
71 | return result; |
---|
72 | } |
---|
73 | |
---|
74 | private List<JSONObject> getJSONFileFormat() |
---|
75 | { |
---|
76 | final FileFormat[] fileFormats = FileFormat.values(); |
---|
77 | |
---|
78 | final List<JSONObject> jsonFileFormats = new ArrayList<JSONObject>( fileFormats.length ); |
---|
79 | |
---|
80 | for( final FileFormat fileFormat : fileFormats ) |
---|
81 | { |
---|
82 | final JSONObject jsonFileFormat = new JSONObject(); |
---|
83 | jsonFileFormat .put( "text", fileFormat.name() ); |
---|
84 | jsonFileFormat .put( "value", fileFormat.name() ); |
---|
85 | jsonFileFormats.add( jsonFileFormat ); |
---|
86 | } |
---|
87 | return jsonFileFormats; |
---|
88 | } |
---|
89 | |
---|
90 | private List<JSONObject> getJSONYesNo() |
---|
91 | { |
---|
92 | final YesNo[] yesNos = YesNo.values(); |
---|
93 | |
---|
94 | final List<JSONObject> jsonYesNos = new ArrayList<JSONObject>( yesNos.length ); |
---|
95 | |
---|
96 | for( final YesNo yesNo : yesNos ) |
---|
97 | { |
---|
98 | final JSONObject jsonYesNo = new JSONObject(); |
---|
99 | jsonYesNo .put( "text", yesNo.name() ); |
---|
100 | jsonYesNo .put( "value", yesNo.name() ); |
---|
101 | jsonYesNos.add( jsonYesNo ); |
---|
102 | } |
---|
103 | return jsonYesNos; |
---|
104 | } |
---|
105 | |
---|
106 | private static final Log LOGGER = LogFactory.getLog( Controller.class ); |
---|
107 | |
---|
108 | private static final String VIEW_INDEX = "init"; |
---|
109 | private static final String VIEW_FORM_TAPAS = "project/formTapas"; |
---|
110 | } |
---|