Project

General

Profile

1
package eu.dnetlib.repo.manager.client.datasources.utils;
2

    
3
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.editor.client.Editor;
5
import com.google.gwt.editor.client.EditorError;
6
import com.google.gwt.event.dom.client.ChangeEvent;
7
import com.google.gwt.event.dom.client.ChangeHandler;
8
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.regexp.shared.RegExp;
11
import com.google.gwt.user.client.rpc.AsyncCallback;
12
import com.google.gwt.user.client.ui.*;
13
import com.google.gwt.user.client.ui.Label;
14
import eu.dnetlib.domain.data.Repository;
15
import eu.dnetlib.gwt.client.MyFormGroup;
16
import eu.dnetlib.repo.manager.client.services.RepositoryService;
17
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
18
import eu.dnetlib.repo.manager.client.widgets.*;
19
import eu.dnetlib.repo.manager.client.widgets.TextArea;
20
import eu.dnetlib.repo.manager.client.widgets.TextBox;
21
import eu.dnetlib.repo.manager.shared.Constants;
22
import eu.dnetlib.repo.manager.shared.DatasourceVocabularies;
23
import org.gwtbootstrap3.client.ui.*;
24
import org.gwtbootstrap3.client.ui.Button;
25
import org.gwtbootstrap3.client.ui.ListBox;
26
import org.gwtbootstrap3.client.ui.constants.AlertType;
27
import org.gwtbootstrap3.client.ui.constants.ButtonType;
28
import org.gwtbootstrap3.client.ui.constants.ValidationState;
29
import org.gwtbootstrap3.client.ui.form.error.BasicEditorError;
30
import org.gwtbootstrap3.client.ui.form.validator.Validator;
31

    
32
import java.util.ArrayList;
33
import java.util.HashMap;
34
import java.util.List;
35
import java.util.Map;
36

    
37
/**
38
 * Created by stefania on 12/21/15.
39
 */
