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
RevLine 
[376]1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
[389]4import com.ether.annotation.Mandatory;
5import com.ether.annotation.ParamName;
[396]6import com.ether.annotation.UseJSON;
[419]7import com.ether.tapas.Observatory;
[400]8import com.ether.tapas.Tapas;
[440]9import com.ether.user.User;
[389]10import net.sf.json.JSONObject;
[376]11import org.apache.commons.logging.Log;
12import org.apache.commons.logging.LogFactory;
[440]13import org.jetbrains.annotations.NotNull;
[376]14
[419]15import java.util.ArrayList;
16import java.util.List;
[376]17
18/**
19 * @author vmipsl
[402]20 * @date 02 march 2012
[376]21 */
22public class Controller
23        extends ControllerEther
24{
[389]25
[376]26    /** *********************************************************** **/
27    /** *********************** VIEWS ***************************** **/
[396]28    /** *********************************************************** **/
[442]29    /**
30     * View for the form
31     *
32     * @return
33     * @throws WebException
34     */
[420]35    //@ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = true, defaultView = VIEW_INDEX)
36    @ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = false, defaultView = VIEW_INDEX)
[419]37    public JSONObject viewForm()
[376]38            throws WebException
39    {
[419]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 );
[442]48            jsonObject.put( "jSonSpectralUnits", getJSONSpectralUnit() );
[419]49            return jsonObject;
50        }
51        catch( ServiceException e )
52        {
53            throw new WebException( WebException.WebCode.ERROR_NO_OBSERVATORY_FOUND, e );
54        }
55
[376]56    }
57
[419]58
[376]59    /** *********************************************************** **/
60    /** *********************** CALLS ***************************** **/
[396]61    /** *********************************************************** **/
[442]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     */
[440]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
[402]72            throws WebException
[389]73    {
[411]74        if( null == javaTapas )
[402]75            throw new WebException( WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL, "Serialization error : jsonTapas is null", WebException.getExceptionThrowable() );
76
[440]77        //TODO recuperer le USER via ControllerEther
78
[389]79        //appel a createxml
[440]80        getTapasService().createXMLRequest( javaTapas ); // en 2ieme parametre
[376]81
[440]82        //appel a runtime
83        //mettre une methode dans tapas service pour appel au shell system
84
85
[389]86        final JSONObject result = new JSONObject();
[396]87        result.put( "result", "SUCCESS" );
[389]88        return result;
89    }
90
[419]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();
[442]100            jsonFileFormat.put( "text", fileFormat.name() );
101            jsonFileFormat.put( "value", fileFormat.name() );
102            jsonFileFormats.add( jsonFileFormat );
[419]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();
[442]116            jsonYesNo.put( "text", yesNo.name() );
117            jsonYesNo.put( "value", yesNo.name() );
[419]118            jsonYesNos.add( jsonYesNo );
119        }
120        return jsonYesNos;
121    }
122
[442]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
[376]139    private static final Log LOGGER = LogFactory.getLog( Controller.class );
140
[416]141    private static final String VIEW_INDEX = "init";
[400]142    private static final String VIEW_FORM_TAPAS = "project/formTapas";
[376]143}
Note: See TracBrowser for help on using the repository browser.