source: tapas/web/src/com/ether/Controller.java @ 442

Last change on this file since 442 was 442, checked in by vmipsl, 12 years ago

Spectral units

File size: 4.8 KB
Line 
1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
4import com.ether.annotation.Mandatory;
5import com.ether.annotation.ParamName;
6import com.ether.annotation.UseJSON;
7import com.ether.tapas.Observatory;
8import com.ether.tapas.Tapas;
9import com.ether.user.User;
10import net.sf.json.JSONObject;
11import org.apache.commons.logging.Log;
12import org.apache.commons.logging.LogFactory;
13import org.jetbrains.annotations.NotNull;
14
15import java.util.ArrayList;
16import java.util.List;
17
18/**
19 * @author vmipsl
20 * @date 02 march 2012
21 */
22public class Controller
23        extends ControllerEther
24{
25
26    /** *********************************************************** **/
27    /** *********************** VIEWS ***************************** **/
28    /** *********************************************************** **/
29    /**
30     * View for the form
31     *
32     * @return
33     * @throws WebException
34     */
35    //@ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = true, defaultView = VIEW_INDEX)
36    @ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = false, defaultView = VIEW_INDEX)
37    public JSONObject viewForm()
38            throws WebException
39    {
40        try
41        {
42            final List<Observatory> allObservatories = getTapasService().getAllObservatories();
43
44            final JSONObject jsonObject = new JSONObject();
45            jsonObject.put( "jSonFileFormats", getJSONFileFormat() );
46            jsonObject.put( "jSonYesNos", getJSONYesNo() );
47            jsonObject.put( "jSonObservatories", allObservatories );
48            jsonObject.put( "jSonSpectralUnits", getJSONSpectralUnit() );
49            return jsonObject;
50        }
51        catch( ServiceException e )
52        {
53            throw new WebException( WebException.WebCode.ERROR_NO_OBSERVATORY_FOUND, e );
54        }
55
56    }
57
58
59    /** *********************************************************** **/
60    /** *********************** CALLS ***************************** **/
61    /** *********************************************************** **/
62    /**
63     * This method create a XML file filled with the javaTapas fields
64     *
65     * @param javaTapas
66     * @param user
67     * @return
68     * @throws WebException
69     */
70    @ControllerMethod(jsonResult = true, userMandatory = true)
71    public JSONObject createUserRequest( @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas javaTapas, @NotNull final User user ) // TODO rajouter parametre USER
72            throws WebException
73    {
74        if( null == javaTapas )
75            throw new WebException( WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL, "Serialization error : jsonTapas is null", WebException.getExceptionThrowable() );
76
77        //TODO recuperer le USER via ControllerEther
78
79        //appel a createxml
80        getTapasService().createXMLRequest( javaTapas ); // en 2ieme parametre
81
82        //appel a runtime
83        //mettre une methode dans tapas service pour appel au shell system
84
85
86        final JSONObject result = new JSONObject();
87        result.put( "result", "SUCCESS" );
88        return result;
89    }
90
91    private List<JSONObject> getJSONFileFormat()
92    {
93        final FileFormat[] fileFormats = FileFormat.values();
94
95        final List<JSONObject> jsonFileFormats = new ArrayList<JSONObject>( fileFormats.length );
96
97        for( final FileFormat fileFormat : fileFormats )
98        {
99            final JSONObject jsonFileFormat = new JSONObject();
100            jsonFileFormat.put( "text", fileFormat.name() );
101            jsonFileFormat.put( "value", fileFormat.name() );
102            jsonFileFormats.add( jsonFileFormat );
103        }
104        return jsonFileFormats;
105    }
106
107    private List<JSONObject> getJSONYesNo()
108    {
109        final YesNo[] yesNos = YesNo.values();
110
111        final List<JSONObject> jsonYesNos = new ArrayList<JSONObject>( yesNos.length );
112
113        for( final YesNo yesNo : yesNos )
114        {
115            final JSONObject jsonYesNo = new JSONObject();
116            jsonYesNo.put( "text", yesNo.name() );
117            jsonYesNo.put( "value", yesNo.name() );
118            jsonYesNos.add( jsonYesNo );
119        }
120        return jsonYesNos;
121    }
122
123    private List<JSONObject> getJSONSpectralUnit()
124    {
125        final SpectralUnit[] spectralUnits = SpectralUnit.values();
126
127        final List<JSONObject> jsonSpectralUnits = new ArrayList<JSONObject>( spectralUnits.length );
128
129        for( final SpectralUnit spectralUnit : spectralUnits )
130        {
131            final JSONObject jsonSpectralUnit = new JSONObject();
132            jsonSpectralUnit.put( "text", spectralUnit.name() );
133            jsonSpectralUnit.put( "value", spectralUnit.name() );
134            jsonSpectralUnits.add( jsonSpectralUnit );
135        }
136        return jsonSpectralUnits;
137    }
138
139    private static final Log LOGGER = LogFactory.getLog( Controller.class );
140
141    private static final String VIEW_INDEX = "init";
142    private static final String VIEW_FORM_TAPAS = "project/formTapas";
143}
Note: See TracBrowser for help on using the repository browser.