40
public class RepositoryInformationFormWidget implements IsWidget {
41

    
42
    private FlowPanel repositoryInformationPanel = new FlowPanel();
43

    
44
    private Alert errorLabel = new Alert();
45
    private Alert successLabel = new Alert();
46

    
47
    private Form repositoryInformationForm = new Form();
48

    
49
    private HTML basicInfoWarningLabel = new HTML();
50

    
51
    private ListBox typologyListBox = new ListBox();
52
    private MyFormGroup typologyListFormGroup = new MyFormGroup(false, "Software Platform (*)", typologyListBox);
53
    private TextBox typologyTextBox = new TextBox();
54
    private MyFormGroup typologyTextFormGroup = new MyFormGroup(false, null, typologyTextBox);
55
    private TextBox officialName = new TextBox();
56
    private MyFormGroup officialNameFormGroup = new MyFormGroup(false, "Official Name (*)", officialName);
57
    private TextBox issn = new TextBox();
58
    private MyFormGroup issnFormGroup = new MyFormGroup(true, "ISSN (*)", issn);
59
    private TextBox eissn = new TextBox();
60
    private MyFormGroup eissnFormGroup = new MyFormGroup(true, "EISSN", eissn);
61
    private TextBox lissn = new TextBox();
62
    private MyFormGroup lissnFormGroup = new MyFormGroup(true, "LISSN", lissn);
63
    private TextArea description = new TextArea();
64
    private MyFormGroup descriptionFormGroup = new MyFormGroup(false, "Description (*)", description);
65
    private ListBox countryListBox = new ListBox();
66
    private MyFormGroup countryFormGroup = new MyFormGroup(false, "Country (*)", countryListBox);
67
    private TextBox longitude = new TextBox();
68
    private MyFormGroup longitudeFormGroup = new MyFormGroup(true, "Longitude (*)", longitude);
69
    private TextBox latitude = new TextBox();
70
    private MyFormGroup latitudeFormGroup = new MyFormGroup(true, "Latitude (*)", latitude);
71
    private TextBox entryURL = new TextBox();
72
    private MyFormGroup entryURLFormGroup = new MyFormGroup(false, "Entry URL (*)", entryURL);
73
    private TextBox institution = new TextBox();
74
    private MyFormGroup institutionFormGroup = new MyFormGroup(false, "Institution (*)", institution);
75

    
76
    private TextBox englishName = new TextBox();
77
    private MyFormGroup englishNameFormGroup = new MyFormGroup(false, "English Name (*)", englishName);
78
    private TextBox logoURL = new TextBox();
79
    private ListBox timezoneListBox = new ListBox();
80
    private MyFormGroup timezoneFormGroup = new MyFormGroup(false, "Timezone (*)", timezoneListBox);
81
    private ListBox datasourceClassListBox = new ListBox();
82
    private MyFormGroup datasourceClassFormGroup = new MyFormGroup(false, "Datasource Type (*)", datasourceClassListBox);
83

    
84
    private TextBox admin = new TextBox();
85
    private MyFormGroup adminFormGroup = new MyFormGroup(true, "Admin Email (*)", admin);
86

    
87
    private Map<String, Integer> typologyValuesMap = new HashMap<String, Integer>();
88
    private Map<String, Integer> countryValuesMap = new HashMap<String, Integer>();
89
    private Map<String, Integer> timezoneValuesMap = new HashMap<String, Integer>();
90
    private Map<String, Integer> datasourceClassValuesMap = new HashMap<String, Integer>();
91

    
92
    private String mode;
93

    
94
    private Repository repository;
95

    
96
    private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
97

    
98
    public RepositoryInformationFormWidget(String mode, DatasourceVocabularies datasourceVocabularies, boolean isUpdate) {
99

    
100
        this.mode = mode;
101

    
102
        basicInfoWarningLabel.addStyleName("alert alert-warning");
103
        basicInfoWarningLabel.setVisible(false);
104

    
105
        errorLabel.setType(AlertType.DANGER);
106
        errorLabel.setDismissable(false);
107
        errorLabel.setVisible(false);
108

    
109
        successLabel.setType(AlertType.SUCCESS);
110
        successLabel.setDismissable(false);
111
        successLabel.setVisible(false);
112

    
113
        repositoryInformationPanel.add(successLabel);
114
        repositoryInformationPanel.add(errorLabel);
115
        repositoryInformationPanel.add(repositoryInformationForm);
116

    
117
        typologyListBox.addItem("-- none selected --", "noneSelected");
118
        for(int i=1; i<datasourceVocabularies.getTypologies().size(); i++) {
119
            if(datasourceVocabularies.getTypologies().get(i-1).equals("[Other]")) {
120
                typologyListBox.addItem("[Other] (enter name below)", "[Other]");
121
                typologyValuesMap.put("[Other]", i);
122
            } else {
123
                typologyListBox.addItem(datasourceVocabularies.getTypologies().get(i - 1), datasourceVocabularies.getTypologies().get(i - 1));
124
                typologyValuesMap.put(datasourceVocabularies.getTypologies().get(i - 1), i);
125
            }
126
        }
127

    
128
        countryListBox.addItem("-- none selected --", "noneSelected");
129
        int counter1 = 1;
130
        for(String country : datasourceVocabularies.getCountries().keySet()) {
131
            countryListBox.addItem(datasourceVocabularies.getCountries().get(country), country);
132
            countryValuesMap.put(country, counter1);
133
            counter1++;
134
        }
135

    
136
        timezoneListBox.addItem("-- none selected --", "noneSelected");
137
        for(int i=1; i<datasourceVocabularies.getTimezones().size(); i++) {
138
            timezoneListBox.addItem(datasourceVocabularies.getTimezones().get(i-1).name, datasourceVocabularies.getTimezones().get(i-1).offset+"");
139
            timezoneValuesMap.put(datasourceVocabularies.getTimezones().get(i-1).offset+"", i);
140
        }
141

    
142
        datasourceClassListBox.addItem("-- none selected --", "noneSelected");
143
        int counter2 = 1;
144
        for(String datasourceClass : datasourceVocabularies.getDatasourceClasses().keySet()) {
145
            datasourceClassListBox.addItem(datasourceVocabularies.getDatasourceClasses().get(datasourceClass), datasourceClass);
146
            datasourceClassValuesMap.put(datasourceClass, counter2);
147
            counter2++;
148
        }
149

    
150
        typologyTextBox.setVisible(false);
151

    
152

    
153
        Label logoURLComment = new Label("Please make sure that the maximum size of the uploaded image is width=360px, height=240px");
154
        logoURLComment.addStyleName("comment");
155
        logoURLComment.addStyleName("fontItalic");
156

    
157
        HTML basicInfoLabel = new HTML("<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\" uk-scrollspy-class=\"\">Basic information</h4>");
158
        repositoryInformationForm.add(basicInfoLabel);
159
        repositoryInformationForm.add(basicInfoWarningLabel);
160
        repositoryInformationForm.add(typologyListFormGroup);
161
        repositoryInformationForm.add(typologyTextFormGroup);
162
        repositoryInformationForm.add(officialNameFormGroup);
163
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
164
            repositoryInformationForm.add(issnFormGroup);
165
            repositoryInformationForm.add(eissnFormGroup);
166
            repositoryInformationForm.add(lissnFormGroup);
167
        }
168
        repositoryInformationForm.add(descriptionFormGroup);
169
        repositoryInformationForm.add(countryFormGroup);
170
        repositoryInformationForm.add(longitudeFormGroup);
171
        repositoryInformationForm.add(latitudeFormGroup);
172
        repositoryInformationForm.add(entryURLFormGroup);
173
        repositoryInformationForm.add(institutionFormGroup);
174

    
175
        HTML extraInfoLabel = new HTML("<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\" uk-scrollspy-class=\"\">Extra information</h4>");
176
        repositoryInformationForm.add(extraInfoLabel);
177
        repositoryInformationForm.add(englishNameFormGroup);
178
        repositoryInformationForm.add(new MyFormGroup(false, "Logo URL", logoURL, logoURLComment));
179
        repositoryInformationForm.add(timezoneFormGroup);
180
        repositoryInformationForm.add(datasourceClassFormGroup);
181

    
182
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL))
183
            datasourceClassFormGroup.setLabelText("Journal Type (*)");
