mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
label validator finished
This commit is contained in:
parent
b19ac2c4c3
commit
72a46367d6
@ -14,4 +14,6 @@ public interface LabelManager {
|
||||
|
||||
@NotNull
|
||||
List<Label> getAllLabels(@NotNull final User user);
|
||||
@Nullable
|
||||
Label getLabelByTitle(@NotNull final String title, @NotNull final User user);
|
||||
}
|
||||
|
@ -25,4 +25,14 @@ public class LabelManagerImpl extends HibernateDaoSupport
|
||||
public List<Label> getAllLabels(@NotNull final User user) {
|
||||
return getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where creator_id=?", user.getId());
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
|
||||
Label result = null;
|
||||
final List<Label> labels = getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where title=? and creator=?", new Object[]{title, user});
|
||||
if (labels != null && !labels.isEmpty()) {
|
||||
result = labels.get(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.wisemapping.model;
|
||||
public class Constants {
|
||||
|
||||
public static final int MAX_MAP_NAME_LENGTH = 512;
|
||||
public static final int MAX_LABEL_NAME_LENGTH = 30;
|
||||
public static final int MAX_MAP_DESCRIPTION_LENGTH = 512;
|
||||
public static final int MAX_USER_LASTNAME_LENGTH = 255;
|
||||
public static final int MAX_USER_FIRSTNAME_LENGTH = 255;
|
||||
|
@ -12,4 +12,5 @@ public interface LabelService {
|
||||
void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException;
|
||||
|
||||
@NotNull List<Label> getAll(@NotNull final User user);
|
||||
public Label getLabelByTitle(@NotNull String title, @NotNull final User user);
|
||||
}
|
||||
|
@ -29,4 +29,9 @@ public class LabelServiceImpl implements LabelService {
|
||||
return labelManager.getAllLabels(user);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
|
||||
return labelManager.getLabelByTitle(title, user);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.wisemapping.validator;
|
||||
|
||||
import com.wisemapping.model.Constants;
|
||||
import com.wisemapping.model.Label;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.service.LabelService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.validation.Errors;
|
||||
@ -8,6 +11,13 @@ import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
public class LabelValidator implements Validator {
|
||||
|
||||
private final LabelService service;
|
||||
|
||||
public LabelValidator(@NotNull final LabelService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return clazz.equals(Label.class);
|
||||
@ -26,7 +36,18 @@ public class LabelValidator implements Validator {
|
||||
|
||||
private void validateLabel(@NotNull final Label label, @NotNull final Errors errors) {
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", Messages.FIELD_REQUIRED);
|
||||
String title = label.getTitle();
|
||||
//todo hacer otras validaciones como si supera el maximo o el label existe
|
||||
final String title = label.getTitle();
|
||||
ValidatorUtils.rejectIfExceeded(
|
||||
errors,
|
||||
"title",
|
||||
"The description must have less than " + Constants.MAX_LABEL_NAME_LENGTH + " characters.",
|
||||
title,
|
||||
Constants.MAX_LABEL_NAME_LENGTH);
|
||||
final User user = com.wisemapping.security.Utils.getUser();
|
||||
assert user != null;
|
||||
final Label foundLabel = service.getLabelByTitle(title, user);
|
||||
if (foundLabel != null) {
|
||||
errors.rejectValue("title", Messages.LABEL_TITLE_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public interface Messages {
|
||||
String FIELD_REQUIRED = "FIELD_REQUIRED";
|
||||
String IMPORT_MAP_ERROR = "IMPORT_MAP_ERROR";
|
||||
String MAP_TITLE_ALREADY_EXISTS = "MAP_TITLE_ALREADY_EXISTS";
|
||||
String LABEL_TITLE_ALREADY_EXISTS = "LABEL_TITLE_ALREADY_EXISTS";
|
||||
String PASSWORD_MISSMATCH = "PASSWORD_MISSMATCH";
|
||||
String CAPTCHA_ERROR = "CAPTCHA_ERROR";
|
||||
String CAPTCHA_LOADING_ERROR = "CAPTCHA_LOADING_ERROR";
|
||||
|
@ -105,6 +105,7 @@ IMPORT_MINDMAP_INFO=You can import FreeMind 0.9 and WiseMapping maps to your lis
|
||||
PRINT=Print
|
||||
IMPORT_MAP_ERROR=FreeMind file could not be imported. {0}
|
||||
MAP_TITLE_ALREADY_EXISTS=You have already a map with the same name
|
||||
LABEL_TITLE_ALREADY_EXISTS=You have already a label with the same name
|
||||
#####FOOTER
|
||||
COPYRIGHT=Powered by WiseMapping
|
||||
TERMS_AND_CONDITIONS=Terms and Conditions
|
||||
|
Loading…
Reference in New Issue
Block a user