<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.Segment" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.SegmentReading" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.SegmentReading.ReadingWord" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.WitnessReading" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.Convert" %> <%@ page import="org.crosswire.utils.Utils" %> <%@ page import="org.crosswire.data.DataObject" %> <%@ page import="org.crosswire.utils.HTTPUtils" %> <%@ page import="org.crosswire.sword.keys.VerseKey" %> <%@ page import="org.crosswire.sword.keys.ListKey" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Vector" %> <%@ page import="java.util.UUID" %> <%@ page import="java.util.Collections" %> <%@ page import="java.util.Arrays" %> <%@ page import="org.apache.log4j.Logger" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="javax.validation.constraints.NotNull" %> <%! @Description(value = "Search variant apparatus data", name = "variant/apparatus/search") public static class MyParameters extends Parameters { protected ProjectManagement.Project project = null; @NotNull @Description(value = "which range of apparatus to search", example = "Acts.4") public String indexContent = null; @Description(value = "limit results to a specific segmentGroupID; -1 = all", defaultValue = "-1", example = "3") public Integer segmentGroupID = null; @Description(value = "Project Name from which data should be retrieved (i.e., lookup the project segmentGroupID by project name)", example = "ECM Matthew") public String projectName; @Description(value = "whether or not to include a unique document list mentioned across the {indexContent}", defaultValue = "false", example = "true") public Boolean uniqueDocList = false; @Description(value = "first document in query", example = "10046") public Integer docID = null; @Description(value = "first document condition; 1 - in a reading not 'a' and not 'zz'; 2 - in a reading not 'a'; 3 - in reading 'zz'; 4 - in reading not 'zz'", example = "4") public Integer condition = null; @Description(value = "second document in query", example = "10047") public Integer docID2 = null; @Description(value = "second document condition; 1 - agrees with first docID witness'; 2 - does not agree with first docID witness and reading not 'zz'", example = "1") public Integer condition2 = null; @Override protected void customValidation() { projectName = Transcription.assureUnicode(projectName); project = segmentGroupID != null ? ProjectManagement.getProject(segmentGroupID) : projectName != null ? ProjectManagement.getProject(projectName) : null; if (segmentGroupID == null && project != null) segmentGroupID = project.getProjectID(); } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0) { StringBuffer bcSQL = new StringBuffer(); StringBuffer projSQL = new StringBuffer(); DataObject query = new DataObject(); if (params.indexContent != null) { VerseKey verse = new VerseKey("Gen.1.1"); verse.setIntros(true); ListKey verses = verse.ParseVerseList(params.indexContent, verse.toString(), true); if (verses.getCount() > 0) { bcSQL.append(" AND ("); for (int i = 0; i < verses.getCount(); ++i) { VerseKey verseKey = (VerseKey) verses.getElement(i); if (i > 0) bcSQL.append(" OR "); bcSQL.append(" (S.VERSE>={VERSEMIN" + i + "} AND S.VERSE<={VERSEMAX" + i + "}) "); query.setIntValue("VERSEMIN" + i, verseKey.getLowerBound().getHashNumber()); query.setIntValue("VERSEMAX" + i, verseKey.getUpperBound().getHashNumber()); } bcSQL.append(" ) "); } } if (params.project != null) { projSQL.append(" AND SGS.SEGMENTGROUPID = {SEGMENTGROUPID}"); query.setIntValue("SEGMENTGROUPID", params.project.getProjectID()); } StringBuffer retVal = new StringBuffer(); retVal.append(""); if (params.condition != null) { StringBuffer sql = new StringBuffer("SELECT distinct VERSE, CONTEXTDESCRIPTION, READINGNAME from SEGMENTREADINGWITNESS SRW left join SEGMENTREADING SR on SRW.SEGMENTID = SR.SEGMENTID and SRW.SEGMENTREADINGID = SR.SEGMENTREADINGID left join SEGMENT S on S.SEGMENTID=SR.SEGMENTID left join SEGMENTGROUPSEGMENT SGS on S.SEGMENTID = SGS.SEGMENTID where SRW.DOCUMENTID > 1000"); sql.append(bcSQL); sql.append(projSQL); switch (params.condition) { case 1: sql.append(" and DOCUMENTID=" + params.docID + " and READINGNAME not in ('a', 'zz')"); break; } if (params.condition2 != null) { switch (params.condition2) { case 1: sql.append(" and exists (select 1 from SEGMENTREADINGWITNESS WHERE DOCUMENTID=" + params.docID2 + " and SEGMENTID=SRW.SEGMENTID and SEGMENTREADINGID=SRW.SEGMENTREADINGID)"); break; case 2: sql.append(" and exists (select 1 from SEGMENTREADINGWITNESS SRW2 left join SEGMENTREADING SR2 on SR2.SEGMENTID=SRW2.SEGMENTID AND SR2.SEGMENTREADINGID=SRW2.SEGMENTREADINGID WHERE SRW2.DOCUMENTID=" + params.docID2 + " and SRW2.SEGMENTID=SRW.SEGMENTID and SRW2.SEGMENTREADINGID<>SRW.SEGMENTREADINGID AND READINGNAME not in ('zz'))"); break; } } sql.append(" ORDER BY VERSE"); params.getLogger().info("sql: " + sql); List rows = query.getDataSet(sql.toString()); VerseKey vk = new VerseKey(); vk.setIntros(true); for (DataObject r : rows) { vk.setHashNumber(r.getIntValue("VERSE")); retVal.append(""); } } if (params.uniqueDocList != null && params.uniqueDocList == true) { StringBuffer sql = new StringBuffer("SELECT distinct SRW.DOCUMENTID, D.GANUMBER from SEGMENTREADINGWITNESS SRW left join SEGMENT S on S.SEGMENTID=SRW.SEGMENTID LEFT JOIN SEGMENTGROUPSEGMENT SGS on SGS.SEGMENTID = S.SEGMENTID LEFT JOIN DOCUMENT D on D.DOCUMENTID=SRW.DOCUMENTID where SRW.DOCUMENTID > 1000"); sql.append(bcSQL); sql.append(projSQL); sql.append(" ORDER BY SRW.DOCUMENTID"); List rows = query.getDataSet(sql.toString()); retVal.append(""); for (DataObject r : rows) { retVal.append(""); } retVal.append(""); } retVal.append(""); Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString())); } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>