184
        else if(mode.equals(Constants.REPOSITORY_MODE_AGGREGATOR))
185
            datasourceClassFormGroup.setLabelText("Aggregator Type (*)");
186

    
187
        HTML adminInfoLabel = new HTML("<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\" uk-scrollspy-class=\"\">Administrator & contact information</h4>");
188
        repositoryInformationForm.add(adminInfoLabel);
189
        repositoryInformationForm.add(adminFormGroup);
190

    
191
        if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR) || mode.equals(Constants.REPOSITORY_MODE_RE3DATA)) {
192
            typologyListBox.setEnabled(false);
193
            typologyTextBox.setEnabled(false);
194
            officialName.setEnabled(false);
195
            description.setEnabled(false);
196
            countryListBox.setEnabled(false);
197
            longitude.setEnabled(false);
198
            latitude.setEnabled(false);
199
            entryURL.setEnabled(false);
200
            institution.setEnabled(false);
201
        }
202

    
203
        if(isUpdate) {
204

    
205
            Button updateInfoButton = new Button("Update Information");
206
            updateInfoButton.setType(ButtonType.PRIMARY);
207
            updateInfoButton.addStyleName("updateRepoInfoButton");
208
            updateInfoButton.addClickHandler(new ClickHandler() {
209
                @Override
210
                public void onClick(ClickEvent event) {
211

    
212
                    errorLabel.setVisible(false);
213
                    successLabel.setVisible(false);
214

    
215
                    Repository repositoryToUpdate = getRepository();
216
                    if(repositoryToUpdate!=null) {
217

    
218
                        final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 35%; " +
219
                                "color: rgb(47, 64, 80); font-weight: bold;\">Updating repository information</div>" +
220
                                "<div class=\"whiteFilm\"></div>");
221
                        repositoryInformationPanel.addStyleName("loading-big");
222
                        repositoryInformationPanel.add(loadingWheel);
223

    
224
                        repositoryService.updateRepositoryInformation(repositoryToUpdate, new AsyncCallback<Void>() {
225

    
226
                            @Override
227
                            public void onFailure(Throwable caught) {
228

    
229
                                repositoryInformationPanel.removeStyleName("loading-big");
230
                                repositoryInformationPanel.remove(loadingWheel);
231

    
232
                                errorLabel.setText("System error updating repository information");
233
                                errorLabel.setVisible(true);
234
                            }
235

    
236
                            @Override
237
                            public void onSuccess(Void result) {
238

    
239
                                repositoryInformationPanel.removeStyleName("loading-big");
240
                                repositoryInformationPanel.remove(loadingWheel);
241

    
242
                                successLabel.setText("Repository information updated successfully");
243
                                successLabel.setVisible(true);
244
                            }
245
                        });
246
                    }
247
                }
248
            });
