Revision 6552a8ce
Added by Marc Nicolas over 9 years ago
hesiod/javaExt/src/META-INF/services/fr.cnes.sitools.converter.ConverterHelper | ||
---|---|---|
1 |
fr.ias.sitools.converters.FileSizeConverter |
|
2 |
fr.ias.sitools.converters.RaDecToXYZConverter |
hesiod/javaExt/src/META-INF/services/fr.cnes.sitools.filter.FilterHelper | ||
---|---|---|
1 |
fr.ias.sitools.filters.basic.BooleanCorotAsteroAndExo |
|
2 |
fr.ias.sitools.filters.basic.BooleanCustom |
|
3 |
fr.ias.sitools.filters.basic.GroupCheckBoxMasterLigthCurves |
|
4 |
fr.ias.sitools.filters.basic.NThreeVariability |
|
5 |
fr.ias.sitools.filters.basic.TextFieldSQLLikeFilter |
|
6 |
fr.ias.sitools.filters.basic.DateBeginEndFilter |
|
7 |
fr.ias.sitools.filters.basic.SingleValueLikeFilter |
|
8 |
fr.ias.sitools.filters.basic.ListBoxSpectralTypeCorot |
|
9 |
fr.ias.sitools.filters.basic.ListBoxLumClassCorot |
|
10 |
fr.ias.sitools.filters.basic.TextAreaCorotFilter |
hesiod/javaExt/src/META-INF/services/fr.cnes.sitools.plugins.resources.ResourceHelper | ||
---|---|---|
1 |
fr.ias.sitools.resources.spectrofits.GetFitsDataSpectroModel |
|
2 |
fr.ias.sitools.resources.fits.ShowHeaderModel |
|
3 |
fr.ias.sitools.astro.resolverName.CorotIdResolverModel |
|
4 |
fr.ias.sitools.resources.vo.SimpleSpectralAccessResourceModel |
|
5 |
fr.ias.sitools.resources.geojson.DatasetToJsonModel |
hesiod/javaExt/src/fr/ias/sitools/astro/resolverName/CorotIdResolverModel.java | ||
---|---|---|
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 |
} |
hesiod/javaExt/src/fr/ias/sitools/astro/resolverName/CorotIdResolverResource.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.ias.sitools.astro.resolverName; |
|
20 |
|
|
21 |
import fr.cnes.sitools.astro.representation.GeoJsonRepresentation; |
|
22 |
import fr.cnes.sitools.common.resource.SitoolsParameterizedResource; |
|
23 |
import fr.cnes.sitools.dataset.DataSetApplication; |
|
24 |
import fr.cnes.sitools.dataset.database.DatabaseRequest; |
|
25 |
import fr.cnes.sitools.dataset.database.DatabaseRequestFactory; |
|
26 |
import fr.cnes.sitools.dataset.database.DatabaseRequestParameters; |
|
27 |
import fr.cnes.sitools.dataset.database.common.DataSetExplorerUtil; |
|
28 |
import fr.cnes.sitools.dataset.model.Column; |
|
29 |
import fr.cnes.sitools.dataset.model.DataSet; |
|
30 |
import fr.cnes.sitools.dataset.model.Operator; |
|
31 |
import fr.cnes.sitools.dataset.model.Predicat; |
|
32 |
import fr.cnes.sitools.datasource.jdbc.model.AttributeValue; |
|
33 |
import fr.cnes.sitools.datasource.jdbc.model.Record; |
|
34 |
import fr.cnes.sitools.extensions.astro.application.opensearch.datamodel.FeatureDataModel; |
|
35 |
import fr.cnes.sitools.extensions.astro.application.opensearch.datamodel.FeaturesDataModel; |
|
36 |
import fr.cnes.sitools.extensions.common.AstroCoordinate; |
|
37 |
import fr.cnes.sitools.plugins.resources.model.ResourceParameter; |
|
38 |
import fr.cnes.sitools.resources.order.utils.OrderResourceUtils; |
|
39 |
import java.util.Map; |
|
40 |
import java.util.logging.Level; |
|
41 |
import org.restlet.Context; |
|
42 |
import org.restlet.data.MediaType; |
|
43 |
import org.restlet.data.Status; |
|
44 |
import org.restlet.ext.wadl.MethodInfo; |
|
45 |
import org.restlet.representation.Representation; |
|
46 |
import org.restlet.representation.Variant; |
|
47 |
import org.restlet.resource.Get; |
|
48 |
import org.restlet.resource.ResourceException; |
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
public class CorotIdResolverResource extends SitoolsParameterizedResource{ |
|
53 |
|
|
54 |
String corotIDValueStr; |
|
55 |
Boolean exoBool; |
|
56 |
|
|
57 |
Double raValue; |
|
58 |
Double decValue; |
|
59 |
ResourceParameter corotIDParam; |
|
60 |
ResourceParameter raParam; |
|
61 |
ResourceParameter decParam; |
|
62 |
|
|
63 |
@Override |
|
64 |
public void sitoolsDescribe() { |
|
65 |
setName("CorotIdResolverResource"); |
|
66 |
setDescription("Get Star coordinates from corotID"); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public void doInit() { |
|
71 |
super.doInit(); |
|
72 |
this.corotIDValueStr = (String) this.getRequestAttributes().get("corotID"); |
|
73 |
this.exoBool = Boolean.parseBoolean(getModel().getParametersMap().get("exoBool").getValue()); |
|
74 |
|
|
75 |
try{ |
|
76 |
int corotIdValuInt = Integer.parseInt(corotIDValueStr); |
|
77 |
}catch(NumberFormatException e){ |
|
78 |
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "CorotID must be a number."); |
|
79 |
} |
|
80 |
if(this.corotIDValueStr.length() != 9 && exoBool){ |
|
81 |
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "CorotID must be composed of 9 digits."); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Get HTML |
|
87 |
* |
|
88 |
* @return Representation the HTML result |
|
89 |
*/ |
|
90 |
@Get |
|
91 |
public Representation getCorotIdResolver() { |
|
92 |
return execute(); |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
protected void describeGet(MethodInfo info) { |
|
97 |
this.addInfo(info); |
|
98 |
info.setIdentifier("get ra and dec coordinates from corotID"); |
|
99 |
info.setDocumentation("Method to retrieve coordinates of a star from its corotID"); |
|
100 |
addStandardGetRequestInfo(info); |
|
101 |
DataSetExplorerUtil.addDatasetExplorerGetRequestInfo(info); |
|
102 |
DataSetApplication application = (DataSetApplication) getApplication(); |
|
103 |
DataSetExplorerUtil.addDatasetExplorerGetFilterInfo(info, application.getFilterChained()); |
|
104 |
addStandardResponseInfo(info); |
|
105 |
addStandardInternalServerErrorInfo(info); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
protected Representation get(Variant variant) { |
|
110 |
Representation repr = super.get(); |
|
111 |
if(repr == null){ |
|
112 |
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,"No reccord matches with your query"); |
|
113 |
} |
|
114 |
repr.setMediaType(MediaType.APPLICATION_JSON); |
|
115 |
return repr; |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Execute the request and return a Representation |
|
120 |
* |
|
121 |
* @return the HTML representation |
|
122 |
*/ |
|
123 |
private Representation execute() { |
|
124 |
|
|
125 |
|
|
126 |
Representation repr = null; |
|
127 |
|
|
128 |
// Get context |
|
129 |
Context context = getContext(); |
|
130 |
|
|
131 |
// generate the DatabaseRequest |
|
132 |
DataSetApplication datasetApp = (DataSetApplication) getApplication(); |
|
133 |
DataSetExplorerUtil dsExplorerUtil = new DataSetExplorerUtil(datasetApp, getRequest(), getContext()); |
|
134 |
|
|
135 |
|
|
136 |
this.corotIDParam = this.getModel().getParameterByName("corotIdCol"); |
|
137 |
this.raParam = this.getModel().getParameterByName("raCol"); |
|
138 |
this.decParam = this.getModel().getParameterByName("decCol"); |
|
139 |
|
|
140 |
|
|
141 |
// Get request parameters |
|
142 |
if (datasetApp.getConverterChained() != null) { |
|
143 |
datasetApp.getConverterChained().getContext().getAttributes().put("REQUEST", getRequest()); |
|
144 |
} |
|
145 |
// Get DatabaseRequestParameters |
|
146 |
DatabaseRequestParameters params = dsExplorerUtil.getDatabaseParams(); |
|
147 |
DataSet ds = datasetApp.getDataSet(); |
|
148 |
createQueryCorotID(params,ds); |
|
149 |
DatabaseRequest databaseRequest = DatabaseRequestFactory.getDatabaseRequest(params); |
|
150 |
|
|
151 |
try { |
|
152 |
|
|
153 |
if (params.getDistinct()) { |
|
154 |
databaseRequest.createDistinctRequest(); |
|
155 |
}else { |
|
156 |
databaseRequest.createRequest(); |
|
157 |
} |
|
158 |
// Recuperation dans la base du fichiers fits |
|
159 |
context.getLogger().log(Level.INFO, "nbr de resultat : "+databaseRequest.getCount()); |
|
160 |
while (databaseRequest.nextResult()) { |
|
161 |
Record rec = databaseRequest.getRecord(); |
|
162 |
this.raValue = Double.parseDouble(OrderResourceUtils.getInParam(raParam, rec).getValue().toString()); |
|
163 |
this.decValue = Double.parseDouble(OrderResourceUtils.getInParam(decParam, rec).getValue().toString()); |
|
164 |
|
|
165 |
Map a = getDataModel(); |
|
166 |
repr = new GeoJsonRepresentation(a); |
|
167 |
|
|
168 |
} |
|
169 |
} catch (Exception e) { |
|
170 |
throw new ResourceException(Status.SERVER_ERROR_INTERNAL,e.getMessage()); |
|
171 |
} |
|
172 |
return repr; |
|
173 |
} |
|
174 |
|
|
175 |
public Map getDataModel(){ |
|
176 |
final FeaturesDataModel features = new FeaturesDataModel(); |
|
177 |
final FeatureDataModel feature = new FeatureDataModel(); |
|
178 |
AstroCoordinate a = new AstroCoordinate(this.raValue,this.decValue); |
|
179 |
|
|
180 |
feature.createGeometry(String.format("[%s,%s]", this.raValue,this.decValue),"Point"); |
|
181 |
feature.createCrs(a.getCoordinateSystem().getCrs()); |
|
182 |
feature.addProperty("credits", "CDS"); |
|
183 |
feature.addProperty("identifier", "CDS0"); |
|
184 |
features.addFeature(feature); |
|
185 |
return features.getFeatures(); |
|
186 |
} |
|
187 |
|
|
188 |
private void createQueryCorotID(DatabaseRequestParameters params, DataSet ds){ |
|
189 |
Column corotIDCol = ds.findByColumnAlias(this.corotIDParam.getValue()); |
|
190 |
Predicat pred = new Predicat(); |
|
191 |
pred.setLogicOperator("AND"); |
|
192 |
pred.setLeftAttribute(corotIDCol); |
|
193 |
pred.setCompareOperator(Operator.EQ); |
|
194 |
pred.setRightValue(this.corotIDValueStr); |
|
195 |
params.getPredicats().add(pred); |
|
196 |
if(exoBool){ |
|
197 |
pred = new Predicat(); |
|
198 |
Column en2WinDescCol = ds.findByColumnAlias("en2_windescriptor"); |
|
199 |
pred.setLogicOperator("AND"); |
|
200 |
pred.setLeftAttribute(en2WinDescCol); |
|
201 |
pred.setCompareOperator(Operator.EQ); |
|
202 |
pred.setRightValue("false"); |
|
203 |
params.getPredicats().add(pred); |
|
204 |
} |
|
205 |
} |
|
206 |
} |
hesiod/javaExt/src/fr/ias/sitools/astro/resolverName/resource/CorotIdResolverAstero.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.ias.sitools.astro.resolverName.resource; |
|
20 |
|
|
21 |
import fr.cnes.sitools.astro.resolver.AbstractNameResolver; |
|
22 |
import fr.cnes.sitools.astro.resolver.NameResolverException; |
|
23 |
import fr.cnes.sitools.astro.resolver.NameResolverResponse; |
|
24 |
import fr.cnes.sitools.util.ClientResourceProxy; |
|
25 |
import java.io.IOException; |
|
26 |
import java.util.logging.Level; |
|
27 |
import java.util.logging.Logger; |
|
28 |
import org.json.JSONArray; |
|
29 |
import org.json.JSONException; |
|
30 |
import org.json.JSONObject; |
|
31 |
import org.restlet.Client; |
|
32 |
import org.restlet.data.Method; |
|
33 |
import org.restlet.data.Protocol; |
|
34 |
import org.restlet.data.Status; |
|
35 |
import org.restlet.resource.ClientResource; |
|
36 |
import org.restlet.resource.ResourceException; |
|
37 |
|
|
38 |
/** |
|
39 |
* Queries the Corot name resolver and returns the list of coordinates for a given identifier.<br/> A CorotIdResolver lets you get a sky |
|
40 |
* position given a Corot identifier |
|
41 |
* |
|
42 |
* @author Marc NICOLAS <marc.nicolas@ias.u-psud.fr> |
|
43 |
*/ |
|
44 |
public class CorotIdResolverAstero extends AbstractNameResolver { |
|
45 |
|
|
46 |
/** |
|
47 |
* Logger. |
|
48 |
*/ |
|
49 |
private static final Logger LOG = Logger.getLogger(CorotIdResolverAstero.class.getName()); |
|
50 |
/** |
|
51 |
* Credits to return for CDS. |
|
52 |
*/ |
|
53 |
private static final String CREDITS_NAME = "IAS Astero/CNES"; |
|
54 |
/** |
|
55 |
* Template URL for the Corot identifier resolver service. |
|
56 |
*/ |
|
57 |
private static final String TEMPLATE_NAME_RESOLVER = "http://idoc-corotn2-public-v2.ias.u-psud.fr/ds/astero/plugin/corotIdResolver/EQUATORIAL/<corotid>"; |
|
58 |
/** |
|
59 |
* Corot service response. |
|
60 |
*/ |
|
61 |
private String corotId; |
|
62 |
|
|
63 |
/** |
|
64 |
* Empty constructor. |
|
65 |
*/ |
|
66 |
protected CorotIdResolverAstero() { |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Constructs a new CorotId resolver. |
|
71 |
* |
|
72 |
* @param corotIdVal Corot ID |
|
73 |
*/ |
|
74 |
public CorotIdResolverAstero(final String corotIdVal) { |
|
75 |
setCorotId(corotIdVal); |
|
76 |
checkInputParameters(); |
|
77 |
} |
|
78 |
/** |
|
79 |
* Sets the Corot Id. |
|
80 |
* @param corotIdVal the Corot ID to set |
|
81 |
*/ |
|
82 |
protected final void setCorotId(final String corotIdVal) { |
|
83 |
this.corotId = corotIdVal; |
|
84 |
} |
|
85 |
/** |
|
86 |
* Returns the Corot ID. |
|
87 |
* @return the Corot ID |
|
88 |
*/ |
|
89 |
protected final String getCorotId() { |
|
90 |
return this.corotId; |
|
91 |
} |
|
92 |
/** |
|
93 |
* Tests if the coroID is set. |
|
94 |
* |
|
95 |
* <p> |
|
96 |
* Returns IllegalArgumentException if <code>corotId</code> is <code>null</code> or empty. |
|
97 |
* </p> |
|
98 |
*/ |
|
99 |
protected final void checkInputParameters() { |
|
100 |
if (getCorotId() == null || getCorotId().isEmpty()) { |
|
101 |
throw new IllegalArgumentException("corotId must be set."); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public final NameResolverResponse getResponse() { |
|
107 |
NameResolverResponse response = new NameResolverResponse(CREDITS_NAME); |
|
108 |
LOG.log(Level.SEVERE, "JE RENTRE DANS LE NAMERESOLVERRESPONSE de l'Astero !!"); |
|
109 |
try { |
|
110 |
final String query = TEMPLATE_NAME_RESOLVER.replace("<corotid>", corotId); |
|
111 |
final JSONObject json = parseResponse(query); |
|
112 |
|
|
113 |
final String[] coordinates = parseCoordinates(json); |
|
114 |
final double rightAscension = Double.valueOf(coordinates[0]); |
|
115 |
final double declination = Double.valueOf(coordinates[1]); |
|
116 |
|
|
117 |
response.addAstroCoordinate(rightAscension, declination); |
|
118 |
} catch (NameResolverException ex) { |
|
119 |
if (getSuccessor() == null) { |
|
120 |
response.setError(ex); |
|
121 |
} else { |
|
122 |
response = getSuccessor().getResponse(); |
|
123 |
} |
|
124 |
} finally { |
|
125 |
return response; |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Queries the SITools2 service at IAS and stores the result in <code>json</code>. |
|
131 |
* |
|
132 |
* @param query query the Corot service |
|
133 |
* @return the response from the server |
|
134 |
* @throws NameResolverException if a problem occurs while the response is being parsed |
|
135 |
*/ |
|
136 |
private JSONObject parseResponse(final String query) throws NameResolverException { |
|
137 |
assert query != null; |
|
138 |
LOG.log(Level.INFO, "Call IAS name resolver: {0}", query); |
|
139 |
final ClientResourceProxy proxy = new ClientResourceProxy(query, Method.GET); |
|
140 |
final ClientResource client = proxy.getClientResource(); |
|
141 |
//client.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "guest", "sitools2public")); |
|
142 |
final Client clientHTTP = new Client(Protocol.HTTP); |
|
143 |
clientHTTP.setConnectTimeout(AbstractNameResolver.SERVER_TIMEOUT); |
|
144 |
client.setNext(clientHTTP); |
|
145 |
final Status status = client.getStatus(); |
|
146 |
if (status.isSuccess()) { |
|
147 |
JSONObject json; |
|
148 |
try { |
|
149 |
json = new JSONObject(client.get().getText()); |
|
150 |
} catch (IOException ex) { |
|
151 |
throw new NameResolverException(Status.SERVER_ERROR_INTERNAL, ex); |
|
152 |
} catch (JSONException ex) { |
|
153 |
LOG.log(Level.WARNING, "the response of Corot server may changed"); |
|
154 |
throw new NameResolverException(Status.CLIENT_ERROR_NOT_ACCEPTABLE, ex); |
|
155 |
} catch (ResourceException ex) { |
|
156 |
throw new NameResolverException(Status.SERVER_ERROR_SERVICE_UNAVAILABLE, ex); |
|
157 |
} |
|
158 |
return json; |
|
159 |
} else { |
|
160 |
throw new NameResolverException(status, status.getThrowable()); |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Parses the coordinates from CDS response and return them. |
|
166 |
* @param json the server's response |
|
167 |
* @return the following array [rightAscension,declination] |
|
168 |
* @throws NameResolverException - if empty response from Corot |
|
169 |
*/ |
|
170 |
private String[] parseCoordinates(final JSONObject json) throws NameResolverException { |
|
171 |
try { |
|
172 |
//final JSONArray jsonArray = json.getJSONArray("data"); |
|
173 |
final JSONArray jsonArray = json.getJSONArray("features"); |
|
174 |
final JSONArray coords = jsonArray.getJSONObject(0).getJSONObject("geometry").getJSONArray("coordinates"); |
|
175 |
|
|
176 |
if (jsonArray.length() != 1) { |
|
177 |
throw new NameResolverException(Status.CLIENT_ERROR_NOT_FOUND, "Not found"); |
|
178 |
} |
|
179 |
|
|
180 |
if (coords.get(0).equals("") || coords.get(1).toString().equals("")) { |
|
181 |
throw new NameResolverException(Status.CLIENT_ERROR_NOT_FOUND, "Not found"); |
|
182 |
} |
|
183 |
return new String[]{coords.get(0).toString(),coords.get(1).toString()}; |
|
184 |
} catch (JSONException ex) { |
|
185 |
throw new NameResolverException(Status.SERVER_ERROR_INTERNAL, "cannot parse the coordinates"); |
|
186 |
} |
|
187 |
} |
|
188 |
} |
hesiod/javaExt/src/fr/ias/sitools/converters/FileSizeConverter.java | ||
---|---|---|
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 FileSizeConverter extends AbstractConverter { |
|
28 |
|
|
29 |
/** Class logger */ |
|
30 |
private static final Logger LOGGER = Logger.getLogger(FileSizeConverter.class.getName()); |
|
31 |
|
|
32 |
public FileSizeConverter() { |
|
33 |
|
|
34 |
this.setName("FileSizeConverter"); |
|
35 |
this.setDescription("A converter applying an unit conversion from bytes into Kb or Mb or Gb"); |
|
36 |
this.setClassAuthor("Marc NICOLAS"); |
|
37 |
this.setClassOwner("IAS"); |
|
38 |
this.setClassVersion("0.1"); |
|
39 |
|
|
40 |
ConverterParameter colFileSize = new ConverterParameter("colFileSizeInBytes", "row of dataset with the filesize in bytes",ConverterParameterType.CONVERTER_PARAMETER_IN); |
|
41 |
ConverterParameter colFileSizeConvert = new ConverterParameter("colFileSizeConvert", "File Size converted", ConverterParameterType.CONVERTER_PARAMETER_OUT); |
|
42 |
this.addParam(colFileSize); |
|
43 |
this.addParam(colFileSizeConvert); |
|
44 |
|
|
45 |
LOGGER.log(Level.INFO, "Converter :{0} version {1}", new Object[] { this.getName(), this.getClassVersion() }); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public Record getConversionOf(Record record) throws Exception { |
|
50 |
Record out = record; |
|
51 |
String result = ""; |
|
52 |
|
|
53 |
AttributeValue attrOut = this.getOutParam("colFileSizeConvert", out); |
|
54 |
|
|
55 |
AttributeValue attrIn = this.getInParam("colFileSizeInBytes", out); |
|
56 |
|
|
57 |
if (!isNull(attrIn) && !isNull(attrOut)) { |
|
58 |
try{ |
|
59 |
double input = Double.parseDouble(attrIn.getValue().toString()); |
|
60 |
if(input>0 && input<1024){ |
|
61 |
result = (double)Math.round(input*10)/10 +" o"; |
|
62 |
}else if(input >= 1024 && input < Math.pow(1024, 2) ){ |
|
63 |
result = (double)Math.round((input/1024)*10)/10+" Ko"; |
|
64 |
}else if(input >=Math.pow(1024, 2) && input < Math.pow(1024, 3)){ |
|
65 |
result = (double)Math.round((input/Math.pow(1024, 2))*10)/10+" Mo" ; |
|
66 |
}else if( input >= Math.pow(1024, 3) && input < Math.pow(1024, 4)){ |
|
67 |
result = (double)Math.round((input/Math.pow(1024, 3))*10)/10+" Go" ; |
|
68 |
} |
|
69 |
|
|
70 |
if(!result.isEmpty()){ |
|
71 |
attrOut.setValue(result); |
|
72 |
} |
|
73 |
}catch (Exception e) { |
|
74 |
attrOut.setValue(Double.NaN); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
return out; |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public Validator<AbstractConverter> getValidator() { |
|
83 |
// TODO Auto-generated method stub |
|
84 |
return new Validator<AbstractConverter>() { |
|
85 |
|
|
86 |
@Override |
|
87 |
public Set<ConstraintViolation> validate(AbstractConverter item) { |
|
88 |
Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>(); |
|
89 |
Map<String, ConverterParameter> params = item.getParametersMap(); |
|
90 |
ConverterParameter param = params.get("colFileSizeInBytes"); |
|
91 |
|
|
92 |
if(param.getAttachedColumn().isEmpty()){ |
|
93 |
ConstraintViolation constraint = new ConstraintViolation(); |
|
94 |
constraint.setMessage("You must choose the column with filesize in bytes data"); |
|
95 |
constraint.setLevel(ConstraintViolationLevel.CRITICAL); |
|
96 |
constraint.setValueName(param.getName()); |
|
97 |
constraints.add(constraint); |
|
98 |
} |
|
99 |
|
|
100 |
param = params.get("colFileSizeConvert"); |
|
101 |
|
|
102 |
if(param.getAttachedColumn().isEmpty()){ |
|
103 |
ConstraintViolation constraint = new ConstraintViolation(); |
|
104 |
constraint.setMessage("You must choose the output column"); |
|
105 |
constraint.setLevel(ConstraintViolationLevel.CRITICAL); |
|
106 |
constraint.setValueName(param.getName()); |
|
107 |
constraints.add(constraint); |
|
108 |
} |
|
109 |
|
|
110 |
return constraints; |
|
111 |
} |
|
112 |
}; |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
} |
hesiod/javaExt/src/fr/ias/sitools/converters/RaDecToXYZConverter.java | ||
---|---|---|
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 |
} |
hesiod/javaExt/src/fr/ias/sitools/filters/basic/BooleanCorotAsteroAndExo.java | ||
---|---|---|
1 |
package fr.ias.sitools.filters.basic; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.List; |
|
7 |
//import java.util.logging.Logger; |
|
8 |
|
|
9 |
import org.restlet.Request; |
|
10 |
import org.restlet.data.Form; |
|
11 |
import org.restlet.ext.wadl.ParameterInfo; |
|
12 |
import org.restlet.ext.wadl.ParameterStyle; |
|
13 |
|
|
14 |
import fr.cnes.sitools.common.validator.Validator; |
|
15 |
import fr.cnes.sitools.dataset.DataSetApplication; |
|
16 |
import fr.cnes.sitools.dataset.database.common.RequestFactory; |
|
17 |
import fr.cnes.sitools.dataset.database.jdbc.RequestSql; |
|
18 |
import fr.cnes.sitools.dataset.model.Column; |
|
19 |
import fr.cnes.sitools.dataset.model.DataSet; |
|
20 |
import fr.cnes.sitools.dataset.model.Predicat; |
|
21 |
import fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter; |
|
22 |
import fr.cnes.sitools.datasource.jdbc.business.SitoolsSQLDataSource; |
|
23 |
import fr.cnes.sitools.datasource.jdbc.business.SitoolsSQLDataSourceFactory; |
|
24 |
import fr.cnes.sitools.util.SQLUtils; |
|
25 |
|
|
26 |
public class BooleanCorotAsteroAndExo extends AbstractFormFilter { |
|
27 |
|
|
28 |
/** |
|
29 |
* The index of TYPE |
|
30 |
*/ |
|
31 |
private static final int TYPE = 0; |
|
32 |
/** |
|
33 |
* The index of COLUMN |
|
34 |
*/ |
|
35 |
private static final int COLUMN = 1; |
|
36 |
/** |
|
37 |
* The index of Values |
|
38 |
*/ |
|
39 |
private static final int VALUES = 2; |
|
40 |
/** |
|
41 |
* The number of values |
|
42 |
*/ |
|
43 |
private static final int NUMBER_OF_VALUES = 4; |
|
44 |
|
|
45 |
private String[] values; |
|
46 |
|
|
47 |
private enum TYPE_COMPONENT { |
|
48 |
/** DefaultType */ |
|
49 |
BOOLEAN_CHECKBOX_COROT, |
|
50 |
CHECKBOX_COROT_ASTERO |
|
51 |
} |
|
52 |
// private static final Logger LOGGER = Logger.getLogger(BooleanCorot.class.getName()); |
|
53 |
|
|
54 |
public BooleanCorotAsteroAndExo() { |
|
55 |
super(); |
|
56 |
this.setName("BooleanCorotAsteroAndExo"); |
|
57 |
this.setDescription("Required when using BooleanCorot for exo or astero data checkbox"); |
|
58 |
this.setClassAuthor("MNICOLAS"); |
|
59 |
this.setClassOwner("IAS"); |
|
60 |
this.setClassVersion("0.1"); |
|
61 |
this.setDefaultFilter(true); |
|
62 |
|
|
63 |
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>(); |
|
64 |
|
|
65 |
ParameterInfo param1 = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "BOOLEAN_CHECKBOX_COROT|columnAlias1,columnAlias2" + |
|
66 |
",columnAlias3,columnAlias4|long|short|center|anticenter"); |
|
67 |
rpd.put("0", param1); |
|
68 |
ParameterInfo param2 = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "CHECKBOX_COROT_ASTERO|columnAlias1,columnAlias2" + |
|
69 |
",columnAlias3,columnAlias4|long|short|center|anticenter"); |
|
70 |
rpd.put("1", param2); |
|
71 |
this.setRequestParamsDescription(rpd); |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception { |
|
76 |
DataSetApplication dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication"); |
|
77 |
DataSet ds = dsApplication.getDataSet(); |
|
78 |
|
|
79 |
Form params = request.getResourceRef().getQueryAsForm(); |
|
80 |
boolean filterExists = true; |
|
81 |
int i = 0; |
|
82 |
while (filterExists) { |
|
83 |
String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++)); |
|
84 |
String formParam = params.getFirstValue(index); |
|
85 |
if (formParam != null) { |
|
86 |
String[] parameters = formParam.split("\\|"); |
|
87 |
TYPE_COMPONENT[] types = TYPE_COMPONENT.values(); |
|
88 |
Boolean trouve = false; |
|
89 |
for (TYPE_COMPONENT typeCmp : types) { |
|
90 |
if (typeCmp.name().equals(parameters[TYPE])) { |
|
91 |
trouve = true; |
|
92 |
} |
|
93 |
} |
|
94 |
if (trouve) { |
|
95 |
if (checkValues(parameters)) { |
|
96 |
String[] columnsAlias = parameters[COLUMN].split(","); |
|
97 |
ArrayList<Column> columns = new ArrayList<Column>(); |
|
98 |
for (String columnAlias : columnsAlias) { |
|
99 |
Column col = ds.findByColumnAlias(columnAlias); |
|
100 |
if (col != null) { |
|
101 |
columns.add(col); |
|
102 |
} |
|
103 |
} |
|
104 |
SitoolsSQLDataSource dsource = SitoolsSQLDataSourceFactory.getDataSource(ds.getDatasource().getId()); |
|
105 |
RequestSql requestSql = RequestFactory.getRequest(dsource.getDsModel().getDriverClass()); |
|
106 |
|
|
107 |
String longRunColStr = requestSql.convertColumnToString(columns.get(0)); |
|
108 |
String shortRunColStr = requestSql.convertColumnToString(columns.get(1)); |
|
109 |
String centerColStr = requestSql.convertColumnToString(columns.get(2)); |
|
110 |
String anticenterColStr = requestSql.convertColumnToString(columns.get(3)); |
|
111 |
|
|
112 |
boolean longRunValue = Boolean.valueOf(SQLUtils.escapeString(values[0])); |
|
113 |
boolean shortRunValue = Boolean.valueOf(SQLUtils.escapeString(values[1])); |
|
114 |
boolean centerValue = Boolean.valueOf(SQLUtils.escapeString(values[2])); |
|
115 |
boolean anticenterValue = Boolean.valueOf(SQLUtils.escapeString(values[3])); |
|
116 |
|
|
117 |
|
|
118 |
Predicat predicat = new Predicat(); |
|
119 |
|
|
120 |
predicat.setStringDefinition(" AND ("+longRunColStr+" = "+longRunValue+" OR "+shortRunColStr+" = "+shortRunValue+")"+" AND ("+centerColStr+ " = "+ centerValue+" OR "+anticenterColStr+" = "+anticenterValue+")"); |
|
121 |
predicats.add(predicat); |
|
122 |
|
|
123 |
} |
|
124 |
} |
|
125 |
}else { |
|
126 |
filterExists = false; |
|
127 |
} |
|
128 |
} |
|
129 |
return predicats; |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
/** |
|
134 |
* Check the number of values |
|
135 |
* |
|
136 |
* @param parameters |
|
137 |
* the values |
|
138 |
* @return true if the number of values is correct |
|
139 |
*/ |
|
140 |
private boolean checkValues(String[] parameters) { |
|
141 |
values = Arrays.copyOfRange(parameters, VALUES, VALUES + NUMBER_OF_VALUES); |
|
142 |
if (values.length == NUMBER_OF_VALUES) { |
|
143 |
return true; |
|
144 |
} |
|
145 |
return false; |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public Validator<?> getValidator() { |
|
150 |
// TODO Auto-generated method stub |
|
151 |
return null; |
|
152 |
} |
|
153 |
|
|
154 |
} |
hesiod/javaExt/src/fr/ias/sitools/filters/basic/BooleanCustom.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* Copyright 2011 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.ias.sitools.filters.basic; |
|
20 |
|
|
21 |
import java.util.Arrays; |
|
22 |
import java.util.HashMap; |
|
23 |
import java.util.List; |
|
24 |
import java.util.Set; |
|
25 |
import java.util.logging.Logger; |
|
26 |
|
|
27 |
import org.restlet.Request; |
|
28 |
import org.restlet.data.Form; |
|
29 |
import org.restlet.ext.wadl.ParameterInfo; |
|
30 |
import org.restlet.ext.wadl.ParameterStyle; |
|
31 |
|
|
32 |
import fr.cnes.sitools.common.validator.ConstraintViolation; |
|
33 |
import fr.cnes.sitools.common.validator.Validator; |
|
34 |
import fr.cnes.sitools.dataset.DataSetApplication; |
|
35 |
import fr.cnes.sitools.dataset.filter.business.AbstractFilter; |
|
36 |
import fr.cnes.sitools.dataset.model.Column; |
|
37 |
import fr.cnes.sitools.dataset.model.DataSet; |
|
38 |
import fr.cnes.sitools.dataset.model.Operator; |
|
39 |
import fr.cnes.sitools.dataset.model.Predicat; |
|
40 |
import fr.cnes.sitools.util.SQLUtils; |
|
41 |
|
|
42 |
/** |
|
43 |
* Filter defined for Single Value Component |
|
44 |
* |
|
45 |
* |
|
46 |
* @author d.arpin |
|
47 |
*/ |
|
48 |
public final class BooleanCustom extends AbstractFilter { |
|
49 |
/** |
|
50 |
* The index of TYPE |
|
51 |
*/ |
|
52 |
private static final int TYPE = 0; |
|
53 |
/** |
|
54 |
* The index of COLUMN |
|
55 |
*/ |
|
56 |
private static final int COLUMN = 1; |
|
57 |
/** |
|
58 |
* The index of Values |
|
59 |
*/ |
|
60 |
private static final int VALUES = 2; |
|
61 |
|
|
62 |
/** |
|
63 |
* The number of values |
|
64 |
*/ |
|
65 |
private static final int NUMBER_OF_VALUES = 1; |
|
66 |
|
|
67 |
/** |
|
68 |
* The list of component that uses this filter |
|
69 |
*/ |
|
70 |
private enum TYPE_COMPONENT { |
|
71 |
/** Boolean Custom type */ |
|
72 |
BOOLEAN_CUSTOM |
|
73 |
} |
|
74 |
|
|
75 |
private String[] values; |
|
76 |
|
|
77 |
private static final Logger LOGGER = Logger.getLogger(BooleanCustom.class.getName()); |
|
78 |
|
|
79 |
/** The TEMPLATE_PARAM */ |
|
80 |
private static final String TEMPLATE_PARAM = "p[#]"; |
|
81 |
|
|
82 |
/** |
|
83 |
* Default constructor |
|
84 |
*/ |
|
85 |
public BooleanCustom() { |
|
86 |
|
|
87 |
super(); |
|
88 |
this.setName("BooleanCustom"); |
|
89 |
this.setDescription("Required when using Boolean Custom Component"); |
|
90 |
this.setClassAuthor("Marc NICOLAS"); |
|
91 |
this.setClassOwner("IAS"); |
|
92 |
this.setClassVersion("0.9"); |
|
93 |
this.setDefaultFilter(true); |
|
94 |
|
|
95 |
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>(); |
|
96 |
|
|
97 |
ParameterInfo paramInfo; |
|
98 |
paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "BOOLEAN_CUSTOM|columnAlias|value"); |
|
99 |
rpd.put("0", paramInfo); |
|
100 |
this.setRequestParamsDescription(rpd); |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception { |
|
106 |
|
|
107 |
DataSetApplication dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication"); |
|
108 |
DataSet ds = dsApplication.getDataSet(); |
|
109 |
|
|
110 |
Form params = request.getResourceRef().getQueryAsForm(); |
|
111 |
boolean filterExists = true; |
|
112 |
int i = 0; |
|
113 |
// Build predicat for filters param |
|
114 |
while (filterExists) { |
|
115 |
String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++)); |
|
116 |
String formParam = params.getFirstValue(index); |
|
117 |
if (formParam != null) { |
|
118 |
String[] parameters = formParam.split("\\|"); |
|
119 |
TYPE_COMPONENT[] types = TYPE_COMPONENT.values(); |
|
120 |
Boolean trouve = false; |
|
121 |
for (TYPE_COMPONENT typeCmp : types) { |
|
122 |
if (typeCmp.name().equals(parameters[TYPE])) { |
|
123 |
trouve = true; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
if (trouve) { |
|
128 |
if (checkValues(parameters)) { |
|
129 |
String columnAlias = null; |
|
130 |
if (parameters.length >= VALUES) { |
|
131 |
|
|
132 |
columnAlias = parameters[COLUMN]; |
|
133 |
Column col = ds.findByColumnAlias(columnAlias); |
|
134 |
if (col != null && col.getFilter() != null && col.getFilter()) { |
|
135 |
// get the value and escape it to avoid SQL injection |
|
136 |
String value = SQLUtils.escapeString(parameters[VALUES]); |
|
137 |
Predicat predicat = new Predicat(); |
|
138 |
if (value != null) { |
|
139 |
predicat.setLeftAttribute(col); |
|
140 |
predicat.setNbOpenedParanthesis(0); |
|
141 |
predicat.setNbClosedParanthesis(0); |
|
142 |
predicat.setCompareOperator(Operator.EQ); |
|
143 |
predicat.setRightValue("'" + value + "'"); |
|
144 |
if(value.equalsIgnoreCase("false")){ |
|
145 |
predicats.add(predicat); |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
else { |
|
155 |
filterExists = false; |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
return predicats; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Check the number of values |
|
164 |
* |
|
165 |
* @param parameters |
|
166 |
* the values |
|
167 |
* @return true if the number of values is correct |
|
168 |
*/ |
|
169 |
private boolean checkValues(String[] parameters) { |
|
170 |
if(parameters.length >= 3){ |
|
171 |
values = Arrays.copyOfRange(parameters, VALUES, VALUES + NUMBER_OF_VALUES); |
|
172 |
if (values.length == NUMBER_OF_VALUES) { |
|
173 |
return true; |
|
174 |
} |
|
175 |
return false; |
|
176 |
}else{ |
|
177 |
return false; |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
|
|
182 |
/** |
|
183 |
* Gets the validator for this Filter |
|
184 |
* |
|
185 |
* @return the validator for the filter |
|
186 |
*/ |
|
187 |
@Override |
|
188 |
public Validator<AbstractFilter> getValidator() { |
|
189 |
return new Validator<AbstractFilter>() { |
|
190 |
@Override |
|
191 |
public Set<ConstraintViolation> validate(AbstractFilter item) { |
|
192 |
// TODO Auto-generated method stub |
|
193 |
return null; |
|
194 |
} |
|
195 |
}; |
|
196 |
} |
|
197 |
|
|
198 |
} |
hesiod/javaExt/src/fr/ias/sitools/filters/basic/DateBeginEndFilter.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* Copyright 2011 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.ias.sitools.filters.basic; |
|
20 |
|
|
21 |
import java.util.Arrays; |
|
22 |
import java.util.HashMap; |
|
23 |
import java.util.List; |
|
24 |
import java.util.Set; |
|
25 |
|
|
26 |
import org.restlet.Request; |
|
27 |
import org.restlet.data.Form; |
|
28 |
import org.restlet.ext.wadl.ParameterInfo; |
|
29 |
import org.restlet.ext.wadl.ParameterStyle; |
|
30 |
|
|
31 |
import fr.cnes.sitools.common.validator.ConstraintViolation; |
|
32 |
import fr.cnes.sitools.common.validator.Validator; |
|
33 |
import fr.cnes.sitools.dataset.DataSetApplication; |
|
34 |
import fr.cnes.sitools.dataset.filter.business.AbstractFilter; |
|
35 |
import fr.cnes.sitools.dataset.model.Column; |
|
36 |
import fr.cnes.sitools.dataset.model.DataSet; |
|
37 |
import fr.cnes.sitools.dataset.model.Operator; |
|
38 |
import fr.cnes.sitools.dataset.model.Predicat; |
|
39 |
import fr.cnes.sitools.util.SQLUtils; |
|
40 |
|
|
41 |
/** |
|
42 |
* Filter defined for Date Between Component |
|
43 |
* |
|
44 |
* |
|
45 |
* @author d.arpin |
|
46 |
* <a href="https://sourceforge.net/tracker/?func=detail&atid=2158259&aid=3411383&group_id=531341">[3411383]</a><br/> |
|
47 |
* 2011/09/19 d.arpin {add quotes arround date Value} |
|
48 |
*/ |
|
49 |
public final class DateBeginEndFilter extends AbstractFilter { |
|
50 |
/** |
|
51 |
* The index of TYPE |
|
52 |
*/ |
|
53 |
private static final int TYPE = 0; |
|
54 |
/** |
|
55 |
* The index of COLUMN |
|
56 |
*/ |
|
57 |
private static final int COLUMN = 1; |
|
58 |
/** |
|
59 |
* The index of Values |
|
60 |
*/ |
|
61 |
private static final int VALUES = 2; |
|
62 |
|
|
63 |
/** The TEMPLATE_PARAM */ |
|
64 |
private static final String TEMPLATE_PARAM = "p[#]"; |
|
65 |
/** |
|
66 |
* the values from to |
|
67 |
*/ |
|
68 |
private String[] values; |
|
69 |
|
|
70 |
/** |
|
71 |
* The list of component that uses this filter |
|
72 |
*/ |
|
73 |
private enum TYPE_COMPONENT { |
|
74 |
/** DefaultType */ |
|
75 |
DATE_BEGIN_END |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Default constructor |
|
80 |
*/ |
|
81 |
public DateBeginEndFilter() { |
|
82 |
|
|
83 |
super(); |
|
84 |
this.setName("DateBeginEndFilter"); |
|
85 |
this.setDescription("Required when using Date Between Components between 2 columns"); |
|
86 |
|
|
87 |
this.setClassAuthor("HUSSON@IAS"); |
|
88 |
this.setClassAuthor("HUSSON@IAS"); |
|
89 |
this.setClassOwner("IAS"); |
|
90 |
this.setClassVersion("0.1"); |
|
91 |
this.setDefaultFilter(true); |
|
92 |
|
|
93 |
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>(); |
|
94 |
|
|
95 |
ParameterInfo paramInfo; |
|
96 |
paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, |
|
97 |
"DATE_BEGIN_END|columnFrom,columnTo|valueFrom|valueTo"); |
|
98 |
rpd.put("0", paramInfo); |
|
99 |
this.setRequestParamsDescription(rpd); |
|
100 |
// |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception { |
|
106 |
// Get the dataset |
|
107 |
DataSetApplication dsApplication = null; |
|
108 |
DataSet ds = null; |
|
109 |
|
|
110 |
Form params = request.getResourceRef().getQueryAsForm(); |
|
111 |
boolean filterExists = true; |
|
112 |
int i = 0; |
|
113 |
// Build predicat for filters param |
|
114 |
while (filterExists) { |
|
115 |
String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++)); |
|
116 |
String formParam = params.getFirstValue(index); |
|
117 |
if (formParam != null) { |
|
118 |
String[] parameters = formParam.split("\\|"); |
|
119 |
TYPE_COMPONENT[] types = TYPE_COMPONENT.values(); |
|
120 |
Boolean trouve = false; |
|
121 |
for (TYPE_COMPONENT typeCmp : types) { |
|
122 |
if (typeCmp.name().equals(parameters[TYPE])) { |
|
123 |
trouve = true; |
|
124 |
} |
|
125 |
} |
|
126 |
if (trouve) { |
|
127 |
if (dsApplication == null) { |
|
128 |
dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication"); |
|
129 |
ds = dsApplication.getDataSet(); |
|
130 |
} |
|
131 |
String columnfrom = null; |
|
132 |
String columnto = null; |
|
133 |
if (parameters.length >= VALUES) { |
|
134 |
columnfrom = parameters[COLUMN].split(",")[0]; |
|
135 |
columnto = parameters[COLUMN].split(",")[1]; |
|
136 |
|
|
137 |
Column colfrom = ds.findByColumnAlias(columnfrom); |
|
138 |
Column colto = ds.findByColumnAlias(columnto); |
|
139 |
|
|
140 |
if (colfrom != null && colfrom.getFilter() != null && colfrom.getFilter() && checkValues(parameters) && colto != null && colto.getFilter() != null && colto.getFilter()) { |
|
141 |
// escape the values to avoid SQL injection |
|
142 |
String valuefrom = "'" + SQLUtils.escapeString(values[0]) + "'"; |
|
143 |
String valueto = "'" + SQLUtils.escapeString(values[1]) + "'"; |
|
144 |
|
|
145 |
Predicat predicat = new Predicat(); |
|
146 |
predicat.setLeftAttribute(colfrom); |
|
147 |
predicat.setNbOpenedParanthesis(1); |
|
148 |
predicat.setNbClosedParanthesis(0); |
|
149 |
predicat.setCompareOperator(Operator.GTE); |
|
150 |
predicat.setRightValue(valuefrom); |
|
151 |
predicats.add(predicat); |
|
152 |
predicat = new Predicat(); |
|
153 |
predicat.setLeftAttribute(colto); |
|
154 |
predicat.setNbOpenedParanthesis(0); |
|
155 |
predicat.setNbClosedParanthesis(1); |
|
156 |
predicat.setCompareOperator(Operator.LTE); |
|
157 |
predicat.setRightValue(valueto); |
|
158 |
predicats.add(predicat); |
|
159 |
} |
|
160 |
|
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
else { |
|
166 |
filterExists = false; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
return predicats; |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Check values of the form |
|
175 |
* |
|
176 |
* @param parameters |
|
177 |
* the parameters of the filter |
|
178 |
* @return true if values agree |
|
179 |
*/ |
|
180 |
private boolean checkValues(String[] parameters) { |
|
181 |
values = Arrays.copyOfRange(parameters, VALUES, parameters.length); |
|
182 |
if (values.length == 2) { |
|
183 |
return true; |
|
184 |
} |
|
185 |
return false; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Gets the validator for this Filter |
|
190 |
* |
|
191 |
* @return the validator for the filter |
|
192 |
*/ |
|
193 |
@Override |
|
194 |
public Validator<AbstractFilter> getValidator() { |
|
195 |
return new Validator<AbstractFilter>() { |
|
196 |
@Override |
|
197 |
public Set<ConstraintViolation> validate(AbstractFilter item) { |
|
198 |
return null; |
|
199 |
} |
|
200 |
}; |
|
201 |
} |
|
202 |
|
|
203 |
} |
hesiod/javaExt/src/fr/ias/sitools/filters/basic/GroupCheckBoxMasterLigthCurves.java | ||
---|---|---|
1 |
package fr.ias.sitools.filters.basic; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.List; |
|
7 |
import org.restlet.Request; |
|
8 |
import org.restlet.data.Form; |
|
9 |
import org.restlet.ext.wadl.ParameterInfo; |
|
10 |
import org.restlet.ext.wadl.ParameterStyle; |
|
11 |
|
|
12 |
import fr.cnes.sitools.common.validator.Validator; |
|
13 |
import fr.cnes.sitools.dataset.DataSetApplication; |
|
14 |
import fr.cnes.sitools.dataset.model.Column; |
|
15 |
import fr.cnes.sitools.dataset.model.DataSet; |
|
16 |
import fr.cnes.sitools.dataset.model.Operator; |
|
17 |
import fr.cnes.sitools.dataset.model.Predicat; |
|
18 |
import fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter; |
|
19 |
import fr.cnes.sitools.util.SQLUtils; |
|
20 |
|
|
21 |
public class GroupCheckBoxMasterLigthCurves extends AbstractFormFilter { |
|
22 |
|
|
23 |
/** |
|
24 |
* The index of TYPE |
|
25 |
*/ |
|
26 |
private static final int TYPE = 0; |
|
27 |
/** |
|
28 |
* The index of COLUMN |
|
29 |
*/ |
|
30 |
private static final int COLUMN = 1; |
|
31 |
/** |
|
32 |
* The index of Values |
|
33 |
*/ |
|
34 |
private static final int VALUES = 2; |
|
35 |
/** |
|
36 |
* The number of values |
|
37 |
*/ |
|
38 |
private static final int NUMBER_OF_VALUES = 4; |
|
39 |
|
|
40 |
private String[] values; |
|
41 |
|
|
42 |
private enum TYPE_COMPONENT { |
|
43 |
/** DefaultType */ |
|
44 |
GROUP_CHECKBOX_LIGHTCURVES_COROT |
|
45 |
} |
|
46 |
//private static final Logger LOGGER = Logger.getLogger(GroupCheckBoxMasterLigthCurves.class.getName()); |
|
47 |
|
|
48 |
public GroupCheckBoxMasterLigthCurves() { |
|
49 |
super(); |
|
50 |
this.setName("GroupCheckBoxLightCurves"); |
|
51 |
this.setDescription("Required when using the LightCurves checkbox component"); |
|
52 |
this.setClassAuthor("MNICOLAS"); |
|
53 |
this.setClassOwner("IAS"); |
|
54 |
this.setClassVersion("0.1"); |
|
55 |
this.setDefaultFilter(true); |
|
56 |
|
|
57 |
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>(); |
|
58 |
|
|
59 |
ParameterInfo param1 = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "GROUP_CHECKBOX_LIGHTCURVES_COROT|columnAlias1,columnAlias2" + |
|
60 |
",columnAlias3,columnAlias4|starChr|starMon|star512|star32"); |
|
61 |
rpd.put("0", param1); |
|
62 |
this.setRequestParamsDescription(rpd); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception { |
|
67 |
DataSetApplication dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication"); |
|
68 |
DataSet ds = dsApplication.getDataSet(); |
|
69 |
|
|
70 |
Form params = request.getResourceRef().getQueryAsForm(); |
|
71 |
boolean filterExists = true; |
Also available in: Unified diff
Add all old java development for hesiod