Project

General

Profile

Revision 444c53d9

Added by Marc Nicolas about 9 years ago

adding vo protocol (SIA and Cone Search) dev

View differences:

hesiod/astronmy-extension/src/fr/cnes/sitools/astro/vo/conesearch/ConeSearchInputParameters.java
1
 /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.cnes.sitools.astro.vo.conesearch;
20

  
21
import fr.cnes.sitools.dataset.DataSetApplication;
22
import fr.cnes.sitools.extensions.common.InputsValidation;
23
import fr.cnes.sitools.extensions.common.NotNullAndNotEmptyValidation;
24
import fr.cnes.sitools.extensions.common.RangeValidation;
25
import fr.cnes.sitools.extensions.common.StatusValidation;
26
import fr.cnes.sitools.extensions.common.Validation;
27
import java.util.ArrayList;
28
import java.util.Collections;
29
import java.util.HashMap;
30
import java.util.List;
31
import java.util.Map;
32
import java.util.Map.Entry;
33
import java.util.Set;
34
import java.util.logging.Level;
35
import java.util.logging.Logger;
36
import net.ivoa.xml.votable.v1.Info;
37
import org.restlet.Context;
38
import org.restlet.Request;
39

  
40
/**
41
 * This object provides methods to handle input parameters for the cone search protocol.
42
 *
43
 * @author Jean-Christophe Malapert
44
 */
45
public class ConeSearchInputParameters implements ConeSearchDataModelInterface {
46

  
47
  /**
48
   * Logger.
49
   */
50
  private static final Logger LOG = Logger.getLogger(ConeSearchInputParameters.class.getName());
51
  /**
52
   * Default verbosity mode.
53
   */
54
  private static final int DEFAULT_VERBOSITY_MODE = 0;
55
  /**
56
   * Verbosity mode.
57
   */
58
  private transient int verb = DEFAULT_VERBOSITY_MODE;
59
  /**
60
   * Data model.
61
   */
62
  private final transient Map dataModel = new HashMap();
63
  /**
64
   * User request.
65
   */
66
  private final transient Request request;
67
  /**
68
   * Application context.
69
   */
70
  private final transient Context context;
71
  /**
72
   * Application.
73
   */
74
  private final transient DataSetApplication datasetApp;
75
  /**
76
   * Right ascension of the cone center.
77
   */
78
  private transient double rightAscension;
79
  /**
80
   * Declination of the cone center.
81
   */
82
  private transient double declination;
83
  /**
84
   * Radius of the cone.
85
   */
86
  private transient double radius;
87

  
88
  /**
89
   * Constructor.
90
   *
91
   * @param datasetAppVal dataset application
92
   * @param requestVal Request
93
   * @param contextVal Context
94
   * @param maxSr maxSr for the cone search
95
   * @param verbosity verbosity
96
   * @param verbVal verbosity level
97
   */
98
  public ConeSearchInputParameters(final DataSetApplication datasetAppVal, final Request requestVal, final Context contextVal,
99
          final double maxSr, final boolean verbosity, final int verbVal) {
100
    this.datasetApp = datasetAppVal;
101
    this.context = contextVal;
102
    this.request = requestVal;
103
    final String raInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.RA);
104
    final String decInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.DEC);
105
    final String srInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.SR);
106
    final String verbInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.VERB);
107
    if(raInput == null && decInput == null && srInput == null){
108
        Info info = new Info();
109
        info.setName("QUERY_STATUS");
110
        info.setValueAttribute("ERROR");
111
        info.setValue("RA, DEC and SR must be not null");
112
        final List<Info> listInfos = new ArrayList<Info>();
113
        listInfos.add(info);
114
        this.dataModel.put("infos", listInfos);
115
    }else{
116
        checkInputParameters(raInput, decInput, srInput, maxSr, verbInput, verbosity, verbVal);
117
    }
118
  }
