11package org .devgateway .toolkit .forms .wicket .page .edit .dataset ;
22
3+ import static org .devgateway .toolkit .persistence .dao .DBConstants .Status .DELETED ;
4+ import static org .devgateway .toolkit .persistence .dao .DBConstants .Status .PUBLISHING ;
5+ import static org .devgateway .toolkit .persistence .dao .DBConstants .Status .UNPUBLISHING ;
6+
37import de .agilecoders .wicket .core .markup .html .bootstrap .button .BootstrapAjaxButton ;
48import de .agilecoders .wicket .core .markup .html .bootstrap .button .Buttons ;
59import de .agilecoders .wicket .extensions .markup .html .bootstrap .icon .FontAwesome5IconType ;
6- import org .devgateway .toolkit .forms .wicket .components .buttons .ladda .LaddaAjaxButton ;
10+ import jakarta .servlet .http .HttpServletResponse ;
11+ import java .io .IOException ;
712import org .apache .commons .lang3 .StringUtils ;
813import org .apache .wicket .ajax .AjaxRequestTarget ;
914import org .apache .wicket .model .IModel ;
1924import org .devgateway .toolkit .forms .service .DatasetClientService ;
2025import org .devgateway .toolkit .forms .service .EurekaClientService ;
2126import org .devgateway .toolkit .forms .wicket .components .breadcrumbs .BreadCrumbPage ;
27+ import org .devgateway .toolkit .forms .wicket .components .buttons .ladda .LaddaAjaxButton ;
2228import org .devgateway .toolkit .forms .wicket .components .form .AJAXDownload ;
2329import org .devgateway .toolkit .forms .wicket .components .form .BootstrapCancelButton ;
2430import org .devgateway .toolkit .forms .wicket .components .form .FileInputBootstrapFormComponent ;
3642import org .springframework .orm .ObjectOptimisticLockingFailureException ;
3743import org .wicketstuff .annotation .mount .MountPath ;
3844
39- import jakarta .servlet .http .HttpServletResponse ;
40- import java .io .IOException ;
41-
42- import static org .devgateway .toolkit .persistence .dao .DBConstants .Status .DELETED ;
43- import static org .devgateway .toolkit .persistence .dao .DBConstants .Status .PUBLISHING ;
44- import static org .devgateway .toolkit .persistence .dao .DBConstants .Status .UNPUBLISHING ;
45-
4645/**
4746 * @author vchihai
4847 */
4948@ MountPath (value = "/editCSVDataset" )
5049@ BreadCrumbPage (parent = ListCSVDatasetPage .class , hasServiceParam = true )
51- public class EditCSVDatasetPage extends AbstractEditStatusEntityPage <CSVDataset > {
50+ public class EditCSVDatasetPage
51+ extends AbstractEditStatusEntityPage <CSVDataset >
52+ {
5253
5354 private static final long serialVersionUID = -5231470856974604314L ;
5455
55- private static final Logger logger = LoggerFactory .getLogger (EditCSVDatasetPage .class );
56+ private static final Logger logger = LoggerFactory .getLogger (
57+ EditCSVDatasetPage .class
58+ );
5659
5760 protected Select2ChoiceBootstrapFormComponent <Integer > year ;
5861
@@ -81,29 +84,37 @@ protected void onInitialize() {
8184 super .onInitialize ();
8285
8386 if (entityId == null ) {
84- String service = getPageParameters ().get (WebConstants .PARAM_SERVICE ).toString ();
87+ String service = getPageParameters ()
88+ .get (WebConstants .PARAM_SERVICE )
89+ .toString ();
8590 editForm .getModelObject ().setDestinationService (service );
8691 }
8792
8893 editForm .add (getYear ());
8994
9095 final TextFieldBootstrapFormComponent <String > description =
91- new TextFieldBootstrapFormComponent <>("description" );
92- description .getField ().add (WebConstants .StringValidators .MAXIMUM_LENGTH_VALIDATOR_ONE_LINE_TEXT );
96+ new TextFieldBootstrapFormComponent <>("description" );
97+ description
98+ .getField ()
99+ .add (
100+ WebConstants .StringValidators .MAXIMUM_LENGTH_VALIDATOR_ONE_LINE_TEXT
101+ );
93102 editForm .add (description );
94103
95- final FileInputBootstrapFormComponent files = new FileInputBootstrapFormComponent ("files" );
104+ final FileInputBootstrapFormComponent files =
105+ new FileInputBootstrapFormComponent ("files" );
96106 files .allowedFileExtensions ("csv" );
97107 files .required ();
98108 files .maxFiles (1 );
99- files .getFileInputBootstrapFormComponentWrapper ().setAllowDownloadWhenReadonly (true );
109+ files
110+ .getFileInputBootstrapFormComponentWrapper ()
111+ .setAllowDownloadWhenReadonly (true );
100112 editForm .add (files );
101113 editForm .add (getService ());
102114
103115 AJAXDownload downloadTemplateBehaviour = getDownloadTemplateBehaviour ();
104116 editForm .add (downloadTemplateBehaviour );
105117 editForm .add (getDownloadTemplateButton (downloadTemplateBehaviour ));
106-
107118 }
108119
109120 private AJAXDownload getDownloadTemplateBehaviour () {
@@ -113,20 +124,35 @@ protected IRequestHandler getHandler() {
113124 return new IRequestHandler () {
114125 @ Override
115126 public void respond (final IRequestCycle requestCycle ) {
116- final HttpServletResponse response = (HttpServletResponse ) requestCycle .getResponse ().getContainerResponse ();
127+ final HttpServletResponse response =
128+ (HttpServletResponse ) requestCycle
129+ .getResponse ()
130+ .getContainerResponse ();
117131 try {
118- String serviceName = editForm .getModelObject ().getDestinationService ();
132+ String serviceName = editForm
133+ .getModelObject ()
134+ .getDestinationService ();
119135
120- final byte [] bytes = datasetClientService .getTemplateDownload (serviceName );
136+ final byte [] bytes =
137+ datasetClientService .getTemplateDownload (
138+ serviceName
139+ );
121140
122141 response .setContentType ("text/csv" );
123- response .setHeader ("Content-Disposition" , "attachment; filename=" + serviceName + "-template.csv" );
142+ response .setHeader (
143+ "Content-Disposition" ,
144+ "attachment; filename=" +
145+ serviceName +
146+ "-template.csv"
147+ );
124148 response .getOutputStream ().write (bytes );
125149 } catch (IOException e ) {
126150 logger .error ("Download Template error" , e );
127151 }
128152
129- RequestCycle .get ().scheduleRequestHandlerAfterCurrent (null );
153+ RequestCycle .get ().scheduleRequestHandlerAfterCurrent (
154+ null
155+ );
130156 }
131157
132158 @ Override
@@ -140,10 +166,14 @@ public void detach(final IRequestCycle requestCycle) {
140166 return download ;
141167 }
142168
143- private BootstrapAjaxButton getDownloadTemplateButton (final AJAXDownload downloadTemplateBehaviour ) {
144- final LaddaAjaxButton templateDownloadButton = new LaddaAjaxButton ("templateDownloadButton" ,
145- new Model <>("Template Download" ),
146- Buttons .Type .Warning ) {
169+ private BootstrapAjaxButton getDownloadTemplateButton (
170+ final AJAXDownload downloadTemplateBehaviour
171+ ) {
172+ final LaddaAjaxButton templateDownloadButton = new LaddaAjaxButton (
173+ "templateDownloadButton" ,
174+ new Model <>("Template Download" ),
175+ Buttons .Type .Warning
176+ ) {
147177 @ Override
148178 protected void onSubmit (final AjaxRequestTarget target ) {
149179 super .onSubmit (target );
@@ -158,16 +188,19 @@ protected void onSubmit(final AjaxRequestTarget target) {
158188 }
159189
160190 private Select2ChoiceBootstrapFormComponent <Integer > getYear () {
161- year = new Select2ChoiceBootstrapFormComponent <>("year" ,
162- new GenericChoiceProvider <>(settingsUtils .getYearsRange ()));
163- editForm .add (year );
191+ year = new Select2ChoiceBootstrapFormComponent <>(
192+ "year" ,
193+ new GenericChoiceProvider <>(settingsUtils .getYearsRange ())
194+ );
164195 year .required ();
165196
166197 return year ;
167198 }
168199
169200 private TextFieldBootstrapFormComponent <String > getService () {
170- destinationService = new TextFieldBootstrapFormComponent ("destinationService" );
201+ destinationService = new TextFieldBootstrapFormComponent (
202+ "destinationService"
203+ );
171204 destinationService .setEnabled (false );
172205
173206 return destinationService ;
@@ -213,7 +246,11 @@ protected void onApprove(final AjaxRequestTarget target) {
213246 try {
214247 CSVDataset dataset = editForm .getModelObject ();
215248
216- FileMetadata fileMetadata = dataset .getFiles ().stream ().findFirst ().get ();
249+ FileMetadata fileMetadata = dataset
250+ .getFiles ()
251+ .stream ()
252+ .findFirst ()
253+ .get ();
217254 String fileName = fileMetadata .getName ();
218255 byte [] content = fileMetadata .getContent ().getBytes ();
219256
@@ -238,13 +275,20 @@ protected void onForceFailPublishing(final AjaxRequestTarget target) {
238275 }
239276
240277 protected BootstrapCancelButton getCancelButton (final String id ) {
241- return new CancelEditPageButton (id , new StringResourceModel ("cancelButton" , this , null ));
278+ return new CancelEditPageButton (
279+ id ,
280+ new StringResourceModel ("cancelButton" , this , null )
281+ );
242282 }
243283
244284 public class CancelEditPageButton extends BootstrapCancelButton {
285+
245286 private static final long serialVersionUID = -1474498211555760931L ;
246287
247- public CancelEditPageButton (final String id , final IModel <String > model ) {
288+ public CancelEditPageButton (
289+ final String id ,
290+ final IModel <String > model
291+ ) {
248292 super (id , model );
249293 }
250294
@@ -259,7 +303,11 @@ protected void onSubmit(final AjaxRequestTarget target) {
259303 protected void enableDisableAutosaveFields (final AjaxRequestTarget target ) {
260304 super .enableDisableAutosaveFields (target );
261305
262- if (StringUtils .isBlank (editForm .getModelObject ().getDestinationService ())) {
306+ CSVDataset model = editForm .getModelObject ();
307+ if (
308+ StringUtils .isBlank (model .getDestinationService ()) ||
309+ model .getYear () == null
310+ ) {
263311 saveApproveButton .setEnabled (false );
264312 approveButton .setEnabled (false );
265313 }
@@ -278,7 +326,10 @@ protected PageParameters getCancelPageParameters() {
278326 protected PageParameters getParamsWithServiceInformation () {
279327 PageParameters pageParams = new PageParameters ();
280328 // add service to the page parameters
281- pageParams .add (WebConstants .PARAM_SERVICE , editForm .getModelObject ().getDestinationService ());
329+ pageParams .add (
330+ WebConstants .PARAM_SERVICE ,
331+ editForm .getModelObject ().getDestinationService ()
332+ );
282333
283334 return pageParams ;
284335 }
0 commit comments