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 net.sf.json.JSONObject; |
---|
7 | import org.apache.commons.logging.Log; |
---|
8 | import org.apache.commons.logging.LogFactory; |
---|
9 | import org.jetbrains.annotations.NotNull; |
---|
10 | import org.springframework.beans.factory.annotation.Required; |
---|
11 | |
---|
12 | import java.util.HashMap; |
---|
13 | import java.util.List; |
---|
14 | import java.util.Map; |
---|
15 | |
---|
16 | /** |
---|
17 | * @author vmipsl |
---|
18 | * @date 17 feb 2011 |
---|
19 | */ |
---|
20 | public class Controller |
---|
21 | extends ControllerEther |
---|
22 | { |
---|
23 | /** *********************************************************** **/ |
---|
24 | /** *********************** VIEWS ***************************** **/ |
---|
25 | /** |
---|
26 | * ********************************************************** * |
---|
27 | */ |
---|
28 | // Default view if url's methodName is unknown |
---|
29 | @ControllerMethod(view = "init") |
---|
30 | public Map<String, Object> home() |
---|
31 | throws WebException |
---|
32 | { |
---|
33 | return new HashMap<String, Object>(); |
---|
34 | } |
---|
35 | |
---|
36 | @ControllerMethod(view = VIEW_VISUALIZATION) |
---|
37 | public Map<String, Object> view() |
---|
38 | throws WebException |
---|
39 | { |
---|
40 | return new HashMap<String, Object>(); |
---|
41 | } |
---|
42 | |
---|
43 | @ControllerMethod(view = VIEW_VISUALIZATION_PLATEFORM) |
---|
44 | public Map<String, Object> viewAllPlateforms() |
---|
45 | throws WebException |
---|
46 | { |
---|
47 | try |
---|
48 | { |
---|
49 | final List<Plateform> plateforms = _etherService.getAllPlateforms(); |
---|
50 | |
---|
51 | final Map<String, Object> model = new HashMap<String, Object>(); |
---|
52 | model.put( "plateforms", getJsonHelper().toJSON( plateforms ) ); |
---|
53 | return model; |
---|
54 | } |
---|
55 | catch( ServiceException e ) |
---|
56 | { |
---|
57 | throw new WebException( WebException.WebCode.PLATEFORM_NOT_FOUND, e ); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | /** *********************************************************** **/ |
---|
62 | /** *********************** CALLS ***************************** **/ |
---|
63 | /** |
---|
64 | * ********************************************************** * |
---|
65 | */ |
---|
66 | @ControllerMethod(jsonResult = true) |
---|
67 | public JSONObject searchParametersByPlateform( @Mandatory @ParamName(ParameterConstants.PARAMETER_ID) final Integer plateformId ) |
---|
68 | throws WebException |
---|
69 | { |
---|
70 | try |
---|
71 | { |
---|
72 | |
---|
73 | // final List<Parameter> parameters = new ArrayList<Parameter>( 3 ); |
---|
74 | // parameters.add( new Parameter( Long.valueOf( 1 ), "parameter1" ) ); |
---|
75 | // parameters.add( new Parameter( Long.valueOf( 2 ), "parameter2" ) ); |
---|
76 | // parameters.add( new Parameter( Long.valueOf( 3 ), "parameter3" ) ); |
---|
77 | |
---|
78 | final List<Parameter> parameters = _etherService.getAllParametersByPlateformId( plateformId ); |
---|
79 | final JSONObject result = new JSONObject(); |
---|
80 | result.put( "parameters", getJsonHelper().toJSON( parameters ) ); |
---|
81 | return result; |
---|
82 | } |
---|
83 | catch( ServiceException e ) |
---|
84 | { |
---|
85 | throw new WebException( WebException.WebCode.PARAMETER_NOT_FOUND, e ); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | @Required |
---|
90 | public void setEtherService( @NotNull final EtherService etherService ) |
---|
91 | { |
---|
92 | _etherService = etherService; |
---|
93 | } |
---|
94 | |
---|
95 | private static final Log LOGGER = LogFactory.getLog( Controller.class ); |
---|
96 | |
---|
97 | private static final String VIEW_VISUALIZATION = "visualization/visu"; |
---|
98 | private static final String VIEW_VISUALIZATION_PLATEFORM = "visualization/visu_plateform"; |
---|
99 | |
---|
100 | private EtherService _etherService; |
---|
101 | } |
---|