Commits

Anonymous committed 43dbefa

added export field and description capabilities

Comments (0)

Files changed (7)

   <groupId>org.nrg</groupId>
   <artifactId>DicomEdit</artifactId>
   <packaging>jar</packaging>
-  <version>1.2.0</version>
+  <version>1.3.0</version>
   <name>DicomEdit</name>
   <description>Implementation of a language for modifying DICOM metadata</description>
   <url>http://nrg.wustl.edu</url>

src/main/antlr3/org/nrg/dcm/edit/EditDCMLexer.g

 NEW	:	'new';
 DESCRIBE:	'describe';
 HIDDEN	:	'hidden';
+EXPORT  :	'export';
 
 
 /* predefined identifiers:

src/main/antlr3/org/nrg/dcm/edit/EditDCMParser.g

 description
 	:	DESCRIBE ID STRING -> ^(DESCRIBE ID STRING)
 	|	DESCRIBE ID HIDDEN -> ^(HIDDEN ID)
+	|	EXPORT ID STRING   -> ^(EXPORT ID STRING)
 	;
 	
 term	:	STRING

src/main/antlr3/org/nrg/dcm/edit/EditDCMTreeParser.g

 	|	^(HIDDEN id=ID) {
 			getVariable(id).setIsHidden(true);
 		}
+	|	^(EXPORT id=ID field=STRING) {
+			getVariable(id).setExportField(extractString(field));
+		}
 	;
 	
 echo returns [Echo echo]

src/main/java/org/nrg/dcm/edit/ScriptReferencedVariable.java

 
 
 /**
- * @author Kevin A. Archie <karchie@npg.wustl.edu>
+ * @author Kevin A. Archie <karchie@wustl.edu>
  *
  */
 public final class ScriptReferencedVariable implements Variable {
-	private final Logger logger = LoggerFactory.getLogger(ScriptReferencedVariable.class);
-	private final String name;
-	private String value = null;
-	private Value initValue = null;
-	private boolean isHidden = false;
-	private String description = null;
+    private final Logger logger = LoggerFactory.getLogger(ScriptReferencedVariable.class);
+    private final String name;
+    private String value = null;
+    private Value initValue = null;
+    private boolean isHidden = false;
+    private String description = null;
+    private String exportField = null;
 
-	public ScriptReferencedVariable(final String name) {
-		this.name = name;
-	}
+    public ScriptReferencedVariable(final String name) {
+        this.name = name;
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#getDescription()
-	 */
-	public String getDescription() { return description; }
-	
-	/* (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#getInitialValue()
-	 */
-	public Value getInitialValue() { return initValue; }
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#getDescription()
+     */
+    public String getDescription() { return description; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#getName()
-	 */
-	public String getName() { return name; }
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#getExportField()
+     */
+    public String getExportField() { return exportField; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#getValue()
-	 */
-	public String getValue() { return value; }
+    /* (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#getInitialValue()
+     */
+    public Value getInitialValue() { return initValue; }
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#isHidden()
-	 */
-	public boolean isHidden() { return isHidden; }
+    /* (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#getName()
+     */
+    public String getName() { return name; }
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#setDescription(java.lang.String)
-	 */
-	public void setDescription(final String description) {
-		this.description = description;
-	}
+    /* (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#getValue()
+     */
+    public String getValue() { return value; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#setInitialValue(org.nrg.dcm.edit.Value)
-	 */
-	public void setInitialValue(final Value value)
-	throws MultipleInitializationException {
-		if (null == initValue) {
-			initValue = value;
-		} else {
-			throw new MultipleInitializationException(this, value);
-		}
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#isHidden()
+     */
+    public boolean isHidden() { return isHidden; }
 
-	}
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#setDescription(java.lang.String)
+     */
+    public void setDescription(final String description) {
+        this.description = description;
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#setIsHidden(boolean)
-	 */
-	public void setIsHidden(final boolean isHidden) {
-		this.isHidden = isHidden;
-	}
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#setExportField(java.lang.String)
+     */
+    public void setExportField(final String exportField) {
+        this.exportField = exportField;
+    }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.dcm.edit.Variable#setValue(java.lang.String)
-	 */
-	public void setValue(final String value) {
-		logger.trace("set " + this + " to " + value);
-		this.value = value;
-	}
+    /* (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#setInitialValue(org.nrg.dcm.edit.Value)
+     */
+    public void setInitialValue(final Value value)
+    throws MultipleInitializationException {
+        if (null == initValue) {
+            initValue = value;
+        } else {
+            throw new MultipleInitializationException(this, value);
+        }
 
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see java.lang.Object#equals(java.lang.Object)
-	 */
-	public boolean equals(final Object o) {
-		return o instanceof Variable && name.equals(((Variable)o).getName());
-	}
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#setIsHidden(boolean)
+     */
+    public void setIsHidden(final boolean isHidden) {
+        this.isHidden = isHidden;
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see java.lang.Object#hashCode()
-	 */
-	public int hashCode() { return name.hashCode(); }
+    /* (non-Javadoc)
+     * @see org.nrg.dcm.edit.Variable#setValue(java.lang.String)
+     */
+    public void setValue(final String value) {
+        logger.trace("set {} to {}", this, value);
+        this.value = value;
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see java.lang.Object#toString()
-	 */
-	public String toString() {
-		return new StringBuffer(super.toString()).append(" (").append(name).append(")").toString();
-	}
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(final Object o) {
+        return o instanceof Variable && name.equals(((Variable)o).getName());
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() { return name.hashCode(); }
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return new StringBuffer(super.toString()).append(" (").append(name).append(")").toString();
+    }
 }

src/main/java/org/nrg/dcm/edit/Variable.java

 /**
- * Copyright (c) 2009 Washington University
+ * Copyright (c) 2009,2010 Washington University
  */
 package org.nrg.dcm.edit;
 
 
 /**
- * @author Kevin A. Archie <karchie@npg.wustl.edu>
+ * @author Kevin A. Archie <karchie@wustl.edu>
  *
  */
 public interface Variable {
+    /**
+     * Gets the human-readable description of this variable.
+     * @return description, or null if not set
+     */
 	String getDescription();
+	
+	/**
+	 * Gets the label that will be used for exporting this variable.
+	 * @return export field label, or null if not set
+	 */
+	String getExportField();
+	
+	/**
+	 * Gets the (brief) name of this variable.
+	 * @return
+	 */
+	
     String getName();
+    
+    /**
+     * Gets the initial Value assigned to this variable.
+     * @return initialization Value, or null if not set
+     */
     Value getInitialValue();
+    
+    /**
+     * Gets the concrete value for this variable.
+     * @return value
+     */
     String getValue();
+    
+    /**
+     * Should this variable be hidden in a user interface?
+     * @return true if this variable should be hidden from users
+     */
     boolean isHidden();
+    
+    /**
+     * Sets the human-readable description of this variable.
+     * @param description
+     */
     void setDescription(String description);
+    
+    /**
+     * Sets the label to be used for exporting this variable.
+     * @param field
+     */
+    void setExportField(String field);
+    
+    /**
+     * Sets an initialization Value for this variable
+     * @param value
+     * @throws MultipleInitializationException if an initial value has already been assigned
+     */
     void setInitialValue(Value value) throws MultipleInitializationException;
+    
+    /**
+     * Specifies whether this variable should be hidden in a user interface.
+     * @param isHidden
+     */
     void setIsHidden(boolean isHidden);
+    
+    /**
+     * Sets the concrete value of this variable.
+     * @param value
+     */
     void setValue(String value);
  }

src/test/java/org/nrg/dcm/edit/ScriptApplicatorTest.java

 	
 	private static final String S_USE_REPLACE = "(0008,103e) := replace[(0008,103e), \"_\", \":\"]\n";
 	
+	private static final String S_DESCRIPTION = "describe foo \"Description\"\nbar := foo\n";
+	
+	private static final String S_EXPORT_FIELD = "export foo \"baz:/my/export/path\"\nbar := foo\n";
+
 	private ByteArrayInputStream bytes(final String s) {
 		return new ByteArrayInputStream(s.getBytes());
 	}
 	    assertEquals(1, applicator.getSortedVariables(Arrays.asList(new String[]{"a", "b"})).size());
 	    assertEquals("c", ((Variable)applicator.getSortedVariables(Arrays.asList(new String[]{"a", "b"})).get(0)).getName());
 	}
+	
+	public void testDescription() throws Exception {
+	    final ScriptApplicator applicator = new ScriptApplicator(bytes(S_DESCRIPTION));
+	    final Variable foo = applicator.getVariable("foo");
+	    assertEquals("Description", foo.getDescription());
+	    final Variable bar = applicator.getVariable("bar");
+	    assertNull(bar.getDescription());
+	}
+	
+	public void testExportField() throws Exception {
+        final ScriptApplicator applicator = new ScriptApplicator(bytes(S_EXPORT_FIELD));
+        final Variable foo = applicator.getVariable("foo");
+        assertEquals("baz:/my/export/path", foo.getExportField());
+        final Variable bar = applicator.getVariable("bar");
+        assertNull(bar.getExportField());   
+	}
 }