119

  
120
  /**
121
   * Check input parameters.
122
   *
123
   * @param raInput Ra
124
   * @param decInput Dec
125
   * @param srInput Sr
126
   * @param maxSr maxSr
127
   * @param verbosity verbosity
128
   * @param verbInput user inpur verb
129
   * @param verbVal verbosity from admin
130
   */
131
  private void checkInputParameters(final String raInput, final String decInput, final String srInput, final double maxSr,
132
          final String verbInput, final boolean verbosity, final int verbVal) {
133
    final List<Info> infos = new ArrayList<Info>();
134
    final Map<String, String> validationMap = new HashMap<String, String>();
135
    validationMap.put(ConeSearchProtocolLibrary.RA, raInput);
136
    validationMap.put(ConeSearchProtocolLibrary.DEC, decInput);
137
    validationMap.put(ConeSearchProtocolLibrary.SR, srInput);
138
    validationMap.put(ConeSearchProtocolLibrary.VERB, verbInput);
139
    validationMap.put(ConeSearchProtocolLibrary.VERBOSITY, String.valueOf(verbosity));
140
    Validation validation = new InputsValidation(validationMap);
141
    validation = new RangeValidation(validation, ConeSearchProtocolLibrary.RA, ConeSearchProtocolLibrary.RA_MIN, ConeSearchProtocolLibrary.RA_MAX);
142
    validation = new RangeValidation(validation, ConeSearchProtocolLibrary.DEC, ConeSearchProtocolLibrary.DEC_MIN, ConeSearchProtocolLibrary.DEC_MAX);
143
    validation = new RangeValidation(validation, ConeSearchProtocolLibrary.SR, 0, maxSr);
144
    validation = new NotNullAndNotEmptyValidation(validation, ConeSearchProtocolLibrary.VERBOSITY);
145
    validation = new NotNullAndNotEmptyValidation(validation, ConeSearchProtocolLibrary.VERB, String.valueOf(verbVal));
146
    final StatusValidation status = validation.validate();
147
    if (status.isValid()) {
148
        final Map<String, String> input = validation.getMap();
149
        this.rightAscension = Double.valueOf(input.get(ConeSearchProtocolLibrary.RA));
150
        this.declination = Double.valueOf(input.get(ConeSearchProtocolLibrary.DEC));
151
        this.radius = Double.valueOf(input.get(ConeSearchProtocolLibrary.SR));
152
        this.verb = Integer.valueOf(input.get(ConeSearchProtocolLibrary.VERB));
153
    } else {
154
        Info infoError = new Info();
155
        infoError.setName("QUERY_STATUS");
156
        infoError.setValueAttribute("ERROR");
157
        infos.add(infoError);
158
        final Map<String, String> errors = status.getMessages();
159
        final Set<Entry<String, String>> entries = errors.entrySet();
160
        for (Entry<String, String> entry : entries) {
161
            final Info info = new Info();
162
            info.setID(entry.getKey());
163
            info.setName("Error in " + entry.getKey());
164
            info.setValueAttribute("Error in input " + entry.getKey() + ": " + entry.getValue());
165
            infos.add(info);
166
            LOG.log(Level.FINEST, "{0}: {1}", new Object[]{entry.getKey(), entry.getValue()});
167
        }
168
    }
169
    if (!infos.isEmpty()) {
170
      this.dataModel.put("infos", infos);
171
    }
172
  }
173

  
174
  /**
175
   * Get Ra.
176
   *
177
   * @return Ra
178
   */
179
  public final double getRa() {
180
    return this.rightAscension;
181
  }
182

  
183
  /**
184
   * Get Dec.
185
   *
186
   * @return Dec
187
   */
188
  public final double getDec() {
189
    return this.declination;
190
  }
191

  
192
  /**
193
   * Get Sr.
194
   *
195
   * @return Sr
196
   */
197
  public final double getSr() {
198
    return this.radius;
199
  }
