You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(141) |
Sep
(184) |
Oct
(159) |
Nov
(77) |
Dec
(114) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(212) |
Feb
(302) |
Mar
(323) |
Apr
(360) |
May
(302) |
Jun
(392) |
Jul
(299) |
Aug
(858) |
Sep
(499) |
Oct
(489) |
Nov
(324) |
Dec
(438) |
2008 |
Jan
(449) |
Feb
(388) |
Mar
(811) |
Apr
(583) |
May
(949) |
Jun
(1431) |
Jul
(943) |
Aug
(527) |
Sep
(576) |
Oct
(440) |
Nov
(1046) |
Dec
(658) |
2009 |
Jan
(259) |
Feb
(192) |
Mar
(495) |
Apr
(2322) |
May
(2023) |
Jun
(1387) |
Jul
(722) |
Aug
(771) |
Sep
(167) |
Oct
(142) |
Nov
(384) |
Dec
(884) |
2010 |
Jan
(344) |
Feb
(82) |
Mar
(248) |
Apr
(341) |
May
(389) |
Jun
(289) |
Jul
(19) |
Aug
(478) |
Sep
(274) |
Oct
(431) |
Nov
(322) |
Dec
(207) |
2011 |
Jan
(125) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14465/src/org/tolven/gen/bean Modified Files: PersonGeneratorDAO.java GenControlFamily.java GenDriver.java Added Files: GeneratorBean.java Removed Files: PoissonValueGen.java DemogMatcher.java UniformValueGen.java ChronicDiseaseGen.java HypertensionGen.java RepeatScenario.java FractureGen.java RadiologyScenario.java GaussianValueGen.java CancerGen.java ProstateCancerGen.java DiseaseGen.java AsthmaGen.java Scenario.java LabTestScenario.java TBGen.java BatteryScenario.java GenMedical.java ChooseScenario.java ProbabilityScenario.java GenSource.java ValueGen.java DiabetesGen.java LabTest.java BreastCancerGen.java Matcher.java CholesterolGen.java PregnantGen.java CHRGeneratorBean.java GroupScenario.java Log Message: Changes associated with new DataGenerator --- Scenario.java DELETED --- --- UniformValueGen.java DELETED --- Index: GenControlFamily.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/bean/GenControlFamily.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenControlFamily.java 4 Dec 2006 08:57:38 -0000 1.1 --- GenControlFamily.java 16 Jan 2007 06:12:46 -0000 1.2 *************** *** 22,26 **** public String toString() { StringBuffer sb = new StringBuffer( 200 ); ! sb.append( "GenControl Account: "); sb.append(getChrAccountId()); sb.append(" Family: "); --- 22,26 ---- public String toString() { StringBuffer sb = new StringBuffer( 200 ); ! sb.append( " Account: "); sb.append(getChrAccountId()); sb.append(" Family: "); --- ChooseScenario.java DELETED --- --- PregnantGen.java DELETED --- Index: GenDriver.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/bean/GenDriver.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenDriver.java 5 Dec 2006 07:40:31 -0000 1.2 --- GenDriver.java 16 Jan 2007 06:12:47 -0000 1.3 *************** *** 14,17 **** --- 14,19 ---- package org.tolven.gen.bean; + import java.io.StringWriter; + import javax.annotation.EJB; import javax.annotation.PostConstruct; *************** *** 29,42 **** import javax.jms.ObjectMessage; import javax.jms.Queue; ! import javax.persistence.EntityManager; ! import javax.persistence.PersistenceContext; ! import org.tolven.app.entity.MenuData; ! import org.tolven.core.entity.Account; ! import org.tolven.core.entity.TolvenUser; ! import org.tolven.gen.CHRGenerator; import org.tolven.gen.PersonGenerator; import org.tolven.gen.entity.FamilyMember; import org.tolven.gen.entity.FamilyUnit; /** * Control the Data Generator process. This process starts when a client queues a message to the --- 31,49 ---- import javax.jms.ObjectMessage; import javax.jms.Queue; ! import javax.xml.bind.JAXBContext; ! import javax.xml.bind.JAXBElement; ! import javax.xml.bind.JAXBException; ! import javax.xml.bind.Marshaller; ! import javax.xml.namespace.QName; ! import org.tolven.ccr.ContinuityOfCareRecord; ! import org.tolven.core.util.Queuer; ! import org.tolven.doc.DocumentLocal; ! import org.tolven.doc.bean.TolvenMessage; import org.tolven.gen.PersonGenerator; import org.tolven.gen.entity.FamilyMember; import org.tolven.gen.entity.FamilyUnit; + import org.tolven.gen.model.GenMedicalCCR; + import org.tolven.gen.util.FamilyGenerator; /** * Control the Data Generator process. This process starts when a client queues a message to the *************** *** 49,54 **** @MessageDriven(activationConfig = { ! // We essentially single-thread this queue so we don't clobber user performance. ! @ActivationConfigProperty(propertyName="maxPoolSize", propertyValue="2"), @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination", propertyValue="queue/generator") --- 56,61 ---- @MessageDriven(activationConfig = { ! // We limit this queue so we don't clobber user performance. ! @ActivationConfigProperty(propertyName="maxPoolSize", propertyValue="4"), @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination", propertyValue="queue/generator") *************** *** 56,102 **** public class GenDriver implements MessageListener { ! @PersistenceContext ! private EntityManager em; ! ! @Resource(mappedName="ConnectionFactory") private ConnectionFactory connectionFactory; @Resource(mappedName="queue/generator") ! private Queue queue; ! ! @EJB private CHRGenerator gen; ! @EJB private PersonGenerator personGen; ! ! @Resource private MessageDrivenContext ctx; ! ! private Connection connection = null; ! private javax.jms.Session session = null; ! private MessageProducer messageProducer = null; ! ! @PostConstruct ! public void initQueue() { ! try { ! connection = connectionFactory.createConnection(); ! session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); ! messageProducer = session.createProducer(queue); ! } catch (Exception e) { ! throw new RuntimeException( "Error creating connection to generator queue", e); ! } ! } ! @PreDestroy ! public void closeQueue() { ! try { ! messageProducer.close(); ! connection.close(); ! } catch (Exception e) { ! throw new RuntimeException( "Error closing connection to generator queue", e); ! } ! } ! public void queueMessage( GenControlFamily familyControl ) throws Exception { ! ObjectMessage message = session.createObjectMessage(familyControl); ! messageProducer.send(message); } --- 63,88 ---- public class GenDriver implements MessageListener { ! // @Resource(mappedName="ConnectionFactory") ! @Resource(mappedName="java:/JmsXA") private ConnectionFactory connectionFactory; @Resource(mappedName="queue/generator") ! private Queue genQueue; ! @Resource(mappedName="queue/rule") ! private Queue ruleQueue; ! private JAXBContext jc = null; ! public String marshall( ContinuityOfCareRecord ccr ) throws JAXBException { ! if (jc==null) { ! jc = JAXBContext.newInstance( "org.tolven.ccr", GenDriver.class.getClassLoader() ); ! } ! JAXBElement<ContinuityOfCareRecord> root = new JAXBElement<ContinuityOfCareRecord>(new QName( "urn:astm-org:CCR", "ContinuityOfCareRecord"), ContinuityOfCareRecord.class, ccr); ! Marshaller m = jc.createMarshaller(); ! m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); ! StringWriter result = new StringWriter( 10000 ); ! m.marshal( root, result ); ! return result.toString(); } *************** *** 107,113 **** GenControlAccount control = (GenControlAccount) ((ObjectMessage)msg).getObject(); System.out.println("MsgID: " + msg.getJMSMessageID() + " "+ control); int count = 0; while (count < control.getCount()) { ! FamilyUnit family = personGen.generateFamily(control.getNow()); GenControlFamily familyControl = new GenControlFamily(); familyControl.setFamilyUnit(family); --- 93,102 ---- GenControlAccount control = (GenControlAccount) ((ObjectMessage)msg).getObject(); System.out.println("MsgID: " + msg.getJMSMessageID() + " "+ control); + FamilyGenerator familyGen = new FamilyGenerator(); int count = 0; + Queuer q = new Queuer(); + q.init(connectionFactory, genQueue); while (count < control.getCount()) { ! FamilyUnit family = familyGen.generateFamily(control.getNow()); GenControlFamily familyControl = new GenControlFamily(); familyControl.setFamilyUnit(family); *************** *** 116,137 **** familyControl.setUserId(control.getUserId()); familyControl.setStartYear(control.getStartYear()); ! queueMessage(familyControl); count = count + familyControl.getFamilyUnit().getMembers().size(); } ! // session.commit(); return; } // Generate data for one family if (((ObjectMessage)msg).getObject() instanceof GenControlFamily ) { GenControlFamily control = (GenControlFamily) ((ObjectMessage)msg).getObject(); System.out.println("start: " + control); ! TolvenUser user = em.find(TolvenUser.class, control.getUserId()); ! Account chrAccount = em.find(Account.class, control.getChrAccountId()); for (FamilyMember member : control.getFamilyUnit().getMembers()) { ! MenuData mdPrimary = gen.registerPatient( user, chrAccount, member.getPerson(), control.getFamilyUnit(), control.getNow(), control.getStartYear() ); ! if (mdPrimary==null) continue; ! gen.generateMedicalData( mdPrimary, null, control.getNow(), control.getStartYear(), member.getPerson().getDod()); } ! System.out.println("stop: " + control); } } catch (JMSException e) { --- 105,146 ---- familyControl.setUserId(control.getUserId()); familyControl.setStartYear(control.getStartYear()); ! q.send(familyControl); count = count + familyControl.getFamilyUnit().getMembers().size(); } ! q.close(); ! System.out.println("***Done generating families***"); return; } // Generate data for one family if (((ObjectMessage)msg).getObject() instanceof GenControlFamily ) { + String OID = System.getProperty("tolven.repository.oid", "0"); GenControlFamily control = (GenControlFamily) ((ObjectMessage)msg).getObject(); System.out.println("start: " + control); ! // TolvenUser user = em.find(TolvenUser.class, control.getUserId()); ! // Account chrAccount = em.find(Account.class, control.getChrAccountId()); ! GenMedicalCCR generator = new GenMedicalCCR( control.getNow(), control.getStartYear()); ! generator.setFamily(control.getFamilyUnit()); ! String baseSeq = "" + control.getNow().getTime(); ! Queuer q = new Queuer(); ! q.init(connectionFactory, ruleQueue); ! int seq = 0; for (FamilyMember member : control.getFamilyUnit().getMembers()) { ! generator.setVp(member.getPerson()); ! seq++; ! generator.setDocumentId(OID + "." + baseSeq + "." + seq ); ! // Create a CCR document which will be the target for this operation ! ContinuityOfCareRecord ccr = generator.generate( ); ! // Send the resulting document to toven for persistence and rule processing ! TolvenMessage tm = new TolvenMessage(); ! tm.setAccountId(control.getChrAccountId()); ! tm.setAuthorId(control.getUserId()); ! tm.setXmlName("ContinuityOfCareRecord"); ! tm.setXmlNS( "urn:astm-org:CCR"); ! tm.setPayload(marshall( ccr)); ! q.send( tm ); ! // System.out.println(tm.getPayload()); } ! q.close(); ! System.out.println("Finished generating: " + control); } } catch (JMSException e) { --- ChronicDiseaseGen.java DELETED --- --- CancerGen.java DELETED --- --- LabTestScenario.java DELETED --- --- BatteryScenario.java DELETED --- --- DemogMatcher.java DELETED --- --- ProstateCancerGen.java DELETED --- --- RadiologyScenario.java DELETED --- --- RepeatScenario.java DELETED --- --- GenSource.java DELETED --- --- ValueGen.java DELETED --- --- CholesterolGen.java DELETED --- --- FractureGen.java DELETED --- --- PoissonValueGen.java DELETED --- --- CHRGeneratorBean.java DELETED --- --- AsthmaGen.java DELETED --- --- GroupScenario.java DELETED --- --- TBGen.java DELETED --- --- HypertensionGen.java DELETED --- --- NEW FILE: GeneratorBean.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.bean; import javax.annotation.Resource; import javax.ejb.Local; import javax.ejb.Stateless; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.tolven.gen.Generator; /** * Generate patients for a CHR account. * @author John Churin */ //@DeclareRoles({"gen"}) @Stateless @Local(Generator.class) public class GeneratorBean implements Generator { // @Resource(mappedName="ConnectionFactory") @Resource(mappedName="java:/JmsXA") private ConnectionFactory connectionFactory; @Resource(mappedName="queue/generator") private Queue queue; public GeneratorBean( ) { } /** * Queue the generation of one or more clinical data events * @param invitation * @throws JMSException */ public void queueGeneration(GenControlBase control) throws JMSException { Connection connection = connectionFactory.createConnection(); javax.jms.Session session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(queue); ObjectMessage message = session.createObjectMessage(control); messageProducer.send(message); messageProducer.close(); connection.close(); } } --- DiseaseGen.java DELETED --- --- Matcher.java DELETED --- --- LabTest.java DELETED --- --- DiabetesGen.java DELETED --- --- GaussianValueGen.java DELETED --- --- GenMedical.java DELETED --- --- BreastCancerGen.java DELETED --- Index: PersonGeneratorDAO.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/bean/PersonGeneratorDAO.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PersonGeneratorDAO.java 4 Dec 2006 08:57:38 -0000 1.9 --- PersonGeneratorDAO.java 16 Jan 2007 06:12:46 -0000 1.10 *************** *** 20,28 **** import java.util.Random; - import javax.annotation.EJB; - import javax.annotation.Resource; import javax.ejb.Local; import javax.ejb.Remote; - import javax.ejb.SessionContext; import javax.ejb.Stateless; import javax.persistence.EntityManager; --- 20,25 ---- *************** *** 30,38 **** import javax.persistence.Query; - import org.tolven.app.MenuLocal; - import org.tolven.app.entity.MenuData; - import org.tolven.app.entity.MenuStructure; - import org.tolven.core.entity.Account; - import org.tolven.core.entity.TolvenUser; import org.tolven.gen.PersonGenerator; import org.tolven.gen.PersonGeneratorRemote; --- 27,30 ---- *************** *** 47,51 **** /** ! * * @author John Churin */ --- 39,45 ---- /** ! * The bulk of this class is now obsolete. The most important method of this class is ! * generateFamily which is used by the data generator. There's really no need to keep a ! * persistent list of people or families any longer. * @author John Churin */ *************** *** 59,65 **** private EntityManager em; - @EJB - private MenuLocal menu; - private RandomNameGenerator nameGenerator; private LifeSpan lifeSpan; --- 53,56 ---- *************** *** 68,73 **** private Random rng; - @Resource SessionContext ctx; - /** Creates a new instance of PersonGenerator */ public PersonGeneratorDAO() { --- 59,62 ---- *************** *** 198,247 **** return rslt; } ! public FamilyUnit generateFamily( Date now ) throws Exception { ! // Start a family ! FamilyUnit family = new FamilyUnit(); ! placeGenerator.generateZipCode(family); ! placeGenerator.generateAddress(family); ! String primaryGender = null; ! int primaryAge = 0; ! // Start with a primary person (we should find a suitable mom or dad in 100 tries) ! for (int c = 0; c < 100; c++) { ! VirtualPerson person = generatePerson(); ! primaryAge = person.getAgeInYears(now); ! if ( primaryAge < 18 ) continue; ! family.setFamilyName(person.getLast()); ! primaryGender = person.getGender(); ! FamilyMemberRole role; ! if ("F".equals(person.getGender())) { ! role = FamilyMember.FamilyMemberRole.MOTHER; ! } else { ! role = FamilyMember.FamilyMemberRole.FATHER; ! } ! family.addMember( person, role ); ! break; ! } ! // Look for a second person (we may not find one) ! for (int c = 0; c < 10; c++) { ! VirtualPerson person = generatePerson(); ! int age = person.getAgeInYears( now ); ! if ( age < 18 ) continue; ! if (primaryGender.equals(person.getGender())) continue; ! int ageDifference = person.getAgeInYears( now )-primaryAge; ! // If too far apart in age, forget it ! if (Math.abs( ageDifference) > 10 ) continue; ! // Same last name, add to family ! person.setLast(family.getFamilyName()); ! FamilyMemberRole role; ! if ("F".equals(person.getGender())) { ! role = FamilyMember.FamilyMemberRole.MOTHER; ! } else { ! role = FamilyMember.FamilyMemberRole.FATHER; ! } ! family.addMember( person, role ); ! break; ! } ! return family; ! } ! /** * Create a simple person object with name, gender, and dob --- 187,191 ---- return rslt; } ! /** * Create a simple person object with name, gender, and dob *************** *** 352,675 **** } - /** - * Add members of a family to our account, but only those that have been born. - * TODO: Add unborn people to the scheduler to be added on the day of the blessed event! - */ - public void adoptFamily( long familyId, long accountId, String path, Date now ) { - // Look for a useful menu structure - MenuStructure ms = menu.findMenuStructure( accountId, path); - // Run through the selected family's members and create patient records - FamilyUnit family = findFamily( familyId ); - for (FamilyMember m : family.getMembers()) { - VirtualPerson p = m.getPerson(); - if (p.getDob().before(now)) { - // Create the patient - MenuData md = new MenuData(); - md.setMenuStructure( ms ); - md.setDate01( p.getDob()); - md.setString01(p.getLast()); - md.setString02(p.getFirst()); - md.setString03(p.getMiddle()); - md.setString04(p.getGender()); - menu.persistMenuData(md); - // // OK, nice start but let's give this patient some medical data. - // generateProblems( md, now ); - // generateMedications( md, now ); - // generateFunctionalStatuses( md, now ); - // generateLabResults( md, now ); - // generateRadResults( md, now ); - // generateSelfAssessments( md, now ); - // generateMedicalHistory( md, now ); - // generateFamilyHistory( md, now ); - // generateImmunizations( md, now ); - } - } - } - - // /** - // * Generate a set of problems for this patient under echr:patient-nnn:overview:summary:probsum - // * @param patient Contains the parent menu data (the patient) for the problems we'll be creating - // * @param now - // */ - // public void generateProblems( MenuData patient, Date now ) { - //// System.out.println( "[generateProblems] accountId: " + patient.getAccount().getId() ); - //// System.out.println( "[generateProblems] path: " + "echr:patient:overview:summary:probsum"); - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:probsum"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -7); - // generateProblem( patient, ms, cal.getTime(), "Congestive Heart Failure"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -22); - // generateProblem( patient, ms, cal.getTime(), "Diabetes Mellitus"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -16); - // generateProblem( patient, ms, cal.getTime(), "Hypertension"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -3); - // generateProblem( patient, ms, cal.getTime(), "Myocardial Infarction"); - // } - // - // /** - // * Generate one problem - // * @return - // */ - // public MenuData generateProblem( MenuData patient, MenuStructure ms, Date onset, String problem ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( onset); - // md.setString01(problem); - // md.setString02("Active"); - // menu.persistMenuData( md); - // return md; - // } - // - // /** - // * Generate a set of medications for this patient under echr:patient-nnn:overview:summary:medsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateMedications( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:medsum"); - // generateMedication( patient, ms, "metformin (Glucophage XR), 500mg", "Refill"); - // generateMedication( patient, ms, "ezetimibe-simvastin (Vytorin) 10mg/20mg", "Active"); - // generateMedication( patient, ms, "insulin lispro (Humolog) 100 units/ml", "Active"); - // generateMedication( patient, ms, "vitamin C, 1000 IU", "Active"); - // generateMedication( patient, ms, "Super-cold formula", "Active"); - // } - // - // /** - // * Generate one medication - // * @return - // */ - // public MenuData generateMedication( MenuData patient, MenuStructure ms, String text, String status ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setString01(text); - // md.setString02(status); - // menu.persistMenuData( md); - // return md; - // } - // /** - // * Generate functional status for this patient under echr:patient-nnn:overview:summary:funStatsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateFunctionalStatuses( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:funStatsum"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateFunctionalStatus( patient, ms, cal.getTime(), "Mobility - Limited"); - // } - // - // /** - // * Generate one functional status - // * @return - // */ - // public MenuData generateFunctionalStatus( MenuData patient, MenuStructure ms, Date effective, String text ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( effective ); - // md.setString01(text); - // menu.persistMenuData( md); - // return md; - // } - // - // /** - // * Generate lab results for this patient under echr:patient-nnn:overview:summary:labsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateLabResults( MenuData patient, Date now ) { - // MenuStructure mss = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:labsum"); - // MenuStructure msa = menu.findMenuStructure( patient.getAccount().getId(), "echr:activity"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -3); - // generateLabResult( patient, mss, msa, cal.getTime(), "Complete cbc w/auto wbc"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateLabResult( patient, mss, msa, cal.getTime(), "Urinalysis, nonauto w/scope"); - // } - // - // /** - // * Generate one lab result: - // * <ul> - // * <li>Add an item to the summary</li> - // * <li>Add the item to the Activity list</li> - // * </ul> - // * @return - // */ - // public void generateLabResult( MenuData patient, MenuStructure mss, MenuStructure msa, Date effective, String text ) { - // // Summary entry - // MenuData mds = new MenuData(); - // mds.setMenuStructure( mss ); - // mds.setParent01(patient); - // mds.setDate01( effective ); - // mds.setString01(text); - // menu.persistMenuData( mds); - // - // // New Activity referencing the result just created - // MenuData mda = new MenuData(); - // mda.setMenuStructure( msa ); - // mda.setDate01( effective ); - // mda.setParent01(patient); - // mda.setParent02(mds); - // menu.persistMenuData( mda); - // } - // - // /** - // * Generate radiology (imaging) results for this patient under echr:patient-nnn:overview:summary:radsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateRadResults( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:radsum"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateRadResult( patient, ms, cal.getTime(), "Coronary angiogram"); - // } - // - // /** - // * Generate one rad result - // * @return - // */ - // public MenuData generateRadResult( MenuData patient, MenuStructure ms, Date effective, String text ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( effective ); - // md.setString01(text); - // menu.persistMenuData( md); - // return md; - // } - // - // /** - // * Generate self-monitoring data for this patient under echr:patient-nnn:overview:summary:selfsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateSelfAssessments( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:selfsum"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateSelfAssessment( patient, ms, cal.getTime(), "Height & Weight"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateSelfAssessment( patient, ms, cal.getTime(), "Cardiac Monitoring"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateSelfAssessment( patient, ms, cal.getTime(), "Blood Pressure"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateSelfAssessment( patient, ms, cal.getTime(), "Respiratory Rate"); - // } - // - // /** - // * Generate one self-assessment - // * @return - // */ - // public MenuData generateSelfAssessment( MenuData patient, MenuStructure ms, Date effective, String text ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( effective ); - // md.setString01(text); - // menu.persistMenuData( md); - // return md; - // } - // - // /** - // * Generate family history for this patient under echr:patient-nnn:overview:summary:mhxsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateMedicalHistory( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:mhxsum"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // cal.add(GregorianCalendar.MONTH, 5); - // generateMedicalHistory( patient, ms, cal.getTime(), "New Patient", "Completed"); - // cal.setTime( now ); - // cal.add(GregorianCalendar.MONTH, -3); - // generateMedicalHistory( patient, ms, cal.getTime(), "Pre-visit questionnaire", "Pending"); - // } - // - // /** - // * Generate one Medical History item - // * @return - // */ - // public MenuData generateMedicalHistory( MenuData patient, MenuStructure ms, Date effective, String text, String status ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( effective ); - // md.setString01(text); - // md.setString02(status); - // menu.persistMenuData( md); - // return md; - // } - // - // /** - // * Generate family history for this patient under echr:patient-nnn:overview:summary:fhxsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateFamilyHistory( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:fhxsum"); - //// GregorianCalendar cal = new GregorianCalendar( ); - //// cal.setTime( now ); - //// cal.add(GregorianCalendar.YEAR, -1); - //// generateFamilyHistory( patient, ms, cal.getTime(), "Item"); - // } - // - // /** - // * Generate one Family History item - // * @return - // */ - // public MenuData generateFamilyHistory( MenuData patient, MenuStructure ms, Date effective, String text ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( effective ); - // md.setString01(text); - // menu.persistMenuData( md); - // return md; - // } - // - // /** - // * Generate immunization data for this patient under echr:patient-nnn:overview:summary:immsum - // * @param patient Contains the parent menu data (the patient) data we'll be creating - // * @param now - // */ - // public void generateImmunizations( MenuData patient, Date now ) { - // MenuStructure ms = menu.findMenuStructure( patient.getAccount().getId(), "echr:patient:overview:summary:immsum"); - // GregorianCalendar cal = new GregorianCalendar( ); - // cal.setTime( now ); - // cal.add(GregorianCalendar.YEAR, -1); - // generateImmunization( patient, ms, cal.getTime(), "Influenza (Split virus, 6-35 mo. dosage)"); - // } - // - // /** - // * Generate one self-assessment - // * @return - // */ - // public MenuData generateImmunization( MenuData patient, MenuStructure ms, Date effective, String text ) { - // MenuData md = new MenuData(); - // md.setMenuStructure( ms ); - // md.setParent01(patient); - // md.setDate01( effective ); - // md.setString01(text); - // menu.persistMenuData( md); - // return md; - // } - - } --- 296,298 ---- --- ProbabilityScenario.java DELETED --- |
From: John C. <jc...@us...> - 2007-01-16 06:12:49
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14465/src/org/tolven/gen/entity Modified Files: FamilyUnit.java FamilyMember.java Log Message: Changes associated with new DataGenerator Index: FamilyMember.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/entity/FamilyMember.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FamilyMember.java 4 Dec 2006 08:57:38 -0000 1.3 --- FamilyMember.java 16 Jan 2007 06:12:47 -0000 1.4 *************** *** 48,51 **** --- 48,54 ---- private VirtualPerson person; + @Column( name="MEMBER_NUMBER" ) + private int memberNumber; + @Column( name="ROLE", length=20 ) private FamilyMemberRole role; *************** *** 61,65 **** public boolean equals(Object obj) { if (obj instanceof FamilyMember ) { ! if (getId()==((FamilyMember)obj).getId()) return true; } return false; --- 64,68 ---- public boolean equals(Object obj) { if (obj instanceof FamilyMember ) { ! if (this.getMemberNumber()==((FamilyMember)obj).getMemberNumber()) return true; } return false; *************** *** 102,104 **** --- 105,115 ---- } + public int getMemberNumber() { + return memberNumber; + } + + public void setMemberNumber(int memberNumber) { + this.memberNumber = memberNumber; + } + } Index: FamilyUnit.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/entity/FamilyUnit.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FamilyUnit.java 4 Dec 2006 08:57:38 -0000 1.4 --- FamilyUnit.java 16 Jan 2007 06:12:47 -0000 1.5 *************** *** 152,155 **** --- 152,156 ---- } this.members.add( member ); + member.setMemberNumber(this.members.size()); member.setFamilyUnit( this ); } |
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/model In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14465/src/org/tolven/gen/model Added Files: PregnantGen.java ChooseScenario.java RepeatScenario.java HypertensionGen.java ValueGen.java ProbabilityScenario.java GenMedicalCCR.java LabTest.java ProstateCancerGen.java GenMedical.java CholesterolGen.java GroupScenario.java LabTestScenario.java RadiologyScenario.java FractureGen.java SimpleMatcher.java BatteryScenario.java CancerGen.java AsthmaGen.java UniformValueGen.java PoissonValueGen.java ChronicDiseaseGen.java GaussianValueGen.java Scenario.java DemogMatcher.java BreastCancerGen.java DiseaseGen.java GenSource.java DiabetesGen.java package-info.java TBGen.java PatientGen.java Matcher.java Log Message: Changes associated with new DataGenerator --- NEW FILE: Scenario.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class Scenario { private String title; public Scenario( ) { } public Scenario( String title ) { this.title = title; } /** * * @param patient * @param startTime * @param endTime * @param rng * @return Return true if this scenario did anything or not. For example, the select-one scenario * means the first (child) scenario to return true finishes the lot. */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng) { // System.out.println( "Generic Scenario " + getTitle() // + " for " + patient.getVp().getFirst() + " " + patient.getVp().getLast() // + " starting " + startTime + " ending " + endTime); return false; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } --- NEW FILE: UniformValueGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import org.apache.commons.math.random.RandomData; public class UniformValueGen extends ValueGen{ private double low; private double high; public double generate( RandomData rng) { return rng.nextUniform(low,high); } public UniformValueGen( double low, double high ) { this.low = low; this.high = high; } public double getHigh() { return high; } public void setHigh(double high) { this.high = high; } public double getLow() { return low; } public void setLow(double low) { this.low = low; } } --- NEW FILE: ChooseScenario.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.math.random.RandomData; /** * A scenario that chooses among the supplied ProbabilityScenarios). * When the apply method is called, a random number is selected between 0.0 and 1.0 and * the probabilities of each choice considered. The choices do not need to total 1.0. If they exceed * 1.0 any latter choices beyond the 1.0 limit would not be selected. For example: Say two choices were in the list: * Choice A = 0.25 and Choice B = 0.50 then 25% of the time Choice A would be selected and 25% of the time * neither choice A nor B would be selected. So as you can see, the probabilities are not normalized to 1.0. * @author John Churin * */ public class ChooseScenario extends Scenario { private List<ProbabilityScenario> scenarios; public ChooseScenario( ProbabilityScenario[] scenarios ) { for ( int x = 0; x < scenarios.length; x++ ) { getScenarios().add(scenarios[x]); } } /** * * @param patient * @param startTime * @param endTime * @param rng * @return Return true if one of the child scenarios did something (returned true), otherwise false. */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng ) { double choice = rng.nextUniform(0.0, 1.0); double base = 0.0; for ( ProbabilityScenario s : getScenarios()) { base += s.getProbability(); if (base>choice) { // System.out.println( "Scenario Choice " + s.getTitle()); return s.apply( patient, startTime, endTime, rng); } } return false; } public List<ProbabilityScenario> getScenarios() { if (scenarios==null) scenarios = new ArrayList<ProbabilityScenario>( 10 ); return scenarios; } public void setScenarios(List<ProbabilityScenario> scenarios) { this.scenarios = scenarios; } /** * Add a Scenario * @param scenario */ public void addScenario( ProbabilityScenario scenario) { getScenarios().add( scenario ); } } --- NEW FILE: PatientGen.java --- /* Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class PatientGen extends GenSource { @Override protected void apply(GenMedical patient, Date eventTime) { super.apply(patient, eventTime); patient.generateNewPatient( eventTime ); } public PatientGen( RandomData rng ) { this.rng = rng; addMatcher( new SimpleMatcher()); } } --- NEW FILE: PregnantGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class PregnantGen extends DiseaseGen { public static long MONTHS = 30L*24L*60L*60L*1000L; @Override protected void apply(GenMedical patient, Date eventTime) { super.apply(patient, eventTime); Date birthDate = new Date(eventTime.getTime() + getMinimumSpacing()); System.out.println( "**********Pregnancy: " + eventTime + " DOB: " + birthDate + " Spacing: " + getMinimumSpacing()); if (patient.getNow().after(birthDate)) { patient.generateProblem(eventTime, getDiseaseName(), "Inactive"); // Usually single, sometimes twins, rarely triples int allBirths = rng.nextInt(0, 4089000); int birthCount = 1; if ( allBirths < 7110 ) birthCount = 3; else if (allBirths < 128000) birthCount = 2; patient.birth(birthCount, birthDate); } else { // Still pregnant to this day patient.generateProblem(eventTime, getDiseaseName(), "Active"); } } public PregnantGen( RandomData rng ) { this.rng = rng; setDiseaseName( "Pregnant" ); addMatcher( new DemogMatcher( 0, 15, "M", 0.0)); addMatcher( new DemogMatcher( 0, 15, "F", 0.0)); addMatcher( new DemogMatcher( 15, 20, "M", 0.0)); addMatcher( new DemogMatcher( 15, 20, "F", 0.01)); addMatcher( new DemogMatcher( 20, 40, "M", 0.0)); addMatcher( new DemogMatcher( 20, 40, "F", 0.03)); addMatcher( new DemogMatcher( 40, 60, "M", 0.0)); addMatcher( new DemogMatcher( 40, 60, "F", 0.02)); addMatcher( new DemogMatcher( 60, 65, "M", 0.0)); addMatcher( new DemogMatcher( 60, 65, "F", 0.01)); this.setMinimumSpacing(9*MONTHS); this.addRepeatProbability(0.5); this.addRepeatProbability(0.25); this.addRepeatProbability(0.25); } } --- NEW FILE: TBGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class TBGen extends DiseaseGen { @Override protected void apply(GenMedical patient, Date eventTime) { super.apply(patient, eventTime); } public TBGen( RandomData rng ) { this.rng = rng; setDiseaseName( "Tuberculosis" ); addMatcher( new DemogMatcher( 0, 20, "M", 0.02)); addMatcher( new DemogMatcher( 0, 20, "F", 0.02)); addMatcher( new DemogMatcher( 20, 40, "M", 0.03)); addMatcher( new DemogMatcher( 20, 40, "F", 0.03)); addMatcher( new DemogMatcher( 40, 60, "M", 0.025)); addMatcher( new DemogMatcher( 40, 60, "F", 0.025)); addMatcher( new DemogMatcher( 60, 200, "M", 0.02)); addMatcher( new DemogMatcher( 60, 200, "F", 0.02)); } } --- NEW FILE: ChronicDiseaseGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; public class ChronicDiseaseGen extends DiseaseGen { @Override protected void apply(GenMedical patient, Date eventTime) { patient.generateProblem(eventTime, getDiseaseName(), "Active"); super.apply(patient, eventTime); } } --- NEW FILE: CancerGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; public class CancerGen extends DiseaseGen { @Override protected void apply(GenMedical patient, Date eventTime) { Date threeYearsAgo = patient.monthsAgo( 36 ); String status; if (eventTime.before(threeYearsAgo)) status = "Active"; else status = "Inactive"; patient.generateProblem(eventTime, getDiseaseName(), status); super.apply(patient, eventTime); } } --- NEW FILE: LabTestScenario.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.math.random.RandomData; public class LabTestScenario extends Scenario { private String test; private String units; private String normalRange; private String pattern; private NumberFormat nf = NumberFormat.getInstance(); private ValueGen valueGen; public LabTestScenario(String test, String units, String normalRange, int fractionDigits, ValueGen valueGen) { this.test = test; this.units = units; this.normalRange = normalRange; this.setFractionDigits(fractionDigits); this.valueGen = valueGen; } /** * Actually create a lab test at the start time (we ignore endTime). Also add to new activity if newer than 30 days old. */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng ) { List<LabTest> tests = new ArrayList<LabTest>(); tests.add(generateTest(startTime, rng )); patient.generateLabResult( startTime, test, tests ); return true; } /** * Create a representation of the test instance with the value we want to see. * @param startTime * @param rng * @return */ public LabTest generateTest( Date startTime, RandomData rng ) { LabTest labTest = new LabTest(); labTest.setValue( getValueGen().generate(rng) ); labTest.setStringValue( nf.format(labTest.getValue())); labTest.setEffectiveTime(startTime); labTest.setTestName(test); labTest.setUnits(units); return labTest; } public ValueGen getValueGen() { return valueGen; } public void setValueGen(ValueGen valueGen) { this.valueGen = valueGen; } public String getTest() { return test; } public void setTest(String test) { this.test = test; } public String getUnits() { return units; } public void setUnits(String units) { this.units = units; } public String getNormalRange() { return normalRange; } public void setNormalRange(String normalRange) { this.normalRange = normalRange; } public String getPattern() { return pattern; } public void setPattern(String pattern) { this.pattern = pattern; } public int getFractionDigits() { return nf.getMaximumFractionDigits(); } public void setFractionDigits(int fractionDigits) { this.nf.setMaximumFractionDigits(fractionDigits); this.nf.setMinimumFractionDigits(fractionDigits); } } --- NEW FILE: BatteryScenario.java --- package org.tolven.gen.model; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.math.random.RandomData; /** * A battery is almost the same as a group scenario except that a battery creates a * manifestation of the group in the output which a group is only a group relative to * the input side. * Functionally, a battery is a group of tests ordered together, usually taken from a single * specimen collection event. * @author John Churin * */ public class BatteryScenario extends GroupScenario { public BatteryScenario( String title, Scenario[] scenarios ) { super( title, scenarios ); } /** * Apply a battery of tests. Each test is asked to return it's result to us rather than * generating a result independently. we then pass the whole collection to the data generator. * @param patient * @param startTime * @param endTime * @param rng * @return Return true if at least one of the child scenarios did something (returned true), otherwise false. */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng ) { boolean rslt = false; List<LabTest> tests = new ArrayList<LabTest>( getScenarios().size()); for ( Scenario s : getScenarios()) { tests.add(((LabTestScenario)s).generateTest(startTime, rng )); } patient.generateLabResult(startTime, getTitle(), tests); return rslt; } } --- NEW FILE: DemogMatcher.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.text.ParseException; import java.util.Date; import java.util.GregorianCalendar; import org.apache.commons.math.random.RandomData; import org.apache.commons.math.random.RandomDataImpl; /** * Match on demographics alone. This matcher is "cumulative" such that a 40 year old * person could match criteria for a 0-20 year old. And if that happens, then the event * will be selected to be within that timeframe. Otherwise, the Even will occur somewhere between the * low age and the current date (now). * @author John Churin */ public class DemogMatcher extends Matcher { private int lowAge; private int highAge; private String gender; public DemogMatcher( int lowAge, int highAge, String gender, double probability ) { super( probability ); setLowAge( lowAge ); setHighAge( highAge); if (gender!=null) { setGender( gender.substring(0, 1).toLowerCase() ); } } /** * Try to match the patient to this criteria * In this case, older patients match younger age ranges because the patient was that * age at one time. The event time will be selected accordingly. */ @Override protected boolean match(GenMedical patient) { int pAge; pAge = patient.getAgeInYears(); // System.out.println( "Matcher (" + getGender() + "): " + patient.getFamilyName() + " is: " + pAge + " Male: " + patient.isMale() + " Female: " + patient.isFemale() ); if (pAge < lowAge) { // System.out.println( "Too young " + lowAge); return false; } // If we're looking for a male, see if this is not one if ("m".equals(getGender())) { if (!patient.isMale()) { // System.out.println( "Not male "); return false; } } // If we're looking for a female, see if this is not one if ("f".equals(getGender())) { if (!patient.isFemale()) { // System.out.println( "Not female "); return false; } } return true; } protected Date getEarliest( GenMedical patient ) { GregorianCalendar eventLow = new GregorianCalendar(); eventLow.setTime(patient.getDOB()); eventLow.add( GregorianCalendar.YEAR, getLowAge()); return eventLow.getTime(); } protected Date getLatest( GenMedical patient ) { GregorianCalendar eventHigh = new GregorianCalendar(); eventHigh.setTime(patient.getDOB()); eventHigh.add( GregorianCalendar.YEAR, getHighAge()); return eventHigh.getTime(); } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public int getHighAge() { return highAge; } public void setHighAge(int highAge) { this.highAge = highAge; } public int getLowAge() { return lowAge; } public void setLowAge(int lowAge) { this.lowAge = lowAge; } } --- NEW FILE: ProstateCancerGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import org.apache.commons.math.random.RandomData; public class ProstateCancerGen extends CancerGen { public ProstateCancerGen(RandomData rng ) { this.rng = rng; setDiseaseName( "Prostate Cancer" ); addMatcher( new DemogMatcher( 0, 20, "M", 0.001)); addMatcher( new DemogMatcher( 0, 20, "F", 0.0)); addMatcher( new DemogMatcher( 20, 40, "M", 0.002)); addMatcher( new DemogMatcher( 20, 40, "F", 0.0)); addMatcher( new DemogMatcher( 40, 60, "M", 0.003)); addMatcher( new DemogMatcher( 40, 60, "F", 0.0)); addMatcher( new DemogMatcher( 60, 200, "M", 0.004)); addMatcher( new DemogMatcher( 60, 200, "F", 0.0)); } } --- NEW FILE: RadiologyScenario.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class RadiologyScenario extends Scenario { private String test; private String report; private String interpretation; public String getInterpretation() { return interpretation; } public void setInterpretation(String interpretation) { this.interpretation = interpretation; } public String getReport() { return report; } public void setReport(String report) { this.report = report; } public String getTest() { return test; } public void setTest(String test) { this.test = test; } public RadiologyScenario(String test, String report, String interpretation) { this.test = test; this.report = report; this.interpretation = interpretation; } /** * Actually create a radiology report at the start time (we ignore endTime). */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng ) { patient.generateRadResult( startTime, test, report, interpretation ); return true; } } --- NEW FILE: RepeatScenario.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import java.util.GregorianCalendar; import org.apache.commons.math.random.RandomData; /** * Repeat the supplied a scenario periodically * @author John Churin * */ public class RepeatScenario extends Scenario { private Scenario scenarioToRepeat; private int intervalType; private int intervalValue; private double deviation; private double deviationMs; private boolean resetClock; private int startOffset; private int maxCount; /** * Because this class uses date arithmatic, it's possible that it could look out of control so * we have an intrinsic maximum. If we hit the maximum, throw an IllegalArgumentException suggesting that * the repeat interval must be wrong. */ public static int MAX_REPEAT = 10000; /** * Repeating a scenario on a periodic basis * @param intervalType From GregorianCalendar (YEAR, MONTH, DAY, etc) * @param intervalValue How many calendar units is the interval (eg 12 months, 1 year, etc) * @param deviation Standard deviation. 0.0 means the scenario is repeated right on schedule each time. The deviation is relative to the * interval so. So the actual applied deviation is multiplied by the number of milliseconds in the specified intervalType (eg months*ms*deviation). * @param resetClock If true, the next instance will be based on the actual time of the current instance. If false, then each instance will * be based on the interval, exactly. For example, the patient might actually show up a few days early for an annual exam. If true, then * the next exam will be 12 months from the visit. If false, it will be 12 months from when the visit SHOULD have occured. * @param start how many calendar periods to wait before the first repeat (zero means the first repeat occurs at the start time exactly) * @param maxCount If non-zero, means number of times to run the scenario. The end time is alway limited by patient death or the current date * regardless of this value. If specified as zero means to repeat until one of the other reasons to end the repeat. * @param scenarioToRepeat The scenario to be repeated */ public RepeatScenario( int intervalType, int intervalValue, double deviation, boolean resetClock, int startOffset, int maxCount, Scenario scenarioToRepeat ) { this.intervalType = intervalType; this.intervalValue = intervalValue; this.setDeviation(deviation); this.resetClock = resetClock; this.scenarioToRepeat = scenarioToRepeat; this.startOffset = startOffset; if (maxCount == 0) this.maxCount = MAX_REPEAT; else this.maxCount = maxCount; this.setTitle("Repeat (" + intervalType + "*" + intervalValue + " " + deviation + ")" + scenarioToRepeat.getTitle()); } /** * To apply this scenario, we will modify the start time of the scenario to repeat to * be the selected event time. For example, if the repeat interval is one year (in milliseconds), * and apply is called with a start time around 1992, then the child scenario is called * with a start time of 1977, 1978, to the end-time (present day or death being most common * for chronic diseases or the duration of the disease for acute diseases). * Since most repeat scenarios represent followup activity, the start date is often offset * by some interval. Thus, with a startOffset of 12 (months), and the * startDate were to be 1976, then the first "repeat" will be around 1977. */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng ) { GregorianCalendar clock = new GregorianCalendar(); clock.setTime(startTime); boolean rslt = false; int count = -startOffset; // System.out.println( getTitle() + " of " + getScenarioToRepeat().getTitle() + " Ranging from " + clock.getTime() + " to " + endTime); while ( true ) { if (count++ >= MAX_REPEAT) throw new IllegalArgumentException( "Maximum repeat for scenario " + getTitle()); if (count > maxCount) break; // Now pick a random time around that clock setting unless this is the first instance or there is no deviation Date instanceTime; if (getDeviation()==0.0 || count <= 0) { instanceTime = new Date( clock.getTimeInMillis()); } else { instanceTime = new Date( ((long)rng.nextGaussian(clock.getTimeInMillis(), getDeviationMs()))); } // Needs to be before the end time, otherwise, we're done. if (instanceTime.after(endTime)) break; // Now apply the instance (if we're past the startOffset) if (count>0) { getScenarioToRepeat().apply(patient, instanceTime, endTime, rng ); } // Reset the clock if requested if (resetClock) clock.setTime(instanceTime); // Advance the clock with no randomness clock.add(intervalType, intervalValue); rslt = true; } return rslt; } public Scenario getScenarioToRepeat() { return scenarioToRepeat; } public void setScenarioToRepeat(Scenario scenarioToRepeat) { this.scenarioToRepeat = scenarioToRepeat; } public double getDeviation() { return deviation; } public double getDeviationMs() { long units; if (intervalType == GregorianCalendar.MINUTE) units = 60L*1000L; else if (intervalType == GregorianCalendar.HOUR) units = 60L*60L*1000L; else if (intervalType == GregorianCalendar.DAY_OF_WEEK || intervalType == GregorianCalendar.DAY_OF_MONTH) units = 24L*60L*60L*1000L; else if (intervalType == GregorianCalendar.MONTH) units = 30L*24L*60L*60L*1000L; else if (intervalType == GregorianCalendar.YEAR) units = 365L*24L*60L*60L*1000L; else units = 1000L; // Calculate it in ms return deviation*units; } public void setDeviation(double deviation) { this.deviation = deviation; } public int getMaxCount() { return maxCount; } public void setMaxCount(int maxCount) { this.maxCount = maxCount; } public int getStartOffset() { return startOffset; } public void setStartOffset(int startOffset) { this.startOffset = startOffset; } } --- NEW FILE: GenSource.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.math.random.RandomData; /** * A source of some kind of medical data to be generated. A source will have an affinity for a certain kind of * patients and certain information about that patient. Typically, an individual source will only apply * to a certain age range or gender and perhaps patients with, or without, a specific problem. * Sources can be arranged in a hierarchy with the top-level looking for the broadest matching criteria * and then lower-levels looking for detailed matches. * @author John Churin */ public abstract class GenSource { private List<Matcher> matchers; private Scenario scenario; protected long matchCount = 0; protected long applyCount = 0; protected RandomData rng; private long minimumSpacing = 0; private List<Double> repeatProbability; /** * See if the specified patient should get data generated for this source and then do so. * @param patient */ public void generate( GenMedical patient) { Matcher m = matchFirst(patient); if (m==null) return; // Ask the matcher to supply a reasonable event time Date eventTime = m.getEventTime(patient, rng, null); // At this point, we are 100% likely to create this event. apply( patient, eventTime ); // Now check the repeats completely ignoring match criteria since we've already got // a match. // TODO: There's a possible flaw here: Since a recurrance is independent of the original match // criteria, a disease that can recur is not limited by age ranges. But there may be no such disease. // It would be a disease that can recur but only within a certain age range, once the patient // is older, the recurrance probability, like the initial disease, drops to zero. for (Double p : getRepeatProbability()) { if (rng.nextUniform(0.0, 1.0) > p.doubleValue()) break; long next; if (eventTime.getTime()+getMinimumSpacing() >= patient.getNow().getTime()) break; next = rng.nextLong(eventTime.getTime()+getMinimumSpacing(), patient.getNow().getTime()); eventTime = m.getEventTime(patient, rng, new Date(next)); apply( patient, eventTime ); } } public GenSource() { }; /** * Call each matcher looking for a match. The first Matcher to match is returned. * A probability will be extrated from the matching entry and used to determine if the patient actually * will have this item triggered. * @return a matching child, or null */ protected Matcher matchFirst( GenMedical patient ) { for (Matcher m : getMatchers()) { if (m.match(patient) && fire( m)) return m; } return null; } /** * This method determines if we should actually fire the trigger, which should have already been determined to match this * sources criteria, should actually apply or not. For example, it 20% of males of a certain age will get * X disease, then this method determines the 20%. * @param matcher * @return True if this patient is actually chosen to get the source. */ protected boolean fire( Matcher matcher ) { return (rng.nextUniform(0.0, 1.0) < matcher.getProbability()); } /** * This method generates the actual data based on matching * criteria. For example, if a patient qualifies for both match() and next() then apply() * will generate one or more medical events appropriate to this source. * For the default behavior, we simply look for a match among our children, if any. * Careful: at this point, we have 100% certainty that the parent matches. Thus, * all probabilities below this level are relative to the parent. For example, if 20% of * people get diabetes, then a child probability of 25% for 40-60 year olds means 25% of * that 20% or a net of 5% probability. the child probabilities do not need to add to 100%. * For example, if nothing happens to a certain portion of the matching population, then it can * simply be omitted, or if you prefer, implement that fraction with nothing in apply function. * You may or may not call super.apply(). If, for example, something happens for ALL diabetics, * then this should be included in the parent level. The method can then call super.apply() which * will apply additional medical data only to that matching group. * @param patient */ protected void apply(GenMedical patient, Date eventTime) { // Now carry out the appropriate scenario // Compute scenario endTime (dod or now) long msDOD = patient.getDateOfDeath( ).getTime(); long msNow = patient.getNow().getTime(); Date endTime; if (msDOD < msNow) endTime = new Date( msDOD ); else endTime = new Date( msNow ); if (getScenario()!=null) getScenario().apply(patient, eventTime, endTime, rng); } /** * Return the actual list of children, creating one if needed. A child is typically restricted by the parent. * For example, the parent can determine that the patient is diabetic and then each child is * only concerned with the age of the patient. In these cases, the child can delegate apply method to the parent * if nothing is different among the different age groups except probability. But be careful: the * course of a disease is often different based on patient age and other factors. * @return */ public List<Matcher> getMatchers() { if (matchers==null) matchers = new ArrayList<Matcher>( 10 ); return matchers; } public void setChildren(List<Matcher> matchers) { this.matchers = matchers; } /** * Add a Matcher * @param matcher */ public void addMatcher( Matcher matcher) { getMatchers().add( matcher ); } /** * Minimum spacing between occurances of this event. * @return */ public long getMinimumSpacing() { return minimumSpacing; } public void setMinimumSpacing(long minimumSpacing) { this.minimumSpacing = minimumSpacing; } /** * Each entry in this list is the probability that this same source will occur again for the nth time. * If this list is empty, then the problem only occurs once (per lifetime). If the problem can * repeat, then spacing should indicate the minimum. For example, pregnancy would have a spacing of, say, 10 months. * Each probability in this list is based on the previous event actually occuring (100% probability). * If breast cancer has an initial occurance of, say, 0.01 it might have a recurrance rate of say 0.20. * Pregnancy (in women) may occur 0.30 with a recurrance of 0.75, 0.20, etc. meaning that 20% of * women with two pregnancies will have a third (it does not mean that 20% of all women will have three pregnancies). * @return */ public List<Double> getRepeatProbability() { if (repeatProbability==null) repeatProbability = new ArrayList<Double>( 10 ); return repeatProbability; } public void setRepeatProbability(List<Double> repeatProbability) { this.repeatProbability = repeatProbability; } public void addRepeatProbability( double probability) { getRepeatProbability().add(new Double( probability )); } public Scenario getScenario() { return scenario; } public void setScenario(Scenario scenario) { this.scenario = scenario; } } --- NEW FILE: ValueGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import org.apache.commons.math.random.RandomData; public abstract class ValueGen { public abstract double generate( RandomData rng); } --- NEW FILE: BreastCancerGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class BreastCancerGen extends CancerGen { @Override protected void apply(GenMedical patient, Date eventTime) { super.apply(patient, eventTime); // TODO Auto-generated method stub } public BreastCancerGen( RandomData rng ) { this.rng = rng; setDiseaseName( "Breast Cancer" ); addMatcher( new DemogMatcher( 0, 20, "M", 0.0015)); addMatcher( new DemogMatcher( 0, 20, "F", 0.0285)); addMatcher( new DemogMatcher( 20, 40, "M", 0.0035)); addMatcher( new DemogMatcher( 20, 40, "F", 0.0475)); addMatcher( new DemogMatcher( 40, 60, "M", 0.0035)); addMatcher( new DemogMatcher( 40, 60, "F", 0.0665)); addMatcher( new DemogMatcher( 60, 200, "M", 0.0035)); addMatcher( new DemogMatcher( 60, 200, "F", 0.0665)); } } --- NEW FILE: FractureGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; public class FractureGen extends DiseaseGen { @Override protected void apply(GenMedical patient, Date eventTime) { Date oneYearsAgo = patient.monthsAgo( 12 ); String status; if (eventTime.before(oneYearsAgo)) status = "Active"; else status = "Inactive"; patient.generateProblem(eventTime, getDiseaseName(), status); super.apply(patient, eventTime); } } --- NEW FILE: PoissonValueGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import org.apache.commons.math.random.RandomData; public class PoissonValueGen extends ValueGen { private double mean; public double generate( RandomData rng) { return rng.nextPoisson(mean); } public PoissonValueGen( double mean ) { this.mean = mean; } public double getMean() { return mean; } public void setMean(double mean) { this.mean = mean; } } --- NEW FILE: AsthmaGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; public class AsthmaGen extends ChronicDiseaseGen { public AsthmaGen( RandomData rng ) { this.rng = rng; setDiseaseName( "Asthma" ); addMatcher( new DemogMatcher( 0, 20, "M", 0.035)); addMatcher( new DemogMatcher( 0, 20, "F", 0.035)); addMatcher( new DemogMatcher( 20, 40, "M", 0.045)); addMatcher( new DemogMatcher( 20, 40, "F", 0.045)); addMatcher( new DemogMatcher( 40, 60, "M", 0.035)); addMatcher( new DemogMatcher( 40, 60, "F", 0.035)); addMatcher( new DemogMatcher( 60, 200, "M", 0.03)); addMatcher( new DemogMatcher( 60, 200, "F", 0.03)); } } --- NEW FILE: GroupScenario.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.math.random.RandomData; /** * Apply all scenarios in the group * @author John Churin * */ public class GroupScenario extends Scenario { private List<Scenario> scenarios; public GroupScenario( String title, Scenario[] scenarios ) { super( title ); for ( int x = 0; x < scenarios.length; x++ ) { getScenarios().add(scenarios[x]); } } /** * Apply a group of scenarios unconditionally. * @param patient * @param startTime * @param endTime * @param rng * @return Return true if at least one of the child scenarios did something (returned true), otherwise false. */ public boolean apply(GenMedical patient, Date startTime, Date endTime, RandomData rng ) { boolean rslt = false; for ( Scenario s : getScenarios()) { if (s.apply( patient, startTime, endTime, rng)) rslt = true; } return rslt; } public List<Scenario> getScenarios() { if (scenarios==null) scenarios = new ArrayList<Scenario>( 10 ); return scenarios; } public void setScenarios(List<Scenario> scenarios) { this.scenarios = scenarios; } /** * Add a Scenario * @param scenario */ public void addScenario( Scenario scenario) { getScenarios().add( scenario ); } } --- NEW FILE: HypertensionGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import org.apache.commons.math.random.RandomData; public class HypertensionGen extends ChronicDiseaseGen { public HypertensionGen( RandomData rng ) { this.rng = rng; setDiseaseName( "Hypertension" ); addMatcher( new DemogMatcher( 0, 20, "M", 0.12)); addMatcher( new DemogMatcher( 0, 20, "F", 0.08)); addMatcher( new DemogMatcher( 20, 40, "M", 0.06)); addMatcher( new DemogMatcher( 20, 40, "F", 0.04)); addMatcher( new DemogMatcher( 40, 60, "M", 0.228)); addMatcher( new DemogMatcher( 40, 60, "F", 0.152)); addMatcher( new DemogMatcher( 60, 200, "M", 0.426)); addMatcher( new DemogMatcher( 60, 200, "F", 0.284)); } } --- NEW FILE: DiabetesGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.GregorianCalendar; import org.apache.commons.math.random.RandomData; /** * A diabetes disease generator. Our superclass handles the basics of getting the disease * added to the patient. We then can go on to apply additional data such as tests, doctor visits, * and secondary diagnoses associated with diabetes. * @author John Churin */ public class DiabetesGen extends ChronicDiseaseGen { public DiabetesGen( RandomData rng ) { this.rng = rng; setDiseaseName( "Diabetes Mellitus" ); addMatcher( new DemogMatcher( 0, 20, "M", 0.04)); addMatcher( new DemogMatcher( 0, 20, "F", 0.06)); addMatcher( new DemogMatcher( 20, 40, "M", 0.012)); addMatcher( new DemogMatcher( 20, 40, "F", 0.018)); addMatcher( new DemogMatcher( 40, 60, "M", 0.052)); addMatcher( new DemogMatcher( 40, 60, "F", 0.078)); addMatcher( new DemogMatcher( 60, 200, "M", 0.08)); addMatcher( new DemogMatcher( 60, 200, "F", 0.12)); // Some scenario components we'll use below Scenario podiatry = new RadiologyScenario( "Foot Exam", "No abnormality noted on either foot.", "Normal"); Scenario eagerLab = new GroupScenario("0.50 scenario in Diabetes", new Scenario[] { new LabTestScenario("hemoglobin A1C test", "%", "7 (or less)", 1, new GaussianValueGen( 6.0, rng.nextUniform(0.5, 1.3)) ), new LabTestScenario("Creatinine", "mg/dL", "0.9 to 1.4 mg/dL", 1, new GaussianValueGen( 1.2, rng.nextUniform(0.1, 0.3)) ), new BatteryScenario( "Lipid Panel", new Scenario[] { new LabTestScenario("low-density lipoprotein (LDL)", "mg/dL", ">100 mg/dL", 0, new GaussianValueGen( 85.0, rng.nextUniform(10.0, 20.0)) ), new LabTestScenario("triglycerides", "mg/dL", ">150 mg/dL", 0, new GaussianValueGen( 140.0, rng.nextUniform(5.0, 15.0)) ) }), new LabTestScenario("urine albumin", "mcg", ">30 mcg", 0, new GaussianValueGen( 29.0, rng.nextUniform(4.0, 7.0)) ) }); Scenario lazyLab = new GroupScenario("0.25 scenario in Diabetes", new Scenario[] { new LabTestScenario("hemoglobin A1C test", "%", "7 (or less)", 1, new GaussianValueGen( 9.0, rng.nextUniform(1.0, 3.5)) ), new LabTestScenario("Creatinine", "mg/dL", "0.9 to 1.4 mg/dL", 1, new GaussianValueGen( 1.1, rng.nextUniform(0.3, 0.7)) ), new BatteryScenario( "Lipid Panel", new Scenario[] { new LabTestScenario("low-density lipoprotein (LDL)", "mg/dL", ">100 mg/dL", 0, new GaussianValueGen( 165.0, rng.nextUniform(10.0, 40.0)) ), new LabTestScenario("triglycerides", "mg/dL", ">150 mg/dL", 0, new GaussianValueGen( 180.0, rng.nextUniform(15.0, 28.0)) ) }), new LabTestScenario("urine albumin", "mcg", ">30 mcg", 0, new GaussianValueGen( 35.0, rng.nextUniform(5.1, 11.2)) ) }); // Specify the scenario here. this.setScenario(new ChooseScenario( new ProbabilityScenario[] { new ProbabilityScenario( 0.50, new RepeatScenario( GregorianCalendar.MONTH, 12,1.5, false, 1, 0, new GroupScenario( "12 month repeat", new Scenario[] {eagerLab, podiatry, new RepeatScenario(GregorianCalendar.MONTH, 6,1.5, false, 1, 1, eagerLab)}))), new ProbabilityScenario( 0.25, new RepeatScenario( GregorianCalendar.MONTH, 8,2.1, true, 0, 0, new GroupScenario( "12 month repeat", new Scenario[] {lazyLab, podiatry, new RepeatScenario(GregorianCalendar.MONTH, 6,1.5, false, 1, 1, lazyLab) }))) })); } } --- NEW FILE: SimpleMatcher.java --- package org.tolven.gen.model; import java.text.ParseException; import java.util.Date; import java.util.GregorianCalendar; import org.apache.commons.math.random.RandomData; /** * This simple matcher always matches (100% probability) with an event time of now as defined in the * GenMedical object. * @author John Churin * */ public class SimpleMatcher extends Matcher { public SimpleMatcher() { super(1.0); } @Override protected Date getEarliest( GenMedical patient ) { return patient.getNow(); } @Override protected Date getLatest( GenMedical patient ) { return patient.getNow(); } @Override protected boolean match(GenMedical patient) { return true; } /** * Event time is overridden to be now. */ @Override public Date getEventTime( GenMedical patient, RandomData rng, Date minTime ) { return patient.getNow(); } } --- NEW FILE: DiseaseGen.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; public class DiseaseGen extends GenSource { private String diseaseName; public DiseaseGen() { } public DiseaseGen(String diseaseName) { setDiseaseName( diseaseName ); } public String getDiseaseName() { return diseaseName; } public void setDiseaseName(String diseaseName) { this.diseaseName = diseaseName; } @Override protected void apply(GenMedical patient, Date eventTime) { // System.out.println( "Patient " + patient.getFamilyName() + " has " + this.getDiseaseName()); super.apply(patient, eventTime); } } --- NEW FILE: Matcher.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.gen.model; import java.util.Date; import org.apache.commons.math.random.RandomData; /** * Attempt to match * @author John Churin * */ public abstract class Matcher { private double probability; public Matcher( double probability ) { setProbability( probability ); } /** * See if this source matches the patient's data. This method only determines that * a patient is potentially qualified. It doesn't mean the specified patient will indeed receive this * source of data. * One of the criteria a source can consider is if a patient can have the condition more than once. * So one source might say the patient never having had mumps will have a certain chance of getting mumps. * Then another source will look for patients with mumps and apply a low probability of * getting it again. * Match criteria is hierarchical. * @param patient * @return */ protected abstract boolean match ( GenMedical patient ); protected abstract Date getEarliest( GenMedical patient ); protected abstract Date getLatest( GenMedical patient ); /** * Calculate a reasonable event time given that this matcher matched. * It probably can't be earlier than the DOB+lowAge and the lesser of DOB+highAge * and now. It also can't be before the previous occurance of this event + minimum spacing. * @param patient * @return */ public Date getEventTime( GenMedical patient, RandomData rng, Date minTime ) { Date eventLow = getEarliest( patient ); if (minTime!=null && minTime.after(eventLow)) eventLow = minTime; Date eventHigh = getLatest( patient ); Date eventNow = patient.getNow(); long msHighOffset; if ( eventHigh.after(eventNow)) msHighOffset = eventNow.getTime()- eventLow.getTime(); else msHighOffset = eventHigh.getTime() - eventLow.getTime(); Date eventTime; if (msHighOffset > 0) { long msOffset = rng.nextLong(eventLow.getTime(), eventLow.getTime()+msHighOffset); eventTime = new Date(msOffset); } else { eventTime = eventLow; } return eventTime; } /** * The probability (between 0.0 and 1.0 that a patient with matching criteria will * actually match. For example, if the patient has risk factory for diabetes including demographics, * in other word, the match function returns true, then a random number is chosen between * 0.0 and 1.0. If it is less than this value, then next will return true. * @return */ public double getProbability() { return probability; } public void setProbability(double probability) { this.probability = probability; } } --- NEW FILE: LabTest.java --- package org.tolven.gen.model; import java.util.Date; /** * A simple bean to hold the essential elements of a lab test. * @author John Churin * */ public class LabTest { private Date effectiveTime; private String testName; private double value; private String stringValue; private String units; private String interpretation; private String source; public String getInterpretation() { return interpretation; } public void setInterpretation(String interpretation) { this.interpretation = interpretation; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } public Date getEffectiveTime() { return effectiveTime; } public void setEffectiveTime(Date effectiveTime) { this.effectiveTime = effectiveTime; } public String getStringValue() { return stringValue; } public void setStringValue(String stringValue) { this.stringValue = stringValue; } public String getTestName() { return testName; } public void setTestName(String testName) { this.testName = testName; } public String getUnits() { return units; } public void setUnits(String units) { this.units = units; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } } --- NEW FILE: GenMedicalCCR.java --- package org.tolven.gen.model; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import javax.xml.bind.JAXBException; import org.apache.commons.math.random.RandomData; import org.tolven.ccr.ActorType; import org.tolven.ccr.CodedDescriptionType; import org.tolven.ccr.ContinuityOfCareRecord; import org.tolven.ccr.DateTimeType; import org.tolven.ccr.IDType; import org.tolven.ccr.PersonNameType; import org.tolven.ccr.ProblemType; import org.tolven.ccr.ResultType; import org.tolven.ccr.TestType; import org.tolven.ccr.ActorType.Address; import org.tolven.doc.entity.CCRException; import org.tolven.gen.entity.FamilyUnit; import org.tolven.gen.entity.VirtualPerson; public class GenMedicalCCR extends GenMedical { private ContinuityOfCareRecord ccr; private org.tolven.ccr.ObjectFactory ccrFactory; private int nextId = 0; /** * Construct a new medical data generator for a specific patient. * @param patient Contains the parent menu data (the patient) for the problems we'll be creating * @param now * @throws CCRException * @throws JAXBException */ public GenMedicalCCR ( Date now, int startYear) { super( now, startYear); this.ccrFactory = org.tolven.ccr.ObjectFactory.getInstance(); } public ContinuityOfCareRecord generate( ) { ccr = ccrFactory.createContinuityOfCareRecord(); ccr.setCCRDocumentObjectID( getDocumentId() ); ccr.setVersion("V1.0"); // We're the callback that the scenarios will call to create ccr data. for (GenSource gs: getCriteria()) { gs.generate( this ); } return ccr; } public ActorType addActor() { ActorType actor = new ActorType(); nextId++; actor.setActorObjectID(String.format("AC%06d", nextId)); // Remember that we're storing actors at the Tolven document level until marshall time // when we put it in the CCR document. if (ccr.getActors()==null) ccr.setActors(new ContinuityOfCareRecord.Actors()); ccr.getActors().getActor().add(actor); return actor; } /** * A nominal callback function to create the patient details in our target document. * All patients generated here are new so we'll just make up a random number as a * patient medicalrecordNumber - there may even be duplicates which we'll chalk up to * reality. * @param startYear * @return */ public void generateNewPatient( Date eventTime ) { // if (vp.getDob().after(now)) return; // if (vp.getDod() != null && vp.getDod().before(now)) return; ActorType patActor = addActor(); IDType id = new IDType(); id.setID(Long.toString(getRng().nextLong(10000000,99999999))); CodedDescriptionType idType = new CodedDescriptionType(); idType.setText("DemoPatient"); id.setType(idType); patActor.getIDs()... [truncated message content] |
From: John C. <jc...@us...> - 2007-01-16 06:12:35
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/model In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14454/src/org/tolven/gen/model Log Message: Directory /cvsroot/tolven/tolvenEJB/src/org/tolven/gen/model added to the repository |
From: John C. <jc...@us...> - 2007-01-16 06:10:36
|
Update of /cvsroot/tolven/tolven/postgres-config In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13923/postgres-config Modified Files: indexes.sql Log Message: Improve query performance with new indexes Index: indexes.sql =================================================================== RCS file: /cvsroot/tolven/tolven/postgres-config/indexes.sql,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** indexes.sql 3 Oct 2006 23:29:45 -0000 1.1 --- indexes.sql 16 Jan 2007 06:10:32 -0000 1.2 *************** *** 1,3 **** --- 1,5 ---- DROP INDEX app.md_index1; + DROP INDEX app.md_index2; + DROP INDEX app.md_index3; DROP INDEX app.ms_index1; DROP INDEX app.mcol_index1; *************** *** 9,14 **** ON app.menu_data USING btree ! (account_id, menustructure_id); CREATE INDEX ms_index1 ON app.menu_structure --- 11,26 ---- ON app.menu_data USING btree ! (menustructure_id); ! ! CREATE INDEX md_index2 ! ON app.menu_data ! USING btree ! (menustructure_id, parent01_id); + CREATE INDEX md_index3 + ON app.menu_data + USING btree + (menustructure_id, lower(string01::text)); + CREATE INDEX ms_index1 ON app.menu_structure |
From: John C. <jc...@us...> - 2007-01-16 06:07:40
|
Update of /cvsroot/tolven/tolven/lib/jboss-rules/lib In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11824/lib/jboss-rules/lib Added Files: antlr-2.7.6.jar README_DEPENDENCIES.txt core-3.2.0.666.jar antlr-3.0ea8.jar commons-jci-core-1.0-406301.jar commons-logging-api-1.0.4.jar commons-jci-eclipse-3.2.0.666.jar stringtemplate-2.3b6.jar Log Message: Add JBoss rules libraries --- NEW FILE: commons-logging-api-1.0.4.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: antlr-2.7.6.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: antlr-3.0ea8.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: commons-jci-core-1.0-406301.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: core-3.2.0.666.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: README_DEPENDENCIES.txt --- This is a summary of what jars you may need in your situation. Abbreviated names have been used (only the first part of the jar name). CORE RUNTIME Runtime assumes that you are "compiling" rules using drools-compiler. * drools-core - the rule engine itself. * optional packages: o xpp3, xstream - if you are using the file based audit feature Note you can use the drools-core stand-alone if you are compiling "outside" your runtime application, and deploying serialized Package or RuleBase? objects. COMPILER - rule assembly time Rule compiler takes rules in some textual format and prepares binary Packages of rules for deployment. This depends on the CORE RUNTIME. * drools-core * drools-compiler - the rule compiler itself. * antlr3 - only if you are using native DRL. if only using XML, you can skip this. * xerces, xml-apis - only if you are using XML rules, if DRL only, can skip this. * commons-jci-core o This also requires only one pair out of: + commons-jci-eclipse, core-3.2 - for eclipse JDT to compile the java semantics (this is default) + commons-jci-janino, janino - for janino. To use this option, set -Ddrools.compiler=JANINO or use PackageBuilderConfiguration? class. * commons-logging - used by various dependencies. * commons-lang - used for string manipulation in various dependencies. * stringtemplate, anlr-2.7.6 - used in generating semantic code. JSR-94 This is the standard api for java rules (javax.rules). This depends on COMPILER. * drools-jsr94 - the implementation of the standard * jsr94-1.1 - the standard API for javax.rules. DECISION TABLES Decision tables use spreadsheets to generate rules. * drools-compiler - required as rules are generated and compiled * drools-decisiontables - contains the spreadsheet compiler for both XLS and CSV * jxl ( jexcelapi ) - for parsing Excel spreadsheets or open office - xls format. The most common use case is for COMPILER - this allows rules to be loaded from their source form, and includes the runtime engine of course. For example, if you wanted to be able to load rules from a drl source you would need: drools-core and the COMPILER jars mentioned above (not xerces, and not xml-apis), and commons-jar-eclipse, core-3.2. You will only need optional core jars if you are using those features. When building from source, the dependencies are managed by maven. In each module, there is a pom.xml file that lists the exact dependencies and exact version numbers. Even if you use ant to build, the dependencies will be downloaded for you based on those pom.xml files. --- NEW FILE: stringtemplate-2.3b6.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: commons-jci-eclipse-3.2.0.666.jar --- (This appears to be a binary file; contents omitted.) |
From: John C. <jc...@us...> - 2007-01-16 06:07:40
|
Update of /cvsroot/tolven/tolven/template In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11824/template Modified Files: ant-build.template Log Message: Add JBoss rules libraries Index: ant-build.template =================================================================== RCS file: /cvsroot/tolven/tolven/template/ant-build.template,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** ant-build.template 8 Nov 2006 07:27:41 -0000 1.49 --- ant-build.template 16 Jan 2007 06:07:38 -0000 1.50 *************** *** 77,80 **** --- 77,81 ---- tolvenWEB.location=${tolven.home}/tolvenWEB + jboss-rules.location=${tolven.location}/lib/jboss-rules openSSL.location=${tolven.location}/lib/openSSL openLDAP.location=${tolven.location}/lib/openLDAP |
From: John C. <jc...@us...> - 2007-01-16 06:07:40
|
Update of /cvsroot/tolven/tolven/lib/jboss-rules In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11824/lib/jboss-rules Added Files: drools-compiler-3.0.5.jar drools-core-3.0.5.jar Log Message: Add JBoss rules libraries --- NEW FILE: drools-compiler-3.0.5.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: drools-core-3.0.5.jar --- (This appears to be a binary file; contents omitted.) |
From: John C. <jc...@us...> - 2007-01-16 06:05:12
|
Update of /cvsroot/tolven/tolven/lib/jboss-rules In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11785/lib/jboss-rules Log Message: Directory /cvsroot/tolven/tolven/lib/jboss-rules added to the repository |
From: John C. <jc...@us...> - 2007-01-16 06:05:12
|
Update of /cvsroot/tolven/tolven/lib/jboss-rules/lib In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11785/lib/jboss-rules/lib Log Message: Directory /cvsroot/tolven/tolven/lib/jboss-rules/lib added to the repository |
From: John C. <jc...@us...> - 2007-01-15 21:59:54
|
Update of /cvsroot/tolven/tolvenWEB/web/images In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv21507/web/images Modified Files: sort_asc.gif sort_desc.gif Log Message: More visible sourt indicators Index: sort_desc.gif =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/web/images/sort_desc.gif,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsghcPdU and /tmp/cvsEmaLAO differ Index: sort_asc.gif =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/web/images/sort_asc.gif,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsGoL2wY and /tmp/cvsNCldXS differ |
From: Joseph I. <jos...@us...> - 2007-01-15 10:15:19
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25926/src/org/tolven/web/security/auth Modified Files: KeyLdapLoginModule.java Log Message: Added a PrivateKeyRing class for storage in a Subject, which ties the TolvenUser to a particular AccountPrivateKey for the Account they are logged into. This key will only allow them to access documents that are in the account to which they are logged in. Index: KeyLdapLoginModule.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth/KeyLdapLoginModule.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** KeyLdapLoginModule.java 15 Jan 2007 06:35:14 -0000 1.3 --- KeyLdapLoginModule.java 15 Jan 2007 10:15:13 -0000 1.4 *************** *** 29,32 **** --- 29,33 ---- import org.jboss.security.auth.spi.LdapLoginModule; import org.tolven.core.entity.TolvenUser; + import org.tolven.security.key.PrivateKeyRing; import org.tolven.security.key.UserPrivateKey; import org.tolven.security.key.UserPublicKey; *************** *** 123,131 **** System.out.println(getClass() + ": Adding UserPrivateKey to Subject " + user.getLdapUID()); userPrivateKey.unlockPrivateKey(passwordCredential.getPassword()); ! // Ensure there is only one UserPrivateKey in a Subject by removing any that might be there ! for (Iterator iter = subject.getPrivateCredentials(UserPrivateKey.class).iterator(); iter.hasNext();) { iter.remove(); } ! subject.getPrivateCredentials().add(userPrivateKey); System.out.println(getClass() + ": Adding getUserPublicKey to Subject " + user.getLdapUID()); // Ensure there is only one UserPublicKey in a Subject by removing any that might be there --- 124,132 ---- System.out.println(getClass() + ": Adding UserPrivateKey to Subject " + user.getLdapUID()); userPrivateKey.unlockPrivateKey(passwordCredential.getPassword()); ! // Ensure there is only one PrivateKeyRing in a Subject by removing any that might be there ! for (Iterator iter = subject.getPrivateCredentials(PrivateKeyRing.class).iterator(); iter.hasNext();) { iter.remove(); } ! subject.getPrivateCredentials().add(new PrivateKeyRing(userPrivateKey)); System.out.println(getClass() + ": Adding getUserPublicKey to Subject " + user.getLdapUID()); // Ensure there is only one UserPublicKey in a Subject by removing any that might be there *************** *** 161,166 **** if (aborted && System.getProperty("tolven.security.keys.activate") != null) { try { ! // Remove all UserPrivateKey ! for (Iterator iter = subject.getPrivateCredentials(UserPrivateKey.class).iterator(); iter.hasNext();) { iter.remove(); } --- 162,167 ---- if (aborted && System.getProperty("tolven.security.keys.activate") != null) { try { ! // Remove PrivateKeyRing ! for (Iterator iter = subject.getPrivateCredentials(PrivateKeyRing.class).iterator(); iter.hasNext();) { iter.remove(); } |
From: Joseph I. <jos...@us...> - 2007-01-15 10:15:18
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25926/src/org/tolven/web Modified Files: TopAction.java Log Message: Added a PrivateKeyRing class for storage in a Subject, which ties the TolvenUser to a particular AccountPrivateKey for the Account they are logged into. This key will only allow them to access documents that are in the account to which they are logged in. Index: TopAction.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/TopAction.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** TopAction.java 11 Jan 2007 08:16:06 -0000 1.28 --- TopAction.java 15 Jan 2007 10:15:12 -0000 1.29 *************** *** 44,47 **** --- 44,48 ---- import org.tolven.security.TolvenPerson; import org.tolven.security.bean.LDAPLocal; + import org.tolven.security.key.PrivateKeyRing; import org.tolven.security.key.UserPrivateKey; *************** *** 216,219 **** --- 217,222 ---- return "dispatch"; } + if (System.getProperty("tolven.security.keys.activate") != null) + updatePrivateKeyRing(); accountUserId = accountUser.getId(); // Save the account Id - we'll need it in subsequent requests *************** *** 282,293 **** } ! public UserPrivateKey getUserPrivateKey() throws PolicyContextException, GeneralSecurityException { Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); if (subject == null) throw new GeneralSecurityException("No Subject found in PolicyContext for " + getUser().getLdapUID()); ! Set privateCredentials = subject.getPrivateCredentials(UserPrivateKey.class); if (privateCredentials.isEmpty()) ! throw new GeneralSecurityException(": No UserPrivateKey found for " + getUser().getLdapUID()); ! return (UserPrivateKey) privateCredentials.iterator().next(); } --- 285,325 ---- } ! /** ! * Return the PrivateKeyRing for the user ! * @return ! * @throws PolicyContextException ! * @throws GeneralSecurityException ! */ ! public PrivateKeyRing getPrivateKeyRing() throws PolicyContextException, GeneralSecurityException { Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); if (subject == null) throw new GeneralSecurityException("No Subject found in PolicyContext for " + getUser().getLdapUID()); ! Set privateCredentials = subject.getPrivateCredentials(PrivateKeyRing.class); if (privateCredentials.isEmpty()) ! throw new GeneralSecurityException(": No PrivateKeyRing found for " + getUser().getLdapUID()); ! return (PrivateKeyRing) privateCredentials.iterator().next(); ! } ! ! /** ! * Return the UserPrivateKey for the user ! * @return ! * @throws PolicyContextException ! * @throws GeneralSecurityException ! */ ! public UserPrivateKey getUserPrivateKey() throws PolicyContextException, GeneralSecurityException { ! return getPrivateKeyRing().getUserPrivateKey(); ! } ! ! /** ! * Update the PrivateKeyRing with the AccountPrivateKey of the Account that the user is currently logged into ! * @throws PolicyContextException ! * @throws GeneralSecurityException ! */ ! private void updatePrivateKeyRing() throws PolicyContextException, GeneralSecurityException { ! PrivateKeyRing privateKeyRing = getPrivateKeyRing(); ! AccountUser accountUser = activation.findAccountUser(accountUserId); ! if (accountUser == null) ! throw new GeneralSecurityException(": No AccountUser found for " + getUser().getLdapUID()); ! privateKeyRing.setAccountPrivateKey(accountUser.getAccountPrivateKey()); } |
From: Joseph I. <jos...@us...> - 2007-01-15 10:15:16
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25891/src/org/tolven/doc/entity Modified Files: DocBase.java Log Message: Added a PrivateKeyRing class for storage in a Subject, which ties the TolvenUser to a particular AccountPrivateKey for the Account they are logged into. This key will only allow them to access documents that are in the account to which they are logged in. Index: DocBase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity/DocBase.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DocBase.java 14 Jan 2007 06:26:24 -0000 1.14 --- DocBase.java 15 Jan 2007 10:15:09 -0000 1.15 *************** *** 19,23 **** import java.security.PublicKey; import java.security.acl.Group; - import java.util.Iterator; import java.util.Set; --- 19,22 ---- *************** *** 45,52 **** import org.apache.commons.codec.binary.Base64; import org.tolven.core.entity.Account; - import org.tolven.core.entity.AccountUser; import org.tolven.core.entity.TolvenUser; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.DocumentSecretKey; import org.tolven.security.key.UserPrivateKey; --- 44,51 ---- import org.apache.commons.codec.binary.Base64; import org.tolven.core.entity.Account; import org.tolven.core.entity.TolvenUser; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.DocumentSecretKey; + import org.tolven.security.key.PrivateKeyRing; import org.tolven.security.key.UserPrivateKey; *************** *** 195,219 **** if (principal == null) throw new IllegalStateException("No Principal found in Subject"); ! Set privateCredentials = subject.getPrivateCredentials(UserPrivateKey.class); if (privateCredentials.isEmpty()) ! throw new RuntimeException(": No UserPrivateKey found in Subject " + principal.getName()); ! UserPrivateKey userPrivateKey = (UserPrivateKey)privateCredentials.iterator().next(); PrivateKey privateKey = userPrivateKey.getPrivateKey(); ! //TODO: Not sure if this is the most efficient way to find the AccountUser of the logged in user ! Set<AccountUser> accountUsers = account.getAccountUsers(); ! AccountUser loggedInAccountUser = null; ! for (Iterator<AccountUser> iter = accountUsers.iterator(); iter.hasNext();) { ! loggedInAccountUser = iter.next(); ! if (loggedInAccountUser.getUser().getLdapUID().equals(principal.getName())) ! break; ! } ! if (loggedInAccountUser == null) ! throw new RuntimeException("No authorization to access documents in this account"); ! AccountPrivateKey loggedInAccountPrivateKey = loggedInAccountUser.getAccountPrivateKey(); ! if (loggedInAccountPrivateKey == null) { //TODO: No AccountPrivateKey means the content cannot be decrypted....for now give it back as encryptedContent return encryptedContent; } ! SecretKey docSecretKey = documentSecretKey.getSecretKey(loggedInAccountPrivateKey.getPrivateKey(privateKey)); Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, docSecretKey); --- 194,209 ---- if (principal == null) throw new IllegalStateException("No Principal found in Subject"); ! Set privateCredentials = subject.getPrivateCredentials(PrivateKeyRing.class); if (privateCredentials.isEmpty()) ! throw new RuntimeException(": No PrivateKeyRing found in Subject " + principal.getName()); ! PrivateKeyRing privateKeyRing = (PrivateKeyRing)privateCredentials.iterator().next(); ! UserPrivateKey userPrivateKey = privateKeyRing.getUserPrivateKey(); PrivateKey privateKey = userPrivateKey.getPrivateKey(); ! AccountPrivateKey activeAccountPrivateKey = privateKeyRing.getAccountPrivateKey(); ! if (activeAccountPrivateKey == null) { //TODO: No AccountPrivateKey means the content cannot be decrypted....for now give it back as encryptedContent return encryptedContent; } ! SecretKey docSecretKey = documentSecretKey.getSecretKey(activeAccountPrivateKey.getPrivateKey(privateKey)); Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, docSecretKey); |
From: Joseph I. <jos...@us...> - 2007-01-15 10:15:16
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/key In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25891/src/org/tolven/security/key Added Files: PrivateKeyRing.java Log Message: Added a PrivateKeyRing class for storage in a Subject, which ties the TolvenUser to a particular AccountPrivateKey for the Account they are logged into. This key will only allow them to access documents that are in the account to which they are logged in. --- NEW FILE: PrivateKeyRing.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; /** * This class contains an unremovable UserPrivateKey and can hold a companion AccountPrivateKey for the account * which the user is logged into. There can only ever be one such account at any given time * @author Joseph Isaac * */ public class PrivateKeyRing { private UserPrivateKey userPrivateKey; private AccountPrivateKey accountPrivateKey; public PrivateKeyRing(UserPrivateKey aUserPrivateKey) { this.userPrivateKey = aUserPrivateKey; } public UserPrivateKey getUserPrivateKey() { return userPrivateKey; } public AccountPrivateKey getAccountPrivateKey() { return accountPrivateKey; } public void setAccountPrivateKey(AccountPrivateKey anAccountPrivateKey) { this.accountPrivateKey = anAccountPrivateKey; } } |
From: Joseph I. <jos...@us...> - 2007-01-15 09:29:13
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2361/src/org/tolven/web/security/auth Modified Files: KeyLdapLoginModule.java Log Message: The Subject is now updated with the * role to match the roles which appear in web.xml. We currently do not distinguish by roles (only by LDAP authentication), but this will probably change in the future. Index: KeyLdapLoginModule.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth/KeyLdapLoginModule.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KeyLdapLoginModule.java 11 Jan 2007 08:16:06 -0000 1.2 --- KeyLdapLoginModule.java 15 Jan 2007 06:35:14 -0000 1.3 *************** *** 47,58 **** //TODO: Currently we treat all roles the same. When we decide to add roles to LDAP, this method can be removed. protected Group[] getRoleSets() { ! Group[] roleSets = null; ! if (System.getProperty("tolven.security.keys.activate") == null) { ! roleSets = new Group[0]; ! } else { ! roleSets = new Group[1]; ! roleSets[0] = new SimpleGroup("Roles"); ! roleSets[0].addMember(new SimplePrincipal("*")); ! } return roleSets; } --- 47,53 ---- //TODO: Currently we treat all roles the same. When we decide to add roles to LDAP, this method can be removed. protected Group[] getRoleSets() { ! Group[] roleSets = new Group[1]; ! roleSets[0] = new SimpleGroup("Roles"); ! roleSets[0].addMember(new SimplePrincipal("*")); return roleSets; } |
From: Joseph I. <jos...@us...> - 2007-01-14 06:45:47
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29367/src/org/tolven/doc/bean Modified Files: DocumentBean.java Log Message: The Demo/Debug/Documents tab now lists all the documents that belong to the user from all accounts, but when ecryption is active, only those associated with the current account will be decrypted. Index: DocumentBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean/DocumentBean.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DocumentBean.java 3 Jan 2007 09:28:12 -0000 1.14 --- DocumentBean.java 14 Jan 2007 06:26:24 -0000 1.15 *************** *** 151,154 **** --- 151,166 ---- } + /** + * Return XML documents for the specified user + */ + public List<DocXML> findAllXMLDocuments(long userId, int pageSize, int offset, String sortAttribute, String sortDir ) { + Query query = em.createQuery( "SELECT d FROM DocCCR d, AccountUser au WHERE au.user.id = :user AND d.account.id = au.account.id ORDER BY d." + sortAttribute + " " + sortDir ); + query.setMaxResults(pageSize); + query.setFirstResult(offset); + query.setParameter( "user", userId); + List<DocXML> items = query.getResultList(); + return items; + } + /** * @see DocumentLocal |
From: Joseph I. <jos...@us...> - 2007-01-14 06:45:46
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/ajax In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29387/src/org/tolven/ajax Modified Files: AjaxServlet.java Log Message: The Demo/Debug/Documents tab now lists all the documents that belong to the user from all accounts, but when ecryption is active, only those associated with the current account will be decrypted. Index: AjaxServlet.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/ajax/AjaxServlet.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** AjaxServlet.java 29 Nov 2006 01:32:50 -0000 1.16 --- AjaxServlet.java 14 Jan 2007 06:26:29 -0000 1.17 *************** *** 355,375 **** } } ! if (uri.endsWith("xmlDocList.ajax")) { ! String sortAttribute = "id"; ! long accountId = (Long) req.getSession(false).getAttribute("accountId"); ! List<DocXML> rows = documentLocal.findXMLDocuments(accountId, pageSize, offset, sortAttribute, sortDir ); ! int line = 0; ! for (DocXML d : rows) { ! line++; ! writer.write( "<tr>" ); ! writer.write( "<td> <a href=\"#\" onclick=\"showPane(containerId(this)+':detail-" + d.getId()+ "')\">"+ d.getId() + "</a> </td>"); ! // writer.write( "<td> " + d.getId() + "</td>"); ! writer.write( "<td> " + d.getBindingContext() + "</td>"); ! writer.write( "<td> " + d.getAuthor().getLdapUID() + "</td>"); ! writer.write( "<td> " + d.getStatus() + "</td>"); ! ! writer.write( "</tr>\n"); ! } ! } // if (uri.endsWith("sponsoredUsers.ajax")) { // String sortAttribute = "requestCode"; --- 355,395 ---- } } ! if (uri.endsWith("xmlDocList.ajax")) { ! String sortAttribute = "id"; ! long userId = ((TopAction) req.getSession(false).getAttribute("top")).getUser().getId(); ! List<DocXML> rows = documentLocal.findAllXMLDocuments(userId, pageSize, offset, sortAttribute, sortDir ); ! int line = 0; ! for (DocXML d : rows) { ! line++; ! writer.write( "<tr>" ); ! writer.write( "<td> <a href=\"#\" onclick=\"showPane(containerId(this)+':detail-" + d.getId()+ "')\">"+ d.getId() + "</a> </td>"); ! // writer.write( "<td> " + d.getId() + "</td>"); ! writer.write( "<td> " + d.getBindingContext() + "</td>"); ! writer.write( "<td> " + d.getAuthor().getLdapUID() + "</td>"); ! writer.write( "<td> " + d.getStatus() + "</td>"); ! writer.write( "<td> " + d.getAccount().getTitle() + "</td>"); ! ! writer.write( "</tr>\n"); ! } ! } ! /* ! if (uri.endsWith("xmlDocList.ajax")) { ! String sortAttribute = "id"; ! long accountId = (Long) req.getSession(false).getAttribute("accountId"); ! List<DocXML> rows = documentLocal.findXMLDocuments(accountId, pageSize, offset, sortAttribute, sortDir ); ! int line = 0; ! for (DocXML d : rows) { ! line++; ! writer.write( "<tr>" ); ! writer.write( "<td> <a href=\"#\" onclick=\"showPane(containerId(this)+':detail-" + d.getId()+ "')\">"+ d.getId() + "</a> </td>"); ! // writer.write( "<td> " + d.getId() + "</td>"); ! writer.write( "<td> " + d.getBindingContext() + "</td>"); ! writer.write( "<td> " + d.getAuthor().getLdapUID() + "</td>"); ! writer.write( "<td> " + d.getStatus() + "</td>"); ! ! writer.write( "</tr>\n"); ! } ! } ! */ // if (uri.endsWith("sponsoredUsers.ajax")) { // String sortAttribute = "requestCode"; |
From: Joseph I. <jos...@us...> - 2007-01-14 06:45:46
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29367/src/org/tolven/doc/entity Modified Files: DocBase.java Log Message: The Demo/Debug/Documents tab now lists all the documents that belong to the user from all accounts, but when ecryption is active, only those associated with the current account will be decrypted. Index: DocBase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity/DocBase.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** DocBase.java 9 Jan 2007 07:44:08 -0000 1.13 --- DocBase.java 14 Jan 2007 06:26:24 -0000 1.14 *************** *** 220,225 **** return cipher.doFinal(encryptedContent); } catch (Exception ex) { ! ex.printStackTrace(); ! return "THIS DOCUMENT IS ENCRYPTED AND YOU DO NOT HAVE A KEY TO DECRYPT IT".getBytes(); } } --- 220,224 ---- return cipher.doFinal(encryptedContent); } catch (Exception ex) { ! return "THIS DOCUMENT CANNOT BE DECRYPTED".getBytes(); } } |
From: Joseph I. <jos...@us...> - 2007-01-14 06:45:45
|
Update of /cvsroot/tolven/tolvenWEB/web/five/test In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29387/web/five/test Modified Files: docList.xhtml Log Message: The Demo/Debug/Documents tab now lists all the documents that belong to the user from all accounts, but when ecryption is active, only those associated with the current account will be decrypted. Index: docList.xhtml =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/web/five/test/docList.xhtml,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** docList.xhtml 7 Nov 2006 08:41:03 -0000 1.3 --- docList.xhtml 14 Jan 2007 06:26:29 -0000 1.4 *************** *** 20,24 **** // ]]> </script> ! <p> Doucments owned by this account</p> <div style="border: 1px solid #E1E1E1;width:590px"> <table id="#{menu.element}LG_header"> --- 20,24 ---- // ]]> </script> ! <p> Documents owned by the logged in user</p> <div style="border: 1px solid #E1E1E1;width:590px"> <table id="#{menu.element}LG_header"> *************** *** 29,32 **** --- 29,33 ---- <th align="left" width="200px">Author</th> <th align="left" width="100px">Status</th> + <th align="left" width="200px">Account</th> </tr> </thead> *************** *** 34,48 **** <table id="#{menu.element}LG" > <tbody> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td></tr> </tbody> </table> --- 35,49 ---- <table id="#{menu.element}LG" > <tbody> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> ! <tr><td align="right" width="60px">-</td><td align="left" width="200px">-</td><td align="left" width="100px">-</td><td align="left" width="200px">-</td><td align="left" width="200px">-</td></tr> </tbody> </table> |
From: Joseph I. <jos...@us...> - 2007-01-14 06:45:45
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29367/src/org/tolven/doc Modified Files: DocumentLocal.java Log Message: The Demo/Debug/Documents tab now lists all the documents that belong to the user from all accounts, but when ecryption is active, only those associated with the current account will be decrypted. Index: DocumentLocal.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/DocumentLocal.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DocumentLocal.java 28 Sep 2006 19:06:01 -0000 1.7 --- DocumentLocal.java 14 Jan 2007 06:26:24 -0000 1.8 *************** *** 81,88 **** public DocBase findDocument( long docId ); ! /** ! * Return XML documents for the specified account ! */ ! public List<DocXML> findXMLDocuments(long accountId, int pageSize, int offset, String sortAttribute, String sortDir ); /** --- 81,93 ---- public DocBase findDocument( long docId ); ! /** ! * Return XML documents for the specified account ! */ ! public List<DocXML> findXMLDocuments(long accountId, int pageSize, int offset, String sortAttribute, String sortDir ); ! ! /** ! * Return XML documents for the specified user ! */ ! public List<DocXML> findAllXMLDocuments(long userId, int pageSize, int offset, String sortAttribute, String sortDir ); /** |
From: Joseph I. <jos...@us...> - 2007-01-11 08:16:39
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14364/src/org/tolven/web Modified Files: TopAction.java Log Message: Move user creation from the LoginModule to TopAction (and later from there to the EJB tier). Index: TopAction.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/TopAction.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** TopAction.java 3 Jan 2007 07:24:05 -0000 1.27 --- TopAction.java 11 Jan 2007 08:16:06 -0000 1.28 *************** *** 41,44 **** --- 41,45 ---- import org.tolven.core.entity.TolvenUser; import org.tolven.gen.CHRGenerator; + import org.tolven.security.LoginLocal; import org.tolven.security.TolvenPerson; import org.tolven.security.bean.LDAPLocal; *************** *** 63,66 **** --- 64,69 ---- // @EJB private CHRGenerator chrGen; + // @EJB + private LoginLocal loginLocal; *************** *** 111,114 **** --- 114,118 ---- propertyBean = (TolvenPropertiesLocal) ctx.lookup("tolven/TolvenProperties/local"); chrGen = (CHRGenerator) ctx.lookup("tolven/CHRGeneratorBean/local"); + loginLocal = (LoginLocal) ctx.lookup("tolven/LoginBean/local"); } catch (NamingException e) *************** *** 148,166 **** */ public String postLogin() throws Exception{ ! // Initialize tolven here ! Map<String,Object> appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap(); ! TolvenContext tolven = (TolvenContext) appMap.get("tolven"); ! if (tolven==null) { ! tolven = new TolvenContext(); ! appMap.put("tolven", tolven); ! } ! tolven.initialize(); ! AccountUser accountUser = null; ! if (accountUserId!=0) { ! accountUser = activation.findAccountUser(accountUserId ); ! accountType = accountUser.getAccount().getAccountType().getKnownType(); ! setPostLoginAction(accountUser.getAccount().getAccountType().getHomePage()); ! return "dispatch"; ! } info = "Login Processing: " + getTp().getUid(); // Get the TolvenUser --- 152,170 ---- */ public String postLogin() throws Exception{ ! // Initialize tolven here ! Map<String,Object> appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap(); ! TolvenContext tolven = (TolvenContext) appMap.get("tolven"); ! if (tolven==null) { ! tolven = new TolvenContext(); ! appMap.put("tolven", tolven); ! } ! tolven.initialize(); ! AccountUser accountUser = null; ! if (accountUserId!=0) { ! accountUser = activation.findAccountUser(accountUserId ); ! accountType = accountUser.getAccount().getAccountType().getKnownType(); ! setPostLoginAction(accountUser.getAccount().getAccountType().getHomePage()); ! return "dispatch"; ! } info = "Login Processing: " + getTp().getUid(); // Get the TolvenUser *************** *** 169,204 **** // If the user object is missing but we have an invitation, see if it might get the user all the way logged in. if ((getUser()==null || Status.NEW_LOGIN.value().equalsIgnoreCase(getUser().getStatus())) && getInvitationId()!=0) { ! // Since we have no user yet, we'll try executing an activation invitation (if it works) ! if (!activation.activate(getTp().getUid(), getInvitationId(), getNow())) { ! return dispatchingLogout("invalidInvitation"); ! } ! // try TolvenUser again setUser( activation.loginUser( getTp().getUid(), getNow() ) ); ! if (getUser()==null) return dispatchingLogout("waitingActivation"); ! // Now we can complete the activation ! invitationBean.executeInvitation( getInvitationId(), getNow()); } // If user still not logged in, send them packing, we've got a problem if (getUser()==null) { ! // It appears that Faces doesn't allow a message to persist beyond a session invalidate so, instead, ! // we'll just go to a page specific to describe the problem for the user. ! // FacesContext.getCurrentInstance().addMessage( null, new FacesMessage("Internal Error: LDAP valid, missing UserObject")); return dispatchingLogout("missingUserObject"); } ! accountUserId = getRequestParameterAsLong( "accountUserId" ); // Otherwise, we dispatch based on the defaultAccount or the one the user selected. ! if (accountUserId!=0) { ! accountUser = activation.findAccountUser(accountUserId ); ! // SAFETY CHECK HERE - Don't trust the accountUserId alone, it must match user. ! if (accountUser.getUser().getId() != getUser().getId()) { ! return dispatchingLogout("invalidInvitation"); ! } ! if (this.isRememberDefault()) { ! accountUser.setDefaultAccount(true); ! activation.updateAccountUser(accountUser); ! } ! } if (accountUser==null && !this.isIgnoreDefault()) { ! accountUser = activation.findDefaultAccountUser(getUser()); } // If still null, because there's no default or maybe because the user has no account yet, ask user what to do --- 173,208 ---- // If the user object is missing but we have an invitation, see if it might get the user all the way logged in. if ((getUser()==null || Status.NEW_LOGIN.value().equalsIgnoreCase(getUser().getStatus())) && getInvitationId()!=0) { ! // Since we have no user yet, we'll try executing an activation invitation (if it works) ! if (!activation.activate(getTp().getUid(), getInvitationId(), getNow())) { ! return dispatchingLogout("invalidInvitation"); ! } ! // try TolvenUser again setUser( activation.loginUser( getTp().getUid(), getNow() ) ); ! if (getUser()==null) return dispatchingLogout("waitingActivation"); ! // Now we can complete the activation ! invitationBean.executeInvitation( getInvitationId(), getNow()); } // If user still not logged in, send them packing, we've got a problem if (getUser()==null) { ! // It appears that Faces doesn't allow a message to persist beyond a session invalidate so, instead, ! // we'll just go to a page specific to describe the problem for the user. ! // FacesContext.getCurrentInstance().addMessage( null, new FacesMessage("Internal Error: LDAP valid, missing UserObject")); return dispatchingLogout("missingUserObject"); } ! accountUserId = getRequestParameterAsLong( "accountUserId" ); // Otherwise, we dispatch based on the defaultAccount or the one the user selected. ! if (accountUserId!=0) { ! accountUser = activation.findAccountUser(accountUserId ); ! // SAFETY CHECK HERE - Don't trust the accountUserId alone, it must match user. ! if (accountUser.getUser().getId() != getUser().getId()) { ! return dispatchingLogout("invalidInvitation"); ! } ! if (this.isRememberDefault()) { ! accountUser.setDefaultAccount(true); ! activation.updateAccountUser(accountUser); ! } ! } if (accountUser==null && !this.isIgnoreDefault()) { ! accountUser = activation.findDefaultAccountUser(getUser()); } // If still null, because there's no default or maybe because the user has no account yet, ask user what to do *************** *** 206,221 **** if (accountUser==null) { if (activation.countUserAccounts( getUser() ) > 0 ) { ! postLoginAction = "selectAccount.jsf"; } else { ! postLoginAction = "createAccount.jsf"; } ! return "dispatch"; } ! accountUserId = accountUser.getId(); ! // Save the account Id - we'll need it in subsequent requests ! accountId = accountUser.getAccount().getId(); ! setAccountTitle( accountUser.getAccount().getTitle()); ! setAccountTimeZone( accountUser.getAccount().getTimeZone()); ! accountType = accountUser.getAccount().getAccountType().getKnownType(); // Ensure that this user has a menu structure setup menuLocal.createDefaultMenuStructure( accountUser.getAccount() ); --- 210,225 ---- if (accountUser==null) { if (activation.countUserAccounts( getUser() ) > 0 ) { ! postLoginAction = "selectAccount.jsf"; } else { ! postLoginAction = "createAccount.jsf"; } ! return "dispatch"; } ! accountUserId = accountUser.getId(); ! // Save the account Id - we'll need it in subsequent requests ! accountId = accountUser.getAccount().getId(); ! setAccountTitle( accountUser.getAccount().getTitle()); ! setAccountTimeZone( accountUser.getAccount().getTimeZone()); ! accountType = accountUser.getAccount().getAccountType().getKnownType(); // Ensure that this user has a menu structure setup menuLocal.createDefaultMenuStructure( accountUser.getAccount() ); *************** *** 226,234 **** accountAdmin = accountUser.isAccountPermission(); if (this.isGenDemoData()) { ! chrGen.createPatients( accountUser.getUser(), accountUser.getAccount(), 100, getTop().getNow(), 1996 ); } ! setPostLoginAction(accountUser.getAccount().getAccountType().getHomePage()); ! return "dispatch"; } --- 230,252 ---- accountAdmin = accountUser.isAccountPermission(); if (this.isGenDemoData()) { ! chrGen.createPatients( accountUser.getUser(), accountUser.getAccount(), 100, getTop().getNow(), 1996 ); } ! setPostLoginAction(accountUser.getAccount().getAccountType().getHomePage()); ! return "dispatch"; ! } ! ! //TODO: This method is currently used during the login process phase One. Perhaps the creation of the user should be pushed to EJB tier ! public TolvenUser intializeUser(String userId) throws Exception { ! user = loginLocal.findUser(userId); ! if (user == null) { ! user = new TolvenUser(); ! user.setLdapUID(userId); ! user.setStatus(Status.NEW_LOGIN.value()); ! user.setLastLogin(null); // Last login is null, never logged in before this ! user.setCreation(getNow()); ! loginLocal.update(user); ! } ! return user; } |
From: Joseph I. <jos...@us...> - 2007-01-11 08:16:12
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14364/src/org/tolven/web/security/auth Modified Files: KeyLdapLoginModule.java Log Message: Move user creation from the LoginModule to TopAction (and later from there to the EJB tier). Index: KeyLdapLoginModule.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth/KeyLdapLoginModule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KeyLdapLoginModule.java 10 Jan 2007 08:52:00 -0000 1.1 --- KeyLdapLoginModule.java 11 Jan 2007 08:16:06 -0000 1.2 *************** *** 16,25 **** import java.security.Principal; import java.security.acl.Group; - import java.util.Date; import java.util.Iterator; import javax.naming.InitialContext; import javax.resource.spi.security.PasswordCredential; - import javax.security.auth.Subject; import javax.security.auth.login.LoginException; import javax.security.jacc.PolicyContext; --- 16,23 ---- *************** *** 30,34 **** import org.jboss.security.SimplePrincipal; import org.jboss.security.auth.spi.LdapLoginModule; - import org.tolven.core.entity.Status; import org.tolven.core.entity.TolvenUser; import org.tolven.security.key.UserPrivateKey; --- 28,31 ---- *************** *** 47,53 **** private transient PasswordCredential passwordCredential; - private transient LoginLocal loginLocal; - private transient TolvenUser user; - private transient boolean userModified = false; //TODO: Currently we treat all roles the same. When we decide to add roles to LDAP, this method can be removed. --- 44,47 ---- *************** *** 87,102 **** password = inputPassword.toCharArray(); passwordCredential = new PasswordCredential(callerPrincipalUserName, password); - InitialContext ictx = new InitialContext(); - loginLocal = (LoginLocal) ictx.lookup("tolven/LoginBean/local"); - user = loginLocal.findUser(callerPrincipalUserName); - if (user == null) { - // Password has validated at this point, so must be a real LDAPUser with no TolvenUser yet (but a registerd user) - user = new TolvenUser(); - user.setLdapUID(callerPrincipalUserName); - user.setStatus(Status.NEW_LOGIN.value()); - user.setLastLogin(null); // Last login is null, never logged in before this - user.setCreation(new Date()); - userModified = true; - } System.out.println(getClass() + ": validate " + callerPrincipalUserName + "=" + validated); } catch (Exception ex) { --- 81,84 ---- *************** *** 116,119 **** --- 98,123 ---- if (committed && System.getProperty("tolven.security.keys.activate") != null) { try { + // Use the session to initialize TolvenUser + HttpServletRequest request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest"); + if (request == null) + throw new LoginException(getClass() + ": could not obtain an HttpServletRequest"); + HttpSession session = request.getSession(); + if (session == null) + throw new LoginException(getClass() + ": could not obtain an HttpSession"); + TopAction top = (TopAction) session.getAttribute("top"); + if (top == null) + throw new LoginException(getClass() + ": could not obtain a TopAction"); + //TODO: Phase One obtain an initialized TolvenUser is valid + Principal callerPrincipal = getIdentity(); + if (callerPrincipal == null) { + //TODO: Should not be null but just in case + throw new LoginException(getClass() + ": Principal is null, login validated false"); + } + String callerPrincipalUserName = callerPrincipal.getName(); + top.intializeUser(callerPrincipalUserName); + TolvenUser user = top.getUser(); + if (user == null) + throw new LoginException(getClass() + ": No User found, access denied"); + boolean userModified = false; if (!user.hasUserPrivateKey()) { System.out.println(getClass() + ": initialize keys "); *************** *** 136,156 **** subject.getPublicCredentials().add(user.getUserPublicKey()); if (userModified) { loginLocal.update(user); System.out.println(getClass() + ": persisted new keys user " + user.getLdapUID()); } // Use the session to determine the AccountUser and AccountPrivateKey for the Subject - HttpServletRequest request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest"); - if (request == null) - throw new LoginException(getClass() + ": could not obtain an HttpServletRequest"); - HttpSession session = request.getSession(); - if (session == null) - throw new LoginException(getClass() + ": could not obtain an HttpSession"); - TopAction top = (TopAction)session.getAttribute("top"); - if (top == null) - throw new LoginException(getClass() + ": could not obtain a TopAction"); //TODO: Use top to obtain the AccountUser that the user is logging into, and provide the appropriate keys System.out.println(getClass() + ": completing login for " + user.getLdapUID()); } catch (Exception ex) { ! System.out.println(getClass() + ": could not complete login for " + user.getLdapUID() + " CAUSE: " + ex.getMessage()); ex.printStackTrace(); throw new LoginException(ex.getMessage()); --- 140,155 ---- subject.getPublicCredentials().add(user.getUserPublicKey()); if (userModified) { + InitialContext ictx = new InitialContext(); + LoginLocal loginLocal = (LoginLocal) ictx.lookup("tolven/LoginBean/local"); + if (loginLocal == null) + throw new LoginException(getClass() + ": Could not locate the LoginBean"); loginLocal.update(user); System.out.println(getClass() + ": persisted new keys user " + user.getLdapUID()); } // Use the session to determine the AccountUser and AccountPrivateKey for the Subject //TODO: Use top to obtain the AccountUser that the user is logging into, and provide the appropriate keys System.out.println(getClass() + ": completing login for " + user.getLdapUID()); } catch (Exception ex) { ! System.out.println(getClass() + ": could not complete login for " + getIdentity().getName() + " CAUSE: " + ex.getMessage()); ex.printStackTrace(); throw new LoginException(ex.getMessage()); *************** *** 167,173 **** if (aborted && System.getProperty("tolven.security.keys.activate") != null) { try { ! if (user != null) { ! subject.getPrivateCredentials().remove(user.getUserPrivateKey()); ! subject.getPublicCredentials().remove(user.getUserPublicKey()); } } catch (Exception ex) { --- 166,176 ---- if (aborted && System.getProperty("tolven.security.keys.activate") != null) { try { ! // Remove all UserPrivateKey ! for (Iterator iter = subject.getPrivateCredentials(UserPrivateKey.class).iterator(); iter.hasNext();) { ! iter.remove(); ! } ! // Remove all UserPublicKey ! for (Iterator iter = subject.getPrivateCredentials(UserPublicKey.class).iterator(); iter.hasNext();) { ! iter.remove(); } } catch (Exception ex) { *************** *** 177,183 **** } passwordCredential = null; - user = null; - userModified = false; - loginLocal = null; return aborted; } --- 180,183 ---- |
From: Joseph I. <jos...@us...> - 2007-01-10 09:14:36
|
Update of /cvsroot/tolven/tolven/jboss-config In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv6812/jboss-config Modified Files: login-config.xml Log Message: Moved KeyLdapLoginModule and KeyLdapCallbackHandler to the web tier to assist in both UserPrivateKey/Public and AccountPrivateKey/PublicKey placement. Index: login-config.xml =================================================================== RCS file: /cvsroot/tolven/tolven/jboss-config/login-config.xml,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** login-config.xml 17 Dec 2006 07:48:37 -0000 1.12 --- login-config.xml 10 Jan 2007 09:14:27 -0000 1.13 *************** *** 67,71 **** <application-policy name="tolvenLDAP"> <authentication> ! <login-module code="org.tolven.security.auth.KeyLdapLoginModule" flag="required"> <module-option name="java.naming.factory.initial"> --- 67,71 ---- <application-policy name="tolvenLDAP"> <authentication> ! <login-module code="org.tolven.web.security.auth.KeyLdapLoginModule" flag="required"> <module-option name="java.naming.factory.initial"> |
From: Joseph I. <jos...@us...> - 2007-01-10 08:52:02
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web/security/auth In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29237/src/org/tolven/web/security/auth Added Files: KeyLdapCallbackHandler.java KeyLdapLoginModule.java Log Message: Moved KeyLdapLoginModule and KeyLdapCallbackHandler to the web tier to assist in both UserPrivateKey/Public and AccountPrivateKey/PublicKey placement. --- NEW FILE: KeyLdapCallbackHandler.java --- package org.tolven.web.security.auth; import java.io.IOException; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.UnsupportedCallbackException; /** * This class, in conjuction with KeyLdapLoginModule, provides a way to verify a user's LDAP identity. * * @author Joseph Isaac * */ public class KeyLdapCallbackHandler implements CallbackHandler { private String username; private char[] password; public KeyLdapCallbackHandler(String username, char[] password) { this.username = username; this.password = password; } public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { NameCallback nc = (NameCallback) callbacks[i]; nc.setName(username); } else if (callbacks[i] instanceof PasswordCallback) { PasswordCallback pc = (PasswordCallback) callbacks[i]; pc.setPassword(password); } else { throw new UnsupportedCallbackException(callbacks[i], "Unsupported Callback"); } } } } --- NEW FILE: KeyLdapLoginModule.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.web.security.auth; import java.security.Principal; import java.security.acl.Group; import java.util.Date; import java.util.Iterator; import javax.naming.InitialContext; import javax.resource.spi.security.PasswordCredential; import javax.security.auth.Subject; import javax.security.auth.login.LoginException; import javax.security.jacc.PolicyContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.jboss.security.SimpleGroup; import org.jboss.security.SimplePrincipal; import org.jboss.security.auth.spi.LdapLoginModule; import org.tolven.core.entity.Status; import org.tolven.core.entity.TolvenUser; import org.tolven.security.key.UserPrivateKey; import org.tolven.security.key.UserPublicKey; import org.tolven.security.LoginLocal; import org.tolven.web.TopAction; /** * This class supplies the Subject with the PrivateCredentials which were used * to authenticate against LDAP * * @author Joseph Isaac * */ public class KeyLdapLoginModule extends LdapLoginModule { private transient PasswordCredential passwordCredential; private transient LoginLocal loginLocal; private transient TolvenUser user; private transient boolean userModified = false; //TODO: Currently we treat all roles the same. When we decide to add roles to LDAP, this method can be removed. protected Group[] getRoleSets() { Group[] roleSets = null; if (System.getProperty("tolven.security.keys.activate") == null) { roleSets = new Group[0]; } else { roleSets = new Group[1]; roleSets[0] = new SimpleGroup("Roles"); roleSets[0].addMember(new SimplePrincipal("*")); } return roleSets; } /** * If the LdapLoginModule superclass validates the inputPassword as true, then create a corresponding TolvenUser with status NEW_LOGIN, if necessary. * Create a UserPrivateKey/PublicKey for the TolvenUser and persist it to the DB. Add the UserPrivateKey/PublicKey to the Subject. * If the caller is an MDB, then give it access. * If the user has no Subject, they did not login, but this can happen when users register, and will be controlled more thoroughly before this code is activated. */ protected boolean validatePassword(String inputPassword, String expectedPassword) { System.out.println(getClass() + ": validatePassword"); boolean validated = super.validatePassword(inputPassword, expectedPassword); if (validated && System.getProperty("tolven.security.keys.activate") != null) { //TODO: Must be a real LDAP validated user logging in try { Principal callerPrincipal = getIdentity(); if (callerPrincipal == null) { //TODO: Should not be null but just in case System.out.println(getClass() + ": Principal is null, login validated false"); return false; } String callerPrincipalUserName = callerPrincipal.getName(); char[] password = null; if (inputPassword != null) password = inputPassword.toCharArray(); passwordCredential = new PasswordCredential(callerPrincipalUserName, password); InitialContext ictx = new InitialContext(); loginLocal = (LoginLocal) ictx.lookup("tolven/LoginBean/local"); user = loginLocal.findUser(callerPrincipalUserName); if (user == null) { // Password has validated at this point, so must be a real LDAPUser with no TolvenUser yet (but a registerd user) user = new TolvenUser(); user.setLdapUID(callerPrincipalUserName); user.setStatus(Status.NEW_LOGIN.value()); user.setLastLogin(null); // Last login is null, never logged in before this user.setCreation(new Date()); userModified = true; } System.out.println(getClass() + ": validate " + callerPrincipalUserName + "=" + validated); } catch (Exception ex) { ex.printStackTrace(); validated = false; } } return validated; } /** * If the superclass commits, then place the PasswordCredential, UserPrivateKey and PublicKey in the Subject */ public boolean commit() throws LoginException { System.out.println(getClass() + ": commit"); boolean committed = super.commit(); if (committed && System.getProperty("tolven.security.keys.activate") != null) { try { if (!user.hasUserPrivateKey()) { System.out.println(getClass() + ": initialize keys "); user.initUserPrivateKey(passwordCredential.getPassword()); userModified = true; } UserPrivateKey userPrivateKey = user.getUserPrivateKey(); System.out.println(getClass() + ": Adding UserPrivateKey to Subject " + user.getLdapUID()); userPrivateKey.unlockPrivateKey(passwordCredential.getPassword()); // Ensure there is only one UserPrivateKey in a Subject by removing any that might be there for (Iterator iter = subject.getPrivateCredentials(UserPrivateKey.class).iterator(); iter.hasNext();) { iter.remove(); } subject.getPrivateCredentials().add(userPrivateKey); System.out.println(getClass() + ": Adding getUserPublicKey to Subject " + user.getLdapUID()); // Ensure there is only one UserPublicKey in a Subject by removing any that might be there for (Iterator iter = subject.getPublicCredentials(UserPublicKey.class).iterator(); iter.hasNext();) { iter.remove(); } subject.getPublicCredentials().add(user.getUserPublicKey()); if (userModified) { loginLocal.update(user); System.out.println(getClass() + ": persisted new keys user " + user.getLdapUID()); } // Use the session to determine the AccountUser and AccountPrivateKey for the Subject HttpServletRequest request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest"); if (request == null) throw new LoginException(getClass() + ": could not obtain an HttpServletRequest"); HttpSession session = request.getSession(); if (session == null) throw new LoginException(getClass() + ": could not obtain an HttpSession"); TopAction top = (TopAction)session.getAttribute("top"); if (top == null) throw new LoginException(getClass() + ": could not obtain a TopAction"); //TODO: Use top to obtain the AccountUser that the user is logging into, and provide the appropriate keys System.out.println(getClass() + ": completing login for " + user.getLdapUID()); } catch (Exception ex) { System.out.println(getClass() + ": could not complete login for " + user.getLdapUID() + " CAUSE: " + ex.getMessage()); ex.printStackTrace(); throw new LoginException(ex.getMessage()); } } return committed; } /** * If the superclass aborts, ensure that the PasswordCredential and UserPrivateKey and PublicKey are removed from the Subject */ public boolean abort() throws LoginException { boolean aborted = super.abort(); if (aborted && System.getProperty("tolven.security.keys.activate") != null) { try { if (user != null) { subject.getPrivateCredentials().remove(user.getUserPrivateKey()); subject.getPublicCredentials().remove(user.getUserPublicKey()); } } catch (Exception ex) { ex.printStackTrace(); throw new LoginException(ex.getMessage()); } } passwordCredential = null; user = null; userModified = false; loginLocal = null; return aborted; } } |