<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.data.DataObject" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="java.util.Date" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.Set" %> <%@ page import="java.util.Arrays" %> <%@ page import="java.util.HashSet" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.TreeMap" %> <%@ page import="java.util.Collections" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document.SearchFilter" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Feature" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement.Project" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="javax.validation.constraints.Pattern" %> <%@ page import="org.crosswire.webtools.*" %> <%! @Description(value = "Retrieve user statistics", name = "lectionaries/reports/lectionindex") public static class MyParameters extends Parameters { @Description(value = "Show this usage help", example = "true", defaultValue = "false") public Boolean help = false; @Description(value = "Change report title", defaultValue = "Synaxarion", example = "Holy Week") public String title = "Synaxarion"; @Description(value = "limit documents to ones which contain one or more featureCode filters; can repeat", defaultValue = "Synaxarion", example = "Holy Week") public String featureCode = null; @Description(value = "Link prefix for callback URLs", defaultValue = "/", example = "/web/my-project") public String callbackPrefix = "/"; @Pattern(regexp = "^(xml|html)?$", message = "Valid response formats: \"xml\", \"json\", \"csv\", \"html\"") @Description(value = "specify the result format: xml, json, csv, html", defaultValue = "html", example = "xml") public String format = "html"; @Description(value = "specify the columns to consider when combining", defaultValue = "period,week,day,service,reading,readingType,tone,comm", example = "period,week,day") public String breakColumns = "period,week,day,service,reading,readingType,tone,comm"; @Override protected void afterLoad() { // if ((userID == null || userID.isEmpty()) && getUser() != null) userID = getUser().getUserName(); // if ("ALL".equals(userID) && limit == null) limit = 100; } @Override protected void afterValidate() { } @Override protected void customValidation() { } @Override protected boolean permissionValidation(HttpServletRequest request, HttpServletResponse response) { return true; } } protected static Map codeDescriptionsBase = new HashMap(); protected static Map hwCodeDescriptions = new HashMap(); protected static Map> codeOverrides = new HashMap>(); static { codeDescriptionsBase.put("P:05HolyW", "Holy Week"); codeDescriptionsBase.put("WD1", "Sunday"); codeDescriptionsBase.put("WD2", "Monday"); codeDescriptionsBase.put("WD3", "Tuesday"); codeDescriptionsBase.put("WD4", "Wednesday"); codeDescriptionsBase.put("WD5", "Thursday"); codeDescriptionsBase.put("WD6", "Friday"); codeDescriptionsBase.put("WD7", "Saturday"); codeDescriptionsBase.put("WD8", "Easter Sunday"); codeDescriptionsBase.put("WD9", "Easter Monday"); codeDescriptionsBase.put("Eve", "Evening"); codeDescriptionsBase.put("Mor", "Morning"); codeDescriptionsBase.put("SvcD1", "1st hour of the day"); codeDescriptionsBase.put("SvcD3", "3rd hour of the day"); codeDescriptionsBase.put("SvcD6", "6th hour of the day"); codeDescriptionsBase.put("SvcD9", "9th hour of the day"); codeDescriptionsBase.put("SvcD11", "11th hour of the day"); codeDescriptionsBase.put("SvcD12", "12th hour of the day"); codeDescriptionsBase.put("SvcN1", "1st hour of the night"); codeDescriptionsBase.put("SvcN3", "3rd hour of the night"); codeDescriptionsBase.put("SvcN6", "6th hour of the night"); codeDescriptionsBase.put("SvcN9", "9th hour of the night"); codeDescriptionsBase.put("SvcN11", "11th hour of the night"); codeDescriptionsBase.put("SvcSy", "Synaxis"); // Holy Week Map overrides = new HashMap(codeDescriptionsBase); overrides.put("WD1", "Palm Sunday"); codeOverrides.put("P:05HolyW", overrides); } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response); if (params.getErrors().size() == 0 && !params.help) { StringBuffer results = new StringBuffer(); Set docs = null; Document.SearchFilter searchFilter = new Document.SearchFilter(); String featureCodesStrings[] = request.getParameterValues("featureCode"); if (featureCodesStrings != null && featureCodesStrings.length > 0) { for (String fc : featureCodesStrings) { SearchFilter.FeatureCriteria featureCriteria = SearchFilter.FeatureCriteria.parseFeatureCodeString(fc); searchFilter.addFeatureCriteria(featureCriteria); } docs = new HashSet(); Document ds[] = Document.searchDocuments(false, searchFilter); if (ds != null) { for (Document d: ds) { docs.add(d.getDocumentID()); } } } if ("html".equals(params.format)) { %>

<%= params.title %>

<% } else { results.append("
"); } // "LectionBookTypeCopt", StringVal1="Holy Week" List features = new ArrayList(); Feature fs[] = Feature.getFeatures(-1, -1, "LectionIndex"); if (fs != null) Collections.addAll(features, fs); fs = Feature.getFeatures(-1, -1, "LectionIndexCopt"); if (fs != null) Collections.addAll(features, fs); Map> lectionIdentifiers = new HashMap>(); Set breakColumnSet = new HashSet(Arrays.asList(params.breakColumns.replaceAll(" ", "").split(","))); for (Feature f: features) { if (docs != null) { if (!docs.contains(f.getDocumentID())) { continue; } } int type = f.getIntVal1(); if (type == 1) { int index = 0; String codesString = f.getStringVal1(); String codes[] = codesString.split(" "); String period = codes.length > index ? codes[index] : ""; String week = codes.length > 1 ? codes[1] : ""; String day = codes.length > 2 ? codes[2] : ""; String service = codes.length > 3 ? codes[3] : ""; String reading = codes.length > 4 ? codes[4] : ""; String readingType = codes.length > 5 ? codes[5] : ""; String tone = codes.length > 6 ? codes[6] : ""; String comm = codes.length > 7 ? codes[7] : ""; List codesForBreak = new ArrayList(); String val = ""; val = period; codesForBreak.add(breakColumnSet.contains("period") ? val : ""); val = week; codesForBreak.add(breakColumnSet.contains("week") ? val : ""); val = day; codesForBreak.add(breakColumnSet.contains("day") ? val : ""); val = service; codesForBreak.add(breakColumnSet.contains("service") ? val : ""); val = reading; codesForBreak.add(breakColumnSet.contains("reading") ? val : ""); val = readingType; codesForBreak.add(breakColumnSet.contains("readingType") ? val : ""); val = tone; codesForBreak.add(breakColumnSet.contains("tone") ? val : ""); val = comm; codesForBreak.add(breakColumnSet.contains("comm") ? val : ""); codesString = String.join(" ", codesForBreak); if (lectionIdentifiers.get(codesString) == null) { lectionIdentifiers.put(codesString, new ArrayList()); } lectionIdentifiers.get(codesString).add(f); } } Map codesStrings = new TreeMap(); for (String codeString : lectionIdentifiers.keySet()) { String alphaString = codeString.replaceAll("([0-9]+)", "0000000000000000000000$1"); alphaString = alphaString.replaceAll("0+([0-9]{15,})", "$1"); codesStrings.put(alphaString, codeString); } for (String alphaString: codesStrings.keySet()) { int index = 0; String codesString = codesStrings.get(alphaString); String codes[] = codesString.split(" "); String period = codes.length > index ? codes[index++] : ""; Map codeDescriptions = codeOverrides.getOrDefault(period, codeDescriptionsBase); String periodDescription = codeDescriptions.get(period); String week = ""; if ("P:05HolyW".equals(period)) { week = "Holy Week"; } else { week = codes.length > index ? codes[index++] : ""; } String weekDescription = codeDescriptions.get(week); String day = codes.length > index ? codes[index++] : ""; String dayDescription = codeDescriptions.get(day); String service = codes.length > index ? codes[index++] : ""; String serviceDescription = codeDescriptions.get(service); String reading = codes.length > index ? codes[index++] : ""; String readingDescription = codeDescriptions.get(reading); String readingType = codes.length > index ? codes[index++] : ""; String readingTypeDescription = codeDescriptions.get(readingType); String tone = codes.length > index ? codes[index++] : ""; String toneDescription = codeDescriptions.get(tone); String comm = codes.length > index ? codes[index++] : ""; String commDescription = codeDescriptions.get(comm); if ("html".equals(params.format)) { %>
<% } Map> indexContents = new HashMap>(); for (Feature f: lectionIdentifiers.get(codesString)) { String indexContent = f.getStringVal2(); if (indexContents.get(indexContent) == null) { indexContents.put(indexContent, new ArrayList()); } indexContents.get(indexContent).add(f); } List ics = new ArrayList(indexContents.keySet()); Collections.sort(ics); for (String indexContent : ics) { %> <% for (Feature f : indexContents.get(indexContent)) { %> <% } } } if ("html".equals(params.format)) { %>
period week day service reading readingType tone comm
data-col="period"><%= period %> data-col="week"><%= week %> data-col="day"><%= day %> data-col="service"><%= service %> data-col="reading"><%= reading %> data-col="readingType"><%= readingType %> data-col="tone"><%= tone %> data-col="comm"><%= comm %>
<%=indexContent%>
<%=f.getDocumentID()%>
<% } /* DataObject query = new DataObject(); String sql = "select DOCUMENTID, USERID, MIN(CREATEDATE) FIRSTCHANGE, MAX(CREATEDATE) LATESTCHANGE, count(1) IMAGECOUNT from SURROGATEIMAGE WHERE 1=1"; if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; query.setValue("USERID", params.userID); } String orderBy = params.sortByDocID ? "DOCUMENTID" : "LATESTCHANGE desc"; sql += " group by DOCUMENTID, USERID order by " + orderBy; if (params.limit != null) sql += " limit " + params.limit; StringBuffer substats = new StringBuffer(); List rows = query.getDataSet(sql); int total1 = 0; for (DataObject r : rows) { if ("html".equals(params.format)) { substats.append(""+r.getIntValue("DOCUMENTID")+""+r.getIntValue("IMAGECOUNT")+""+r.getStringValue("USERID")+""+r.getDateValue("LATESTCHANGE")+""); } else { substats.append(""); } total1 += r.getIntValue("IMAGECOUNT"); } if ("html".equals(params.format)) { results.append("

Images

"); results.append(""); results.append("" + substats.toString() + "
docIDimageCountuserIDlatestChange
"); } else { results.append(""); results.append(substats.toString()); results.append(""); } */ if ("html".equals(params.format)) { response.setContentType("text/html"); out.print(results.toString()); } else { results.append(""); Serializer.output(response, out, params, XMLBlock.createXMLBlock(results.toString())); } return; } else { ((Parameters)params).format = "html"; } Serializer.reportErrors(request, response, out, params, true); %>