source: ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/DescriptionValidator.java @ 1633

Last change on this file since 1633 was 1633, checked in by jeafer, 13 years ago

Jean-Charles branch commit2,
Changes regarding comment on the ComponentRegistry service.
Delete_comment from RestService? to Database access (CommentsDao?) implemented.
Post_comment from RestService? to Database access (CommentsDao?) implemented. (Not yet tested)
Comment class updated
TestComment? class updated
DataBase? : Table comment updated, Corrections of fkey references
Validate classes implemented to validate comment

File size: 1003 bytes
Line 
1package clarin.cmdi.componentregistry.rest;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.apache.commons.lang.StringUtils;
7
8import clarin.cmdi.componentregistry.model.AbstractDescription;
9
10public class DescriptionValidator implements Validator {
11
12    private final AbstractDescription desc;
13    private List<String> errorMessages = new ArrayList<String>();
14
15    public DescriptionValidator(AbstractDescription desc) {
16        this.desc = desc;
17    }
18   
19    public List<String> getErrorMessages() {
20        return errorMessages;
21    }
22
23    public boolean validate() {
24        if (!isOk(desc.getCreatorName(), desc.getDescription(), desc.getName())) {
25            errorMessages.add("Fields are not filled in correctly");
26        }
27        return errorMessages.isEmpty();
28    }
29   
30    private boolean isOk(String... fields) {
31        boolean isOk = true;
32        for (String field : fields) {
33            isOk &= StringUtils.isNotBlank(field);
34        }
35        return isOk;
36    }
37
38}
Note: See TracBrowser for help on using the repository browser.