1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
package fr.cnes.sitools.resources.order;
|
20
|
|
21
|
import java.util.HashSet;
|
22
|
import java.util.Map;
|
23
|
import java.util.Set;
|
24
|
|
25
|
import fr.cnes.sitools.common.validator.ConstraintViolation;
|
26
|
import fr.cnes.sitools.common.validator.ConstraintViolationLevel;
|
27
|
import fr.cnes.sitools.common.validator.Validator;
|
28
|
import fr.cnes.sitools.dataset.DataSetApplication;
|
29
|
import fr.cnes.sitools.plugins.resources.model.DataSetSelectionType;
|
30
|
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
|
31
|
import fr.cnes.sitools.plugins.resources.model.ResourceParameter;
|
32
|
import fr.cnes.sitools.plugins.resources.model.ResourceParameterType;
|
33
|
import fr.cnes.sitools.tasks.model.TaskResourceModel;
|
34
|
import fr.cnes.sitools.tasks.model.TaskRunTypeAdministration;
|
35
|
|
36
|
|
37
|
|
38
|
|
39
|
|
40
|
|
41
|
|
42
|
public class PublicOrderResourceModel extends TaskResourceModel {
|
43
|
|
44
|
|
45
|
|
46
|
|
47
|
public PublicOrderResourceModel() {
|
48
|
|
49
|
super();
|
50
|
setClassAuthor("Shuo");
|
51
|
setClassOwner("IAS");
|
52
|
setClassVersion("0.1");
|
53
|
setName("PublicOrderResourceModel");
|
54
|
setDescription("Order resources associated to metadata for public user and save it in public storage. (Can also create a ZIP, TAR or TAR.GZ 'on the fly')");
|
55
|
|
56
|
setResourceClassName("fr.cnes.sitools.resources.order.PublicOrderResourceFacade");
|
57
|
|
58
|
setResourceImplClassName("fr.cnes.sitools.resources.order.PublicOrderResource");
|
59
|
|
60
|
setRunTypeAdministration(TaskRunTypeAdministration.TASK_DEFAULT_RUN_ASYNC);
|
61
|
|
62
|
ResourceParameter paramColUrl = new ResourceParameter("colUrl", "Colum containing data url for order",
|
63
|
ResourceParameterType.PARAMETER_INTERN);
|
64
|
|
65
|
paramColUrl.setValueType("xs:dataset.columnAlias");
|
66
|
ResourceParameter param2 = new ResourceParameter("zip",
|
67
|
"(true or false) If the data needs to be zipped at the end", ResourceParameterType.PARAMETER_USER_INPUT);
|
68
|
param2.setValue("false");
|
69
|
|
70
|
param2.setValueType("xs:boolean");
|
71
|
ResourceParameter email= new ResourceParameter("Email","Send alert email when download ready",ResourceParameterType.PARAMETER_USER_INPUT);
|
72
|
email.setValue("");
|
73
|
email.setValueType("xs:string");
|
74
|
this.addParam(paramColUrl);
|
75
|
this.addParam(param2);
|
76
|
this.addParam(email);
|
77
|
|
78
|
this.setApplicationClassName(DataSetApplication.class.getName());
|
79
|
this.getParameterByName("methods").setValue("POST");
|
80
|
this.setDataSetSelection(DataSetSelectionType.MULTIPLE);
|
81
|
|
82
|
|
83
|
ResourceParameter paramMaxWarningThreshold = new ResourceParameter("max_warning_threshold",
|
84
|
"Maximum number of files allowed to be downloaded before client warning, download is still allowed",
|
85
|
ResourceParameterType.PARAMETER_USER_GUI);
|
86
|
paramMaxWarningThreshold.setValueType("xs:integer");
|
87
|
|
88
|
ResourceParameter paramTooManySelectedThreshold = new ResourceParameter("too_many_selected_threshold",
|
89
|
"Maximum number of files allowed to be downloaded (-1 to set no limit)", ResourceParameterType.PARAMETER_INTERN);
|
90
|
paramTooManySelectedThreshold.setValueType("xs:integer");
|
91
|
paramTooManySelectedThreshold.setValue("-1");
|
92
|
|
93
|
ResourceParameter paramMaxWarningThresholdText = new ResourceParameter("max_warning_threshold_text",
|
94
|
"Text to display to the user when Warning threshold is reached", ResourceParameterType.PARAMETER_USER_GUI);
|
95
|
paramMaxWarningThresholdText.setValueType("xs:string");
|
96
|
|
97
|
ResourceParameter paramTooManySelectedThresholdText = new ResourceParameter("too_many_selected_threshold_text",
|
98
|
"Text to display to the user when TooMaxySelected threshold is reached",
|
99
|
ResourceParameterType.PARAMETER_USER_GUI);
|
100
|
paramTooManySelectedThresholdText.setValueType("xs:string");
|
101
|
|
102
|
this.addParam(paramMaxWarningThreshold);
|
103
|
this.addParam(paramTooManySelectedThreshold);
|
104
|
this.addParam(paramMaxWarningThresholdText);
|
105
|
this.addParam(paramTooManySelectedThresholdText);
|
106
|
|
107
|
this.getParameterByName("fileName").setValue("dataset_order_" + "${date:yyyy-MM-dd HH_mm_ss}");
|
108
|
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public Validator<ResourceModel> getValidator() {
|
113
|
return new Validator<ResourceModel>() {
|
114
|
|
115
|
@Override
|
116
|
public Set<ConstraintViolation> validate(ResourceModel item) {
|
117
|
Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>();
|
118
|
Map<String, ResourceParameter> params = item.getParametersMap();
|
119
|
ResourceParameter param = params.get("colUrl");
|
120
|
String value = param.getValue();
|
121
|
if (value == null || value.equals("")) {
|
122
|
ConstraintViolation constraint = new ConstraintViolation();
|
123
|
constraint.setMessage("An attribute of the dataset must be choosen");
|
124
|
constraint.setLevel(ConstraintViolationLevel.CRITICAL);
|
125
|
constraint.setValueName(param.getName());
|
126
|
constraints.add(constraint);
|
127
|
}
|
128
|
param = params.get("zip");
|
129
|
if (param != null) {
|
130
|
value = param.getValue();
|
131
|
if (value == null || (!"false".equals(value) && !"true".equals(value))) {
|
132
|
ConstraintViolation constraint = new ConstraintViolation();
|
133
|
constraint.setMessage("Must be a boolean");
|
134
|
constraint.setLevel(ConstraintViolationLevel.CRITICAL);
|
135
|
constraint.setInvalidValue(value);
|
136
|
constraint.setValueName(param.getName());
|
137
|
constraints.add(constraint);
|
138
|
}
|
139
|
}
|
140
|
param = params.get("too_many_selected_threshold");
|
141
|
value = param.getValue();
|
142
|
if (value == null || "".equals(value)) {
|
143
|
ConstraintViolation constraint = new ConstraintViolation();
|
144
|
constraint.setMessage("Cannot be null");
|
145
|
constraint.setLevel(ConstraintViolationLevel.CRITICAL);
|
146
|
constraint.setInvalidValue(value);
|
147
|
constraint.setValueName(param.getName());
|
148
|
constraints.add(constraint);
|
149
|
}
|
150
|
else {
|
151
|
try {
|
152
|
Integer.parseInt(value);
|
153
|
}
|
154
|
catch (NumberFormatException e) {
|
155
|
ConstraintViolation constraint = new ConstraintViolation();
|
156
|
constraint.setMessage("Must be an integer value");
|
157
|
constraint.setLevel(ConstraintViolationLevel.CRITICAL);
|
158
|
constraint.setInvalidValue(value);
|
159
|
constraint.setValueName(param.getName());
|
160
|
constraints.add(constraint);
|
161
|
}
|
162
|
}
|
163
|
return constraints;
|
164
|
}
|
165
|
};
|
166
|
}
|
167
|
|
168
|
}
|