Tuesday, June 2, 2020

Sailpoint IdentityIQ Copy Report to Server Directory

OOTB Any custom or OOTB report can be scheduled to send the Details to the users in the email containing the attachment of data in pdf/CSV but If we have a requirement where we need to copy the report to some location in the server in the CSV format this can be done by writing the custom code which can be triggered using  rule runner task which in turn can be scheduled and will copy the required report to the location on the server

Here code can be modified accordingly, here I have hardcoded the report name and the directory location at which this report needs to be copied.

Report name - TestReport
Directory location- C:/Vishal/

		String byteString = "";
		int count = 0;
		String fileName;
		TaskManager taskManager = new TaskManager(context);
		TaskResult taskResult = taskManager.runSync("TestReport",
				new HashMap<String, Object>());

		if (null != taskResult) {
			JasperResult jasperResult = taskResult.getReport();

			if (null != jasperResult) {
				List<PersistedFile> fileList = jasperResult.getFiles();

				for (PersistedFile file : fileList) {
					if (file.isCsv()) {
						SimpleDateFormat sdf = new SimpleDateFormat(
								"MMddyyyy-HH-mm-ss");
						Date date = new Date();
						fileName = file.getName().substring(0,
								file.getName().indexOf(".csv"))
								+ "_" + sdf.format(date) + ".csv";

						QueryOptions qo = new QueryOptions();
						Filter filter = Filter.eq("parent", file);
						qo.addFilter(filter);
						qo.addOrdering("fileIndex", true);

						List<FileBucket> fileBucketList = context.getObjects(
								FileBucket.class, qo);
						for (FileBucket fileBucket : fileBucketList) {
							byteString += sailpoint.tools.Util
									.bytesToString(fileBucket.getData());
							count++;
						}
						Util.writeFile("C://Vishal//" + fileName, byteString);

					}
				}
			}
		}