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:
parent
faacfd859a
commit
5ff4665a07
@ -9,8 +9,9 @@ public abstract class Issue {
|
||||
protected Status status
|
||||
protected int priority
|
||||
protected String text
|
||||
protected Date deliveryDate
|
||||
protected Date creationDate
|
||||
protected String title
|
||||
|
||||
protected Map extendedPropeties = [:]
|
||||
|
||||
Issue(String id, Category c = Category.TASK, Status s = Status.NEW,
|
||||
int p = 9) {
|
||||
@ -18,8 +19,6 @@ public abstract class Issue {
|
||||
this.category = c
|
||||
this.status = s
|
||||
this.priority = p
|
||||
this.creationDate = new Date()
|
||||
this.deliveryDate = null
|
||||
}
|
||||
|
||||
public String getId() { return id; }
|
||||
@ -48,19 +47,18 @@ public abstract class Issue {
|
||||
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 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 Date getDeliveryDate() { return deliveryDate }
|
||||
|
||||
public void setDeliveryDate(Date dd) { deliveryDate = dd }
|
||||
public def propertyMissing(String name, def value) {
|
||||
extendedProperties[name] = value }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -25,6 +25,7 @@ public class FileIssue extends Issue {
|
||||
this.source = file
|
||||
|
||||
super.@text = file.text
|
||||
super.@title = super.@text.readLines()[0]
|
||||
}
|
||||
|
||||
public void setCategory(Category c) throws IOException {
|
||||
@ -73,15 +74,14 @@ public class FileIssue extends Issue {
|
||||
return makeFilename(id, category, status, priority)
|
||||
}
|
||||
|
||||
public void setText(String text) throws IOException {
|
||||
try { source.write(text) }
|
||||
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).")
|
||||
public void setTitle(String title) throws IOException {
|
||||
super.setTitle(title)
|
||||
writeFile()
|
||||
}
|
||||
|
||||
public void setText(String text) throws IOException {
|
||||
super.setText(text)
|
||||
writeFile()
|
||||
}
|
||||
|
||||
boolean deleteFile() { return source.deleteDir() }
|
||||
@ -107,4 +107,51 @@ public class FileIssue extends Issue {
|
||||
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).")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ public class XmlIssue extends Issue {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
this.project = project
|
||||
@ -26,9 +27,10 @@ public class XmlIssue extends Issue {
|
||||
|
||||
// Node constructor adds the node to the parent node
|
||||
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
|
||||
|
||||
repository.persist()
|
||||
@ -62,4 +64,11 @@ public class XmlIssue extends Issue {
|
||||
repository.persist()
|
||||
}
|
||||
|
||||
public void setTitle(String t) {
|
||||
super.setTitle(t)
|
||||
|
||||
issueNode.@title = t
|
||||
repository.persist()
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user