Project

General

Profile

Download (4.93 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / hesiod / javaExt / src / fr / ias / sitools / astro / resolverName / CorotIdResolverModel.java @ 6552a8ce

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6

    
7
package fr.ias.sitools.astro.resolverName;
8

    
9
import fr.cnes.sitools.common.validator.ConstraintViolation;
10
import fr.cnes.sitools.common.validator.ConstraintViolationLevel;
11
import fr.cnes.sitools.common.validator.Validator;
12
import fr.cnes.sitools.dataset.DataSetApplication;
13
import fr.cnes.sitools.plugins.resources.model.DataSetSelectionType;
14
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
15
import fr.cnes.sitools.plugins.resources.model.ResourceParameter;
16
import fr.cnes.sitools.plugins.resources.model.ResourceParameterType;
17

    
18
import java.util.HashSet;
19
import java.util.Map;
20
import java.util.Set;
21
import java.util.logging.Level;
22

    
23
/**
24
 *
25
 * @author marc
26
 */
27
public class CorotIdResolverModel extends ResourceModel {
28
    
29
    
30
    public CorotIdResolverModel(){
31
        super();
32
        setClassAuthor("Marc NICOLAS");
33
        setClassOwner("IAS");
34
        setClassVersion("0.6.1");
35
        setName("Corot ID Resolver service");
36
        setDescription("This service provides a resolver name from corotID");
37
        setResourceClassName(fr.ias.sitools.astro.resolverName.CorotIdResolverResource.class.getName());
38
        
39
        ResourceParameter paramExo = new ResourceParameter("exoBool", "true if it's a exo dataset, false in other cases",
40
        ResourceParameterType.PARAMETER_USER_INPUT);
41
        paramExo.setValueType("xs:boolean");
42
        this.addParam(paramExo);
43
        
44
        ResourceParameter paramRaCol = new ResourceParameter("raCol", "Colum containing the right ascension.",
45
        ResourceParameterType.PARAMETER_INTERN);
46
        paramRaCol.setValueType("xs:dataset.columnAlias");
47
        this.addParam(paramRaCol);
48

    
49
        ResourceParameter paramDecCol = new ResourceParameter("decCol", "Colum containing the declination.",
50
        ResourceParameterType.PARAMETER_INTERN);
51
        paramDecCol.setValueType("xs:dataset.columnAlias");
52
        this.addParam(paramDecCol);
53

    
54
        ResourceParameter paramcorotIdCol = new ResourceParameter("corotIdCol", "Colum containing the Corot ID.",
55
        ResourceParameterType.PARAMETER_INTERN);
56
        paramcorotIdCol.setValueType("xs:dataset.columnAlias");
57
        this.addParam(paramcorotIdCol);
58
        
59
        this.setApplicationClassName(DataSetApplication.class.getName());
60
        this.setDataSetSelection(DataSetSelectionType.SINGLE);
61
        this.getParameterByName("methods").setValue("GET");
62
        this.completeAttachUrlWith("/corotIdResolver/EQUATORIAL/{corotID}");
63
    }
64
    
65
    @Override
66
  public Validator<ResourceModel> getValidator() {
67
      return new Validator<ResourceModel>() {
68
      
69
        @Override
70
        public Set<ConstraintViolation> validate(ResourceModel item) {
71
            Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>();
72
            Map<String, ResourceParameter> params = item.getParametersMap();
73
            ResourceParameter param = params.get("exoBool");
74
        
75
            String value = param.getValue();
76
            if (value == null || value.equals("")) {
77
                ConstraintViolation constraint = new ConstraintViolation();
78
                constraint.setMessage("The boolean exoBool must be set.");
79
                constraint.setLevel(ConstraintViolationLevel.CRITICAL);
80
                constraint.setValueName(param.getName());
81
                constraints.add(constraint);
82
            }
83
            
84
            param = params.get("raCol");
85
            value = param.getValue();
86
            if (value == null || value.equals("")) {
87
                ConstraintViolation constraint = new ConstraintViolation();
88
                constraint.setMessage("The attribute for RA must be set.");
89
                constraint.setLevel(ConstraintViolationLevel.CRITICAL);
90
                constraint.setValueName(param.getName());
91
                constraints.add(constraint);
92
            }
93
        
94
            param = params.get("decCol");
95
            value = param.getValue();
96
            if (value == null || value.equals("")) {
97
                ConstraintViolation constraint = new ConstraintViolation();
98
                constraint.setMessage("The attribute for DEC must be set.");
99
                constraint.setLevel(ConstraintViolationLevel.CRITICAL);
100
                constraint.setValueName(param.getName());
101
                constraints.add(constraint);
102
            }
103
        
104
            param = params.get("corotIdCol");
105
            value = param.getValue();
106
            if (value == null || value.equals("")) {
107
                ConstraintViolation constraint = new ConstraintViolation();
108
                constraint.setMessage("The attribute for CorotID must be set.");
109
                constraint.setLevel(ConstraintViolationLevel.CRITICAL);
110
                constraint.setValueName(param.getName());
111
                constraints.add(constraint);
112
            }
113
            return constraints;
114
        }
115
    };
116
  }
117
}