200

  
201
  /**
202
   * Get verbosity level.
203
   *
204
   * @return verbosity level
205
   */
206
  public final int getVerb() {
207
    return this.verb;
208
  }
209

  
210
  @Override
211
  public final Map getDataModel() {
212
    return Collections.unmodifiableMap(this.dataModel);
213
  }
214

  
215
  /**
216
   * Returns the request.
217
   *
218
   * @return Request
219
   */
220
  public final Request getRequest() {
221
    return this.request;
222
  }
223

  
224
  /**
225
   * Returns the context.
226
   *
227
   * @return Context
228
   */
229
  public final Context getContext() {
230
    return this.context;
231
  }
232

  
233
  /**
234
   * Get DatasetApplication.
235
   *
236
   * @return Dataset application
237
   */
238
  public final DataSetApplication getDatasetApplication() {
239
    return this.datasetApp;
240
  }
241
}
hesiod/astronmy-extension/src/fr/cnes/sitools/astro/vo/sia/SimpleImageAccessInputParameters.java
1
 /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.cnes.sitools.astro.vo.sia;
20

  
21
import fr.cnes.sitools.dataset.DataSetApplication;
22
import fr.cnes.sitools.dataset.dto.ColumnConceptMappingDTO;
23
import fr.cnes.sitools.dictionary.model.Concept;
24
import fr.cnes.sitools.extensions.common.InputsValidation;
25
import fr.cnes.sitools.extensions.common.NotNullAndNotEmptyValidation;
26
import fr.cnes.sitools.extensions.common.NumberArrayValidation;
27
import fr.cnes.sitools.extensions.common.SpatialGeoValidation; 
28
import fr.cnes.sitools.extensions.common.StatusValidation;
29
import fr.cnes.sitools.extensions.common.Validation;
30
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
31
import fr.cnes.sitools.util.Util;
32
import java.math.BigInteger;
33
import java.util.ArrayList;
34
import java.util.Collections;
35
import java.util.HashMap;
36
import java.util.List;
37
import java.util.Map;
38
import java.util.Set;
39
import java.util.logging.Level;
40
import java.util.logging.Logger;
41
import net.ivoa.xml.votable.v1.AnyTEXT;
42
import net.ivoa.xml.votable.v1.DataType;
43
import net.ivoa.xml.votable.v1.Field;
44
import net.ivoa.xml.votable.v1.Info;
45
import net.ivoa.xml.votable.v1.Option;
46
import net.ivoa.xml.votable.v1.Param;
47
import net.ivoa.xml.votable.v1.Values;
48
import org.restlet.Context;
49
import org.restlet.Request;
50

  
51

  
52
/**
53
 * Input parameters for SIA.
54
 *
55
 * @author Jean-Crhistophe Malapert <jean-christophe.malapert@cnes.fr>
56
 */
57
import fr.cnes.sitools.common.exception.SitoolsException;
58
import fr.cnes.sitools.dataset.dto.DictionaryMappingDTO;
59
public class SimpleImageAccessInputParameters implements DataModelInterface {
60
  /**
61
   * Logger.
62
   */
63
  private static final Logger LOG = Logger.getLogger(SimpleImageAccessInputParameters.class.getName());
64
  /**
65
   * Init value for right ascension parameter of the user input.
66
   */
67
  private transient double ra = 0.0;
68
  /**
69
   * Init value for declination parameter of the user input.
70
   */
71
  private transient double dec = 0.0;
72
  /**
73
   * Array that stores the size parameter of the user input.
74
   */
75
  private transient double[] size;
76
  /**
77
   * Default value for the verb parameter of the user input.
78
   */
79
  private transient int verb = 0;
80
  /**
81
   * Data model that stores the metadata response of the service.
82
   */
83
  private final transient Map dataModel = new HashMap();
84
  /**
85
   * Request.
86
   */
87
  private final transient Request request;
88
  /**
89
   * Context.
90
   */
91
  private final transient Context context;
92
  /**
93
   * Application where this resources is linked.
94
   */
95
  private final transient DataSetApplication datasetApp;
96
  /**
97
   * Configuration parameters of this resource.
98
   */
99
  private final transient ResourceModel resourceModel;
100

  
101
  /**
102
   * Constructs the objet that returns the metadata of the service.
103
   * @param datasetAppVal application
104
   * @param requestVal request
105
   * @param contextVal context
106
   * @param resourceModelVal configuration parameters
107
   */
108
  public SimpleImageAccessInputParameters(final DataSetApplication datasetAppVal, final Request requestVal, final Context contextVal, final ResourceModel resourceModelVal) {
109
    this.datasetApp = datasetAppVal;
110
    this.context = contextVal;
111
    this.request = requestVal;
112
    this.resourceModel = resourceModelVal;
113
    final String posInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.POS);
114
    final String sizeInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.SIZE);
115
    final String format = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.FORMAT);
116
    final String intersect = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.INTERSECT);
117
    final String verbosity = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.VERB);
118
    //TODO check the differentParameters
119
    if(posInput == null && sizeInput == null){
120
        Info info = new Info();
121
        info.setName("QUERY_STATUS");
122
        info.setValueAttribute("ERROR");
123
        final List<Info> listInfos = new ArrayList<Info>();
124
        listInfos.add(info);
125
        this.dataModel.put("infos", listInfos);
126
        if(format.equalsIgnoreCase("METADATA")){
127
            fillMetadataFormat();
128
        }
129
    }else{
130
        if (Util.isSet(format) && format.equals(SimpleImageAccessProtocolLibrary.ParamStandardFormat.METADATA.name())) {
131
            fillMetadataFormat();
132
        } else {
133
            checkInputParameters(posInput, sizeInput);
134
        }
135
    }
136
  }
137

  
138
  /**
139
   * Fills metadata response.
140
   */
141
  private void fillMetadataFormat() {
142
      
143
    this.dataModel.put("description", this.resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.DESCRIPTION).getValue());
144

  
145
    final Info info = new Info();
146
    info.setName("QUERY_STATUS");
147
    info.setValueAttribute("OK");
148
    final List<Info> listInfos = new ArrayList<Info>();
149
    listInfos.add(info);
150
    this.dataModel.put("infos", listInfos);
151
   
152
    final List<Param> listParam = new ArrayList<Param>();
153
    Param param = new Param();
154
    param.setName("INPUT:POS");
155
    param.setValue("0,0");
156
    param.setDatatype(DataType.DOUBLE);
157
    AnyTEXT anyText = new AnyTEXT();
158
    anyText.getContent().add("Search Position in the form ra,dec where ra and dec are given in decimal degrees in the ICRS coordinate system.");
159
    param.setDESCRIPTION(anyText);
160
    listParam.add(param);
161

  
162
    param = new Param();
163
    param.setName("INPUT:SIZE");
164
    param.setValue("0.05");
165
    param.setDatatype(DataType.DOUBLE);
166
    anyText = new AnyTEXT();
167
    anyText.getContent().add("Size of search region in the RA and Dec directions.");
168
    param.setDESCRIPTION(anyText);
169
    listParam.add(param);
170

  
171
    param = new Param();
172
    param.setName("INPUT:FORMAT");
173
    param.setValue(SimpleImageAccessProtocolLibrary.ParamStandardFormat.ALL.name());
174
    param.setDatatype(DataType.CHAR);
175
    param.setArraysize("*");
176
    anyText = new AnyTEXT();
177
    anyText.getContent().add("Requested format of images.");
178
    param.setDESCRIPTION(anyText);
179
    final List<String> formatList = SimpleImageAccessProtocolLibrary.ParamStandardFormat.getCtes();
180
    final Values values = new Values();
181
    for (String formatIter : formatList) {
182
      final Option option = new Option();
183
      option.setValue(formatIter);
184
      values.getOPTION().add(option);
185
    }
