Mercurial Hosting > nabble
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| -1:000000000000 | 0:7ecd1a4ef557 | 
|---|---|
| 1 package nabble.model; | |
| 2 | |
| 3 import fschmidt.db.DbObject; | |
| 4 import fschmidt.db.LongKey; | |
| 5 import fschmidt.util.java.Filter; | |
| 6 import nabble.model.export.NodeData; | |
| 7 | |
| 8 import java.util.Collection; | |
| 9 import java.util.Comparator; | |
| 10 import java.util.Date; | |
| 11 import java.util.Map; | |
| 12 | |
| 13 | |
| 14 // for both posts and apps | |
| 15 public interface Node extends Message.Source, DbObject<LongKey,NodeImpl> { | |
| 16 public long getId(); | |
| 17 public Person getOwner(); | |
| 18 public void setOwner(User user); | |
| 19 public Node getParent(); | |
| 20 public void changeParent(Node parent) throws ModelException; | |
| 21 public Site getSite(); | |
| 22 public boolean isRoot(); | |
| 23 public NodeIterator<? extends Node> getChildren(); | |
| 24 public NodeIterator<? extends Node> getChildren(String cnd); | |
| 25 public int getChildCount(); | |
| 26 public MailingList getMailingList(); | |
| 27 public MailingList getAssociatedMailingList(); // only returns MailingList if not isUIHidden | |
| 28 public Kind getKind(); | |
| 29 public NodeIterator<? extends Node> getAncestors(); // starting with self | |
| 30 public NodeIterator<? extends Node> getDescendants(); | |
| 31 public NodeIterator<? extends Node> getDescendantApps(); | |
| 32 public int getDescendantCount(); | |
| 33 public int getDescendantAppCount(); | |
| 34 public int getDescendantPostCount(); | |
| 35 public NodeIterator<? extends Node> getPostsByDate(Filter<Node> filter); | |
| 36 public NodeIterator<? extends Node> getPostsByDateAscending(Filter<Node> filter); | |
| 37 public NodeIterator<? extends Node> getTopicsByLastNodeDate(String cnd,Filter<Node> filter); | |
| 38 public NodeIterator<? extends Node> getTopicsBySubject(String cnd,Filter<Node> filter); | |
| 39 public NodeIterator<? extends Node> getTopicsByPinnedAndLastNodeDate(String cnd,Filter<Node> filter); | |
| 40 public NodeIterator<? extends Node> getTopicsByPinnedAndRootNodeDate(String cnd,Filter<Node> filter); | |
| 41 public NodeIterator<? extends Node> getTopicsByPopularity(String cnd,Filter<Node> filter); | |
| 42 public int getTopicCount(String cnd,Filter<Node> filter); | |
| 43 public Node getLastNode(); | |
| 44 public Date getLastNodeDate(); | |
| 45 public MailToList getMailToList(); | |
| 46 public MailFromList getMailFromList(); | |
| 47 public String getSubject(); | |
| 48 public void setSubject(String subject) throws ModelException.RequiredSubject; | |
| 49 public String getSubjectHtml(); | |
| 50 public Message getMessage(); | |
| 51 public void setMessage(String message,Message.Format msgFmt); | |
| 52 public void deleteMessageOrNode(); | |
| 53 public void deleteRecursively(); | |
| 54 public Date getWhenCreated(); | |
| 55 public void setWhenCreated(Date whenCreated); | |
| 56 public Date getWhenUpdated(); | |
| 57 public Node getGoodCopy(); | |
| 58 public Node getApp(); | |
| 59 public Node getTopic(); | |
| 60 public void update(); | |
| 61 public void insert(boolean isDoneByOwner) throws ModelException.TooManyPosts; | |
| 62 public boolean isInDb(); | |
| 63 public Collection<Subscription> getSubscriptions(int i, int n); | |
| 64 public int getSubscriptionCount(); | |
| 65 public Map<User,Subscription> getSubscribersToNotify(); | |
| 66 public String getType(); | |
| 67 public void setType(String type); | |
| 68 public boolean isPinned(); | |
| 69 public void pin(Node[] children); | |
| 70 public long getExportedNodeId(); | |
| 71 public void setExportedNodeId(long id); | |
| 72 public NodeData getData(); | |
| 73 public void export(String permalink,String email); | |
| 74 public String getEmbeddingUrl(); | |
| 75 public void setEmbeddingUrl(String url); | |
| 76 public Map<ExtensionFactory<Node, ?>, Object> getExtensionMap(); | |
| 77 | |
| 78 public boolean hasPreviousTopic(); | |
| 79 public Node getPreviousTopic(); | |
| 80 public boolean hasNextTopic(); | |
| 81 public Node getNextTopic(); | |
| 82 | |
| 83 public boolean hasChildApps(); | |
| 84 public boolean hasChildTopics(); | |
| 85 public boolean hasPinnedApps(); | |
| 86 public boolean hasPinnedTopics(); | |
| 87 public NodeIterator<? extends Node> getChildApps(); | |
| 88 public NodeIterator<? extends Node> getChildApps(String cnd); | |
| 89 public MailingList newMailingList(ListServer listServer,String listAddress,String url) throws ModelException; | |
| 90 public void deleteMailingList(); | |
| 91 | |
| 92 public interface MailToList { | |
| 93 public Node getNode(); | |
| 94 public boolean isPending(); | |
| 95 public void clearPending(); | |
| 96 public Date getWhenSent(); | |
| 97 public String getOrGenerateMessageID(); | |
| 98 } | |
| 99 | |
| 100 public interface MailFromList { | |
| 101 public boolean hasGuessedParent(); | |
| 102 public String getMessageID(); | |
| 103 public MailFromList getParentMailFromList(); | |
| 104 } | |
| 105 | |
| 106 public enum Kind { APP, POST } | |
| 107 | |
| 108 public static final class Type { | |
| 109 // apps | |
| 110 public static final String FORUM = "forum"; | |
| 111 public static final String MIXED = "mixed"; | |
| 112 public static final String BOARD = "board"; | |
| 113 public static final String CATEGORY = "category"; | |
| 114 public static final String NEWS = "news"; | |
| 115 public static final String GALLERY = "gallery"; | |
| 116 public static final String BLOG = "blog"; | |
| 117 | |
| 118 // posts | |
| 119 public static final String BLOG_ENTRY = "blog_entry"; | |
| 120 public static final String GALLERY_ENTRY = "gallery_entry"; | |
| 121 public static final String NEWS_ENTRY = "news_entry"; | |
| 122 public static final String COMMENT = "comment"; | |
| 123 } | |
| 124 | |
| 125 | |
| 126 public Comparator<Node> dateComparator = new Comparator<Node>(){ | |
| 127 public int compare(Node n1,Node n2) { | |
| 128 return n1.getWhenCreated().compareTo(n2.getWhenCreated()); | |
| 129 } | |
| 130 }; | |
| 131 | |
| 132 public Comparator<Node> subjectComparator = new Comparator<Node>(){ | |
| 133 public int compare(Node o1,Node o2) { | |
| 134 NodeImpl n1 = (NodeImpl)o1; | |
| 135 NodeImpl n2 = (NodeImpl)o2; | |
| 136 return n1.getCollationKey().compareTo(n2.getCollationKey()); | |
| 137 } | |
| 138 }; | |
| 139 | |
| 140 public <T> T getExtension(ExtensionFactory<Node,T> factory); | |
| 141 | |
| 142 public String getProperty(String key); | |
| 143 public void setProperty(String key,String value); | |
| 144 | |
| 145 public interface Order { | |
| 146 public String sqlOrder(); | |
| 147 public Comparable getComparable(Node node); | |
| 148 public Comparable getPostComparable(Node node); | |
| 149 | |
| 150 public abstract class BasicOrder implements Order { | |
| 151 public Comparable getPostComparable(Node node) { | |
| 152 return getComparable(node); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 public static final Order BY_LAST_NODE_DATE_DESC = new BasicOrder() { | |
| 157 public String sqlOrder() { | |
| 158 return "last_node_date desc, node_id desc"; | |
| 159 } | |
| 160 public Comparable getComparable(Node node) { | |
| 161 return -node.getLastNodeDate().getTime(); | |
| 162 } | |
| 163 }; | |
| 164 | |
| 165 public static final Order BY_WHEN_CREATED = new BasicOrder() { | |
| 166 public String sqlOrder() { | |
| 167 return "when_created, node_id"; | |
| 168 } | |
| 169 public Comparable getComparable(Node node) { | |
| 170 return node.getWhenCreated(); | |
| 171 } | |
| 172 }; | |
| 173 | |
| 174 public static final Order BY_SUBJECT = new BasicOrder() { | |
| 175 public String sqlOrder() { | |
| 176 return "is_app, lower(subject), node_id"; | |
| 177 } | |
| 178 public Comparable getComparable(Node node) { | |
| 179 return node.getKind()==Kind.APP ? "" : node.getSubject().toLowerCase(); | |
| 180 } | |
| 181 }; | |
| 182 | |
| 183 public static final Order BY_DATE_DESC = new Order() { | |
| 184 public String sqlOrder() { | |
| 185 return "last_node_date desc, node_id desc"; | |
| 186 } | |
| 187 public Comparable getComparable(Node node) { | |
| 188 return -node.getLastNodeDate().getTime(); | |
| 189 } | |
| 190 public Comparable getPostComparable(Node node) { | |
| 191 return -node.getWhenCreated().getTime(); | |
| 192 } | |
| 193 }; | |
| 194 | |
| 195 } | |
| 196 } | 
