%@page contentType="text/html"%>
<%@ page import="gov.globe.tg.*" %>
<%@ page import="gov.globe.tg.torque.*" %>
<%@ page import="java.sql.*" import="java.util.ArrayList"
import="java.util.List" import="org.apache.torque.util.Criteria"
%>
<%@ page errorPage="concepterror.jsp" %>
<%@ taglib uri="WEB-INF/taglib.tld" prefix="set" %>
<% // %>
<%
String contextPath = request.getContextPath();
//create a new pageInfo object for this page.
//PageInfo pageInfo = new PageInfo(request);
//history.update(pageInfo);
//HttpServletRequest req = BreadCrumbUtils.getHistoricPage(request);
//if (req != null) request = req;
//get results from search
String gradelevelIdParam[] = request.getParameterValues("gradelevel");
int invToTaskIds[] = null;
String conceptParam = request.getParameter("concept");
//Revert to the previous sectionId if the the current sectionIdParam is not specified in the request.
if (gradelevelIdParam == null && conceptParam == null) {
gradelevelIdParam = (String[]) session.getAttribute("gradelevel");
conceptParam = (String) session.getAttribute("concept");
}
else {
session.setAttribute("gradelevel", gradelevelIdParam);
session.setAttribute("concept", conceptParam);
}
if (gradelevelIdParam == null && conceptParam == null) {
throw new Exception("Your session has expired. Please start over at the eGuide Homepage" );
}
if (gradelevelIdParam == null && conceptParam == null) {
throw new Exception ("Go back and select a grade level and "
+ "choose either a concept or an investigation area.");
}
else if (gradelevelIdParam == null) {
throw new Exception ("Go back and select a grade level.");
}
else if (conceptParam == null) {
throw new Exception ("Go back and select a concept or an investigation area.");
}
System.out.println("Testing just checking the request?" + request.getParameter("concept"));
//find where the pipe is in the string
int index = conceptParam.indexOf("|");
System.out.println("print conceptParam: " + conceptParam);
//get the concept type and put it in the conceptType object
String conceptType = conceptParam.substring(0,index);
//get the concept id and put it in the conceptId
String conceptId = conceptParam.substring(index + 1);
//populate this with ConceptIdStructures to be displayed later
ConceptStructure conceptStruct = null;
ArrayList conceptIdStructures = new ArrayList();
if ("inv".equals(conceptType)) {
//if this conceptId now equals "inv|" then convert conceptId from a string to an integer:
Integer invid = new Integer(conceptId);
//Now that conceptId is an integer, retrieve an investigation area by primary key given an id represented by object "invid".
InvestigationArea investarea = InvestigationAreaPeer.retrieveByPK(invid);
//create the conceptStructure which is displayed later
conceptStruct = new ConceptStructure();
conceptStruct.conceptHeader = investarea.getName();
//now we get all the tasks the relate to the investigation area
//first we get all the Investigations To Tasks
List invToTasks = investarea.getInvestigationToTasks();
//now we get all the Tasks, that are associated with
//grade level and investigation
//get the taskIds from the investigation to task table.
invToTaskIds = new int[invToTasks.size()];
//cycle through each investigation to task , extracting the task id
//and placing it in the taskIds array
for (int i = 0; i < invToTasks.size(); i++){
InvestigationToTask iToTask = (InvestigationToTask) invToTasks.get(i);
invToTaskIds[i] = iToTask.getTaskId().intValue();
}
//GOAL: get the task id from the gradelevels to task join table
//create a query to get all grade levels to task rows.
Criteria glCrit = new Criteria();
glCrit.addIn(TgGradeLevelsToTaskPeer.GRADELEVELID,gradelevelIdParam);
//execute the query
List gls = TgGradeLevelsToTaskPeer.doSelect(glCrit);
int glToTaskId[] = new int[gls.size()];
//cycle though each grade levels to task row extracting the
//task id, and placing that in the glToTaskId array
for (int i = 0; i < gls.size(); i++){
TgGradeLevelsToTask gltot = (TgGradeLevelsToTask) gls.get(i);
glToTaskId[i] = gltot.getTaskId().intValue();
}
//build the criteria to query the task id
Criteria invCrit = new Criteria();
invCrit.addIn(TgGlobeTaskPeer.TASKID,invToTaskIds);
Criteria c = new Criteria();
c.addIn(TgGlobeTaskPeer.TASKID,glToTaskId);
Criteria andCrit = new Criteria();
andCrit.add(invCrit.getCriterion(TgGlobeTaskPeer.TASKID));
andCrit.and(c.getCriterion(TgGlobeTaskPeer.TASKID));
//query for the tasks
List tasks = TgGlobeTaskPeer.doSelect(andCrit);
//GOAL: get concepts to task
//now we get the conceptToTasks ids
int taskIds[] = new int[tasks.size()];
//cycle through each task, placing its id in the taskIds array
for (int i = 0; i < tasks.size(); i++){
TgGlobeTask tg = (TgGlobeTask) tasks.get(i);
taskIds[i] = tg.getTaskId().intValue();
}
//create the criteria to query for concepts to tasks
invCrit.clear();
//adding the array we just created of conceptToTask ids to the criteria
invCrit.addIn(ConceptToTaskPeer.TASKID, taskIds);
//do the query
List conceptToTasks = ConceptToTaskPeer.doSelect(invCrit);
//GOAL get the criteria
String conceptIds[] = new String[conceptToTasks.size()];
//cycle through each concepttoTask object, extracting the concept
//id into the conceptIds array
for (int i = 0; i < conceptToTasks.size(); i++){
ConceptToTask conceptToTask = (ConceptToTask) conceptToTasks.get(i);
conceptIds[i] = conceptToTask.getConceptCode();
}
//create the criteria
invCrit.clear();
invCrit.addIn(EducationConceptPeer.CONCEPTCODE,conceptIds);
invCrit.addAscendingOrderByColumn(EducationConceptPeer.CONCEPTCODE);
//execute the query
List educationConcepts = EducationConceptPeer.doSelect(invCrit);
//we have all concepts, now we cycle through each of the concepts
//extracting the name and the code, placing those into the
//conceptStructure which is used to display later
for (int i = 0; i < educationConcepts.size(); i++){
EducationConcept concept = (EducationConcept) educationConcepts.get(i);
ConceptIdPair pair = new ConceptIdPair();
pair.conceptName = concept.getConceptName();
pair.conceptCode = concept.getConceptCode();
conceptStruct.conceptIdPairs.add(pair);
}
}
else if ("area".equals(conceptType)) {
//No integer conversion is necessary at this point since the fields we will query are Varchars.
//Retrieve an education area by primary key given an id represented by object "conceptId".
EducationArea educarea = EducationAreaPeer.retrieveByPK(conceptId);
//create the conceptStructure which is displayed later
conceptStruct = new ConceptStructure();
conceptStruct.conceptHeader = educarea.getAreaName();
//now we get all the tasks and concept codes that relate to the education area
//first we get all the concepts associated with the Area from Area To Concepts
List areaToConcepts = educarea.getAreaToConcepts();
//now we get all the Concepts, that are associated with an Areacode
//get the ConceptCode rows from the tg area to concept table.
String conCodes[] = new String[areaToConcepts.size()];
//cycle through each area to concept row , extracting the conceptcodes
//and placing them in the conCodes array
for (int i = 0; i < areaToConcepts.size(); i++){
AreaToConcept aToConcept = (AreaToConcept) areaToConcepts.get(i);
conCodes[i] = aToConcept.getConceptCode();
}
//GOAL: get the task id from the gradelevels to task join table
//create a query to get all grade levels to task rows.
Criteria glCrit = new Criteria();
glCrit.addIn(TgGradeLevelsToTaskPeer.GRADELEVELID,gradelevelIdParam);
//execute the query
List gls = TgGradeLevelsToTaskPeer.doSelect(glCrit);
int glToTaskId[] = new int[gls.size()];
//cycle though each grade levels to task row extracting the
//task id, and placing that in the glToTaskId array
for (int i = 0; i < gls.size(); i++){
TgGradeLevelsToTask gltot = (TgGradeLevelsToTask) gls.get(i);
glToTaskId[i] = gltot.getTaskId().intValue();
}
//build the criteria to query concept_to_tasks
Criteria conCodeCrit = new Criteria();
conCodeCrit.addIn(ConceptToTaskPeer.CONCEPTCODE,conCodes);
Criteria taskIdCrit = new Criteria();
taskIdCrit.addIn(ConceptToTaskPeer.TASKID,glToTaskId);
Criteria andCrit = new Criteria();
andCrit.add(conCodeCrit.getCriterion(ConceptToTaskPeer.CONCEPTCODE));
andCrit.and(taskIdCrit.getCriterion(ConceptToTaskPeer.TASKID));
//execute query
List cttConCodes = ConceptToTaskPeer.doSelect(andCrit);
String edConCodes[] = new String[cttConCodes.size()];
//cycle though each concept to task row extracting the
//conceptcode, and placing that in the edConCode array
for (int i = 0; i < cttConCodes.size(); i++){
ConceptToTask ccContot = (ConceptToTask) cttConCodes.get(i);
edConCodes[i] = ccContot.getConceptCode();
}
//create the criteria
conCodeCrit.clear();
conCodeCrit.addIn(EducationConceptPeer.CONCEPTCODE,edConCodes);
conCodeCrit.addAscendingOrderByColumn(EducationConceptPeer.CONCEPTCODE);
//execute the query
List educationConcepts = EducationConceptPeer.doSelect(conCodeCrit);
//we have all concepts, now we cycle through each of the concepts
//extracting the name and the code, placing those into the
//conceptStructure which is used to display later
for (int i = 0; i < educationConcepts.size(); i++){
EducationConcept concept = (EducationConcept) educationConcepts.get(i);
ConceptIdPair pair = new ConceptIdPair();
pair.conceptName = concept.getConceptName();
pair.conceptCode = concept.getConceptCode();
conceptStruct.conceptIdPairs.add(pair);
}
}
//query for grade levels
Criteria glCrit = new Criteria();
glCrit.addIn(TgGradeLevelsPeer.GRADELEVELID,gradelevelIdParam);
glCrit.addAscendingOrderByColumn(TgGradeLevelsPeer.GRADELEVELID);
List gradelevlist = TgGradeLevelsPeer.doSelect(glCrit);
//iterate through list to form part of the get request parms
StringBuffer sb = new StringBuffer();
for (int i = 0 ; i < gradelevelIdParam.length; i++){
sb.append("gradeLevelId=");
sb.append(gradelevelIdParam[i]);
sb.append("&");
}
String gradeGetRequest = sb.toString();
//}
//For breadcrumbs add:
//pageInfo.setTitle(conceptStruct.conceptHeader + " Concepts");
%>
GLOBE eGuide Concept Search Results
<% //%>
> <%=conceptStruct.conceptHeader%> Concepts
<%=conceptStruct.conceptHeader%> Concepts
for
<%
for (int i = 0 ; i < gradelevlist.size(); ){
TgGradeLevels tggl = (TgGradeLevels) gradelevlist.get(i);
out.print(tggl.getGradeLevel());
//next to last element
if (i == gradelevlist.size() - 2) {
out.print(" and ");
}
//last element
else if (i == gradelevlist.size() - 1){
}
//all others
else if (i < gradelevlist.size()) {
out.print(", ");
}
i++;
}
%> Grades
Click a concept to retrieve related GLOBE protocols and learning activities.
Concept List
<%
//cycle through tg_investigation_area
String tgToTaskGet = null;
if (invToTaskIds == null) {
tgToTaskGet = "";
}
else {
StringBuffer sb2 = new StringBuffer("&invToTask=");
for (int i = 0; i < invToTaskIds.length; i++){
sb2.append(invToTaskIds[i]);
if (i < invToTaskIds.length - 1) {
sb2.append(',');
}
}
tgToTaskGet = sb2.toString();
}
//cycle through concepts
for (int i = 0 ; i < conceptStruct.conceptIdPairs.size(); i++){
ConceptIdPair pair = (ConceptIdPair) conceptStruct.conceptIdPairs.get(i);
%>
<%!
private class ConceptIdPair {
public String conceptName;
public String conceptCode;
}
private class ConceptStructure {
public String conceptHeader;
public ArrayList conceptIdPairs = new ArrayList();
}
%>