249
            repositoryInformationForm.add(new MyFormGroup(false, null, updateInfoButton));
250
        }
251

    
252
        addValueChangeHandlersToFormFields();
253
        addFieldValidators();
254
    }
255

    
256
    @Override
257
    public Widget asWidget() {
258
        return repositoryInformationPanel;
259
    }
260

    
261
    public void loadRepository(Repository repository) {
262

    
263
        errorLabel.setVisible(false);
264
        successLabel.setVisible(false);
265

    
266
        this.repository = repository;
267

    
268
        if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR)) {
269
            basicInfoWarningLabel.setHTML("The following fields are completed by OpenDOAR.<br>" +
270
                    "If you want to edit them, you can do it by using this <a target=\"_blank\" " +
271
                    "href=\"http://www.opendoar.org/suggest.php?rID=" + repository.getId().split("::")[1] + "\">OpenDOAR link</a>");
272
            basicInfoWarningLabel.setVisible(true);
273
        } else if(mode.equals(Constants.REPOSITORY_MODE_RE3DATA)) {
274
            basicInfoWarningLabel.setHTML("The following fields are completed by Re3data.<br>" +
275
                    "If you want to edit them, you can do it by using this <a target=\"_blank\" " +
276
                    "href=\"http://service.re3data.org/repository/" + repository.getId().split("::")[1] + "\">Re3data link</a>");
277
            basicInfoWarningLabel.setVisible(true);
278
        }
279

    
280
        if (repository.getTypology() != null) {
281
            if(timezoneValuesMap.get(repository.getTypology())!=null)
282
                typologyListBox.setSelectedIndex(typologyValuesMap.get(repository.getTypology()));
283
            else if(typologyValuesMap.containsKey("[Other]")){
284
                typologyListBox.setSelectedIndex(typologyValuesMap.get("[Other]"));
285
                typologyTextBox.setVisible(true);
286
                typologyTextBox.setValue(repository.getTypology());
287
            }
288
        }
289

    
290
        if (repository.getOfficialName() != null)
291
            officialName.setValue(repository.getOfficialName());
292

    
293
        if (mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
294
            if (repository.getIssn() != null)
295
                issn.setValue(repository.getIssn());
296
            if (repository.getEissn() != null)
297
                eissn.setValue(repository.getEissn());
298
            if (repository.getLissn() != null)
299
                lissn.setValue(repository.getLissn());
300
        }
301

    
302
        if (repository.getDescription() != null)
303
            description.setValue(repository.getDescription());
304
        if (repository.getCountryName() != null)
305
            countryListBox.setSelectedIndex(countryValuesMap.get(repository.getCountryName()));
306
        if (repository.getLongitude() != null)
307
            longitude.setValue(repository.getLongitude() + "");
308
        if (repository.getLatitude() != null)
309
            latitude.setValue(repository.getLatitude() + "");
310
        if (repository.getWebsiteUrl() != null)
311
            entryURL.setValue(repository.getWebsiteUrl());
312
        if (repository.getOrganization() != null)
313
            institution.setValue(repository.getOrganization());
314

    
315
        if (repository.getEnglishName() != null)
