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

Last change on this file since 440 was 440, checked in by rboipsl, 12 years ago

ajout anotations
usermandatory

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