186
    param.setVALUES(values);
187
    //TODO : le faire pour chaque format
188
    listParam.add(param);
189
    
190
    param = new Param();
191
    param.setName("INPUT:INTERSECT");
192
    param.setValue(this.resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.INTERSECT).getValue());
193
    param.setDatatype(DataType.CHAR);
194
    anyText = new AnyTEXT();
195
    anyText.getContent().add("Choice of overlap with requested region.");
196
    param.setDESCRIPTION(anyText);
197
    listParam.add(param);
198

  
199
    param = new Param();
200
    param.setName("INPUT:VERB");
201
    param.setValue(this.resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.VERB).getValue());
202
    param.setDatatype(DataType.INT);
203
    anyText = new AnyTEXT();
204
    anyText.getContent().add("Verbosity level, controlling the number of columns returned.");
205
    param.setDESCRIPTION(anyText);
206
    listParam.add(param);
207

  
208
    dataModel.put("params", listParam);
209
    //******************************************************************************************************************
210
    //******************************************************************************************************************
211
    //******************************************************************************************************************
212
    String dictionaryName = resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.DICTIONARY).getValue();
213
    final List<String> columnList = new ArrayList<String>();
214
    List<Field> fieldList = new ArrayList<Field>();
215
    try {
216
        List<ColumnConceptMappingDTO> mappingList = getDicoFromConfiguration(datasetApp, dictionaryName);
217
        setFields(fieldList, columnList, mappingList);
218
    }catch (SitoolsException ex) {
219
             
220
    }
221
    
222
  }
223

  
224
  /**
225
   * Checks input parameters.
226
   * @param posInput input parameter for POS
227
   * @param sizeInput input parameter for SIZE
228
   */
229
  private void checkInputParameters(final String posInput, final String sizeInput) {
230
    final List<Info> infos = new ArrayList<Info>();
231
    final Map<String, String> validationMap = new HashMap<String, String>();
232
    validationMap.put(SimpleImageAccessProtocolLibrary.POS, posInput);
233
    validationMap.put(SimpleImageAccessProtocolLibrary.SIZE, sizeInput);    
234
    Validation validation = new InputsValidation(validationMap);
235
    validation = new NotNullAndNotEmptyValidation(validation, SimpleImageAccessProtocolLibrary.POS);
236
    validation = new NotNullAndNotEmptyValidation(validation, SimpleImageAccessProtocolLibrary.SIZE);
237
    if(validation.validate().isValid()){
238
        validation = new SpatialGeoValidation(validation, SimpleImageAccessProtocolLibrary.POS, 0, 1, new double[]{0.0, 360.0}, new double[]{-90.0, 90.0});
239
        // LA LIGNE SUIVANTE A ETE AJOUTEE POUR VERIFIER QUE LA SIZE EST BIEN UN ARRAY DE NOMBRE
240
        validation = new NumberArrayValidation(validation, SimpleImageAccessProtocolLibrary.SIZE, ",", 1, 2);
241
        //-----------------------------------------------------------------------------------------------
242
    }  
243
    StatusValidation status = validation.validate();
244
    if (status.isValid()) {
245
        final String pos = validation.getMap().get(SimpleImageAccessProtocolLibrary.POS);
246
        final String[] arrayPos = pos.split(",");
247
        this.ra = Double.valueOf(arrayPos[0]);
248
        this.dec = Double.valueOf(arrayPos[1]);
249
        final String size = validation.getMap().get(SimpleImageAccessProtocolLibrary.SIZE);
250
        final String[] arraySize = size.split(",");
251
        if(arraySize.length == 1) {
252
            this.size = new double[1];
253
            this.size[0] = Double.valueOf(arraySize[0]);
254
        } else {
255
            this.size = new double[2];
256
            this.size[0] = Double.valueOf(arraySize[0]);
257
            this.size[1] = Double.valueOf(arraySize[1]);
258
        }
259
        
260
    } else {
261
        Info info = new Info();
262
        info.setName("QUERY_STATUS");
263
        info.setValueAttribute("ERROR");
264
        infos.add(info);
265
        final Map<String, String> errors = status.getMessages();
266
        final Set<Map.Entry<String, String>> entries = errors.entrySet();        
267
        for (Map.Entry<String, String> entry : entries) {
268
            info = new Info();
269
            info.setID(entry.getKey());
270
            info.setName("Error in " + entry.getKey());
271
            info.setValueAttribute("Error in input " + entry.getKey() + ": " + entry.getValue());
272
            infos.add(info);
273
            LOG.log(Level.FINEST, "{0}: {1}", new Object[]{entry.getKey(), entry.getValue()});            
274
        }
275
        
276
    }
277
    
278
    if (!infos.isEmpty()) {
279
      this.dataModel.put("infos", infos);
280
    }
281
  }