316
            englishName.setValue(repository.getEnglishName());
317
        if (repository.getLogoUrl() != null)
318
            logoURL.setValue(repository.getLogoUrl());
319
        if(repository.getTimezone()!=null)
320
            timezoneListBox.setSelectedIndex(timezoneValuesMap.get(repository.getTimezone()+""));
321
        if(repository.getDatasourceClass()!=null && datasourceClassValuesMap.containsKey(repository.getDatasourceClass()))
322
            datasourceClassListBox.setSelectedIndex(datasourceClassValuesMap.get(repository.getDatasourceClass()));
323

    
324
        if (repository.getContactEmail() != null)
325
            admin.setValue(repository.getContactEmail());
326
    }
327

    
328
    public Repository getRepository() {
329

    
330
        if(isComplete()) {
331

    
332
            if(repositoryInformationForm.validate()) {
333

    
334
                if (typologyListBox.getSelectedValue().equals("[Other]"))
335
                    repository.setTypology(typologyTextBox.getValue().trim());
336
                else
337
                    repository.setTypology(typologyListBox.getSelectedValue());
338

    
339
                repository.setOfficialName(officialName.getValue().trim());
340

    
341
                if (mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
342
                    repository.setIssn(issn.getValue().trim());
343
                    if (eissn.getValue() != null && !eissn.getValue().trim().isEmpty())
344
                        repository.setEissn(eissn.getValue().trim());
345
                    if (lissn.getValue() != null && !lissn.getValue().trim().isEmpty())
346
                        repository.setLissn(lissn.getValue().trim());
347
                }
348

    
349
                repository.setDescription(description.getValue().trim());
350
                repository.setCountryName(countryListBox.getSelectedValue());
351
                repository.setLongitude(Double.parseDouble(longitude.getValue().trim()));
352
                repository.setLatitude(Double.parseDouble(latitude.getValue().trim()));
353
                repository.setWebsiteUrl(entryURL.getValue().trim());
354
                repository.setOrganization(institution.getValue().trim());
355

    
356
                repository.setEnglishName(englishName.getValue().trim());
357
                repository.setLogoUrl(logoURL.getValue().trim());
358
                repository.setTimezone(Double.parseDouble(timezoneListBox.getSelectedValue()));
359
                repository.setDatasourceClass(datasourceClassListBox.getSelectedValue());
360

    
361
                repository.setContactEmail(admin.getValue());
362

    
363
                return repository;
364
            }
365
        }
366

    
367
        return null;
368
    }
369

    
370
    private boolean isComplete() {
371

    
372
        boolean isComplete = true;
373

    
374
        errorLabel.setVisible(false);
375
        successLabel.setVisible(false);
376

    
377
        if(typologyListBox.getSelectedValue().equals("noneSelected")) {
378
            isComplete = false;
379
            typologyListFormGroup.setFormGroupValidationState(ValidationState.ERROR);
380
        } else if(typologyListBox.getSelectedValue().equals("[Other]")
381
                && (typologyTextBox.getValue()==null || typologyTextBox.getValue().trim().isEmpty())) {
382
            isComplete = false;
383
            typologyTextFormGroup.setFormGroupValidationState(ValidationState.ERROR);
384
        }
385

    
386
        if(officialName.getValue()==null || officialName.getValue().trim().isEmpty()) {
387
            isComplete = false;
388
            officialNameFormGroup.setFormGroupValidationState(ValidationState.ERROR);
389
        }
390

    
391
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL)
392
                && (issn.getValue()==null || issn.getValue().trim().isEmpty())) {
393
            isComplete = false;
394
            issnFormGroup.setFormGroupValidationState(ValidationState.ERROR);
395
        }
396

    
397
        if(description.getValue()==null || description.getValue().trim().isEmpty()) {
398
            isComplete = false;
399
            descriptionFormGroup.setFormGroupValidationState(ValidationState.ERROR);
400
        }
401

    
402
        if(countryListBox.getSelectedValue().equals("noneSelected")) {
403
            isComplete = false;
404
            countryFormGroup.setFormGroupValidationState(ValidationState.ERROR);
405
        }
