ment
SysOperation framework - Assignment
Problem statement:
You have a table (CountryPopulation) which is having below fields.
1. Name
2. Age
3. Gender (enum)
4. Address
5. Occupation
Now,
Create a batch job using SysOperation framework. from the front end it will filter gender and occupation and based on the filter it will export data in a csv table from above table.
Steps to solve:
To solve above assignment we have to follow below steps:
1. We need to have a table. Which is already present in our system.
2. We need a controller class
3. We need a data contract class
4. We need a service class
5. We need a menu item. [This menu item will call the controller class so that it executes]
Project Structure will be like below:
You already have a table like below:
Controller Class
[SysOperationJournaledParametersAttribute(true)] class CountryPopulationExportController extends SysOperationServiceController { CountryPopulationExportContract countryPopulationExportContract; public static void main(Args _args) { CountryPopulationExportController controller = new CountryPopulationExportController(classStr(CountryPopulationExportService), methodStr(CountryPopulationExportService, processData), SysOperationExecutionMode::Synchronous); controller.parmArgs(_args); controller.parmShowDialog(true); controller.startOperation(); } public ClassDescription defaultCaption(){ return "Country Population export"; } private static ClassDescription description() { return "Country Population export"; } }
Contract Class
[DataContractAttribute] class CountryPopulationExportContract { public Gender genderFilter; public str occupationFilter; [DataMemberAttribute('GenderFilter'), SysOperationLabelAttribute(literalStr("Gender")), SysOperationDisplayOrderAttribute('1')] public Gender parmGenderFilter(Gender _genderFilter = genderFilter) { genderFilter = _genderFilter; return genderFilter; } [DataMemberAttribute('OccupationFilter'), SysOperationLabelAttribute(literalStr("Occupation")), SysOperationDisplayOrderAttribute('2')] public str parmOccupationFilter(str _occupationFilter = occupationFilter) { occupationFilter = _occupationFilter; return occupationFilter; } }
Service Class
[SRSReportParameterAttribute(classStr(CountryPopulationExportContract))] class CountryPopulationExportService extends SysOperationServiceBase { // CountryPopulationExportContract countryPopulationExportContract; [SysEntryPointAttribute] public void processData(CountryPopulationExportContract countryPopulationExportContract) { CountryPopulation countryPopulation; CommaStreamIo io = CommaStreamIo::constructForWrite(); str fileName = 'File.csv', fileContent; Gender genderFilter = countryPopulationExportContract.parmGenderFilter() ; str occupationFilter = countryPopulationExportContract.parmOccupationFilter(); Query query = new Query(); QueryBuildDataSource countryPopulationQbds; QueryBuildRange countryPopulationGenderRange, countryPopulationOccupationRange; countryPopulationQbds = query.addDataSource(tableNum(CountryPopulation)); countryPopulationGenderRange = countryPopulationQbds.addRange(fieldNum(CountryPopulation, Gender)); countryPopulationGenderRange.value(queryValue(genderFilter)); countryPopulationOccupationRange = countryPopulationQbds.addRange(fieldNum(CountryPopulation, Occupation)); countryPopulationOccupationRange.value(queryValue(occupationFilter)); io.writeExp(["Name","Age","Gender","Address","Occupation"]); // Retrieve and export data from the table ttsBegin; QueryRun queryRun = new QueryRun(query); while (queryRun.next()) { countryPopulation = queryRun.get(tableNum(CountryPopulation)); io.writeExp([countryPopulation.Name, countryPopulation.Age, CountryPopulation.Gender, countryPopulation.Address, countryPopulation.Occupation]); } ttsCommit; // Set stream System.IO.Stream stream = io.getStream(); stream.Position = 0; // Set stream reader System.IO.StreamReader sReader = new System.IO.StreamReader(stream); // Set file contentn string fileContent = sReader.ReadToEnd(); // Save file File::SendStringAsFileToUser(fileContent, fileName); } }
Comments
Post a Comment