Skip to content

Commit

Permalink
Merge pull request #191 from chrisala/master
Browse files Browse the repository at this point in the history
Contract dates
  • Loading branch information
chrisala committed Mar 30, 2015
2 parents e7abdda + ba859f2 commit 3ada9eb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class OrganisationController extends au.org.ala.fieldcapture.OrganisationControl
results << "Project ${project.grantId} actual commencement date ${plannedStartDate} plannedStartDate ${project.plannedStartDate}\n"
}

def newDetails= [plannedStartDate: plannedStartDate, workOrderStartDate: plannedStartDate, plannedEndDate: plannedEndDate, workOrderEndDate: plannedEndDate, workOrderId: workOrderId, timeline:null]
def newDetails= [plannedStartDate: plannedStartDate, contractStartDate: plannedStartDate, plannedEndDate: plannedEndDate, contractEndDate: plannedEndDate, workOrderId: workOrderId, timeline:null]
resp = projectService.update(project.projectId, newDetails)
if (!resp || resp.error) {
errors << "Unable to update project ${project.grantId} : ${resp?.error}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,8 @@ class ImportService {
cacheService.clear(PROJECTS_CACHE_KEY)
def reader = new InputStreamReader(csv, charEncoding)
try {

def mapper = new GmsMapper(metadataService.activitiesModel(), metadataService.programsModel())
def first = true
def prevGrantId = null
def prevExternalId = null
def projectRows = []
Expand All @@ -1210,6 +1211,12 @@ class ImportService {
projectRows << rowMap
prevGrantId = currentGrantId
prevExternalId = currentExternalId
if (first) {
def errors = mapper.validateHeaders(projectRows)
status << [grantId:'Column Headers', externalId:'', success:errors.size() == 0, errors:errors]
first = false
}

}
// import the last project
action(projectRows)
Expand Down
40 changes: 36 additions & 4 deletions src/groovy/au/org/ala/fieldcapture/GmsMapper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ class GmsMapper {
ROUND_NM:[name:'associatedSubProgram', type:'string'],
EXTERNAL_ID:[name:'externalId', type:'string'],
ORG_TRADING_NAME:[name:'organisationName', type:'string'],
START_DT:[name:'plannedStartDate', type:'date'],
FINISH_DT:[name:'plannedEndDate', type:'date'],
START_DT:[name:'plannedStartDate', type:'date', mandatory:true],
FINISH_DT:[name:'plannedEndDate', type:'date', mandatory:true],
CONTRACT_START_DT:[name:'contractStartDate', type:'date'],
CONTRACT_END_DT:[name:'contractEndDate', type:'date'],
WORK_ORDER_ID:[name:'workOrderId', type:'string'],
FUNDING:[name:'funding', type:'decimal'],
AUTHORISEDP_EMAIL:[name:'adminEmail', type:'email'],
GRANT_MGR_EMAIL:[name:'grantManagerEmail', type:'email'],
Expand Down Expand Up @@ -103,6 +106,32 @@ class GmsMapper {
this.includeProgress = includeProgress
}

def validateHeaders(projectRows) {
def errors = []
def mappings = projectMapping + siteMapping + activityMapping + outputTargetColumnMapping + riskMapping
def mappingKeys = new HashSet(mappings.keySet())
mappingKeys.add(GRANT_ID_COLUMN)
mappingKeys.add(DATA_TYPE_COLUMN)
mappingKeys.add(DATA_SUB_TYPE_COLUMN)
mappingKeys.add(REPORTING_THEME_COLUMN)

projectRows[0].keySet().each { key ->
if (key == 'index') {
return
}
if (!(key in mappingKeys)) {
errors << "Unused column header ${key}, please check it is not named incorrectly"
}
}
mappingKeys.each { key ->

if (!(key in projectRows[0].keySet())) {
errors << "Missing column in spreadsheet ${key} - load may be incomplete without this"
}
}
return errors
}

def mapProject(projectRows) {

def errors = []
Expand Down Expand Up @@ -325,7 +354,7 @@ class GmsMapper {
value = value?value.trim():''
switch (type) {
case 'date':
return convertDate(value)
return convertDate(value, mapping.mandatory)
case 'decimal':
return convertDecimal(value)
case 'string':
Expand All @@ -349,8 +378,11 @@ class GmsMapper {
throw new IllegalArgumentException("Unsupported type: ${type}")
}

private def convertDate(date) {
private def convertDate(date, mandatory) {

if (!mandatory && !date) {
return ''
}

if (date && date.isInteger()) {
final long DAYS_FROM_1900_TO_1970 = 25567
Expand Down

0 comments on commit 3ada9eb

Please sign in to comment.