406

    
407
        if(longitude.getValue()==null || longitude.getValue().trim().isEmpty()) {
408
            isComplete = false;
409
            longitudeFormGroup.setFormGroupValidationState(ValidationState.ERROR);
410
        }
411

    
412
        if(latitude.getValue()==null || latitude.getValue().trim().isEmpty()) {
413
            isComplete = false;
414
            latitudeFormGroup.setFormGroupValidationState(ValidationState.ERROR);
415
        }
416

    
417
        if(entryURL.getValue()==null || entryURL.getValue().trim().isEmpty()) {
418
            isComplete = false;
419
            entryURLFormGroup.setFormGroupValidationState(ValidationState.ERROR);
420
        }
421

    
422
        if(institution.getValue()==null || institution.getValue().trim().isEmpty()) {
423
            isComplete = false;
424
            institutionFormGroup.setFormGroupValidationState(ValidationState.ERROR);
425
        }
426

    
427
        if(englishName.getValue()==null || englishName.getValue().trim().isEmpty()) {
428
            isComplete = false;
429
            englishNameFormGroup.setFormGroupValidationState(ValidationState.ERROR);
430
        }
431

    
432
        if(timezoneListBox.getSelectedValue().equals("noneSelected")) {
433
            isComplete = false;
434
            timezoneFormGroup.setFormGroupValidationState(ValidationState.ERROR);
435
        }
436

    
437
        if(datasourceClassListBox.getSelectedValue().equals("noneSelected")) {
438
            isComplete = false;
439
            datasourceClassFormGroup.setFormGroupValidationState(ValidationState.ERROR);
440
        }
441

    
442
        if(admin.getValue()==null || admin.getValue().trim().isEmpty()) {
443
            isComplete = false;
444
            adminFormGroup.setFormGroupValidationState(ValidationState.ERROR);
445
        }
446

    
447
        if(!isComplete) {
448
            errorLabel.setText("All fields marked with * are mandatory.");
449
            errorLabel.setVisible(true);
450
        }
451

    
452
        return isComplete;
453
    }
