|
From: Michael K. <ko...@us...> - 2006-10-18 16:49:28
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv23857/util/migration Added Files: CourseMigration.java Log Message: --- NEW FILE: CourseMigration.java --- /** * Copyright (c) 2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software * License, either version 1.0 of the License, or (at your option) any * later version (see www.cobricks.de). * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. */ package org.cobricks.util.migration; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.math.BigDecimal; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import org.apache.log4j.Logger; import org.cobricks.core.ComponentDirectory; import org.cobricks.core.CoreManager; import org.cobricks.core.db.DBAccess; import org.cobricks.core.util.DateUtil; import org.cobricks.core.util.IOUtil; import org.cobricks.course.Course; import org.cobricks.course.CourseManager; import org.cobricks.course.CourseModule; import org.cobricks.course.CourseRoom; import org.cobricks.user.User; import org.cobricks.user.UserManager; /** * This class is used for migration of the course data from the Cobricks 1 * to Cobricks 2 platform */ public class CourseMigration { static Logger logger = Logger.getLogger(CourseMigration.class); private FromDBAccess fromDBAccess; private DBAccess toDBAccess; private Properties old2newItemId = new Properties(); private ComponentDirectory compDir; private CourseManager courseManager; public CourseMigration(FromDBAccess fromDB, CoreManager coreManager) { this.fromDBAccess = fromDB; toDBAccess = coreManager.getDBAccess(); ComponentDirectory compDir = coreManager.getComponentDirectory(); if (compDir != null) { courseManager = (CourseManager) compDir.getManager("courseManager"); } } public void migrate() { logger.info(">>>>>>>>>>> Starting course migration <<<<<<<<<<<<<"); migrateCourses(); } public void emptyDestinationTables() { logger.info(">>>>>>>>>>> Starting emptying course tables <<<<<<<<<<<"); toDBAccess.sqlExecute("DELETE FROM course"); toDBAccess.sqlExecute("DELETE FROM course_date"); toDBAccess.sqlExecute("DELETE FROM course_lecturerrel"); toDBAccess.sqlExecute("DELETE FROM course_notes"); toDBAccess.sqlExecute("DELETE FROM course_timetable"); logger.info(">>>>>>>>>>> Finished emptying item tables <<<<<<<<<<<"); } private void migrateCourses() { List result = fromDBAccess. sqlQuery("SELECT * FROM veranstaltung, veranstklasse " +"WHERE veranstaltung.klid = veranstklasse.klid " +"AND vajahr = 2006 AND vasem='WS'"); Iterator resIter = result.iterator(); while(resIter.hasNext()) { Map fromMap = (Map)resIter.next(); Map toMap = new HashMap(); try { Object o = fromMap.get("vaid"); if (o==null) continue; String vaid = o.toString(); // search module in target database String title = (String)fromMap.get("klname"); if (title == null) continue; // TBD: special handling for "keine Zuordnung bekannt", klid=0 // TBD: special handling for NULL, klid=0 int pos = title.indexOf("(IN"); if (pos < 1) continue; int pos2 = title.indexOf(")", pos); if (pos2 < 1) continue; String mshort = title.substring(pos+1, pos2); Map sattrs = new HashMap(); sattrs.put("cmsid", mshort); List resultcm = courseManager. searchCourseModules(sattrs, "cmname"); CourseModule cm = null; if (resultcm!=null && resultcm.size()>0) cm = (CourseModule)(resultcm.iterator().next()); if (cm == null) { logger.warn("failed accessing course module >"+mshort+"<"); continue; } // create course in target database Map attrs = new HashMap(); Integer tmpi = null; String tmps = null, tmps2 = null; // cmid(Integer), cterm, cname, cname_en, ccomment, clang, // curl, ccapacity(Integer), cectscredits(BigDecimal), // cexaminername, cexaminerid, // chours_lec, chours_ex, chours_sem, chours_lab attrs.put("cmid", new Integer(cm.getId())); tmpi = getIntObject(fromMap, "vajahr"); tmps = (String)fromMap.get("vasem"); String cterm = tmpi.toString(); if (tmps.equals("WS")) cterm+="w"; else cterm+="s"; attrs.put("cterm", cterm); tmps = (String)fromMap.get("vauntertitel"); if (tmps!=null && tmps.length()>0) attrs.put("cname", tmps); tmps = (String)fromMap.get("vauntertitel_en"); if (tmps!=null && tmps.length()>0) attrs.put("cname_en", tmps); tmps = (String)fromMap.get("lang"); attrs.put("clang", tmps); tmps = (String)fromMap.get("vacomment"); attrs.put("ccomment", tmps); tmps = (String)fromMap.get("vaurl"); attrs.put("curl", tmps); tmpi = getIntObject(fromMap, "vateilno"); attrs.put("ccapacity", tmpi); o = fromMap.get("vaectscredits"); if (o!=null) o = new BigDecimal(o.toString()); attrs.put("cectscredits", o); tmpi = getIntObject(fromMap, "vasws"); attrs.put("chours_lec", tmpi); tmpi = getIntObject(fromMap, "vaswsueb"); attrs.put("chours_ex", tmpi); tmpi = getIntObject(fromMap, "vaswssem"); attrs.put("chours_sem", tmpi); tmpi = getIntObject(fromMap, "vaswslab"); attrs.put("chours_lab", tmpi); // lecturers List result2 = fromDBAccess. sqlQuery("SELECT * FROM bietetan, dozent " +"WHERE bietetan.vaid = "+vaid +" AND bietetan.doid = dozent.doid"); int lcount = 0; Iterator resIter2 = result2.iterator(); List lecturers = new ArrayList(); while (resIter2.hasNext()) { lcount++; // doname, dounivisid, dotyp, dovorname, doteilbereich // doimageurl, dourl Map m = (Map)resIter2.next(); tmps = (String)m.get("doname"); tmps2 = (String)m.get("dovorname"); if (tmps2!=null) { tmps = tmps + ", "+tmps2; } int lid = courseManager.getLecturerIdByName(tmps); if (lid < 1) { logger.error("- create entry for lecturer "+tmps); // create new entry for lecturer Map attrs2 = new HashMap(); tmps = (String)m.get("doname"); if (tmps!=null) attrs2.put("llastname", tmps); tmps = (String)m.get("dovorname"); if (tmps!=null) attrs2.put("lfirstname", tmps); tmps = (String)m.get("dotyp"); if (tmps!=null) attrs2.put("ltyp", tmps); tmps = (String)m.get("doteilbereich"); if (tmps!=null) attrs2.put("lgroup", tmps); tmps = (String)m.get("dounivisid"); if (tmps!=null) attrs2.put("lextid", tmps); tmps = (String)m.get("dourl"); if (tmps!=null) attrs2.put("lurl", tmps); tmps = (String)m.get("doimageurl"); if (tmps!=null) attrs2.put("limageurl", tmps); lid = courseManager.createLecturer(attrs2, null); } if (lid > 0) { lecturers.add(new Integer(lid)); } } attrs.put("lecturers", lecturers); result2 = fromDBAccess. sqlQuery("SELECT * FROM termin, raum " +"WHERE vaid = "+vaid +" AND termin.teraid = raum.raid"); int dcount = 0; resIter2 = result2.iterator(); while (resIter2.hasNext()) { dcount++; // teanstd, teanmin, tewotag, teenstd, teenmin, // teturnus, tetyp, tedat // raname, raunivisid, rainfo, rateilbereich, rahidden, // raverantw Map m = (Map)resIter2.next(); o = getIntObject(m, "tewotag"); if (o != null) { o = new Integer(((Integer)o).intValue()+1); } attrs.put("dweekday"+Integer.toString(dcount), o); o = getIntObject(m, "teanstd"); attrs.put("dstarthour"+Integer.toString(dcount), o); o = getIntObject(m, "teanmin"); attrs.put("dstartmin"+Integer.toString(dcount), o); o = getIntObject(m, "teenstd"); attrs.put("dendhour"+Integer.toString(dcount), o); o = getIntObject(m, "teenmin"); attrs.put("dendmin"+Integer.toString(dcount), o); o = getDateObject(m, "tedat"); attrs.put("dstartdate"+Integer.toString(dcount), o); o = getIntObject(m, "tetyp"); attrs.put("dtype"+Integer.toString(dcount), o); o = getIntObject(m, "teturnus"); attrs.put("dcycle"+Integer.toString(dcount), o); tmps = (String)m.get("raname"); if (tmps != null) { sattrs = new HashMap(); sattrs.put("crname", tmps); List rooms = courseManager.searchRooms(sattrs); if (rooms!=null && rooms.size()>0) { CourseRoom cr = (CourseRoom) rooms.iterator().next(); o = new Integer(cr.getId()); attrs.put("droom"+Integer.toString(dcount), o); } else { // create new room object Map attrs2 = new HashMap(); tmps = (String)m.get("raname"); if (tmps!=null) attrs2.put("crname", tmps); tmps = (String)m.get("raunivisid"); if (tmps!=null) attrs2.put("crextid", tmps); tmps = (String)m.get("rainfo"); if (tmps!=null) attrs2.put("crinfo", tmps); tmps = (String)m.get("raverantw"); if (tmps!=null) attrs2.put("crcontact", tmps); int rid = courseManager.createRoom(attrs2, null); if (rid > 0) { o = new Integer(rid); attrs.put("droom"+Integer.toString(dcount), o); } } } } int cid = courseManager.createCourse(attrs, null); } catch(Exception ex){ logger.error("Failed migrating course", ex); } } // while end } private Integer getIntObject(Map map, String aname) { Object o = map.get(aname); if (o == null) return null; if (o instanceof Integer) return (Integer)o; String tmps = o.toString().trim(); if (tmps.length()<1) return null; try { o = new Integer(Integer.parseInt(tmps)); } catch (Exception e) { return null; } return (Integer)o; } private Date getDateObject(Map map, String aname) { Object o = map.get(aname); if (o == null) return null; if (o instanceof Date) return (Date)o; String tmps = o.toString().trim(); if (tmps.length()<1) return null; o = DateUtil.string2Date(tmps); return (Date)o; } } |
|
From: Michael K. <ko...@us...> - 2006-11-24 08:06:06
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv375/src/org/cobricks/util/migration Modified Files: CourseMigration.java Log Message: Index: CourseMigration.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration/CourseMigration.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CourseMigration.java 18 Oct 2006 16:49:22 -0000 1.1 +++ CourseMigration.java 24 Nov 2006 08:06:00 -0000 1.2 @@ -39,6 +39,8 @@ import org.cobricks.course.Course; import org.cobricks.course.CourseManager; import org.cobricks.course.CourseModule; +import org.cobricks.course.CourseModuleProgramRel; +import org.cobricks.course.CourseProgram; import org.cobricks.course.CourseRoom; import org.cobricks.user.User; import org.cobricks.user.UserManager; @@ -151,6 +153,8 @@ tmps = (String)fromMap.get("vauntertitel_en"); if (tmps!=null && tmps.length()>0) attrs.put("cname_en", tmps); + + logger.info("createCourse "+cm.getName()+" - "+tmps); tmps = (String)fromMap.get("lang"); attrs.put("clang", tmps); @@ -281,7 +285,64 @@ } int cid = courseManager.createCourse(attrs, null); - + + // additional course programs? + + List result3 = fromDBAccess. + sqlQuery("SELECT * FROM veranstberzuordnung, " + +"veranstbereiche " + +"WHERE klid = " + fromMap.get("klid") + +" AND veranstberzuordnung.berid = " + +"veranstbereiche.berid"); + Iterator resIter3 = result3.iterator(); + while (resIter3.hasNext()) { + Map m = (Map)resIter3.next(); + String id = (String)m.get("berprogid"); + + // check if course program exists + CourseProgram cp = courseManager.getProgramForLabel(id); + if (cp == null) { + Map attrs2 = new HashMap(); + attrs2.put("cplabel", id); + String tmps3 = (String)m.get("bername"); + if (tmps3 == null) tmps3 = id; + attrs2.put("cpname", tmps3); + tmps3 = (String)m.get("bername_en"); + if (tmps3 == null) tmps3 = id; + attrs2.put("cpname_en", tmps3); + tmps3 = (String)m.get("bercomment"); + if (tmps3 != null) { + attrs2.put("cpcomment", tmps3); + } + int cpid = courseManager.createProgram(attrs2, null); + cp = courseManager.getProgramForLabel(id); + } + + // check if course program is assigned to module + boolean foundit = false; + List cprl = cm.getProgramRel(); + Iterator icprl = cprl.iterator(); + while (icprl.hasNext()) { + CourseModuleProgramRel cmpr = (CourseModuleProgramRel) + icprl.next(); + CourseProgram cp2 = cmpr.getProgram(); + String tmps3 = cp2.getLabel(); + if (tmps3.equals(id)) { + foundit = true; + break; + } + } + if (foundit == false) { + Map attrs2 = new HashMap(); + attrs2.put("cmid", new Integer(cm.getId())); + attrs2.put("cpid", new Integer(cp.getId())); + attrs2.put("cptype", m.get("type")); + attrs2.put("cpstartsem", m.get("startsem")); + attrs2.put("cpendsem", m.get("endsem")); + courseManager.addProgramToModule(attrs2); + } + } + } catch(Exception ex){ logger.error("Failed migrating course", ex); } |
|
From: Michael K. <ko...@us...> - 2006-12-14 22:07:23
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv17979/util/migration Modified Files: CourseMigration.java Log Message: Index: CourseMigration.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration/CourseMigration.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CourseMigration.java 30 Nov 2006 14:02:00 -0000 1.3 +++ CourseMigration.java 14 Dec 2006 22:06:49 -0000 1.4 @@ -94,8 +94,8 @@ List result = fromDBAccess. sqlQuery("SELECT * FROM veranstaltung, veranstklasse " +"WHERE veranstaltung.klid = veranstklasse.klid " - +"AND ((vajahr = 2006 AND vasem='WS') OR " - +"(vajahr = 2007 AND vasem='SS'))"); + +"AND ((vajahr = 2005 AND vasem='SS') OR " + +"(vajahr < 2005 AND vajahr > 1999))"); Iterator resIter = result.iterator(); while(resIter.hasNext()) { Map fromMap = (Map)resIter.next(); |
|
From: Michael K. <ko...@us...> - 2006-12-15 23:06:37
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1553/org/cobricks/util/migration Modified Files: CourseMigration.java Log Message: Index: CourseMigration.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/util/migration/CourseMigration.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CourseMigration.java 14 Dec 2006 22:06:49 -0000 1.4 +++ CourseMigration.java 15 Dec 2006 23:06:33 -0000 1.5 @@ -94,8 +94,7 @@ List result = fromDBAccess. sqlQuery("SELECT * FROM veranstaltung, veranstklasse " +"WHERE veranstaltung.klid = veranstklasse.klid " - +"AND ((vajahr = 2005 AND vasem='SS') OR " - +"(vajahr < 2005 AND vajahr > 1999))"); + +"AND vajahr > 1999"); Iterator resIter = result.iterator(); while(resIter.hasNext()) { Map fromMap = (Map)resIter.next(); |