Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #16 from ncharles/ust_3426/dev/3427_add_generation…
Browse files Browse the repository at this point in the history
…_timestamp_in_promises

Fixes #3427 : add a variable that contains the promises generation timestamp
  • Loading branch information
ncharles committed Apr 11, 2013
2 parents 28bbc38 + c577247 commit b624fdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Cf3PromisesFileWriterServiceImpl(

logger.trace("Repository loaded")

private[this] val generationTimestampVariable = "GENERATIONTIMESTAMP"

/**
* Compute the TMLs list to be written
* @param container : the container of the policies we want to write
Expand Down Expand Up @@ -145,6 +147,8 @@ class Cf3PromisesFileWriterServiceImpl(
, outPath : String
): Unit = {
try {
val generationVariable = getGenerationVariable()

for (fileEntry <- fileSet) {
techniqueRepository.getTemplateContent(fileEntry.source) { optInputStream =>
optInputStream match {
Expand All @@ -158,7 +162,7 @@ class Cf3PromisesFileWriterServiceImpl(
template.registerRenderer(classOf[LocalDate], new LocalDateRenderer());
template.registerRenderer(classOf[LocalTime], new LocalTimeRenderer());

for (variable <- variableSet) {
for (variable <- variableSet++generationVariable) {
if ( (variable.mayBeEmpty) && ((variable.values.size == 0) || (variable.values.size ==1 && variable.values.head == "") ) ) {
template.setAttribute(variable.name, null)
} else if(variable.values.size == 0) {
Expand Down Expand Up @@ -187,6 +191,16 @@ class Cf3PromisesFileWriterServiceImpl(

}

/**
* Returns variable relative to a specific promise generation
* For the moment, only the timestamp
*/
private[this] def getGenerationVariable() : Seq[STVariable]= {
// compute the generation timestamp
val promiseGenerationTimestamp = DateTime.now()

Seq(STVariable(generationTimestampVariable, false, Seq(promiseGenerationTimestamp)))
}

private[this] def prepareVariables(
container: Cf3PolicyDraftContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ class SystemVariableSpecServiceImpl extends SystemVariableSpecService {
, isUniqueVariable = true
, constraint = Constraint(typeName = IntegerVType())
)
// this variable may be empty, has it is not filled by rudder, but by cf-clerk
, SystemVariableSpec("GENERATIONTIMESTAMP"
, "Timestamp of the promises generation"
, multivalued = false
, isUniqueVariable = true
, constraint = Constraint(mayBeEmpty=true)
)


)

Expand Down

0 comments on commit b624fdb

Please sign in to comment.