454

    
455
    private void addFieldValidators() {
456

    
457
        longitude.addValidator(new Validator<String>() {
458

    
459
            @Override
460
            public int getPriority() {
461
                return 0;
462
            }
463

    
464
            @Override
465
            public List<EditorError> validate(Editor<String> editor, String value) {
466

    
467
                List<EditorError> result = new ArrayList<EditorError>();
468
                String valueStr = value == null ? "" : value.toString();
469

    
470
                RegExp regExp = RegExp.compile(Constants.LONGITUDE_PATTERN);
471
               /* if (!regExp.test(valueStr.trim().toLowerCase())) {
472

    
473
                    longitudeFormGroup.displayInlineError("Invalid longitude");
474
                    result.add(new BasicEditorError(longitude, value, "Invalid longitude"));
475
                    errorLabel.setText("Invalid fields!");
476
                    errorLabel.setVisible(true);
477
                }*/
478

    
479
                return result;
480
            }
481
        });
482

    
483
        latitude.addValidator(new Validator<String>() {
484

    
485
            @Override
486
            public int getPriority() {
487
                return 0;
488
            }
489

    
490
            @Override
491
            public List<EditorError> validate(Editor<String> editor, String value) {
492

    
493
                List<EditorError> result = new ArrayList<EditorError>();
494
                String valueStr = value == null ? "" : value.toString();
495

    
496
                RegExp regExp = RegExp.compile(Constants.LATITUDE_PATTERN);
497
                /*if (!regExp.test(valueStr.trim().toLowerCase())) {
498

    
499
                    latitudeFormGroup.displayInlineError("Invalid latitude");
500
                    result.add(new BasicEditorError(latitude, value, "Invalid latitude"));
501
                    errorLabel.setText("Invalid fields!");
502
                    errorLabel.setVisible(true);
503
                }*/
504

    
505
                return result;
506
            }
507
        });
508

    
509
        admin.addValidator(new Validator<String>() {
510

    
511
            @Override
512
            public int getPriority() {
513
                return 0;
514
            }
515

    
516
            @Override
517
            public List<EditorError> validate(Editor<String> editor, String value) {
518

    
519
                List<EditorError> result = new ArrayList<EditorError>();
520
                String valueStr = value == null ? "" : value.toString();
521

    
522
                RegExp regExp = RegExp.compile(Constants.EMAIL_PATTERN);
523
                if (!regExp.test(valueStr.trim().toLowerCase())) {
524

    
525
                    adminFormGroup.displayInlineError("Invalid email address");
526
                    result.add(new BasicEditorError(admin, value, "Invalid email address"));
527
                    errorLabel.setText("Invalid fields!");
528
                    errorLabel.setVisible(true);
529
                }
530

    
531
                return result;
532
            }
533
        });
534

    
535
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
536

    
537
            issn.addValidator(new Validator<String>() {
538

    
539
                @Override
540
                public int getPriority() {
541
                    return 0;
542
                }
543

    
544
                @Override
545
                public List<EditorError> validate(Editor<String> editor, String value) {
546

    
547
                    List<EditorError> result = new ArrayList<EditorError>();
548
                    String valueStr = value == null ? "" : value.toString();
549

    
550
                    if (valueStr.length()!=8) {
551
                        issnFormGroup.displayInlineError("Issn length has to be 8 characters");
552
                        result.add(new BasicEditorError(issn, value, "Issn length has to be 8 characters"));
553
                        errorLabel.setText("Invalid fields!");
554
                        errorLabel.setVisible(true);
555
                    }
556

    
557
                    return result;
558
                }
559
            });
560

    
561
            eissn.addValidator(new Validator<String>() {
562

    
563
                @Override
564
                public int getPriority() {
565
                    return 0;
566
                }
567

    
568
                @Override
569
                public List<EditorError> validate(Editor<String> editor, String value) {
570

    
571
                    List<EditorError> result = new ArrayList<EditorError>();
572
                    String valueStr = value == null ? "" : value.toString();
573

    
574
                    if (valueStr.length()!=8) {
575
                        eissnFormGroup.displayInlineError("Eissn length has to be 8 characters");
576
                        result.add(new BasicEditorError(eissn, value, "Eissn length has to be 8 characters"));
577
                        errorLabel.setText("Invalid fields!");
578
                        errorLabel.setVisible(true);
579
                    }
580

    
581
                    return result;
582
                }
583
            });
584

    
585
            lissn.addValidator(new Validator<String>() {
586

    
587
                @Override
588
                public int getPriority() {
589
                    return 0;
590
                }
591

    
592
                @Override
593
                public List<EditorError> validate(Editor<String> editor, String value) {
594

    
595
                    List<EditorError> result = new ArrayList<EditorError>();
596
                    String valueStr = value == null ? "" : value.toString();
597

    
598
                    if (valueStr.length()!=8) {
599
                        lissnFormGroup.displayInlineError("Lissn length has to be 8 characters");
600
                        result.add(new BasicEditorError(lissn, value, "Lissn length has to be 8 characters"));
601
                        errorLabel.setText("Invalid fields!");
602
                        errorLabel.setVisible(true);
603
                    }
604

    
605
                    return result;
606
                }
607
            });
608

    
609
        }
610

    
611
    }
