diff src/nabble/model/Node.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children 72765b66e2c3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/nabble/model/Node.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,196 @@
+package nabble.model;
+
+import fschmidt.db.DbObject;
+import fschmidt.db.LongKey;
+import fschmidt.util.java.Filter;
+import nabble.model.export.NodeData;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Map;
+
+
+// for both posts and apps
+public interface Node extends Message.Source, DbObject<LongKey,NodeImpl> {
+	public long getId();
+	public Person getOwner();
+	public void setOwner(User user);
+	public Node getParent();
+	public void changeParent(Node parent) throws ModelException;
+	public Site getSite();
+	public boolean isRoot();
+	public NodeIterator<? extends Node> getChildren();
+	public NodeIterator<? extends Node> getChildren(String cnd);
+	public int getChildCount();
+	public MailingList getMailingList();
+	public MailingList getAssociatedMailingList();  // only returns MailingList if not isUIHidden
+	public Kind getKind();
+	public NodeIterator<? extends Node> getAncestors();  // starting with self
+	public NodeIterator<? extends Node> getDescendants();
+	public NodeIterator<? extends Node> getDescendantApps();
+	public int getDescendantCount();
+	public int getDescendantAppCount();
+	public int getDescendantPostCount();
+	public NodeIterator<? extends Node> getPostsByDate(Filter<Node> filter);
+	public NodeIterator<? extends Node> getPostsByDateAscending(Filter<Node> filter);
+	public NodeIterator<? extends Node> getTopicsByLastNodeDate(String cnd,Filter<Node> filter);
+	public NodeIterator<? extends Node> getTopicsBySubject(String cnd,Filter<Node> filter);
+	public NodeIterator<? extends Node> getTopicsByPinnedAndLastNodeDate(String cnd,Filter<Node> filter);
+	public NodeIterator<? extends Node> getTopicsByPinnedAndRootNodeDate(String cnd,Filter<Node> filter);
+	public NodeIterator<? extends Node> getTopicsByPopularity(String cnd,Filter<Node> filter);
+	public int getTopicCount(String cnd,Filter<Node> filter);
+	public Node getLastNode();
+	public Date getLastNodeDate();
+	public MailToList getMailToList();
+	public MailFromList getMailFromList();
+	public String getSubject();
+	public void setSubject(String subject) throws ModelException.RequiredSubject;
+	public String getSubjectHtml();
+	public Message getMessage();
+	public void setMessage(String message,Message.Format msgFmt);
+	public void deleteMessageOrNode();
+	public void deleteRecursively();
+	public Date getWhenCreated();
+	public void setWhenCreated(Date whenCreated);
+	public Date getWhenUpdated();
+	public Node getGoodCopy();
+	public Node getApp();
+	public Node getTopic();
+	public void update();
+	public void insert(boolean isDoneByOwner) throws ModelException.TooManyPosts;
+	public boolean isInDb();
+	public Collection<Subscription> getSubscriptions(int i, int n);
+	public int getSubscriptionCount();
+	public Map<User,Subscription> getSubscribersToNotify();
+	public String getType();
+	public void setType(String type);
+	public boolean isPinned();
+	public void pin(Node[] children);
+	public long getExportedNodeId();
+	public void setExportedNodeId(long id);
+	public NodeData getData();
+	public void export(String permalink,String email);
+	public String getEmbeddingUrl();
+	public void setEmbeddingUrl(String url);
+	public Map<ExtensionFactory<Node, ?>, Object> getExtensionMap();
+
+	public boolean hasPreviousTopic();
+	public Node getPreviousTopic();
+	public boolean hasNextTopic();
+	public Node getNextTopic();
+
+	public boolean hasChildApps();
+	public boolean hasChildTopics();
+	public boolean hasPinnedApps();
+	public boolean hasPinnedTopics();
+	public NodeIterator<? extends Node> getChildApps();
+	public NodeIterator<? extends Node> getChildApps(String cnd);
+	public MailingList newMailingList(ListServer listServer,String listAddress,String url) throws ModelException;
+	public void deleteMailingList();
+
+	public interface MailToList {
+		public Node getNode();
+		public boolean isPending();
+		public void clearPending();
+		public Date getWhenSent();
+		public String getOrGenerateMessageID();
+	}
+
+	public interface MailFromList {
+		public boolean hasGuessedParent();
+		public String getMessageID();
+		public MailFromList getParentMailFromList();
+	}
+
+	public enum Kind { APP, POST }
+
+	public static final class Type {
+		// apps
+		public static final String FORUM = "forum";
+		public static final String MIXED = "mixed";
+		public static final String BOARD = "board";
+		public static final String CATEGORY = "category";
+		public static final String NEWS = "news";
+		public static final String GALLERY = "gallery";
+		public static final String BLOG = "blog";
+
+		// posts
+		public static final String BLOG_ENTRY = "blog_entry";
+		public static final String GALLERY_ENTRY = "gallery_entry";
+		public static final String NEWS_ENTRY = "news_entry";
+		public static final String COMMENT = "comment";
+	}
+
+
+	public Comparator<Node> dateComparator = new Comparator<Node>(){
+		public int compare(Node n1,Node n2) {
+			return n1.getWhenCreated().compareTo(n2.getWhenCreated());
+		}
+	};
+
+	public Comparator<Node> subjectComparator = new Comparator<Node>(){
+		public int compare(Node o1,Node o2) {
+			NodeImpl n1 = (NodeImpl)o1;
+			NodeImpl n2 = (NodeImpl)o2;
+			return n1.getCollationKey().compareTo(n2.getCollationKey());
+		}
+	};
+
+	public <T> T getExtension(ExtensionFactory<Node,T> factory);
+
+	public String getProperty(String key);
+	public void setProperty(String key,String value);
+
+	public interface Order {
+		public String sqlOrder();
+		public Comparable getComparable(Node node);
+		public Comparable getPostComparable(Node node);
+
+		public abstract class BasicOrder implements Order {
+			public Comparable getPostComparable(Node node) {
+				return getComparable(node);
+			}
+		}
+
+		public static final Order BY_LAST_NODE_DATE_DESC = new BasicOrder() {
+			public String sqlOrder() {
+				return "last_node_date desc, node_id desc";
+			}
+			public Comparable getComparable(Node node) {
+				return -node.getLastNodeDate().getTime();
+			}
+		};
+
+		public static final Order BY_WHEN_CREATED = new BasicOrder() {
+			public String sqlOrder() {
+				return "when_created, node_id";
+			}
+			public Comparable getComparable(Node node) {
+				return node.getWhenCreated();
+			}
+		};
+
+		public static final Order BY_SUBJECT = new BasicOrder() {
+			public String sqlOrder() {
+				return "is_app, lower(subject), node_id";
+			}
+			public Comparable getComparable(Node node) {
+				return node.getKind()==Kind.APP ? "" : node.getSubject().toLowerCase();
+			}
+		};
+
+		public static final Order BY_DATE_DESC = new Order() {
+			public String sqlOrder() {
+				return "last_node_date desc, node_id desc";
+			}
+			public Comparable getComparable(Node node) {
+				return -node.getLastNodeDate().getTime();
+			}
+			public Comparable getPostComparable(Node node) {
+				return -node.getWhenCreated().getTime();
+			}
+		};
+
+	}
+}