282

  
283
  @Override
284
  public final Map getDataModel() {
285
    return Collections.unmodifiableMap(this.dataModel);
286
  }
287

  
288
  /**
289
   * Get Ra.
290
   *
291
   * @return Ra
292
   */
293
  public final double getRa() {
294
    return this.ra;
295
  }
296

  
297
  /**
298
   * Get Dec.
299
   *
300
   * @return Dec
301
   */
302
  public final double getDec() {
303
    return this.dec;
304
  }
305

  
306
  /**
307
   * Get Sr.
308
   *
309
   * @return Sr
310
   */
311
  public final double[] getSize() {
312
      final double[] copySize = new double[this.size.length];
313
      System.arraycopy(this.size, 0, copySize, 0, this.size.length);
314
      return copySize;
315
  }
316

  
317
  /**
318
   * Get the request.
319
   *
320
   * @return Request
321
   */
322
  public final Request getRequest() {
323
    return this.request;
324
  }
325

  
326
  /**
327
   * Get the context.
328
   *
329
   * @return Context
330
   */
331
  public final Context getContext() {
332
    return this.context;
333
  }
334

  
335
  /**
336
   * Get DatasetApplication.
337
   *
338
   * @return Dataset application
339
   */
340
  public final DataSetApplication getDatasetApplication() {
341
    return this.datasetApp;
342
  }
343

  
344
  /**
345
   * Get verb.
346
   * @return verb
347
   */
348
  public final int getVerb() {
349
    return this.verb;
350
  }
351
  
352
  //----------------------------------------------------------------------------
353
  //----------------------------------------------------------------------------
354
  //----------------------------------------------------------------------------
355
  /**
356
   * Set Fields and columnSqlAliasList.
357
   *
358
   * @param fieldList List of fields to display on the VOTable
359
   * @param columnList List of SQL column
360
   * @param mappingList List of SQL column/concept
361
   */