612

    
613
    private void addValueChangeHandlersToFormFields() {
614

    
615
        typologyListBox.addChangeHandler(new ChangeHandler() {
616
            @Override
617
            public void onChange(ChangeEvent event) {
618
                typologyListFormGroup.setFormGroupValidationState(ValidationState.NONE);
619
                if(typologyListBox.getSelectedValue().equals("[Other]"))
620
                    typologyTextBox.setVisible(true);
621
                else
622
                    typologyTextBox.setVisible(false);
623
            }
624
        });
625

    
626
        typologyTextBox.setValueChangeHandler(new ValueChangeHandler() {
627
            @Override
628
            public void handle(ValueChangeEvent valueChangeEvent) {
629
                typologyTextFormGroup.setFormGroupValidationState(ValidationState.NONE);
630
            }
631
        });
632

    
633
        officialName.setValueChangeHandler(new ValueChangeHandler() {
634
            @Override
635
            public void handle(ValueChangeEvent valueChangeEvent) {
636
                officialNameFormGroup.setFormGroupValidationState(ValidationState.NONE);
637
            }
638
        });
639

    
640
        issn.setValueChangeHandler(new ValueChangeHandler() {
641
            @Override
642
            public void handle(ValueChangeEvent valueChangeEvent) {
643
                issnFormGroup.setFormGroupValidationState(ValidationState.NONE);
644
            }
645
        });
646

    
647
        eissn.setValueChangeHandler(new ValueChangeHandler() {
648
            @Override
649
            public void handle(ValueChangeEvent valueChangeEvent) {
650
                eissnFormGroup.setFormGroupValidationState(ValidationState.NONE);
651
            }
652
        });
653

    
654
        lissn.setValueChangeHandler(new ValueChangeHandler() {
655
            @Override
656
            public void handle(ValueChangeEvent valueChangeEvent) {
657
                lissnFormGroup.setFormGroupValidationState(ValidationState.NONE);
658
            }
659
        });
660

    
661
        description.setValueChangeHandler(new ValueChangeHandler() {
662
            @Override
663
            public void handle(ValueChangeEvent valueChangeEvent) {
664
                descriptionFormGroup.setFormGroupValidationState(ValidationState.NONE);
665
            }
666
        });
667

    
668
        countryListBox.addChangeHandler(new ChangeHandler() {
669
            @Override
670
            public void onChange(ChangeEvent event) {
671
                countryFormGroup.setFormGroupValidationState(ValidationState.NONE);
672
            }
673
        });
674

    
675
        longitude.setValueChangeHandler(new ValueChangeHandler() {
676
            @Override
677
            public void handle(ValueChangeEvent valueChangeEvent) {
678
                longitudeFormGroup.setFormGroupValidationState(ValidationState.NONE);
679
            }
680
        });
681

    
682
        latitude.setValueChangeHandler(new ValueChangeHandler() {
683
            @Override
684
            public void handle(ValueChangeEvent valueChangeEvent) {
685
                latitudeFormGroup.setFormGroupValidationState(ValidationState.NONE);
686
            }
687
        });
688

    
689
        entryURL.setValueChangeHandler(new ValueChangeHandler() {
690
            @Override
691
            public void handle(ValueChangeEvent valueChangeEvent) {
692
                entryURLFormGroup.setFormGroupValidationState(ValidationState.NONE);
693
            }
694
        });
695

    
696
        institution.setValueChangeHandler(new ValueChangeHandler() {
697
            @Override
698
            public void handle(ValueChangeEvent valueChangeEvent) {
699
                institutionFormGroup.setFormGroupValidationState(ValidationState.NONE);
700
            }
701
        });
702

    
703
        englishName.setValueChangeHandler(new ValueChangeHandler() {
704
            @Override
705
            public void handle(ValueChangeEvent valueChangeEvent) {
706
                englishNameFormGroup.setFormGroupValidationState(ValidationState.NONE);
707
            }
708
        });
709

    
710
        timezoneListBox.addChangeHandler(new ChangeHandler() {
711
            @Override
712
            public void onChange(ChangeEvent event) {
713
                timezoneFormGroup.setFormGroupValidationState(ValidationState.NONE);
714
            }
715
        });
716

    
717
        datasourceClassListBox.addChangeHandler(new ChangeHandler() {
718
            @Override
719
            public void onChange(ChangeEvent event) {
720
                datasourceClassFormGroup.setFormGroupValidationState(ValidationState.NONE);
721
            }
722
        });
723

    
724
        admin.setValueChangeHandler(new ValueChangeHandler() {
725
            @Override
726
            public void handle(ValueChangeEvent valueChangeEvent) {
727
                adminFormGroup.setFormGroupValidationState(ValidationState.NONE);
728
            }
729
        });
730
    }
731
}
(2-2/5)