projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
be1d948
)
Add custom exception for adding duplicate fields
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sun, 15 Mar 2015 10:28:34 +0000
(11:28 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sun, 15 Mar 2015 10:28:34 +0000
(11:28 +0100)
src/main/java/net/pterodactylus/sone/core/SoneParser.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/Profile.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/core/SoneParser.java
b/src/main/java/net/pterodactylus/sone/core/SoneParser.java
index
5851b18
..
e234965
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/SoneParser.java
+++ b/
src/main/java/net/pterodactylus/sone/core/SoneParser.java
@@
-20,6
+20,7
@@
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.DuplicateField;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
@@
-150,8
+151,8
@@
public class SoneParser {
}
try {
profile.addField(fieldName.trim()).setValue(fieldValue);
}
try {
profile.addField(fieldName.trim()).setValue(fieldValue);
- } catch (
IllegalArgumentException iae
1) {
- logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName),
iae
1);
+ } catch (
DuplicateField df
1) {
+ logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName),
df
1);
return null;
}
}
return null;
}
}
diff --git
a/src/main/java/net/pterodactylus/sone/data/Profile.java
b/src/main/java/net/pterodactylus/sone/data/Profile.java
index
4bf26cc
..
1f80248
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Profile.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Profile.java
@@
-326,7
+326,9
@@
public class Profile implements Fingerprintable {
public Field addField(String fieldName) throws IllegalArgumentException {
checkNotNull(fieldName, "fieldName must not be null");
checkArgument(fieldName.length() > 0, "fieldName must not be empty");
public Field addField(String fieldName) throws IllegalArgumentException {
checkNotNull(fieldName, "fieldName must not be null");
checkArgument(fieldName.length() > 0, "fieldName must not be empty");
- checkArgument(getFieldByName(fieldName) == null, "fieldName must be unique");
+ if (getFieldByName(fieldName) != null) {
+ throw new DuplicateField();
+ }
@SuppressWarnings("synthetic-access")
Field field = new Field().setName(fieldName);
fields.add(field);
@SuppressWarnings("synthetic-access")
Field field = new Field().setName(fieldName);
fields.add(field);
@@
-553,4
+555,11
@@
public class Profile implements Fingerprintable {
}
}
+ /**
+ * Exception that signals the addition of a field that already exists.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ public static class DuplicateField extends IllegalArgumentException { }
+
}
}
diff --git
a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
index
39c2561
..
d7d729f
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
@@
-23,6
+23,7
@@
import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
import java.util.List;
import net.pterodactylus.sone.data.Profile;
import java.util.List;
import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.DuplicateField;
import net.pterodactylus.sone.data.Profile.Field;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.data.Profile.Field;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.FreenetRequest;
@@
-101,7
+102,7
@@
public class EditProfilePage extends SoneTemplatePage {
fields = profile.getFields();
webInterface.getCore().touchConfiguration();
throw new RedirectException("editProfile.html#profile-fields");
fields = profile.getFields();
webInterface.getCore().touchConfiguration();
throw new RedirectException("editProfile.html#profile-fields");
- } catch (
IllegalArgumentException iae
1) {
+ } catch (
DuplicateField df
1) {
templateContext.set("fieldName", fieldName);
templateContext.set("duplicateFieldName", true);
}
templateContext.set("fieldName", fieldName);
templateContext.set("duplicateFieldName", true);
}