source: geisa/web/src/com/ether/Controller.java @ 552

Last change on this file since 552 was 552, checked in by npipsl, 12 years ago

transitions

File size: 10.3 KB
Line 
1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
4import com.ether.annotation.ParamName;
5import net.sf.json.JSONObject;
6import org.apache.commons.logging.Log;
7import org.apache.commons.logging.LogFactory;
8import org.jetbrains.annotations.NotNull;
9import org.springframework.beans.factory.annotation.Required;
10
11import java.io.File;
12import java.util.Arrays;
13import java.util.Calendar;
14import java.util.HashMap;
15import java.util.List;
16import java.util.Map;
17import java.util.Set;
18
19/**
20 * @author vmipsl
21 * @date 17 feb 2011
22 */
23public class Controller
24        extends ControllerEther
25{
26
27    /** *********************************************************** **/
28    /** *********************** VIEWS ***************************** **/
29    /**
30     * ********************************************************** *
31     */
32    @ControllerMethod(view = VIEW_INIT)
33    public Map<String, Object> home()
34            throws WebException
35    {
36        return new HashMap<String, Object>();
37    }
38
39    @ControllerMethod(view = VIEW_INIT2)
40    public Map<String, Object> geisaMethod()
41            throws WebException
42    {
43        return new HashMap<String, Object>();
44    }
45    /** *********************************************************** **/
46    /** *********************** CALLS ***************************** **/
47    /**
48     * ********************************************************** *
49     */
50
51    @ControllerMethod(jsonResult = true)
52    //public JSONObject createUserRequest( @ParamName("fortranRequest") final String fortranRequest,  @ParamName("nbGraph") @NotNull final String nbGraph)
53    public JSONObject createUserRequest( @ParamName("fortranRequest") final String fortranRequest, @ParamName("transitionUpper") final String transitionUpper, @ParamName("transitionLower") final String transitionLower, @ParamName("nbGraph") @NotNull final String nbGraph)
54            throws WebException
55    {
56
57
58        //variable temps en milliseconde pour donner un nom unique au fichier crée
59        final Calendar calendar = Calendar.getInstance();
60        final long timeInMillis = calendar.getTimeInMillis();
61
62        try {
63            //Pour lancer le programme fortran
64//            Process p = Runtime.getRuntime().exec("/home/npipsl/Desktop/geisa-Graphique/prog-ether/graph.sh  " + fortranRequest + " " + timeInMillis + "");
65           // Process p = Runtime.getRuntime().exec(PATH_PROCESS+File.separatorChar+"graph.sh  " + fortranRequest + " " + timeInMillis + "");
66        //////// Process p = Runtime.getRuntime().exec(PATH_PROCESS+"graph.sh  " + fortranRequest + " " + timeInMillis + "");
67                 Process p = Runtime.getRuntime().exec(PATH_PROCESS+"graph.sh  " + fortranRequest + " " + transitionUpper  + " " + transitionLower +" " + timeInMillis + "");
68            //     Process p = Runtime.getRuntime().exec("/home/www/GEISA/graph.sh  " + fortranRequest + " " + timeInMillis + "");
69
70
71            //permet de connaitre le nom du dernier fichier creer (en cas de plusieurs graphs à tracer) pour tester si le dernier fichier est bien present
72            final String lastFileName = "graph" + timeInMillis +"-"+nbGraph+ ".png";
73            //final File lastFile = new java.io.File(LONG_PATH_IMAGES+File.separatorChar+lastFileName);
74            final File lastFile = new java.io.File(LONG_PATH_IMAGES+lastFileName);
75            final Integer maxTimeWait = 65000;
76
77
78            //(si le fichier n'exite pas ou si il existe mais la taille est nulle) et le temps d'exécution n'est pas trop long  (inferieur a   maxTimeWait)
79            Integer timeWait = 0;
80            while ((!lastFile .exists() || (lastFile .exists()  && lastFile.length()==0)) && timeWait < maxTimeWait ){
81                try
82                {
83                    Thread.sleep(1000);
84                    timeWait+=1000;
85
86                }
87                catch( InterruptedException e )
88                {
89                    throw new WebException(WebException.WebCode.ERROR_EXECUTION_PROCESS, e);
90                }
91            }
92
93
94            // TODO : vérifier que le temps n'est pas écoulé et si c'est le cas retourner une erreur
95//            if(timeWait == maxTimeWait)
96//
97
98        } catch (java.io.IOException e) {
99        }
100
101
102
103        final JSONObject result = new JSONObject();
104        //result.put( "resultAjax", valselectTraceAxeY1 + valselectTraceAxeY2 + inputSpectralRangeLower + inputSpectralRangeUpper + inputIntensityLower + inputIntensityUpper + valselectTypeTrace);
105//        result.put( "pathImg", PATH_IMAGES );
106        result.put("nb",  timeInMillis);
107
108        return result;
109    }
110
111//    @ControllerMethod(jsonResult = true)
112//    public JSONObject transition( @ParamName("transitionValue") final String transitionValue)
113//            throws WebException
114//    {
115//        final JSONObject result = new JSONObject();
116//        try
117//        {
118//            final List<IsotopeG03> allIsotopeG03 = _geisaService.getAllIsotopeG03();
119//            final String bob = "bib";
120//        }
121//        catch( ServiceException e )
122//        {
123//            throw new WebException( WebException.WebCode.ISOTOPE_NOT_FOUND, e );
124//        }
125//        return  result;
126//    }
127
128    @ControllerMethod(jsonResult = true)
129    public JSONObject getTransitionByIsotopeName( @ParamName("isotopesSelectedNameArray") final String isotopesSelectedName,
130                                                  @ParamName("geisaSelectedDatabase") final String geisaSelectedDatabase,
131                                                  @ParamName("spectralRangeLower") final Float spectralRangeLower,
132                                                  @ParamName("spectralRangeUpper") final Float spectralRangeUpper)
133            throws WebException
134    {
135        final JSONObject result = new JSONObject();
136        try
137        {
138            final List<String> isotopesSelectedNameList = Arrays.asList( isotopesSelectedName.split( "," ) );
139//            final List<IsotopeG03> isotopeG03 = _geisaService.getTransitionsByIsotopeG03Name( isotopesSelectedNameList, spectralRangeLower, spectralRangeUpper );
140            final Set<String> transitionsLower = _geisaService.getTransitionsLower( geisaSelectedDatabase, isotopesSelectedNameList, spectralRangeLower, spectralRangeUpper );
141            final Set<String> transitionsUpper = _geisaService.getTransitionsUpper( geisaSelectedDatabase, isotopesSelectedNameList, spectralRangeLower, spectralRangeUpper );
142            result.put( "transitionsLower", transitionsLower );
143            result.put( "transitionsUpper", transitionsUpper );
144        }
145        catch( ServiceException e )
146        {
147            throw new WebException( WebException.WebCode.ISOTOPE_NOT_FOUND, e );
148        }
149        return  result;
150    }
151
152   @ControllerMethod(jsonResult = true)
153    public JSONObject getTransitionByIsotopeNameByTransitionLower( @ParamName("isotopesSelectedNameArray") final String isotopesSelectedName,
154                                                                   @ParamName("geisaSelectedDatabase") final String geisaSelectedDatabase,
155                                                                   @ParamName("spectralRangeLower") final Float spectralRangeLower,
156                                                                   @ParamName("spectralRangeUpper") final Float spectralRangeUpper,
157                                                                   @ParamName("transitionLower") final String transitionLower)
158            throws WebException
159    {
160        final JSONObject result = new JSONObject();
161        try
162       {
163            final List<String> isotopesSelectedNameList = Arrays.asList( isotopesSelectedName.split( "," ) );
164            final Set<String> transitionsUpperBis = _geisaService.getTransitionsUpperByTransitionLower( geisaSelectedDatabase, isotopesSelectedNameList, spectralRangeLower, spectralRangeUpper, transitionLower );
165            result.put( "transitionsUpperBis", transitionsUpperBis );
166        }
167        catch( ServiceException e )
168       {
169            throw new WebException( WebException.WebCode.ISOTOPE_NOT_FOUND, e );
170        }
171        return  result;
172    }
173
174
175    @ControllerMethod(jsonResult = true)
176    public JSONObject getTransitionByIsotopeNameByTransitionUpper( @ParamName("isotopesSelectedNameArray") final String isotopesSelectedName,
177                                                                   @ParamName("geisaSelectedDatabase") final String geisaSelectedDatabase,
178                                                                   @ParamName("spectralRangeLower") final Float spectralRangeLower,
179                                                                   @ParamName("spectralRangeUpper") final Float spectralRangeUpper,
180                                                                   @ParamName("transitionUpper") final String transitionUpper)
181            throws WebException
182    {
183        final JSONObject result = new JSONObject();
184        try
185       {
186            final List<String> isotopesSelectedNameList = Arrays.asList( isotopesSelectedName.split( "," ) );
187            final Set<String> transitionsLowerBis = _geisaService.getTransitionsUpperByTransitionUpper( geisaSelectedDatabase, isotopesSelectedNameList, spectralRangeLower, spectralRangeUpper, transitionUpper );
188            result.put( "transitionsLowerBis", transitionsLowerBis );
189        }
190        catch( ServiceException e )
191       {
192            throw new WebException( WebException.WebCode.ISOTOPE_NOT_FOUND, e );
193        }
194        return  result;
195    }
196
197
198    @ControllerMethod(downloadFile = "")
199    public void downloadFile( @ParamName("fileName") final String fileName )
200    {
201    }
202
203    @Required
204    public void setGeisaService( final GeisaService geisaService )
205    {
206        _geisaService = geisaService;
207    }
208
209    private static final Log LOGGER = LogFactory.getLog( Controller.class );
210
211    public static final String PATH_IMAGES = "resources/images/graphGeisa/";
212    public static final String LONG_PATH_IMAGES = "/home_local/npipsl/workspaces/GEISA/web/resources/images/graphGeisa/";
213     //  naboo
214     // public static final String LONG_PATH_IMAGES = "/usr/local/apache-tomcat/webapps/geisa/resources/images/graphGeisa/";
215    public static final String PATH_PROCESS = "/home/npipsl/Desktop/geisa-Graphique/prog-ether/";
216    //naboo
217   // public static final String PATH_PROCESS = "/home/www/GEISA/";
218    private static final String VIEW_INIT = "init";
219    private static final String VIEW_INIT2 = "initGeisa";
220
221    private GeisaService _geisaService;
222}
Note: See TracBrowser for help on using the repository browser.