Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue3466 #3483

Merged
merged 10 commits into from
Mar 23, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class AdminController {
session.status = status
def fileIn = new FileInputStream(file)
try {
def result = importService.gmsImport(fileIn, status.projects, preview, update)
def result = importService.projectImport(fileIn, status.projects, preview, update)
status.finished = true
status.error = result.error
}
Expand Down
14 changes: 5 additions & 9 deletions grails-app/services/au/org/ala/merit/ImportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class ImportService {
organisations += metadataService.organisationList()?.list
}

Map gmsImport(InputStream csv, List status, Boolean preview, Boolean update, String charEncoding = 'Cp1252') {
Map projectImport(InputStream csv, List status, Boolean preview, Boolean update, String charEncoding = 'Cp1252') {

Map programs = [:].withDefault{name ->
programService.getByName(name)
Expand All @@ -307,8 +307,7 @@ class ImportService {
mu?.managementUnitId
}
refreshOrganisationList()
def mapper = new GmsMapper(metadataService.activitiesModel(), metadataService.programsModel(), organisations, abnLookupService, metadataService.getOutputTargetScores(), programs, managementUnits)

def mapper = new GmsMapper(metadataService.activitiesModel(), metadataService.programsModel(), organisations, abnLookupService, metadataService.getOutputTargetScores(), programs, managementUnits, false, update)
def action = preview?{rows -> mapProjectRows(rows, status, mapper, update)}:{rows -> importAll(rows, status, mapper, update)}

Map result = [:]
Expand Down Expand Up @@ -360,7 +359,7 @@ class ImportService {

def mapProjectRows(projectRows, List status, GmsMapper mapper, Boolean update) {

Map mappingResults = mapper.mapProject(projectRows)
Map mappingResults = mapper.mapProject(projectRows, update)

String grantId = mappingResults.project.grantId
String externalId = mappingResults.project.externalId
Expand All @@ -380,7 +379,7 @@ class ImportService {

void importAll(projectRows, List status, GmsMapper mapper, Boolean update) {

def projectDetails = mapper.mapProject(projectRows)
def projectDetails = mapper.mapProject(projectRows, update)

def grantId = projectDetails.project.grantId?:'<not mapped>'
def externalId = projectDetails.project.externalId?:'<not mapped>'
Expand All @@ -394,9 +393,6 @@ class ImportService {
def editorEmail = projectDetails.project.remove('editorEmail')
def editorEmail2 = projectDetails.project.remove('editorEmail2')

//When projects are loaded into MERIT via CSV upload, they are given a status of "Application".
projectDetails.project.status ?: 'application'

// Create the organisation first so we can link it to the project.
if (projectDetails.organisation) {
Map orgCreationResult = organisationService.update(null, projectDetails.organisation)
Expand All @@ -409,7 +405,7 @@ class ImportService {
}
}

def result = importProject(projectDetails.project, update) // Do not overwrite existing projects because of the impacts to sites / activities etc.
def result = importProject(projectDetails.project, update)

if (result.project == 'existing' && !update) {
status << [grantId:grantId, externalId:externalId, success:false, errors:['Project already exists in MERIT, skipping']]
Expand Down
4 changes: 1 addition & 3 deletions grails-app/views/admin/import.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
</p>
<div data-bind="if:update">
<p class="alert alert-warning" >
Please note this function will replace all project information for each project. <br/>
It is designed for use with grants hub data and to fix newly loaded projects. Please test changes
to existing MERIT projects in the staging system before running the update in production.
Please test changes to existing MERIT projects in the staging system before running the update in production.
</p>
</div>
<div class="form-check">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImportProjectsSpec extends StubbedCasSpec {
and:
List rows2 = projectResults()
rows2.size() == 2
rows2[1].success == 'Yes'

when:
to Organisation, 'test_organisation'
Expand All @@ -75,6 +76,8 @@ class ImportProjectsSpec extends StubbedCasSpec {
and: "The data is relevant to the projects loaded"
List rows = projectResults()
rows.size() == 3
rows[1].success == 'Yes'
rows[2].success == 'Yes'

when:
importProjects()
Expand Down Expand Up @@ -125,6 +128,7 @@ class ImportProjectsSpec extends StubbedCasSpec {
and:
List rows2 = projectResults()
rows2.size() == 2
rows2[1].success == 'Yes'

when: "We navigate to the program page to find the new imported project, then open it"
to ProgramPage, 'configurable_meri_plan'
Expand Down Expand Up @@ -152,4 +156,59 @@ class ImportProjectsSpec extends StubbedCasSpec {
adminContent.meriPlan.budget[0].budgetAmounts()*.value() == ["20000", "10000"]

}

def "Projects can be updated via import with only the fields provided in the spreadsheet being updated"() {

setup:
File csv = new File(getClass().getResource("/grants-hub-update-data.csv").toURI())
loginAsMeritAdmin(browser)

when:
to ProjectImport
checkUpdateCheckbox()
attachFile(csv)

then: "The projects are validated and the validation results are displayed"
waitFor{validateComplete()}

and: "The data is relevant to the projects loaded"
projectResults().size() == 2

when:
importProjects()

then:
waitFor{loadComplete()}
and:
List rows2 = projectResults()
rows2.size() == 2
rows2[1].success == 'Yes'

when: "We navigate to the program page to find the new imported project, then open it"
to ProgramPage, 'configurable_meri_plan'
openProjectByGrantId('cep-1')

then:
at RlpProjectPage

when:
displayOverview()

then:
overview.program.text() == "Configurable MERI Plan Program"
overview.projectId.text() == "cep-1"
overview.status.text().equalsIgnoreCase("Active")
overview.externalIds*.text() == ["1234"]
overview.description.text() == "Grants project description - updated"

when:
openMeriPlanEditTab()

then:
adminContent.meriPlan.budget.size() == 1
adminContent.meriPlan.budget[0].description.value() == "Project funding"
adminContent.meriPlan.budget[0].budgetAmounts()*.value() == ["1", "2"]

}

}
14 changes: 13 additions & 1 deletion src/integration-test/groovy/pages/ProjectImport.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pages

import geb.Page
import geb.module.Checkbox

class ProjectImport extends Page {

Expand All @@ -12,6 +13,7 @@ class ProjectImport extends Page {
fileInput { $('#fileUpload') }
importButton { $('button[data-bind*=doImport]')}
progressSummary { $('span[data-bind*=progressSummary]') }
updateCheckbox { $('#update').module(Checkbox) }
}

def attachFile(File file) {
Expand All @@ -22,15 +24,25 @@ class ProjectImport extends Page {
importButton.click()
}

def checkUpdateCheckbox() {
updateCheckbox.check()
}

List<List> projectResults() {

List columns = ["grantId", "externalId", "success", "errors", "messages"]
List rows = []
def progressTable = $('table.table')
progressTable.find("tbody tr").each {
List cols = []
it.find("td").each { col ->
cols << col.text()
}
rows << cols
Map row = [:]
columns.eachWithIndex{ col, index ->
row[col] = cols[index]
}
rows << row
}

rows
Expand Down
2 changes: 2 additions & 0 deletions src/integration-test/resources/grants-hub-update-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_ID,EXTERNAL_ID,APP_NM,APP_DESC,PROGRAM_NM,ABN,ORG_ID,START_DT,FINISH_DT,ORDER_NO,FUNDING,AUTHORISEDP_EMAIL,GRANT_MGR_EMAIL,GRANT_MGR_EMAIL_2,APPLICANT_EMAIL,ADMIN_EMAIL,EDITOR_EMAIL,EDITOR_EMAIL_2,TAGS,PROJECT_STATUS,MERI_PLAN_STATUS,FUNDING_TYPE,ORIGIN_SYSTEM,FINANCIAL_YEAR_FUNDING_DESCRIPTION,FUNDING_21_22,FUNDING_22_23
cep-1,,,Grants project description - updated,,,,,,,,,,,,,,,,Active,,,,Project funding,1,2
Loading
Loading