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.medias.database.objects.Parametre; |
---|
7 | import com.medias.database.objects.Plateforme; |
---|
8 | import net.sf.json.JSONObject; |
---|
9 | import org.apache.commons.logging.Log; |
---|
10 | import org.apache.commons.logging.LogFactory; |
---|
11 | import org.jetbrains.annotations.NotNull; |
---|
12 | import org.springframework.beans.factory.annotation.Required; |
---|
13 | import org.springframework.web.servlet.ModelAndView; |
---|
14 | |
---|
15 | import javax.servlet.http.HttpServletRequest; |
---|
16 | import javax.servlet.http.HttpServletResponse; |
---|
17 | import java.util.ArrayList; |
---|
18 | import java.util.HashMap; |
---|
19 | import java.util.List; |
---|
20 | import java.util.Map; |
---|
21 | |
---|
22 | /** |
---|
23 | * @author vmipsl |
---|
24 | * @date 17 feb 2011 |
---|
25 | */ |
---|
26 | public class Controller |
---|
27 | extends ControllerEther |
---|
28 | { |
---|
29 | /** *********************************************************** **/ |
---|
30 | /** *********************** VIEWS ***************************** **/ |
---|
31 | /** |
---|
32 | * ********************************************************** * |
---|
33 | */ |
---|
34 | // Default view if methodName is unknown |
---|
35 | public ModelAndView home( final HttpServletRequest request, final HttpServletResponse response ) |
---|
36 | throws EtherException |
---|
37 | { |
---|
38 | return new ModelAndView( "index" ); |
---|
39 | } |
---|
40 | |
---|
41 | @ControllerMethod(view = VIEW_VISUALIZATION) |
---|
42 | public Map<String, Object> view() |
---|
43 | throws ServiceException |
---|
44 | { |
---|
45 | return new HashMap<String, Object>(); |
---|
46 | } |
---|
47 | |
---|
48 | @ControllerMethod(view = VIEW_VISUALIZATION_PARAMETER_BY_PLATEFORM) |
---|
49 | public Map<String, Object> viewParametersByPlateform() |
---|
50 | throws ServiceException |
---|
51 | { |
---|
52 | // final List<Plateforme> plateforms = _etherService.getAllPlateforms(); |
---|
53 | final List<Plateforme> plateforms = BouchonHelper.createPlateforms(); |
---|
54 | |
---|
55 | final Map<String, Object> model = new HashMap<String, Object>(); |
---|
56 | model.put( "plateforms", getJsonHelper().toJSON( plateforms ) ); |
---|
57 | model.put( "axeTypesForFixedPlateforms", getJSONAxeTypesForFixedPlateforms() ); |
---|
58 | model.put( "axeTypesForMobilePlateforms", getJSONAxeTypesForMobilePlateforms() ); |
---|
59 | return model; |
---|
60 | } |
---|
61 | |
---|
62 | /** *********************************************************** **/ |
---|
63 | /** *********************** CALLS ***************************** **/ |
---|
64 | /** |
---|
65 | * ********************************************************** * |
---|
66 | */ |
---|
67 | @ControllerMethod(jsonResult = true) |
---|
68 | public JSONObject searchParametersByPlateform( @Mandatory @ParamName(ParameterConstants.PARAMETER_ID) final Integer plateformId ) |
---|
69 | throws ServiceException, EtherException |
---|
70 | { |
---|
71 | // final List<Parametre> parametersByPlateform = _etherService.getParametersByPlateformId( plateformId ); |
---|
72 | final List<Parametre> parametersByPlateform = BouchonHelper.createParameters( plateformId ); |
---|
73 | |
---|
74 | final JSONObject result = new JSONObject(); |
---|
75 | result.put( ParameterConstants.PARAMETER_PARAMETERS, getJsonHelper().toJSON( parametersByPlateform ) ); |
---|
76 | return result; |
---|
77 | } |
---|
78 | |
---|
79 | private List<JSONObject> getJSONAxeTypesForFixedPlateforms() |
---|
80 | { |
---|
81 | final AxeTypeForFixedPlateform[] axeTypes = AxeTypeForFixedPlateform.values(); |
---|
82 | |
---|
83 | final List<JSONObject> jsonAxeTypes = new ArrayList<JSONObject>( axeTypes.length ); |
---|
84 | |
---|
85 | for( final AxeTypeForFixedPlateform axeType : axeTypes ) |
---|
86 | { |
---|
87 | final JSONObject jsonAxeType = new JSONObject(); |
---|
88 | jsonAxeType.put( "text", axeType.name() ); |
---|
89 | jsonAxeType.put( "value", axeType.name() ); |
---|
90 | jsonAxeTypes.add( jsonAxeType ); |
---|
91 | } |
---|
92 | return jsonAxeTypes; |
---|
93 | } |
---|
94 | |
---|
95 | private List<JSONObject> getJSONAxeTypesForMobilePlateforms() |
---|
96 | { |
---|
97 | final AxeTypeForMobilePlateform[] axeTypes = AxeTypeForMobilePlateform.values(); |
---|
98 | |
---|
99 | final List<JSONObject> jsonAxeTypes = new ArrayList<JSONObject>( axeTypes.length ); |
---|
100 | |
---|
101 | for( final AxeTypeForMobilePlateform axeType : axeTypes ) |
---|
102 | { |
---|
103 | final JSONObject jsonAxeType = new JSONObject(); |
---|
104 | jsonAxeType.put( "text", axeType.name() ); |
---|
105 | jsonAxeType.put( "value", axeType.name() ); |
---|
106 | jsonAxeTypes.add( jsonAxeType ); |
---|
107 | } |
---|
108 | return jsonAxeTypes; |
---|
109 | } |
---|
110 | |
---|
111 | @Required |
---|
112 | public void setEtherService( @NotNull final EtherService etherService ) |
---|
113 | { |
---|
114 | _etherService = etherService; |
---|
115 | } |
---|
116 | |
---|
117 | private static final Log LOGGER = LogFactory.getLog( Controller.class ); |
---|
118 | |
---|
119 | private static final String VIEW_VISUALIZATION = "visualization/visu"; |
---|
120 | private static final String VIEW_VISUALIZATION_PARAMETER_BY_PLATEFORM = "visualization/visu_parameter_by_pf"; |
---|
121 | |
---|
122 | private EtherService _etherService; |
---|
123 | } |
---|