Add short name to groups.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 31 Jul 2012 19:05:29 +0000 (21:05 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 31 Jul 2012 19:05:29 +0000 (21:05 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java
src/main/java/net/pterodactylus/demoscenemusic/data/DefaultGroup.java
src/main/java/net/pterodactylus/demoscenemusic/data/Group.java
src/main/java/net/pterodactylus/demoscenemusic/page/admin/AddGroupPage.java
src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditGroupPage.java
src/main/resources/templates/admin.edit-group
src/main/resources/templates/include/admin.add-group

index eb5e1c7..2ad834a 100644 (file)
@@ -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"));
                }
 
        }
index 57cbf40..aaa85da 100644 (file)
@@ -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<Artist> getArtists() {
                return getValue("artists", Collection.class).get();
index 9c86181..08ce879 100644 (file)
@@ -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
index 1fd7d11..55cd521 100644 (file)
@@ -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);
index c9e25fc..dcfeb54 100644 (file)
@@ -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);
index 545526d..3c62c87 100644 (file)
@@ -6,7 +6,14 @@
 
        <input type="hidden" name="id" value="<%group.id|html>"/>
 
-       <label>Name: <input type="text" name="name" value="<% group.name|html>"></label>
+       <div>
+               Name:
+               <input type="text" name="name" value="<% group.name|html>">
+       </div>
+       <div>
+               Short Name:
+               <input type="text" name="shortName" value="<% group.shortName|html>">
+       </div>
        <button type="submit">Edit Group</button>
 
        <%foreach group.properties property>
index f9d439f..a28d785 100644 (file)
@@ -3,8 +3,12 @@
        <div>
                Name:
                <input type="text" name="name" value=""/>
-               <button type="submit">Add Group</button>
        </div>
+       <div>
+               Short Name:
+               <input type="text" name="shortName" value="">
+       </div>
+       <button type="submit">Add Group</button>
 
 </form>