From: David ‘Bombe’ Roden Date: Tue, 31 Jul 2012 19:05:29 +0000 (+0200) Subject: Add short name to groups. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ca45a291a94957a166d842ff483acf8e80876a60;p=demoscenemusic.git Add short name to groups. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index eb5e1c7..2ad834a 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -673,11 +673,12 @@ public class DataManager { * @throws DatabaseException * if a database error occurs */ - public Group createGroup(String name) throws DatabaseException { + public Group createGroup(String name, String shortName) throws DatabaseException { Query query = new Query(Type.INSERT, "GROUPS"); String id = UUID.randomUUID().toString(); query.addValueField(new ValueField("ID", new StringParameter(id))); query.addValueField(new ValueField("NAME", new StringParameter(name))); + query.addValueField(new ValueField("SHORT_NAME", new StringParameter(shortName))); database.insert(query); return getGroupById(id); } @@ -693,6 +694,7 @@ public class DataManager { public void saveGroup(Group group) throws DatabaseException { Query query = new Query(Type.UPDATE, "GROUPS"); query.addValueField(new ValueField("NAME", new StringParameter(group.getName()))); + query.addValueField(new ValueField("SHORT_NAME", new StringParameter(group.getShortName()))); query.addWhereClause(new ValueFieldWhereClause(new ValueField("ID", new StringParameter(group.getId())))); database.update(query); /* save properties. */ @@ -1134,7 +1136,7 @@ public class DataManager { */ @Override public Group createObject(ResultSet resultSet) throws SQLException { - return new LazyGroup(resultSet.getString("GROUPS.ID")).setName(resultSet.getString("GROUPS.NAME")); + return new LazyGroup(resultSet.getString("GROUPS.ID")).setName(resultSet.getString("GROUPS.NAME")).setShortName(resultSet.getString("GROUPS.SHORT_NAME")); } } diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultGroup.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultGroup.java index 57cbf40..aaa85da 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultGroup.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultGroup.java @@ -72,6 +72,23 @@ public class DefaultGroup extends DefaultBase implements Group { * {@inheritDoc} */ @Override + public String getShortName() { + return getValue("shortName", String.class).get(); + } + + /** + * {@inheritDoc} + */ + @Override + public Group setShortName(String shortName) { + getValue("shortName", String.class).set(shortName); + return this; + } + + /** + * {@inheritDoc} + */ + @Override @SuppressWarnings("unchecked") public Collection getArtists() { return getValue("artists", Collection.class).get(); diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/Group.java b/src/main/java/net/pterodactylus/demoscenemusic/data/Group.java index 9c86181..08ce879 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/Group.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/Group.java @@ -43,6 +43,23 @@ public interface Group extends Base { public Group setName(String name); /** + * Returns the short name of this group. + * + * @return The short name of this group, or {@code null} if this group does + * not have a short name + */ + public String getShortName(); + + /** + * Sets the short name of this group. + * + * @param shortName + * The new short name of this group + * @return This group + */ + public Group setShortName(String shortName); + + /** * Returns all artists belonging to this group. * * @return All artists belonging to this group diff --git a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/AddGroupPage.java b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/AddGroupPage.java index 1fd7d11..55cd521 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/AddGroupPage.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/AddGroupPage.java @@ -61,12 +61,16 @@ public class AddGroupPage extends AdminBasePage { super.processTemplate(templateContext, request); if (request.getMethod() == Method.POST) { String name = request.getServletRequest().getParameter("name").trim(); + String shortName = request.getServletRequest().getParameter("shortName").trim(); if (name.length() == 0) { templateContext.set("error", "no-name-given"); return; } + if (shortName.length() == 0) { + shortName = null; + } try { - Group group = getCore().getDataManager().createGroup(name); + Group group = getCore().getDataManager().createGroup(name, shortName); throw new RedirectException("admin.edit-group?id=" + group.getId()); } catch (DatabaseException de1) { throw new RuntimeException("Could not create group.", de1); diff --git a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditGroupPage.java b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditGroupPage.java index c9e25fc..dcfeb54 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditGroupPage.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditGroupPage.java @@ -67,6 +67,8 @@ public class EditGroupPage extends AdminBasePage { if (request.getMethod() == Method.POST) { String name = request.getServletRequest().getParameter("name"); group.setName(name); + String shortName = request.getServletRequest().getParameter("shortName").trim(); + group.setShortName((shortName.length() == 0) ? null : shortName); /* process property changes. */ processProperties(request, group); diff --git a/src/main/resources/templates/admin.edit-group b/src/main/resources/templates/admin.edit-group index 545526d..3c62c87 100644 --- a/src/main/resources/templates/admin.edit-group +++ b/src/main/resources/templates/admin.edit-group @@ -6,7 +6,14 @@ - +
+ Name: + +
+
+ Short Name: + +
<%foreach group.properties property> diff --git a/src/main/resources/templates/include/admin.add-group b/src/main/resources/templates/include/admin.add-group index f9d439f..a28d785 100644 --- a/src/main/resources/templates/include/admin.add-group +++ b/src/main/resources/templates/include/admin.add-group @@ -3,8 +3,12 @@
Name: -
+
+ Short Name: + +
+