source: ether_megapoli/trunk/web/src/com/ether/Controller.java @ 184

Last change on this file since 184 was 184, checked in by vmipsl, 13 years ago

Servlet _ TimeSerie? : double axes

File size: 5.9 KB
Line 
1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
4import com.ether.annotation.Mandatory;
5import com.ether.annotation.ParamName;
6import com.medias.database.objects.Parametre;
7import com.medias.database.objects.Plateforme;
8import com.medias.database.objects.TypePlateforme;
9import net.sf.json.JSONObject;
10import org.apache.commons.logging.Log;
11import org.apache.commons.logging.LogFactory;
12import org.jetbrains.annotations.NotNull;
13import org.springframework.beans.factory.annotation.Required;
14import org.springframework.web.servlet.ModelAndView;
15
16import javax.servlet.http.HttpServletRequest;
17import javax.servlet.http.HttpServletResponse;
18import java.util.ArrayList;
19import java.util.HashMap;
20import java.util.List;
21import java.util.Map;
22
23/**
24 * @author vmipsl
25 * @date 17 feb 2011
26 */
27public class Controller
28        extends ControllerEther
29{
30    /** *********************************************************** **/
31    /** *********************** VIEWS ***************************** **/
32    /**
33     * ********************************************************** *
34     */
35    // Default view if methodName is unknown
36    public ModelAndView home( final HttpServletRequest request, final HttpServletResponse response )
37            throws EtherException
38    {
39        return new ModelAndView( "index" );
40    }
41
42    @ControllerMethod(view = VIEW_VISUALIZATION)
43    public Map<String, Object> view()
44            throws ServiceException
45    {
46        return new HashMap<String, Object>();
47    }
48
49    @ControllerMethod(view = VIEW_VISUALIZATION_PARAMETER_BY_PLATEFORM)
50    public Map<String, Object> viewParametersByPlateform()
51            throws ServiceException
52    {
53//        final List<Plateforme> plateforms = _etherService.getAllPlateforms();
54        final List<Plateforme> plateforms = new ArrayList<Plateforme>();
55        final Plateforme pf = new Plateforme();
56        pf.setPlateformeId( 1 );
57        pf.setPlateformeNom( "LHVP" );
58        pf.setTypePlateforme( new TypePlateforme( 1, "FIXE" ) );
59        plateforms.add( pf );
60        final Plateforme pf2 = new Plateforme();
61        pf2.setPlateformeId( 2 );
62        pf2.setPlateformeNom( "SIRTA" );
63        pf2.setTypePlateforme( new TypePlateforme( 1, "MOBILE" ) );
64        plateforms.add( pf2 );
65
66        final Map<String, Object> model = new HashMap<String, Object>();
67        model.put( "plateforms", getJsonHelper().toJSON( plateforms ) );
68        model.put( "axeTypesForFixedPlateforms", getJSONAxeTypesForFixedPlateforms() );
69        model.put( "axeTypesForMobilePlateforms", getJSONAxeTypesForMobilePlateforms() );
70        return model;
71    }
72
73    /** *********************************************************** **/
74    /** *********************** CALLS ***************************** **/
75    /**
76     * ********************************************************** *
77     */
78    @ControllerMethod(jsonResult = true)
79    public JSONObject searchParametersByPlateform( @Mandatory @ParamName(ParameterConstants.PARAMETER_ID) final Integer plateformId )
80            throws ServiceException, EtherException
81    {
82//        final List<Parametre> parametersByPlateform = _etherService.getParametersByPlateformId( plateformId );
83        final List<Parametre> parametersByPlateform = new ArrayList<Parametre>( 2 );
84        final Parametre p1 = new Parametre();
85        p1.setParametreId( 1 );
86        p1.setParametreNom( "JNO2" );
87        parametersByPlateform.add( p1 );
88        final Parametre p2 = new Parametre();
89        p2.setParametreId( 2 );
90        p2.setParametreNom( "CO2" );
91        parametersByPlateform.add( p2 );
92
93        if( plateformId == 1 )
94        {
95            final Parametre p3 = new Parametre();
96            p3.setParametreId( 3 );
97            p3.setParametreNom( "Ethane" );
98            parametersByPlateform.add( p3 );
99        }
100        else
101        {
102            final Parametre p3 = new Parametre();
103            p3.setParametreId( 3 );
104            p3.setParametreNom( "Sulfate" );
105            parametersByPlateform.add( p3 );
106            final Parametre p4 = new Parametre();
107            p4.setParametreId( 4 );
108            p4.setParametreNom( "Benzene" );
109            parametersByPlateform.add( p4 );
110        }
111
112        final JSONObject result = new JSONObject();
113        result.put( ParameterConstants.PARAMETER_PARAMETERS, getJsonHelper().toJSON( parametersByPlateform ) );
114        return result;
115    }
116
117    private List<JSONObject> getJSONAxeTypesForFixedPlateforms()
118    {
119        final AxeTypeForFixedPlateform[] axeTypes = AxeTypeForFixedPlateform.values();
120
121        final List<JSONObject> jsonAxeTypes = new ArrayList<JSONObject>( axeTypes.length );
122
123        for( final AxeTypeForFixedPlateform axeType : axeTypes )
124        {
125            final JSONObject jsonAxeType = new JSONObject();
126            jsonAxeType.put( "text", axeType.name() );
127            jsonAxeType.put( "value", axeType.name() );
128            jsonAxeTypes.add( jsonAxeType );
129        }
130        return jsonAxeTypes;
131    }
132
133    private List<JSONObject> getJSONAxeTypesForMobilePlateforms()
134    {
135        final AxeTypeForMobilePlateform[] axeTypes = AxeTypeForMobilePlateform.values();
136
137        final List<JSONObject> jsonAxeTypes = new ArrayList<JSONObject>( axeTypes.length );
138
139        for( final AxeTypeForMobilePlateform axeType : axeTypes )
140        {
141            final JSONObject jsonAxeType = new JSONObject();
142            jsonAxeType.put( "text", axeType.name() );
143            jsonAxeType.put( "value", axeType.name() );
144            jsonAxeTypes.add( jsonAxeType );
145        }
146        return jsonAxeTypes;
147    }
148
149    @Required
150    public void setEtherService( @NotNull final EtherService etherService )
151    {
152        _etherService = etherService;
153    }
154
155    private static final Log LOGGER = LogFactory.getLog( Controller.class );
156
157    private static final String VIEW_VISUALIZATION = "visualization/visu";
158    private static final String VIEW_VISUALIZATION_PARAMETER_BY_PLATEFORM = "visualization/visu_parameter_by_pf";
159
160    private EtherService _etherService;
161}
Note: See TracBrowser for help on using the repository browser.