<%-- #RevizeProperties USE REVIZE MENU (DOCUMENT PROPERTIES) TO EDIT DATA BELOW: status=edit options= server=localhost:8080 projectName=calendar_app label=calendar_mapping_update_editform location=calendar_app/editpages/calendar_mapping_update-editform.jsp version=3 docType=editpage subType=form moduleName=calendar_mapping fieldName= channels=revize| description= --%><%-- #BeginRZ-PageHeader --%><%@ page language="java" %><% String rzmodule = "calendar_mapping"; %><%@ include file = "/util/setup_editform_header.jsp" %><%-- #EndRZ-PageHeader --%> Mapping Update <%-- ___________________________________________________________________________________ Update mapping table by adding or updating existing mapping records. For details on overall mapping strategy, see: calendar_db_data.rzt Mapping must be updated for the following scenarios: 1) new event (not needed for new calendar or newe group) events editform 2) all edits if rollup changes calendar & event editforms Input Parameters: eventids Event id(s) as of 03-25-2012 only single event supported calendarids calendar ids to map to event: i.e. master and event calendar id and any rollup selections that currently show events from this calendar TODO: may need to be any rollup calendars selected NOT allowed; activedatatemplate will ignore if not allowed year_month list of month dates separated by commas year_week list of week dates separated by commas set=eventid=-1 dummy events record to forces publish of calendar_db_names.xml (propably not needed; see calendar_db_names for more details) Example nexturl: http://localhost:8080/revize/calendar_app/calendar_view_common/calendar_mapping-editform.jsp ?module=calendar_mapping&set=eventid%3D-1 &eventid=253&year_month=201201,201202&year_week=201201,2012xx,...&calenderids=20|42 ___________________________________________________________________________________ --%> <%@ include file="/util/setup_editform_javascript.jsp" %> <%@ include file="/plugins/calendar/calendar3.head_version_include.jsp" %><%-- //-------------------------------------------------------------------------------\\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DW use only (below tags NOT published); required files loaded during page setup * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --%><% if (false) { %> <% } %><%-- \\-------------------------------------------------------------------------------// --%><% /**********************************/ /*BOOKMARK Page specific JSP Code*/ /********************************/ LOADING = "Updating Database..."; // fetch does not always work after delete code runs ??? String counter = rz.fetch("calendar_mapping","counter"); %><%@ page import = "java.util.Vector, contentimporter.Importer" %><% boolean nodebug = request.getParameter("nodebug") != null; if (nodebug) debug = false; //override debug for this page // INPUT: returnurl = StringUtils.getParameter(request,"returnurl"); calendarids = StringUtils.split( StringUtils.getParameter(request,"calendarids") , ","); eventids = StringUtils.split( StringUtils.getParameter(request,"eventids") , ","); year_month = StringUtils.getParameter(request,"year_month"); year_months = StringUtils.split(year_month,","); monthCount = year_months.length; year_week = StringUtils.getParameter(request,"year_week"); year_weeks = StringUtils.split(year_week,","); weekCount = year_weeks.length; // OUTPUT variables notes = ""; errMsg = ""; requestDesc = ""; eventname = ""; String mappingLegion = "legend:
mapid:calid:evtid-->month~week
"; calendarIdsMsg = ""; currentMappingCount = 0; currentMappingMsg = mappingLegion; addIdCount = 0; addIdsMsg = mappingLegion; deleteIdCount = 0; deleteIdsMsg = mappingLegion; // initialize work variables (shared with functions) eventNames = new HashMap(); calendarNames = new HashMap(); currentMapping = new TreeMap(); //keep sorted by calendarid neededMapping = new ArrayList3D(); // work variables (NOT shared with functions) int i,j,k; Vector recordsDeleted = new Vector(); Vector fieldNames = new Vector(); Vector fieldTypes = new Vector(); Vector recordsAdded = new Vector(); %><%! // INPUT: String returnurl; String [] calendarids; String [] eventids; String year_month; String [] year_months; String year_week; String [] year_weeks; int monthCount; int weekCount; // OUTPUT variables String notes; String errMsg; String requestDesc; String eventname; String calendarIdsMsg; int currentMappingCount; String currentMappingMsg; int addIdCount; String addIdsMsg; int deleteIdCount; String deleteIdsMsg; //TODO: delete boolean hasDateChangedMonth; boolean hasDateChangedWeek; int outOfDateCount; // work variables (shared with functions) initialized above HashMap eventNames; HashMap calendarNames; TreeMap currentMapping; ArrayList3D neededMapping; int WEEK = 0; int MONTH = 1; // work variables (shared with function - initialize in code when used) int count; String filter; String calid; String evtid; String mapid; Iterator iter; String activemonthsdata_filename; String activeweeksdata_filename; String month; String week; String periods; /*----------------------------------------------------------------------------- 3/4 Dimentional ArrayList; calendarid,eventid,MONTH|WEEK references an ArrayList which contains a list of year_month or year_week respectively. Foundation Credit (2D example base): http://www.javaprogrammingforums.com/java-programming-tutorials/696-multi-dimension-arraylist-example.html -----------------------------------------------------------------------------*/ /*BOOKMARK class ArrayList3D*/ class ArrayList3D { ArrayList array; ArrayList3D() { array = new ArrayList(); } ArrayList get3rdArrayList(int calendarid, int eventid, int periodid) { while (calendarid >= array.size()) array.add(new ArrayList()); ArrayList calendars = (ArrayList)array.get(calendarid); while (eventid >= calendars.size()) calendars.add(new ArrayList()); ArrayList events = (ArrayList)calendars.get(eventid); while (periodid >= events.size()) events.add(new ArrayList()); ArrayList periods = (ArrayList)events.get(periodid); return periods; } Object get(String calendarid, String eventid, int periodid) { int cid = StringUtils.toInt(calendarid); int eid = StringUtils.toInt(eventid); return get(cid,eid,periodid); } Object get(int calendarid, int eventid, int periodid) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); if (periods.size() == 0) return null; else return periods.get(0); } String add(String calendarid, String eventid, int periodid, Object data) { int cid = StringUtils.toInt(calendarid); int eid = StringUtils.toInt(eventid); return cid + ":" + eid + ":" + periodid + "=" + add(cid,eid,periodid,data); } String add(int calendarid, int eventid, int periodid, Object data) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); periods.add(data); return data + ""; } void set(int calendarid, int eventid, int periodid, Object data) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); periods.set(periodid,data); } void remove(String calendarid, String eventid, int periodid, Object data) { int calid = new Integer(calendarid).intValue(); int evtid = new Integer(eventid).intValue(); ArrayList periods = get3rdArrayList(calid, evtid, periodid); periods.remove(data); } void remove(int calendarid, int eventid, int periodid, Object data) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); periods.remove(data); } int size(int calendarid, int eventid, int periodid) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); return periods.size(); } int indexOf(String calendarid, String eventid, int periodid, Object data) { int calid = new Integer(calendarid).intValue(); int evtid = new Integer(eventid).intValue(); ArrayList periods = get3rdArrayList(calid, evtid, periodid); return periods.indexOf(data+""); } int indexOf(int calendarid, int eventid, int periodid, Object data) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); return periods.indexOf(data); } boolean contains(String calendarid, String eventid, int periodid, Object data) { int calid = new Integer(calendarid).intValue(); int evtid = new Integer(eventid).intValue(); ArrayList periods = get3rdArrayList(calid, evtid, periodid); return periods.contains(data); } boolean contains(int calendarid, int eventid, int periodid, Object data) { ArrayList periods = get3rdArrayList(calendarid, eventid, periodid); return periods.contains(data); } boolean contains(Object data) { for (int i = 0; i < array.size(); i++) { for (int j=0; j< ((ArrayList)((ArrayList)array).get(i)).size(); j++) if (((ArrayList)((ArrayList)array).get(i)).contains(data)) return true; } return false; } String dump() { String text = "ArrayList3D Dump:\n"; for (int calendarid=0;calendarid 1) //multiple calendarids { if (calendarNames.get(calid) != null && count <= 10) calendarDisplay = calendarNames.get(calid) + "[" + calendarDisplay + "]"; } // show eventid; include name on 1st 10 when multiple events eventDisplay = ""; if (evtid != null) { eventDisplay = evtid; if (eventNames.get(evtid) != null && count <= 10 && evtid.indexOf(",") != -1) { eventDisplay = eventNames.get(evtid) + ""; if (eventDisplay.length() > 15) eventDisplay = eventDisplay.substring(0,15) + "..."; eventDisplay = eventDisplay.trim() + "[" + evtid + "]"; } } // show yearMonth and weekMonth on first 10 periodsDisplay = ""; if (periods != null && count <= 10) { periodsDisplay = "-->" + periods; periodsDisplay = periodsDisplay.replaceAll("\\|","~"); periodsDisplay = periodsDisplay.replaceAll(",","-"); //should not appear } // combine calendar, event, mapip & periods // master[calendarid]:mapid|yearMonth|yearWeek html = calendarDisplay; if (evtid != null) html += (html.length() > 0 ? ":" : "") + eventDisplay; if (mapid != null) html = mapid + ":" + html; if (periods != null) html += periodsDisplay; html += ", "; return html; } /*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ void buildActiveDataFilenames(String calid, String year_month, String year_week) { activemonthsdata_filename = ""; activeweeksdata_filename = ""; // convert yyyym to yyyy-mm (mm 1 based with leading 0 e.g. 2005-01 for Jan) if (year_month.length() > 0) activemonthsdata_filename = "calendar_" + calid + "_activemonthsdata_" + year_month.substring(0,4) + "-" + year_month.substring(4) + ".xml"; // convert yyyyw to yyyy-ww (ww 1 based with leading 0 e.g. 2005-01 for 1st week) if (year_week.length() > 0) activeweeksdata_filename = "calendar_" + calid + "_activeweeksdata_" + year_week.substring(0,4) + "-" + year_week.substring(4) + ".xml"; } /*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ String trim(String msg) { if (msg.endsWith(", ")) msg = msg.substring(0,msg.length()-2); return msg; } %><% /*BOOKMARK ----- scan CALENDAR_NAMES*/ //--------------------------------------------------------------------- // Scan CALENDAR_NAMES for all calendar names // Build filter for calendar_events scan if multiple calendarids //--------------------------------------------------------------------- filter = ""; //build filter for events scan if no events specified rz.listsetup("calendar_names", "noemptylistmessage", "", ""); while ( rz.listnext() ) { if (rz.listindex < 0) break; rz.fetch("calendar_names","calendar_name"); calid = rz.recordid; if (rz.content.indexOf("..no") != -1 //invalid record || rz.content.indexOf("Data Error Reading List Records") >=0) errMsg = "calendar_names data unavailable"; else { calendarNames.put(calid,rz.content); filter += ",calid=" + calid; // for all specified calendars if (rz.checkoptions( StringUtils.join(calendarids,","), calid )) calendarIdsMsg = rz.content + "[" + rz.recordid + "], "; } } calendarIdsMsg = trim(calendarIdsMsg); /*BOOKMARK ----- scan CALENDAR_EVENTS*/ //--------------------------------------------------------------------- // Scan CALENDAR_EVENTS for all specified eventids; save event names // if no eventids specified, scan for all eventids (including orphans) //--------------------------------------------------------------------- //TODO: if no eventids, rebuild for all or specified calendarids count = 0; filter = ""; if (eventids.length == 0) { rz.listsetup("calendar_events", "noemptylistmessage", filter, ""); while ( rz.listnext() ) { if (rz.listindex < 0) break; } } // As of 03-24-2012, only supports single eventid for (i=0;i<% while ( rz.listnext() ) { if (rz.listindex < 0) break; %><% calid = rz.fetch("calendar_mapping", "calendarid"); evtid = rz.fetch("calendar_mapping", "eventid"); mapid = rz.recordid; month = rz.fetch("calendar_mapping","year_month"); week = rz.fetch("calendar_mapping","year_week"); // event not in this calendar OR not in year_month or year_week if (!rz.checkoptions( StringUtils.join(calendarids,",") ,calid) || (month.length() > 0 && !neededMapping.contains(calid,evtid,MONTH,month)) || (week.length() > 0 && !neededMapping.contains(calid,evtid,WEEK,week))) { recordsDeleted.addElement(new Integer(mapid)); deleteIdsMsg += formatDisplay(calid,evtid,mapid,periods).replaceAll(", ","
"); } // remove mapping from needed month or week list if still in list else { if (month.length() > 0 && neededMapping.contains(calid,evtid,MONTH,month)) neededMapping.remove(calid,evtid,MONTH,month); if (week.length() > 0 && neededMapping.contains(calid,evtid,WEEK,week)) neededMapping.remove(calid,evtid,WEEK,week); } periods = month + "|" + week; currentMappingCount++; currentMappingMsg += formatDisplay(calid,evtid,mapid,periods).replaceAll(", ","
"); %>
<% }%>
<% deleteIdCount = recordsDeleted.size(); deleteIdsMsg = trim(deleteIdsMsg); //currentMappingCount = rz.listlength; currentMappingMsg = trim(currentMappingMsg); /*BOOKMARK ----- ADD MAPPING records*/ //--------------------------------------------------------------------- // build list of mapping records still needed // and eventids which includes existing mapping records that must be updated. //--------------------------------------------------------------------- fieldNames.addElement("eventid"); fieldNames.addElement("year_month"); fieldNames.addElement("year_week"); fieldNames.addElement("calendarid"); fieldNames.addElement("activemonthsdata_filename"); fieldNames.addElement("activeweeksdata_filename"); //fieldNames.addElement("counter"); fieldTypes.addElement("NUMBER"); fieldTypes.addElement("TEXT"); fieldTypes.addElement("TEXT"); fieldTypes.addElement("NUMBER"); fieldTypes.addElement("TEXT"); fieldTypes.addElement("TEXT"); //fieldTypes.addElement("NUMBER"); //counter: contains RZ.calendar.now.getTime() String now = (new GregorianCalendar()).getTime()+""; //----- for all specified calendars for (i=0;i 0) { notes += "

