Starting work on extended attributes.

* `Issue` implementation is tentatively complete.
* Started ona direction for implementation with `FileIssue`.
* Revisiting the code for `XmlIssue` to polish it up. The XML code was never
  really finished, but it should be for 3.0.x
This commit is contained in:
Jonathan Bernard 2011-11-03 02:39:36 -05:00
parent faacfd859a
commit 5ff4665a07
3 changed files with 75 additions and 21 deletions

View File

@ -9,8 +9,9 @@ public abstract class Issue {
protected Status status protected Status status
protected int priority protected int priority
protected String text protected String text
protected Date deliveryDate protected String title
protected Date creationDate
protected Map extendedPropeties = [:]
Issue(String id, Category c = Category.TASK, Status s = Status.NEW, Issue(String id, Category c = Category.TASK, Status s = Status.NEW,
int p = 9) { int p = 9) {
@ -18,8 +19,6 @@ public abstract class Issue {
this.category = c this.category = c
this.status = s this.status = s
this.priority = p this.priority = p
this.creationDate = new Date()
this.deliveryDate = null
} }
public String getId() { return id; } public String getId() { return id; }
@ -48,19 +47,18 @@ public abstract class Issue {
priority = Math.min(9, Math.max(0, p)) priority = Math.min(9, Math.max(0, p))
} }
public String getTitle() { return text.readLines()[0] } public String getTitle() { return title }
public String setTitle(String t) throws IOException { title = t }
public String getText() { return text } public String getText() { return text }
public void setText(String t) throws IOException { text = t } public void setText(String t) throws IOException { text = t }
public boolean hasDelivery() { return deliveryDate == null } public def propertyMissing(String name) { extendedProperties[name] }
public Date getCreationDate() { return creationDate } public def propertyMissing(String name, def value) {
extendedProperties[name] = value }
public Date getDeliveryDate() { return deliveryDate }
public void setDeliveryDate(Date dd) { deliveryDate = dd }
@Override @Override
public String toString() { public String toString() {

View File

@ -25,6 +25,7 @@ public class FileIssue extends Issue {
this.source = file this.source = file
super.@text = file.text super.@text = file.text
super.@title = super.@text.readLines()[0]
} }
public void setCategory(Category c) throws IOException { public void setCategory(Category c) throws IOException {
@ -73,15 +74,14 @@ public class FileIssue extends Issue {
return makeFilename(id, category, status, priority) return makeFilename(id, category, status, priority)
} }
public void setText(String text) throws IOException { public void setTitle(String title) throws IOException {
try { source.write(text) } super.setTitle(title)
catch (IOException ioe) { writeFile()
throw new IOException("I could not save the new text for this "
+ "issue. I can not write to the file for this issue. I do not"
+ " know why, I am sorry (maybe the file can not be reached).")
} }
public void setText(String text) throws IOException {
super.setText(text) super.setText(text)
writeFile()
} }
boolean deleteFile() { return source.deleteDir() } boolean deleteFile() { return source.deleteDir() }
@ -107,4 +107,51 @@ public class FileIssue extends Issue {
return id + category.symbol + status.symbol + priority + ".rst"; return id + category.symbol + status.symbol + priority + ".rst";
} }
public static String formatIssue(Issue issue) {
def result = new StringBuilder()
result.append(title)
result.append("\n")
result.append("=".multiply(title.length()))
result.append("\n")
result.append(text)
result.append("\n----\n")
// If there are any extended properties, let's write those.
if (super.@extendedProperties.size() > 0) {
def extOutput = [:]
def maxKeyLen = 0
def maxValLen = 0
// Find the longest key and value, convert all to strings.
super.@extendedProperties.each { key, val ->
def ks = key.toString(), vs = val.toString()
extOutput[ks] = vs
if (ks.length() > maxKeyLen) { maxKeyLen = ks.length() }
if (vs.length() > maxKeyLen) { maxValLen = vs.length() } }
result.append("=".multiply(maxKeyLen + 1))
result.append(" ")
result.append("=".multiply(maxValLen))
result.append("\n")
extOutput.sort().each { key, val ->
result.append(key.padRight(maxKeyLen))
result.append(": ")
result.append(val.padRight(maxValLen))
result.append("\n") }
result.append("=".multiply(maxKeyLen + 1))
result.append(" ")
result.append("=".multiply(maxValLen))
result.append("\n") }}
protected void writeFile() {
try { source.write(formatIssue(this) }
catch (IOException ioe) {
throw new IOException("I could not save the new text for this "
+ "issue. I can not write to the file for this issue. I do not"
+ " know why, I am sorry (maybe the file can not be reached).")
}
}
} }

View File

@ -18,7 +18,8 @@ public class XmlIssue extends Issue {
} }
XmlIssue(String id, Category c = Category.TASK, Status s = Status.NEW, XmlIssue(String id, Category c = Category.TASK, Status s = Status.NEW,
int p = 9, String text, XmlRepository repository, XmlProject project) { int p = 9, String title, String text, XmlRepository repository,
XmlProject project) {
super(id, c, s, p) super(id, c, s, p)
this.project = project this.project = project
@ -26,9 +27,10 @@ public class XmlIssue extends Issue {
// Node constructor adds the node to the parent node // Node constructor adds the node to the parent node
issueNode = new Node(project.projectNode, "Issue", issueNode = new Node(project.projectNode, "Issue",
[id: id, category: c, status: s, priority: p]) [id: id, category: c, status: s, priority: p, title: title])
this.text = text super.@title = title
super.@text = text
issueNode.value = text issueNode.value = text
repository.persist() repository.persist()
@ -62,4 +64,11 @@ public class XmlIssue extends Issue {
repository.persist() repository.persist()
} }
public void setTitle(String t) {
super.setTitle(t)
issueNode.@title = t
repository.persist()
}
} }