362
  private void setFields(final List<Field> fieldList, final List<String> columnList, final List<ColumnConceptMappingDTO> mappingList) {
363

  
364
    for (ColumnConceptMappingDTO mappingIter : mappingList) {
365

  
366
      String id = null;
367
      String name = null;
368
      String ucd = null;
369
      String utype = null;
370
      String ref = null;
371
      String datatype = null;
372
      String width = null;
373
      String precision = null;
374
      String unit = null;
375
      String type = null;
376
      String xtype = null;
377
      String arraysize = null;
378
      String descriptionValue = null;
379
      columnList.add(mappingIter.getColumnAlias());
380
      final Concept concept = mappingIter.getConcept();
381
      if (concept.getName() != null) {
382
        name = concept.getName();
383
      }
384
      if (concept.getPropertyFromName("ID").getValue() != null) {
385
        id = concept.getPropertyFromName("ID").getValue();
386
      }
387
      if (concept.getPropertyFromName("ucd").getValue() != null) {
388
        ucd = concept.getPropertyFromName("ucd").getValue();
389
      }
390
      if (concept.getPropertyFromName("utype").getValue() != null) {
391
        utype = concept.getPropertyFromName("utype").getValue();
392
      }
393
      if (concept.getPropertyFromName("ref").getValue() != null) {
394
        ref = concept.getPropertyFromName("ref").getValue();
395
      }
396
      if (concept.getPropertyFromName("datatype").getValue() != null) {
397
        datatype = concept.getPropertyFromName("datatype").getValue();
398
      }
399
      if (concept.getPropertyFromName("width").getValue() != null) {
400
        width = concept.getPropertyFromName("width").getValue();
401
      }
402
      if (concept.getPropertyFromName("precision").getValue() != null) {
403
        precision = concept.getPropertyFromName("precision").getValue();
404
      }
405
      if (concept.getPropertyFromName("unit").getValue() != null) {
406
        unit = concept.getPropertyFromName("unit").getValue();
407
      }
408
      if (concept.getPropertyFromName("type").getValue() != null) {
409
        type = concept.getPropertyFromName("type").getValue();
410
      }
411
      if (concept.getPropertyFromName("xtype").getValue() != null) {
412
        xtype = concept.getPropertyFromName("xtype").getValue();
413
      }
414
      if (concept.getPropertyFromName("arraysize").getValue() != null) {
415
        arraysize = concept.getPropertyFromName("arraysize").getValue();
416
      }
417
      if (concept.getDescription() != null) {
418
        descriptionValue = concept.getDescription();
419
      }
420
      final Field field = new Field();
421
      field.setID(id);
422
      field.setName(name);
423
      field.setUcd(ucd);
424
      field.setUtype(utype);
425
      field.setRef(ref);
426
      field.setDatatype(DataType.fromValue(datatype));
427
      if (width != null) {
428
        field.setWidth(BigInteger.valueOf(Long.valueOf(width)));
429
      }
430
      field.setPrecision(precision);
431
      field.setUnit(unit);
432
      field.setType(type);
433
      field.setXtype(xtype);
434
      field.setArraysize(arraysize);
435
      final AnyTEXT anyText = new AnyTEXT();
436
      anyText.getContent().add(descriptionValue);
437
      field.setDESCRIPTION(anyText);
438
      fieldList.add(field);
439
    }
440
    dataModel.put("fields", fieldList);
441
  }
442
  
443
  /**
444
   * Provide the mapping between SQL column/concept for a given dictionary.
445
   *
446
   * @param datasetApp Application where this service is attached
447
   * @param dicoToFind Dictionary name to find
448
   * @return Returns a mapping SQL column/Concept
449
   * @throws SitoolsException No mapping has been done or cannot find the dico
450
   */
451
  protected List<ColumnConceptMappingDTO> getDicoFromConfiguration(final DataSetApplication datasetApp,
452
          final String dicoToFind) throws SitoolsException {
453
    List<ColumnConceptMappingDTO> colConceptMappingDTOList = null;
454

  
455
    // Get the list of dictionnaries related to the datasetApplication
456
    final List<DictionaryMappingDTO> dicoMappingList = datasetApp.getDictionaryMappings();
457
    if (!Util.isSet(dicoMappingList) || dicoMappingList.isEmpty()) {
458
      throw new SitoolsException("No mapping with VO concepts has been done. please contact the administrator");
459
    }
460

  
461
    // For each dictionary, find the interesting one and return the mapping SQLcolumn/concept
462
    for (DictionaryMappingDTO dicoMappingIter : dicoMappingList) {
463
      final String dicoName = dicoMappingIter.getDictionaryName();
464
      if (dicoToFind.equals(dicoName)) {
465
        colConceptMappingDTOList = dicoMappingIter.getMapping();
466
        break;
467
      }
468
    }
469
    return colConceptMappingDTOList;
470
  }
471
  
472
  
473
  
474
}

Also available in: Unified diff