Как вывести в лог данные из List
final List< ReportRow > result = new ArrayList<>(queryBase(filter)) как вывести в лог данные из этого листа?
public class DataSetApprovalOfBankPartyMP implements ReportDS {
private static final Logger log = getLogger(DataSetApprovalOfBankPartyMP.class);
private final CollectionsService collectionService = BeansUtils.getBean("collectionsService");
private final CrudService crud = BeansUtils.getBean("crudService");
private static final String DIALOG_PERIOD_START = "DATE_PARAM.Start";
private static final String DIALOG_PERIOD_END = "DATE_PARAM.End";
private static final String DIALOG_TYPE = "DocumentType";
private static final String DIALOG_SP = "SP_EMP.Value";
private static final String DIALOG_GO = "FIL_GO";
private static final String ALLNOVISA = "allnoVisa";
private static final String ALLYESVISA = "allyesVisa";
private static final String ALLINTERM = "allinterm";
private static final String YESINTERM = "yesinterm";
private static final String SPECINTERM = "specinterm";
private static final String NOINTERM = "nointerm";
private static final String ALLEX = "allex";
private static final String YESEX = "yesex";
private static final String SPECEX = "specex";
private static final String NOEX = "noex";
private static final String PROCENT = "procent";
private static final String DEPPARTY = "depparty";
@Override
public JRDataSource getJRDataSource(Connection connection, Map<String, Object> params) throws Exception {
final Date periodStart = (Date) params.get(DIALOG_PERIOD_START);
final Date periodEnd = (Date) params.get(DIALOG_PERIOD_END);
final List<Id> sp = (List<Id>) params.get(DIALOG_SP);
final Id go = (Id) params.get(DIALOG_GO);
final String documentType = (String) params.get(DIALOG_TYPE);
final List<Value<?>> filter = new ArrayList<>();
filter.add(new DateTimeValue(periodStart));
filter.add(new DateTimeValue(periodEnd));
filter.add(new ReferenceValue(go));
if (sp != null ) {
filter.add(createIdListValue(sp));
}
filter.add(new StringValue(documentType));
final List<ReportRow> result = new ArrayList<>(queryBase(filter));
return new JRBeanCollectionDataSource(result);
}
private List<ReportRow> queryBase(final List<Value<?>> filter) {
final List<ReportRow> result = new ArrayList<>();
Map<String, Map<String, Integer>> resultMap = new HashMap<String, Map<String, Integer>>();
final boolean sessionAlreadyOpened = AFSession.isDefinedOrOpened();
if (!sessionAlreadyOpened) {
AFSession.Manual.defineLocalUser();
}
IdentifiableObjectCollection collection = null;
// получаем коллекцию по sql-запросу
if (filter.size() == 5) {
collection = collectionService.findCollectionByQuery(QUERY_BASE, filter);
} else {
collection = collectionService.findCollectionByQuery(QUERY_BASE_WITHOUT_SP, filter);
}
for (IdentifiableObject o : collection) {
Map<String, Integer> tmpMap = new HashMap<String, Integer>();
String unidAndStage = o.getString("unidVisa");
Id idInit = o.getReference("idInit");
final String userUNID = getBeardUnid((Id) idInit);
SOBeard initBeard = null;
if (userUNID != null) {
final SOApplication soApp = AFSession.get().getApplication(SOApplication.class);
final List<SOBeard> beards = soApp.getBeardsByCMIds(singletonList(userUNID));
if (!beards.isEmpty()) {
initBeard = beards.get(0);
}
}
setFakeUser(initBeard);
if (isBeginStage(unidAndStage)) {
String depparty = o.getString(DEPPARTY);
String answer = o.getString("answer");
AFDate dateVisa = null;
Integer allnoVisa = 0;
Integer allyesVisa = 0;
Integer allinterm = 0;
Integer yesinterm = 0;
Integer specinterm = 0;
Integer nointerm = 0;
Integer allex = 0;
Integer yesex = 0;
Integer specex = 0;
Integer noex = 0;
Integer procent = 0;
if ("".equals(answer)) {
allnoVisa++;
} else {
allyesVisa++;
}
TimelessDate timevisa = o.getTimelessDate("timevisa");
if (timevisa != null) {
dateVisa = AFDate.fromJavaDate(timevisa.toDate(), false);
}
AFDate dueDate = getDueDateForStage(unidAndStage);
if (dateVisa != null && dueDate != null && dateVisa.compareTo(dueDate) <= 0) {
allinterm++;
if ("1".equals(answer)) {
yesinterm++;
} else if ("2".equals(answer)) {
nointerm++;
} else {
specinterm++;
}
} else if (dateVisa != null && dueDate != null && dateVisa.compareTo(dueDate) > 0) {
allex++;
if ("1".equals(answer)) {
yesex++;
} else if ("2".equals(answer)) {
noex++;
} else {
specex++;
}
}
if (resultMap.containsKey(depparty)) {
tmpMap = resultMap.get(depparty);
tmpMap.put(ALLNOVISA, tmpMap.get(ALLNOVISA)+allnoVisa);
tmpMap.put(ALLYESVISA, tmpMap.get(ALLYESVISA)+allyesVisa);
tmpMap.put(ALLINTERM, tmpMap.get(ALLINTERM)+allinterm);
tmpMap.put(YESINTERM, tmpMap.get(YESINTERM)+yesinterm);
tmpMap.put(SPECINTERM, tmpMap.get(SPECINTERM)+specinterm);
tmpMap.put(NOINTERM, tmpMap.get(NOINTERM)+nointerm);
tmpMap.put(ALLEX, tmpMap.get(ALLEX)+allex);
tmpMap.put(YESEX, tmpMap.get(YESEX)+yesex);
tmpMap.put(SPECEX, tmpMap.get(SPECEX)+specex);
tmpMap.put(NOEX, tmpMap.get(NOEX)+noex);
} else {
tmpMap.put(ALLNOVISA, allnoVisa);
tmpMap.put(ALLYESVISA, allyesVisa);
tmpMap.put(ALLINTERM, allinterm);
tmpMap.put(YESINTERM, yesinterm);
tmpMap.put(SPECINTERM, specinterm);
tmpMap.put(NOINTERM, nointerm);
tmpMap.put(ALLEX, allex);
tmpMap.put(YESEX, yesex);
tmpMap.put(SPECEX, specex);
tmpMap.put(NOEX, noex);
}
resultMap.put(depparty, tmpMap);
}
}
Integer allnovisa = 0;
Integer allyesvisa = 0;
Integer allinterm = 0;
Integer yesinterm = 0;
Integer specinterm = 0;
Integer nointerm = 0;
Integer allex = 0;
Integer yesex = 0;
Integer specex = 0;
Integer noex = 0;
Integer procent = 0;
resultMap = new TreeMap<String, Map<String, Integer>>(resultMap);
for (Map.Entry<String, Map<String, Integer>> entry: resultMap.entrySet()) {
ReportRow reportRow = new ReportRow();
reportRow.setDepparty(entry.getKey());
Map<String, Integer> mapValue = entry.getValue();
allnovisa = allnovisa + mapValue.get(ALLNOVISA);
allyesvisa = allyesvisa + mapValue.get(ALLYESVISA);
allinterm = allinterm + mapValue.get(ALLINTERM);
yesinterm = yesinterm + mapValue.get(YESINTERM);
specinterm = specinterm + mapValue.get(SPECINTERM);
nointerm = nointerm + mapValue.get(NOINTERM);
allex = allex + mapValue.get(ALLEX);
yesex = yesex + mapValue.get(YESEX);
specex = specex + mapValue.get(SPECEX);
noex = noex + mapValue.get(NOEX);
float percent = 0;
Integer allyesvisap = mapValue.get(ALLYESVISA);
Integer allexp = mapValue.get(ALLEX);
if (allyesvisap != 0 && allexp != 0) {
percent = (float)(allexp*100)/allyesvisap;
}
reportRow.setAllnoVisa(Integer.toString(mapValue.get(ALLNOVISA)));
reportRow.setAllyesVisa(Integer.toString(mapValue.get(ALLYESVISA)));
reportRow.setAllinterm(Integer.toString(mapValue.get(ALLINTERM)));
reportRow.setYesinterm(Integer.toString(mapValue.get(YESINTERM)));
reportRow.setSpecinterm(Integer.toString(mapValue.get(SPECINTERM)));
reportRow.setNointerm(Integer.toString(mapValue.get(NOINTERM)));
reportRow.setAllex(Integer.toString(mapValue.get(ALLEX)));
reportRow.setYesex(Integer.toString(mapValue.get(YESEX)));
reportRow.setSpecex(Integer.toString(mapValue.get(SPECEX)));
reportRow.setNoex(Integer.toString(mapValue.get(NOEX)));
reportRow.setProcent(String.format("%.2f", percent));
result.add(reportRow);
}
ReportRow reportRow = new ReportRow();
reportRow.setDepparty("ИТОГО:");
reportRow.setAllnoVisa(Integer.toString(allnovisa));
reportRow.setAllyesVisa(Integer.toString(allyesvisa));
reportRow.setAllinterm(Integer.toString(allinterm));
reportRow.setYesinterm(Integer.toString(yesinterm));
reportRow.setSpecinterm(Integer.toString(specinterm));
reportRow.setNointerm(Integer.toString(nointerm));
reportRow.setAllex(Integer.toString(allex));
reportRow.setYesex(Integer.toString(yesex));
reportRow.setSpecex(Integer.toString(specex));
reportRow.setNoex(Integer.toString(noex));
reportRow.setProcent("");
result.add(reportRow);
if (!sessionAlreadyOpened) {
close();
}
return result;
}
public static class ReportRow {
private String depparty;
private String allnoVisa;
private String allyesVisa;
private String allinterm;
private String yesinterm;
private String specinterm;
private String nointerm;
private String allex;
private String yesex;
private String specex;
private String noex;
private String procent;
public String getDepparty() {
return depparty;
}
public String getAllnoVisa() {
return allnoVisa;
}
public String getAllyesVisa() {
return allyesVisa;
}
public String getAllinterm() {
return allinterm;
}
public String getYesinterm() {
return yesinterm;
}
public String getSpecinterm() {
return specinterm;
}
public String getNointerm() {
return nointerm;
}
public String getAllex() {
return allex;
}
public String getYesex() {
return yesex;
}
public String getSpecex() {
return specex;
}
public String getNoex() {
return noex;
}
public String getProcent() {
return procent;
}
public void setDepparty(String depparty) {
this.depparty = depparty;
}
public void setAllnoVisa(String allnoVisa) {
this.allnoVisa = allnoVisa;
}
public void setAllyesVisa(String allyesVisa) {
this.allyesVisa = allyesVisa;
}
public void setAllinterm(String allinterm) {
this.allinterm = allinterm;
}
public void setYesinterm(String yesinterm) {
this.yesinterm = yesinterm;
}
public void setSpecinterm(String specinterm) {
this.specinterm = specinterm;
}
public void setNointerm(String nointerm) {
this.nointerm = nointerm;
}
public void setAllex(String allex) {
this.allex = allex;
}
public void setYesex(String yesex) {
this.yesex = yesex;
}
public void setSpecex(String specex) {
this.specex = specex;
}
public void setNoex(String noex) {
this.noex = noex;
}
public void setProcent(String procent) {
this.procent = procent;
}
}
private void setFakeUser(final SOBeard beard) {
if (beard != null) {
final SOBeard.Type type = beard.originalData().getType();
if (SOBeard.Type.SYS_HUMAN.equals(type) || SOBeard.Type.SYS_HUMAN_HEAD.equals(type)) {
final SOParty party = beard.originalData().getParty();
if (party instanceof SOAppointment) {
final SOPersonSystem person = ((SOAppointment)party).getPerson();
AFSession.get().setFakeUser(person);
}
}
}
}
private String getBeardUnid(final Id id) {
if (id != null) {
final IdentifiableObjectCollection collection = collectionService
.findCollectionByQuery(QUERY_BEARD_UNID, singletonList(new ReferenceValue(id)));
if (collection != null) {
for (final IdentifiableObject obj : collection) {
return obj.getString("unid");
}
}
}
return null;
}
private boolean setFakeUser(final String beard) throws NotesException {
final SOApplication soApp = AFSession.get().getApplication(SOApplication.class);
final SOBeard soBeard = soApp.getBeard(beard);
SOBeard.Type type = soBeard.originalData().getType();
if (SOBeard.Type.SYS_HUMAN.equals(type) || SOBeard.Type.SYS_HUMAN_HEAD.equals(type)) {
ru.intertrust.cmj.af.so.SOParty party = soBeard.originalData().getParty();
if (party instanceof SOAppointment) {
SOPersonSystem person = ((SOAppointment)party).getPerson();
AFSession.get().setFakeUser(person);
return true;
}
}
return false;
}
private ListValue createIdListValue(final List<Id> ids) {
final List<ReferenceValue> values = ids.stream()
.map(ReferenceValue::new)
.collect(Collectors.toList());
return ListValue.createListValue(values);
}
private ListValue createStringListValue(final List<String> values) {
final List<StringValue> refvalues = values.stream()
.map(StringValue::new)
.collect(Collectors.toList());
return ListValue.createListValue(refvalues);
}
public AFDate getDueDateForStage(String unidAndStage) {
AFDate dueTime = null;
String unid = unidAndStage.split("%")[0];
Integer stage = Integer.parseInt(unidAndStage.split("%")[1]);
ARApplicationApproving arApplication = AFSession.get().getApplication(ARApplicationApproving.class);
ARListApproving arList = arApplication.getEntityByUNID(unid);
if (ARStagesApproving.ProcessType.PARALLEL.equals(arList.stages().getProcessType())) {
dueTime = arList.getGlobalDueDate();
} else {
dueTime = arList.stages().get(stage).getFinishTime().toAFDate();
}
return dueTime;
}
public String getStartDateForStage(String unidAndStage) {
String startTimeStr = "";
String unid = unidAndStage.split("%")[0];
Integer stage = Integer.parseInt(unidAndStage.split("%")[1]);
ARApplicationApproving arApplication = AFSession.get().getApplication(ARApplicationApproving.class);
ARListApproving arList = arApplication.getEntityByUNID(unid);
if (ARStagesApproving.ProcessType.PARALLEL.equals(arList.stages().getProcessType())) {
startTimeStr = arList.getStartTime().toAFDate().toString();
} else {
startTimeStr = arList.stages().get(stage).getStartTime().toAFDate().toString();
}
return startTimeStr;
}
public Boolean isBeginStage(String unidAndStage) {
Boolean isBeginStage = true;
AFDate startDate = null;
AFDate currDate = new AFDate(Calendar.getInstance());
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
String startDateStr = getStartDateForStage(unidAndStage);
try {
startDate = AFDate.fromJavaDateSafeTZ(formatter.parse(startDateStr), false);
} catch (ParseException e) {
throw new RuntimeException(e);
}
if (startDate.toJavaDate().after(currDate.toJavaDate())) {
isBeginStage = false;
}
return isBeginStage;
}
}