* " + deleteIdCount + " existing mapping record(s) must be updated."; } boolean dbUpdated = (recordsDeleted.size() > 0 || recordsAdded.size() > 0); if (!dbUpdated) notes += "

"; //--------------------------------------------------------------------- // ********** Update database if NOT debug mode ********** //--------------------------------------------------------------------- if (!debug) { Importer importer = new Importer(); if (recordsDeleted.size() > 0) importer.delete( rz.webspace, "calendar_mapping", recordsDeleted ); if (recordsAdded.size() > 0) importer.insert(rz.webspace,"calendar_mapping", fieldNames, fieldTypes, recordsAdded, true); } String SAVE_RETURN = "refreshData()"; /************************************/ /*BOOKMARK Page specific JavaScript*/ /**********************************/ %> <%-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DELETE standard javascript include file after the body tag (if shown above); it is included in the head section for edit pages and not used on templates. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --%>

Debug Mode pause on this URL
location.href
Event Id / Name: <%=StringUtils.join(eventids,", ")%> <%=eventname%> 
Event MUST be mapped to <%=calendarids.length%> Calendar(s): <%=calendarIdsMsg%> 
Event MUST be mapped to <%=monthCount%> Month(s): <%=year_month.replaceAll(",",", ")%> 
Event MUST be mapped to <%=weekCount%> Week(s): <%=year_week.replaceAll(",",", ")%> 
Event CURRENTLY has <%=currentMappingCount%> Mapping record(s): <%=currentMappingMsg%> 
   
<%=(deleteIdCount > 0)?"*":""%> <%=deleteIdCount%> Calendar mapping records to Update / Delete: <%=deleteIdsMsg%> 
<%=(deleteIdCount > 0)?"*":""%> <%=addIdCount%> Calendar mapping records to Add: <%=addIdsMsg%> 
Database update required: <%=dbUpdated ? "YES" : "no"%> 
calendar_mapping.counter:

<%=notes%>

nexturl: