git_sitools_idoc / sitools-idoc / hesiod / javaExt / src / fr / ias / sitools / converters / RaDecToXYZConverter.java @ 779bac69
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.converters; |
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.converter.business.AbstractConverter; |
13 |
import fr.cnes.sitools.dataset.converter.model.ConverterParameter; |
14 |
import fr.cnes.sitools.dataset.converter.model.ConverterParameterType; |
15 |
import fr.cnes.sitools.datasource.jdbc.model.AttributeValue; |
16 |
import fr.cnes.sitools.datasource.jdbc.model.Record; |
17 |
import java.util.HashSet; |
18 |
import java.util.Map; |
19 |
import java.util.Set; |
20 |
import java.util.logging.Level; |
21 |
import java.util.logging.Logger; |
22 |
|
23 |
/**
|
24 |
*
|
25 |
* @author marc
|
26 |
*/
|
27 |
public class RaDecToXYZConverter extends AbstractConverter { |
28 |
|
29 |
/*
|
30 |
Formule de changement de coordonée :
|
31 |
|
32 |
X=cos(DEC)*cos(RA)
|
33 |
Y=cos(DEC)*sin(RA)
|
34 |
Z=sin(DEC)
|
35 |
|
36 |
*/
|
37 |
|
38 |
/** Class logger */
|
39 |
private static final Logger LOGGER = Logger.getLogger(RaDecToXYZConverter.class.getName()); |
40 |
|
41 |
public RaDecToXYZConverter() {
|
42 |
|
43 |
this.setName("RaDecToXYZConverter"); |
44 |
this.setDescription("A converter applying an unit conversion from Ra and Dec into X, Y and Z coordinates"); |
45 |
this.setClassAuthor("Marc NICOLAS"); |
46 |
this.setClassOwner("IAS"); |
47 |
this.setClassVersion("0.1"); |
48 |
|
49 |
ConverterParameter colRa = new ConverterParameter("colRa", "row of dataset with the ra coordinate",ConverterParameterType.CONVERTER_PARAMETER_IN); |
50 |
ConverterParameter colDec = new ConverterParameter("colDec", "row of dataset with the dec coordinate",ConverterParameterType.CONVERTER_PARAMETER_IN); |
51 |
|
52 |
ConverterParameter colX = new ConverterParameter("colX", "Column for coordiante X", ConverterParameterType.CONVERTER_PARAMETER_OUT); |
53 |
ConverterParameter colY = new ConverterParameter("colY", "Column for coordiante Y", ConverterParameterType.CONVERTER_PARAMETER_OUT); |
54 |
ConverterParameter colZ = new ConverterParameter("colZ", "Column for coordiante Z", ConverterParameterType.CONVERTER_PARAMETER_OUT); |
55 |
|
56 |
this.addParam(colRa);
|
57 |
this.addParam(colDec);
|
58 |
this.addParam(colX);
|
59 |
this.addParam(colY);
|
60 |
this.addParam(colZ);
|
61 |
|
62 |
LOGGER.log(Level.INFO, "Converter :{0} version {1}", new Object[] { this.getName(), this.getClassVersion() }); |
63 |
} |
64 |
|
65 |
|
66 |
|
67 |
@Override
|
68 |
public Record getConversionOf(Record record) throws Exception { |
69 |
Record out = record; |
70 |
Double x, y, z;
|
71 |
|
72 |
AttributeValue attrOutX = this.getOutParam("colX", out); |
73 |
AttributeValue attrOutY = this.getOutParam("colY", out); |
74 |
AttributeValue attrOutZ = this.getOutParam("colZ", out); |
75 |
|
76 |
AttributeValue attrInRa = this.getInParam("colRa", out); |
77 |
AttributeValue attrInDec = this.getInParam("colDec", out); |
78 |
|
79 |
if(!isNull(attrInRa) && !isNull(attrInRa)/* && !isNull(attrOutX) && !isNull(attrOutY) && !isNull(attrOutZ)*/){ |
80 |
try{
|
81 |
Double ra = Double.parseDouble(attrInRa.getValue().toString()); |
82 |
Double dec = Double.parseDouble(attrInDec.getValue().toString()); |
83 |
|
84 |
x = Math.cos(dec)*Math.cos(ra); |
85 |
y = Math.cos(dec)*Math.sin(ra); |
86 |
z = Math.sin(dec);
|
87 |
|
88 |
if(!x.isNaN()){
|
89 |
attrOutX.setValue(x); |
90 |
} |
91 |
if(!y.isNaN()){
|
92 |
attrOutY.setValue(y); |
93 |
} |
94 |
if(!z.isNaN()){
|
95 |
|
96 |
attrOutZ.setValue(z); |
97 |
} |
98 |
}catch(NumberFormatException e){ |
99 |
|
100 |
} |
101 |
} |
102 |
|
103 |
return out;
|
104 |
} |
105 |
|
106 |
@Override
|
107 |
public Validator<?> getValidator() { |
108 |
// TODO Auto-generated method stub
|
109 |
return new Validator<AbstractConverter>() { |
110 |
|
111 |
@Override
|
112 |
public Set<ConstraintViolation> validate(AbstractConverter item) { |
113 |
Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>(); |
114 |
/*Map<String, ConverterParameter> params = item.getParametersMap();
|
115 |
ConverterParameter param = params.get("colFileSizeInBytes");
|
116 |
|
117 |
if(param.getAttachedColumn().isEmpty()){
|
118 |
ConstraintViolation constraint = new ConstraintViolation();
|
119 |
constraint.setMessage("You must choose the column with filesize in bytes data");
|
120 |
constraint.setLevel(ConstraintViolationLevel.CRITICAL);
|
121 |
constraint.setValueName(param.getName());
|
122 |
constraints.add(constraint);
|
123 |
}
|
124 |
|
125 |
param = params.get("colFileSizeConvert");
|
126 |
|
127 |
if(param.getAttachedColumn().isEmpty()){
|
128 |
ConstraintViolation constraint = new ConstraintViolation();
|
129 |
constraint.setMessage("You must choose the output column");
|
130 |
constraint.setLevel(ConstraintViolationLevel.CRITICAL);
|
131 |
constraint.setValueName(param.getName());
|
132 |
constraints.add(constraint);
|
133 |
}*/
|
134 |
|
135 |
return constraints;
|
136 |
} |
137 |
}; |
138 |
} |
139 |
|
140 |
} |