Created
October 3, 2023 07:52
-
-
Save vikrantyadav11/356015d0cbb2fe0da72396ed07cb5e2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate | |
import groovy.json.JsonBuilder | |
import groovy.json.JsonOutput | |
import groovy.transform.BaseScript | |
import groovyx.net.http.ContentType | |
import groovyx.net.http.HTTPBuilder | |
import groovyx.net.http.Method | |
import javax.ws.rs.core.MultivaluedMap | |
import javax.ws.rs.core.Response | |
import groovyx.net.http.RESTClient | |
@BaseScript CustomEndpointDelegate delegate | |
accountsorted(httpMethod: "GET") { MultivaluedMap queryParams -> | |
// Specify the path to the CSV file on the server | |
def csvFilePath = "/jirasharevsa/sharehome_a3/accounts-sorted.csv" | |
// Read CSV file and process data | |
def csvFile = new File(csvFilePath) | |
def csvData = csvFile.text | |
// Process CSV data (example: split lines) | |
def lines = csvData.split('\n') | |
def processedData = [] | |
lines.each { line -> | |
def fields = line.split(',') | |
// Process each field of the CSV | |
// Example: println(fields[0]) // prints the first field of each line | |
processedData << fields[0].trim() // Add the processed data to the list, trimmed to remove extra spaces | |
} | |
// Convert processed data to JSON | |
def jsonResponse = new groovy.json.JsonBuilder(processedData).toPrettyString() | |
// Return the processed data as JSON | |
return Response.ok(jsonResponse).build() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment