[376] | 1 | package com.ether; |
---|
| 2 | |
---|
| 3 | import com.ether.annotation.ControllerMethod; |
---|
[389] | 4 | import com.ether.annotation.Mandatory; |
---|
| 5 | import com.ether.annotation.ParamName; |
---|
[396] | 6 | import com.ether.annotation.UseJSON; |
---|
[419] | 7 | import com.ether.tapas.Observatory; |
---|
[400] | 8 | import com.ether.tapas.Tapas; |
---|
[419] | 9 | import com.ether.user.UserRole; |
---|
[389] | 10 | import net.sf.json.JSONObject; |
---|
[376] | 11 | import org.apache.commons.logging.Log; |
---|
| 12 | import org.apache.commons.logging.LogFactory; |
---|
| 13 | |
---|
[419] | 14 | import java.util.ArrayList; |
---|
[376] | 15 | import java.util.HashMap; |
---|
[419] | 16 | import java.util.List; |
---|
[376] | 17 | import java.util.Map; |
---|
| 18 | |
---|
| 19 | /** |
---|
| 20 | * @author vmipsl |
---|
[402] | 21 | * @date 02 march 2012 |
---|
[376] | 22 | */ |
---|
| 23 | public class Controller |
---|
| 24 | extends ControllerEther |
---|
| 25 | { |
---|
[389] | 26 | |
---|
[376] | 27 | /** *********************************************************** **/ |
---|
| 28 | /** *********************** VIEWS ***************************** **/ |
---|
[396] | 29 | /** *********************************************************** **/ |
---|
[416] | 30 | @ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = true, defaultView = VIEW_INDEX) |
---|
[419] | 31 | public JSONObject viewForm() |
---|
[376] | 32 | throws WebException |
---|
| 33 | { |
---|
[419] | 34 | |
---|
| 35 | try |
---|
| 36 | { |
---|
| 37 | final List<Observatory> allObservatories = getTapasService().getAllObservatories(); |
---|
| 38 | |
---|
| 39 | final JSONObject jsonObject = new JSONObject(); |
---|
| 40 | jsonObject.put( "jSonFileFormats", getJSONFileFormat() ); |
---|
| 41 | jsonObject.put( "jSonYesNos", getJSONYesNo() ); |
---|
| 42 | jsonObject.put( "jSonObservatories", allObservatories ); |
---|
| 43 | return jsonObject; |
---|
| 44 | } |
---|
| 45 | catch( ServiceException e ) |
---|
| 46 | { |
---|
| 47 | throw new WebException( WebException.WebCode.ERROR_NO_OBSERVATORY_FOUND, e ); |
---|
| 48 | } |
---|
| 49 | |
---|
[376] | 50 | } |
---|
| 51 | |
---|
[419] | 52 | |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
[376] | 56 | /** *********************************************************** **/ |
---|
| 57 | /** *********************** CALLS ***************************** **/ |
---|
[396] | 58 | /** *********************************************************** **/ |
---|
[389] | 59 | @ControllerMethod(jsonResult = true) |
---|
[411] | 60 | public JSONObject createUserRequest( @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas javaTapas ) |
---|
[402] | 61 | throws WebException |
---|
[389] | 62 | { |
---|
[411] | 63 | if( null == javaTapas ) |
---|
[402] | 64 | throw new WebException( WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL, "Serialization error : jsonTapas is null", WebException.getExceptionThrowable() ); |
---|
| 65 | |
---|
[389] | 66 | //appel a createxml |
---|
[411] | 67 | getTapasService().createXMLRequest( javaTapas ); |
---|
[376] | 68 | |
---|
[389] | 69 | final JSONObject result = new JSONObject(); |
---|
[396] | 70 | result.put( "result", "SUCCESS" ); |
---|
[389] | 71 | return result; |
---|
| 72 | } |
---|
| 73 | |
---|
[419] | 74 | private List<JSONObject> getJSONFileFormat() |
---|
| 75 | { |
---|
| 76 | final FileFormat[] fileFormats = FileFormat.values(); |
---|
| 77 | |
---|
| 78 | final List<JSONObject> jsonFileFormats = new ArrayList<JSONObject>( fileFormats.length ); |
---|
| 79 | |
---|
| 80 | for( final FileFormat fileFormat : fileFormats ) |
---|
| 81 | { |
---|
| 82 | final JSONObject jsonFileFormat = new JSONObject(); |
---|
| 83 | jsonFileFormat .put( "text", fileFormat.name() ); |
---|
| 84 | jsonFileFormat .put( "value", fileFormat.name() ); |
---|
| 85 | jsonFileFormats.add( jsonFileFormat ); |
---|
| 86 | } |
---|
| 87 | return jsonFileFormats; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | private List<JSONObject> getJSONYesNo() |
---|
| 91 | { |
---|
| 92 | final YesNo[] yesNos = YesNo.values(); |
---|
| 93 | |
---|
| 94 | final List<JSONObject> jsonYesNos = new ArrayList<JSONObject>( yesNos.length ); |
---|
| 95 | |
---|
| 96 | for( final YesNo yesNo : yesNos ) |
---|
| 97 | { |
---|
| 98 | final JSONObject jsonYesNo = new JSONObject(); |
---|
| 99 | jsonYesNo .put( "text", yesNo.name() ); |
---|
| 100 | jsonYesNo .put( "value", yesNo.name() ); |
---|
| 101 | jsonYesNos.add( jsonYesNo ); |
---|
| 102 | } |
---|
| 103 | return jsonYesNos; |
---|
| 104 | } |
---|
| 105 | |
---|
[376] | 106 | private static final Log LOGGER = LogFactory.getLog( Controller.class ); |
---|
| 107 | |
---|
[416] | 108 | private static final String VIEW_INDEX = "init"; |
---|
[400] | 109 | private static final String VIEW_FORM_TAPAS = "project/formTapas"; |
---|
[376] | 110 | } |
---|