001package com.identityworksllc.iiq.common.reporting;
002
003import net.sf.jasperreports.engine.JRException;
004import net.sf.jasperreports.engine.JRField;
005import sailpoint.api.SailPointContext;
006import sailpoint.object.Attributes;
007import sailpoint.object.LiveReport;
008import sailpoint.object.QueryOptions;
009import sailpoint.object.ReportColumnConfig;
010import sailpoint.object.ReportDataSource;
011import sailpoint.object.Sort;
012import sailpoint.reporting.datasource.JavaDataSource;
013import sailpoint.task.Monitor;
014import sailpoint.tools.GeneralException;
015import sailpoint.tools.Util;
016
017import java.util.ArrayList;
018import java.util.List;
019
020/**
021 * Parent class for Java data sources, making certain things easier
022 */
023public abstract class AbstractJavaDataSource implements JavaDataSource {
024
025        protected SailPointContext context;
026        protected String groupBy;
027        protected Attributes<Object, Object> inputs;
028        protected int limit;
029        protected LiveReport liveReport;
030        protected Monitor monitor;
031        protected ArrayList<Object> sortBy;
032        protected int start;
033
034        @Override
035        public void close() {
036                // No-op by default
037        }
038
039        @Override
040        public String getBaseHql() {
041                // TODO Auto-generated method stub
042                return null;
043        }
044
045        @Override
046        public QueryOptions getBaseQueryOptions() {
047                // TODO Auto-generated method stub
048                return null;
049        }
050
051        public Object getFieldValue(JRField jrField) throws JRException {
052                String name = jrField.getName();
053                Object value = null;
054                try {
055                        value = getFieldValue(name);
056                }
057                catch (GeneralException e) {
058                        throw new JRException(e);
059                }
060                return value;
061        }
062        
063        @Override
064        public int getSizeEstimate() throws GeneralException {
065                return 0;
066        }
067
068        @Override
069        public void initialize(SailPointContext context, LiveReport liveReport, Attributes<String, Object> taskArguments, String groupBy, List<Sort> sortBy) throws GeneralException {
070                this.context = context;
071                this.liveReport = liveReport;
072                this.inputs = new Attributes<>();
073                if (taskArguments != null) {
074                        this.inputs.putAll(taskArguments);
075                }
076                this.groupBy = groupBy;
077
078                this.sortBy = new ArrayList<>();
079                if (sortBy != null) {
080                        this.sortBy.addAll(sortBy);
081                }
082        }
083
084        @Override
085        public void setLimit(int arg0, int arg1) {
086                start = arg0;
087                limit = arg1;
088        }
089
090        @Override
091        public void setMonitor(Monitor arg0) {
092                this.monitor = arg0;
093        }
094
095}