@SuppressWarnings("synthetic-access")
private final ObjectCreator<Style> styleCreator = new StyleCreator();
+ /** The party object creator. */
+ @SuppressWarnings("synthetic-access")
+ private final ObjectCreator<Party> partyCreator = new PartyCreator();
+
/** The {@link User} object creator. */
@SuppressWarnings("synthetic-access")
private final ObjectCreator<User> userCreator = new UserCreator();
}
/**
+ * Returns all tracks that were released at the party with the given ID.
+ *
+ * @param partyId
+ * The ID of the party
+ * @return All tracks that were released at the given party
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public Collection<Track> getTracksByParty(String partyId) throws DatabaseException {
+ Query query = new Query(Type.SELECT, "TRACKS");
+ query.addField(new Field("TRACKS.*"));
+ query.addJoin(new Join(JoinType.INNER, "PARTY_TRACKS", new Field("PARTY_TRACKS.TRACK"), new Field("TRACKS.ID")));
+ query.addWhereClause(new ValueFieldWhereClause(new ValueField("PARTY_TRACKS.PARTY", new StringParameter(partyId))));
+ return loadTrackProperties(database.getMultiple(query, trackCreator));
+ }
+
+ /**
* Loads the properties for the given track.
*
* @param track
}
/**
+ * Returns all parties.
+ *
+ * @return All parties
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public Collection<Party> getAllParties() throws DatabaseException {
+ Query query = new Query(Type.SELECT, "PARTIES");
+ query.addField(new Field("PARTIES.*"));
+ return loadPartyProperties(database.getMultiple(query, partyCreator));
+ }
+
+ /**
* Returns the user with the given name.
*
* @param username
}
/**
+ * {@link Party} implementation that loads additional information only on
+ * demand.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ private class LazyParty extends DefaultParty {
+
+ /**
+ * Creates a new party.
+ *
+ * @param id
+ * The ID of the party
+ */
+ public LazyParty(String id) {
+ super(id);
+ }
+
+ //
+ // PARTY METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<Track> getReleases() {
+ if (!hasValue("releases")) {
+ try {
+ getValue("releases", Collection.class).set(getTracksByParty(getId()));
+ } catch (DatabaseException de1) {
+ throw new RuntimeException("Could not loaded Tracks for Party " + getId() + ".", de1);
+ }
+ }
+ return super.getReleases();
+ }
+
+ }
+
+ /**
+ * {@link ObjectCreator} implementation that can create {@link Party}
+ * objects.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ private class PartyCreator implements ObjectCreator<Party> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Party createObject(ResultSet resultSet) throws SQLException {
+ return new LazyParty(resultSet.getString("PARTIES.ID")).setName(resultSet.getString("PARTIES.NAME"));
+ }
+
+ }
+
+ /**
* {@link User} implementation that retrieves some attributes (such as
* {@link #getOpenIds()}) from the {@link DataManager} on demand.
*
--- /dev/null
+/*
+ * DemosceneMusic - ListPartiesPage.java - Copyright © 2012 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.demoscenemusic.page.admin;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import net.pterodactylus.demoscenemusic.core.Core;
+import net.pterodactylus.demoscenemusic.data.DefaultParty;
+import net.pterodactylus.demoscenemusic.data.Party;
+import net.pterodactylus.demoscenemusic.page.ServletRequest;
+import net.pterodactylus.util.database.DatabaseException;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
+import net.pterodactylus.util.web.RedirectException;
+
+/**
+ * Page that lists all parties.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ListPartiesPage extends AdminBasePage {
+
+ /**
+ * Creates a new “list parties” page.
+ *
+ * @param core
+ * The core
+ * @param templateContextFactory
+ * The template context factory
+ * @param template
+ * The template to render
+ */
+ public ListPartiesPage(Core core, TemplateContextFactory templateContextFactory, Template template) {
+ super(core, templateContextFactory, template, "admin.list-parties");
+ }
+
+ //
+ // BASEPAGE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException {
+ super.processTemplate(templateContext, request);
+ try {
+ List<Party> allParties = new ArrayList<Party>(getCore().getDataManager().getAllParties());
+ Collections.sort(allParties, DefaultParty.NAME_YEAR_COMPARATOR);
+ templateContext.set("parties", allParties);
+ } catch (DatabaseException de1) {
+ throw new RuntimeException("Could not load parties.", de1);
+ }
+ }
+
+}
--- /dev/null
+<%include include/header title=="Manage Parties">
+
+<h1>Manage Parties</h1>
+
+<%foreach parties party>
+ <%first><ul><%/first>
+ <li><% party.name|html> <a href="admin.edit-party?id=<% party.id|html>">edit</a></li>
+ <%last></ul><%/last>
+<%/foreach>
+
+<h2>Add a New Party</h2>
+
+<%include include/admin.add-party>
+
+<%include include/footer>
\ No newline at end of file
admin:
(
<a href="admin.artists">artists</a>
+|
+<a href="admin.list-parties">parties</a>
)
|
<%/if>
<param-name>admin.edit-track</param-name>
<param-value>net.pterodactylus.demoscenemusic.page.admin.EditTrackPage</param-value>
</init-param>
+ <init-param>
+ <param-name>admin.list-parties</param-name>
+ <param-value>net.pterodactylus.demoscenemusic.page.admin.ListPartiesPage</param-value>
+ </init-param>
<load-on-startup>0</load-on-startup>
</servlet>