Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
augustearth committed Mar 27, 2023
1 parent fe237d8 commit 5391338
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 51 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ task allGroovydoc(type: Groovydoc, group: "Documentation") {
source subprojects.collect { it.sourceSets.main.allGroovy }
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/groovydoc")
overviewText = resources.text.fromFile("groovydoc-header.html")
windowTitle = "Carnival API"
docTitle "Carnival API"
}

task localPublishGroovydoc(type: Copy, group: "Documentation") {
Expand Down
62 changes: 52 additions & 10 deletions app/carnival-util/src/main/groovy/carnival/util/CoreUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import carnival.util.StringUtils
class CoreUtil {


/** */
/**
* Return a unique fingerprint computed from the provided map of args.
* @param args Map of arguments
* @return A unique fingerprint as a string
*/
static public String argumentsUniquifier(Map args) {
assert args != null

Expand All @@ -21,14 +25,24 @@ class CoreUtil {
}


/** */
/**
* Return a string representation of the provided object tagged with the
* type of the object; Null provided objects are accepted.
* @param v The source object
* @return The string representation
*/
static String nullSafeTypedString(Object v) {
if (v == null) return String.valueOf(v)
else return typedString(v)
}


/** */
/**
* Return a string representation of the provided object tagged with the
* type of the object.
* @param v The source object
* @return The string representation
*/
static String typedString(Object v) {
assert v != null

Expand All @@ -45,7 +59,11 @@ class CoreUtil {
}


/** */
/**
* Return a string representation of the provided object map.
* @param v The source map
* @return The string representation
*/
static String typedStringMap(Map map) {
assert map != null

Expand All @@ -62,7 +80,11 @@ class CoreUtil {
}


/** */
/**
* Return a string representation of the provided object list.
* @param v The source list
* @return The string representation
*/
static String typedStringList(List list) {
assert list != null

Expand All @@ -78,7 +100,11 @@ class CoreUtil {
}


/** */
/**
* The type tag for the provided object.
* @param v The source object
* @param The type tag as a string
*/
static String typeTag(Object v) {
assert v != null

Expand All @@ -95,7 +121,11 @@ class CoreUtil {
}


/** */
/**
* Return a standard unique fingerprint for the provided string.
* @param seed The source string
* @return The unique fingerprint as a string
*/
static public String standardizedUniquifier(String seed) {
assert seed != null
assert seed.trim().length() > 0
Expand All @@ -104,14 +134,22 @@ class CoreUtil {
}


/** */
/**
* Return a standard computed filename for the provided object.
* @param obj The source object
* @return The standard filename as a string
*/
static public String standardizedFileName(Object obj) {
assert obj != null
standardizedFileName(obj.class)
}


/** */
/**
* Return a standard computed filename for the provided class.
* @param cl The source class
* @return The filename as a string
*/
static public String standardizedFileName(Class cl) {
String cn = cl.name
//println "cn: $cn"
Expand All @@ -129,7 +167,11 @@ class CoreUtil {
}


/** */
/**
* Return all the classes that apply to the provided object.
* @param obj The source object
* @return A set of class objects
*/
public static Set<Class> allClasses(Object obj) {
Set<Class> classes = new HashSet<Class>()
Class cl = obj.class
Expand Down
43 changes: 41 additions & 2 deletions app/carnival-util/src/main/groovy/carnival/util/CsvUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ import com.opencsv.CSVParserWriter



/**
* A set of static utility methods applicable to CSV data.
*/
class CsvUtil {

/** A singleton CSV parser that can be shared */
static final ICSVParser DEFAULT_PARSER = new CSVParserBuilder()
.withSeparator(ICSVParser.DEFAULT_SEPARATOR)
.withQuoteChar(ICSVParser.DEFAULT_QUOTE_CHARACTER)
Expand All @@ -36,13 +40,23 @@ class CsvUtil {
.build()


/**
* Create and return a header aware reader for the provided text.
* @param text The text to parse
* @return The CSV reader
*/
static CSVReaderHeaderAware createReaderHeaderAware(String text) {
assert text != null
def reader = new StringReader(text)
createReaderHeaderAware(reader)
}


/**
* Create and return a header aware CSV reader for the provided text file.
* @param file The text file to parse
* @return The CSV reader
*/
static CSVReaderHeaderAware createReaderHeaderAware(File file) {
def reader = new FileReader(file)
new CSVReaderHeaderAwareBuilder(reader)
Expand All @@ -51,20 +65,38 @@ class CsvUtil {
}


/**
* Create and return a header aware CSV reader for the provided Java
* reader.
* @param reader A Java reader
* @return The CSV reader
*/
static CSVReaderHeaderAware createReaderHeaderAware(Reader reader) {
new CSVReaderHeaderAwareBuilder(reader)
.withCSVParser(DEFAULT_PARSER)
.build()
}


/**
* Create and return a header aware CSV writer for the provided target
* file.
* @param file The target file
* @return The CSV writer
*/
static CSVWriter createWriterHeaderAware(File file) {
assert file != null
def writer = new FileWriter(file)
createWriterHeaderAware(writer)
}


/**
* Create and return a header aware CSV writer for the provided target
* writer.
* @param writer The target writer
* @param The CSV writer
*/
static CSVParserWriter createWriterHeaderAware(Writer writer) {
new CSVWriterBuilder(writer)
.withParser(DEFAULT_PARSER)
Expand All @@ -73,6 +105,11 @@ class CsvUtil {
}


/**
* Return true if the provided CSV reader has another token to read.
* @param csvReader The CSV reader to test
* @return True if there is another read available
*/
static boolean hasNext(CSVReader csvReader) {
assert csvReader != null
return csvReader.peek() != null
Expand All @@ -86,7 +123,8 @@ class CsvUtil {

/**
* Generic read from CSV file.
*
* @param filename The full path to the CSV file
* @return A list of maps containing the CSV data
*/
static List<Map> readFromCsvFile(String filename) {
assert filename != null
Expand All @@ -97,7 +135,8 @@ class CsvUtil {

/**
* Generic read from CSV file.
*
* @param file The CSV file
* @return A list of maps containing the CSV data
*/
static List<Map> readFromCsvFile(File file) {
assert file != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package carnival.util


/**
*
* An encasulation of the files that can persist a data table.
*
*/
class DataTableFiles {
Expand All @@ -13,8 +13,11 @@ class DataTableFiles {
///////////////////////////////////////////////////////////////////////////

/**
*
*
* Create the data table files in the provided directory for the provided
* name.
* @param name The name of the data table
* @param dir The target directory
* @return The data table files
*/
static DataTableFiles create(File dir, String name) {
File meta = DataTable.metaFile(dir, name)
Expand All @@ -27,53 +30,83 @@ class DataTableFiles {
// FIELDS
///////////////////////////////////////////////////////////////////////////

/** */
/** The metadata file */
File meta

/** */
/** The data file */
File data


///////////////////////////////////////////////////////////////////////////
// METHODS
///////////////////////////////////////////////////////////////////////////

/**
* Return true if any of the data table files are null.
* @return True if any of the data table files are null.
*/
boolean areNull() {
meta == null || data == null
}


/**
* Return true if all data files exist.
* @return True if all data files exist
*/
boolean exist() {
if (areNull()) return false
meta.exists() && data.exists()
}


/**
* Return true if all the data table files exist and are files.
* @return True if all the data table files exist and are files
*/
boolean areFiles() {
if (areNull()) return false
if (!exist()) return false
meta.isFile() && data.isFile()
}


/**
* Return true if all the data table files exist and are readable.
* @return True if all the data table files exist and are readable
*/
boolean areReadable() {
if (areNull()) return false
if (!exist()) return false
meta.canRead() && data.canRead()
}


/**
* Return the data table files in a map.
* @return The data table files in a map
*/
Map<String,File> toMap() {
[meta:meta, data:data]
}


/**
* Return the data table file in a list.
* @return The data table files in a list
*/
List<File> toList() {
[meta, data]
}


/**
* Delete the data table files from the file system.
*/
void delete() {
if (meta != null) meta.delete()
if (data != null) data.delete()
}

Object each(Closure cl) {
[meta, data].each(cl)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ public class DataTableRepresenter extends Representer {
// STATIC
///////////////////////////////////////////////////////////////////////////

/** */
static Logger elog = LoggerFactory.getLogger('db-entity-report')

/** */
/** Log to use */
static Logger log = LoggerFactory.getLogger(DataTableRepresenter)


/**
* No argument constructor.
*
*/
public DataTableRepresenter() {
this.representers.put(org.codehaus.groovy.runtime.GStringImpl.class, new RepresentGString())
Expand Down Expand Up @@ -113,7 +109,6 @@ public class DataTableRepresenter extends Representer {
} catch (org.yaml.snakeyaml.error.YAMLException e) {
def msg = "representJavaBeanProperty failure javaBean:$javaBean property:$property propertyValue:$propertyValue customTag:$customTag"
log.error(msg, e)
elog.error(msg, e)
}

return representation
Expand Down
Loading

0 comments on commit 5391338

Please sign in to comment.