From: Michele Silva Date: Tue, 17 Jan 2012 22:32:42 +0000 (-0200) Subject: Added UI (JSF) and JPA to bayesian network entities. X-Git-Url: http://200.18.67.61/gitweb/?p=simdecs.git;a=commitdiff_plain;h=c547eea0255390e5763eac8ffbca336a1acf5b41 Added UI (JSF) and JPA to bayesian network entities. --- diff --git a/nbproject/project.properties b/nbproject/project.properties index 4656a63..d1c5ee5 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,124 +1,126 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=true -annotation.processing.processor.options=-Aeclipselink.canonicalmodel.use_static_factory=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -auxiliary.org-netbeans-modules-projectapi.jsf_2e_language=Facelets -build.classes.dir=${build.web.dir}/WEB-INF/classes -build.classes.excludes=**/*.java,**/*.form -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -build.web.dir=${build.dir}/web -build.web.excludes=${build.classes.excludes} -client.urlPart= -compile.jsps=false -conf.dir=${source.root}/conf -debug.classpath=${build.classes.dir}:${javac.classpath} -debug.test.classpath=\ - ${run.test.classpath} -display.browser=true -dist.dir=dist -dist.ear.war=${dist.dir}/${war.ear.name} -dist.javadoc.dir=${dist.dir}/javadoc -dist.war=${dist.dir}/${war.name} -endorsed.classpath= -excludes= -file.reference.avalon-framework-4.1.3.jar=lib/avalon-framework-4.1.3.jar -file.reference.commons-lang3-3.1.jar=lib/commons-lang3-3.1.jar -file.reference.commons-logging-1.1.jar=lib/commons-logging-1.1.jar -file.reference.icu4j-3.8.jar=lib/icu4j-3.8.jar -file.reference.javahelp-2.0.02.jar=lib/javahelp-2.0.02.jar -file.reference.jaxme2-0.5.1.jar=lib/jaxme2-0.5.1.jar -file.reference.jaxme2-rt-0.5.1.jar=lib/jaxme2-rt-0.5.1.jar -file.reference.jaxmeapi-0.5.1.jar=lib/jaxmeapi-0.5.1.jar -file.reference.jaxmejs-0.5.1.jar=lib/jaxmejs-0.5.1.jar -file.reference.jaxmexs-0.5.1.jar=lib/jaxmexs-0.5.1.jar -file.reference.jpf-1.5.jar=lib/jpf-1.5.jar -file.reference.junit-4.1.jar=lib/junit-4.1.jar -file.reference.log4j-1.2.12.jar=lib/log4j-1.2.12.jar -file.reference.logkit-1.0.1.jar=lib/logkit-1.0.1.jar -file.reference.servlet-api-2.3.jar=lib/servlet-api-2.3.jar -file.reference.unbbayes-4.10.4-1s.jar=lib/unbbayes-4.10.4-1s.jar -file.reference.xalan-2.7.0.jar=lib/xalan-2.7.0.jar -file.reference.xml-apis-1.0.b2.jar=lib/xml-apis-1.0.b2.jar -includes=** -j2ee.compile.on.save=true -j2ee.deploy.on.save=true -j2ee.platform=1.5 -j2ee.platform.classpath=${j2ee.server.home}/modules/jsf-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.enterprise.deploy.jar:${j2ee.server.home}/modules/javax.ejb.jar:${j2ee.server.home}/modules/javax.transaction.jar:${j2ee.server.home}/modules/jstl-impl.jar:${j2ee.server.home}/modules/jsf-impl.jar:${j2ee.server.home}/modules/javax.management.j2ee.jar:${j2ee.server.home}/modules/javax.jms.jar:${j2ee.server.home}/modules/endorsed/javax.annotation.jar:${j2ee.server.home}/modules/jersey-core.jar:${j2ee.server.home}/modules/javax.security.jacc.jar:${j2ee.server.home}/modules/javax.resource.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/javax.security.auth.message.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.servlet.jar -j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar -j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar -j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.ejb.jar -j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.ejb.jar -j2ee.platform.wsit.classpath= -j2ee.server.type=gfv3ee6 -jar.compress=false -javac.classpath=\ - ${libs.primefaces.classpath}:\ - ${libs.hibernate-support.classpath}:\ - ${file.reference.avalon-framework-4.1.3.jar}:\ - ${file.reference.commons-logging-1.1.jar}:\ - ${file.reference.icu4j-3.8.jar}:\ - ${file.reference.javahelp-2.0.02.jar}:\ - ${file.reference.jaxme2-0.5.1.jar}:\ - ${file.reference.jaxme2-rt-0.5.1.jar}:\ - ${file.reference.jaxmeapi-0.5.1.jar}:\ - ${file.reference.jaxmejs-0.5.1.jar}:\ - ${file.reference.jaxmexs-0.5.1.jar}:\ - ${file.reference.jpf-1.5.jar}:\ - ${file.reference.junit-4.1.jar}:\ - ${file.reference.log4j-1.2.12.jar}:\ - ${file.reference.logkit-1.0.1.jar}:\ - ${file.reference.servlet-api-2.3.jar}:\ - ${file.reference.unbbayes-4.10.4-1s.jar}:\ - ${file.reference.xalan-2.7.0.jar}:\ - ${file.reference.xml-apis-1.0.b2.jar}:\ - ${file.reference.commons-lang3-3.1.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.debug=true -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.5 -javac.target=1.5 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.preview=true -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -lib.dir=${web.docbase.dir}/WEB-INF/lib -persistence.xml.dir=${conf.dir} -platform.active=default_platform -resource.dir=setup -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -# Space-separated list of JVM arguments used when running a class with a main method or a unit test -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): -runmain.jvmargs= -source.encoding=UTF-8 -source.root=src -src.dir=${source.root}/java -test.src.dir=test -war.content.additional= -war.ear.name=simdecs.war -war.name=simdecs.war -web.docbase.dir=web -webinf.dir=web/WEB-INF +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processor.options=-Aeclipselink.canonicalmodel.use_static_factory=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +auxiliary.org-netbeans-modules-projectapi.jsf_2e_language=Facelets +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath= +excludes= +file.reference.avalon-framework-4.1.3.jar=lib/avalon-framework-4.1.3.jar +file.reference.commons-lang3-3.1.jar=lib/commons-lang3-3.1.jar +file.reference.commons-logging-1.1.jar=lib/commons-logging-1.1.jar +file.reference.icu4j-3.8.jar=lib/icu4j-3.8.jar +file.reference.javahelp-2.0.02.jar=lib/javahelp-2.0.02.jar +file.reference.jaxme2-0.5.1.jar=lib/jaxme2-0.5.1.jar +file.reference.jaxme2-rt-0.5.1.jar=lib/jaxme2-rt-0.5.1.jar +file.reference.jaxmeapi-0.5.1.jar=lib/jaxmeapi-0.5.1.jar +file.reference.jaxmejs-0.5.1.jar=lib/jaxmejs-0.5.1.jar +file.reference.jaxmexs-0.5.1.jar=lib/jaxmexs-0.5.1.jar +file.reference.jpf-1.5.jar=lib/jpf-1.5.jar +file.reference.junit-4.1.jar=lib/junit-4.1.jar +file.reference.log4j-1.2.12.jar=lib/log4j-1.2.12.jar +file.reference.logkit-1.0.1.jar=lib/logkit-1.0.1.jar +file.reference.servlet-api-2.3.jar=lib/servlet-api-2.3.jar +file.reference.unbbayes-4.10.4-1s.jar=lib/unbbayes-4.10.4-1s.jar +file.reference.xalan-2.7.0.jar=lib/xalan-2.7.0.jar +file.reference.xml-apis-1.0.b2.jar=lib/xml-apis-1.0.b2.jar +includes=** +j2ee.compile.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.5 +j2ee.platform.classpath=${j2ee.server.home}/modules/jstl-impl.jar:${j2ee.server.home}/modules/javax.resource.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.ejb.jar:${j2ee.server.home}/modules/jsf-impl.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/javax.annotation.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/javax.security.auth.message.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/javax.management.j2ee.jar:${j2ee.server.home}/modules/jsf-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/javax.enterprise.deploy.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.security.jacc.jar:${j2ee.server.home}/modules/javax.transaction.jar:${j2ee.server.home}/modules/jersey-core.jar:${j2ee.server.home}/modules/javax.servlet.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.jms.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.ejb.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.ejb.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath=\ + ${libs.primefaces.classpath}:\ + ${libs.hibernate-support.classpath}:\ + ${file.reference.avalon-framework-4.1.3.jar}:\ + ${file.reference.commons-logging-1.1.jar}:\ + ${file.reference.icu4j-3.8.jar}:\ + ${file.reference.javahelp-2.0.02.jar}:\ + ${file.reference.jaxme2-0.5.1.jar}:\ + ${file.reference.jaxme2-rt-0.5.1.jar}:\ + ${file.reference.jaxmeapi-0.5.1.jar}:\ + ${file.reference.jaxmejs-0.5.1.jar}:\ + ${file.reference.jaxmexs-0.5.1.jar}:\ + ${file.reference.jpf-1.5.jar}:\ + ${file.reference.junit-4.1.jar}:\ + ${file.reference.log4j-1.2.12.jar}:\ + ${file.reference.logkit-1.0.1.jar}:\ + ${file.reference.servlet-api-2.3.jar}:\ + ${file.reference.unbbayes-4.10.4-1s.jar}:\ + ${file.reference.xalan-2.7.0.jar}:\ + ${file.reference.xml-apis-1.0.b2.jar}:\ + ${file.reference.commons-lang3-3.1.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath}:\ + ${libs.eclipselink.classpath}:\ + ${libs.eclipselinkmodelgen.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=simdecs.war +war.name=simdecs.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml index 6d7420e..8af6f9d 100644 --- a/src/conf/persistence.xml +++ b/src/conf/persistence.xml @@ -17,4 +17,16 @@ + + org.eclipse.persistence.jpa.PersistenceProvider + pg + org.ufcspa.simdecs.bn.entity.Answer + org.ufcspa.simdecs.bn.entity.BayesianNetwork + org.ufcspa.simdecs.bn.entity.Node + org.ufcspa.simdecs.bn.entity.Question + true + + + + diff --git a/src/java/org/ufcspa/simdecs/bn/Bundle.properties b/src/java/org/ufcspa/simdecs/bn/Bundle.properties new file mode 100644 index 0000000..d76d0fb --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/Bundle.properties @@ -0,0 +1,209 @@ +PersistenceErrorOccured=A persistence error occurred. +Previous=Previous +Next=Next + +AnswerCreated=Answer was successfully created. +AnswerUpdated=Answer was successfully updated. +AnswerDeleted=Answer was successfully deleted. +CreateAnswerTitle=Create New Answer +CreateAnswerSaveLink=Save +CreateAnswerShowAllLink=Show All Answer Items +CreateAnswerIndexLink=Index +CreateAnswerLabel_id=Id: +CreateAnswerTitle_id=Id +CreateAnswerLabel_text=Text: +CreateAnswerTitle_text=Text +CreateAnswerLabel_likelihood=Likelihood: +CreateAnswerTitle_likelihood=Likelihood +CreateAnswerLabel_question=Question: +CreateAnswerTitle_question=Question +EditAnswerTitle=Edit Answer +EditAnswerSaveLink=Save +EditAnswerViewLink=View +EditAnswerShowAllLink=Show All Answer Items +EditAnswerIndexLink=Index +EditAnswerLabel_id=Id: +EditAnswerTitle_id=Id +EditAnswerLabel_text=Text: +EditAnswerTitle_text=Text +EditAnswerLabel_likelihood=Likelihood: +EditAnswerTitle_likelihood=Likelihood +EditAnswerLabel_question=Question: +EditAnswerTitle_question=Question +ViewAnswerTitle=View +ViewAnswerDestroyLink=Destroy +ViewAnswerEditLink=Edit +ViewAnswerCreateLink=Create New Answer +ViewAnswerShowAllLink=Show All Answer Items +ViewAnswerIndexLink=Index +ViewAnswerLabel_id=Id: +ViewAnswerTitle_id=Id +ViewAnswerLabel_text=Text: +ViewAnswerTitle_text=Text +ViewAnswerLabel_likelihood=Likelihood: +ViewAnswerTitle_likelihood=Likelihood +ViewAnswerLabel_question=Question: +ViewAnswerTitle_question=Question +ListAnswerTitle=List +ListAnswerEmpty=(No Answer Items Found) +ListAnswerDestroyLink=Destroy +ListAnswerEditLink=Edit +ListAnswerViewLink=View +ListAnswerCreateLink=Create New Answer +ListAnswerIndexLink=Index +ListAnswerTitle_id=Id +ListAnswerTitle_text=Text +ListAnswerTitle_likelihood=Likelihood +ListAnswerTitle_question=Question +BayesianNetworkCreated=BayesianNetwork was successfully created. +BayesianNetworkUpdated=BayesianNetwork was successfully updated. +BayesianNetworkDeleted=BayesianNetwork was successfully deleted. +CreateBayesianNetworkTitle=Create New BayesianNetwork +CreateBayesianNetworkSaveLink=Save +CreateBayesianNetworkShowAllLink=Show All BayesianNetwork Items +CreateBayesianNetworkIndexLink=Index +CreateBayesianNetworkLabel_id=Id: +CreateBayesianNetworkTitle_id=Id +CreateBayesianNetworkLabel_name=Name: +CreateBayesianNetworkTitle_name=Name +EditBayesianNetworkTitle=Edit BayesianNetwork +EditBayesianNetworkSaveLink=Save +EditBayesianNetworkViewLink=View +EditBayesianNetworkShowAllLink=Show All BayesianNetwork Items +EditBayesianNetworkIndexLink=Index +EditBayesianNetworkLabel_id=Id: +EditBayesianNetworkTitle_id=Id +EditBayesianNetworkLabel_name=Name: +EditBayesianNetworkTitle_name=Name +ViewBayesianNetworkTitle=View +ViewBayesianNetworkDestroyLink=Destroy +ViewBayesianNetworkEditLink=Edit +ViewBayesianNetworkCreateLink=Create New BayesianNetwork +ViewBayesianNetworkShowAllLink=Show All BayesianNetwork Items +ViewBayesianNetworkIndexLink=Index +ViewBayesianNetworkLabel_id=Id: +ViewBayesianNetworkTitle_id=Id +ViewBayesianNetworkLabel_name=Name: +ViewBayesianNetworkTitle_name=Name +ListBayesianNetworkTitle=List +ListBayesianNetworkEmpty=(No BayesianNetwork Items Found) +ListBayesianNetworkDestroyLink=Destroy +ListBayesianNetworkEditLink=Edit +ListBayesianNetworkViewLink=View +ListBayesianNetworkCreateLink=Create New BayesianNetwork +ListBayesianNetworkIndexLink=Index +ListBayesianNetworkTitle_id=Id +ListBayesianNetworkTitle_name=Name +NodeCreated=Node was successfully created. +NodeUpdated=Node was successfully updated. +NodeDeleted=Node was successfully deleted. +CreateNodeTitle=Create New Node +CreateNodeSaveLink=Save +CreateNodeShowAllLink=Show All Node Items +CreateNodeIndexLink=Index +CreateNodeLabel_id=Id: +CreateNodeTitle_id=Id +CreateNodeLabel_name=Name: +CreateNodeTitle_name=Name +CreateNodeLabel_nodeType=NodeType: +CreateNodeTitle_nodeType=NodeType +CreateNodeLabel_time=Time: +CreateNodeTitle_time=Time +CreateNodeLabel_cost=Cost: +CreateNodeTitle_cost=Cost +CreateNodeLabel_bayesianNetwork=BayesianNetwork: +CreateNodeTitle_bayesianNetwork=BayesianNetwork +EditNodeTitle=Edit Node +EditNodeSaveLink=Save +EditNodeViewLink=View +EditNodeShowAllLink=Show All Node Items +EditNodeIndexLink=Index +EditNodeLabel_id=Id: +EditNodeTitle_id=Id +EditNodeLabel_name=Name: +EditNodeTitle_name=Name +EditNodeLabel_nodeType=NodeType: +EditNodeTitle_nodeType=NodeType +EditNodeLabel_time=Time: +EditNodeTitle_time=Time +EditNodeLabel_cost=Cost: +EditNodeTitle_cost=Cost +EditNodeLabel_bayesianNetwork=BayesianNetwork: +EditNodeTitle_bayesianNetwork=BayesianNetwork +ViewNodeTitle=View +ViewNodeDestroyLink=Destroy +ViewNodeEditLink=Edit +ViewNodeCreateLink=Create New Node +ViewNodeShowAllLink=Show All Node Items +ViewNodeIndexLink=Index +ViewNodeLabel_id=Id: +ViewNodeTitle_id=Id +ViewNodeLabel_name=Name: +ViewNodeTitle_name=Name +ViewNodeLabel_nodeType=NodeType: +ViewNodeTitle_nodeType=NodeType +ViewNodeLabel_time=Time: +ViewNodeTitle_time=Time +ViewNodeLabel_cost=Cost: +ViewNodeTitle_cost=Cost +ViewNodeLabel_bayesianNetwork=BayesianNetwork: +ViewNodeTitle_bayesianNetwork=BayesianNetwork +ListNodeTitle=List +ListNodeEmpty=(No Node Items Found) +ListNodeDestroyLink=Destroy +ListNodeEditLink=Edit +ListNodeViewLink=View +ListNodeCreateLink=Create New Node +ListNodeIndexLink=Index +ListNodeTitle_id=Id +ListNodeTitle_name=Name +ListNodeTitle_nodeType=NodeType +ListNodeTitle_time=Time +ListNodeTitle_cost=Cost +ListNodeTitle_bayesianNetwork=BayesianNetwork +QuestionCreated=Question was successfully created. +QuestionUpdated=Question was successfully updated. +QuestionDeleted=Question was successfully deleted. +CreateQuestionTitle=Create New Question +CreateQuestionSaveLink=Save +CreateQuestionShowAllLink=Show All Question Items +CreateQuestionIndexLink=Index +CreateQuestionLabel_id=Id: +CreateQuestionTitle_id=Id +CreateQuestionLabel_text=Text: +CreateQuestionTitle_text=Text +CreateQuestionLabel_node=Node: +CreateQuestionTitle_node=Node +EditQuestionTitle=Edit Question +EditQuestionSaveLink=Save +EditQuestionViewLink=View +EditQuestionShowAllLink=Show All Question Items +EditQuestionIndexLink=Index +EditQuestionLabel_id=Id: +EditQuestionTitle_id=Id +EditQuestionLabel_text=Text: +EditQuestionTitle_text=Text +EditQuestionLabel_node=Node: +EditQuestionTitle_node=Node +ViewQuestionTitle=View +ViewQuestionDestroyLink=Destroy +ViewQuestionEditLink=Edit +ViewQuestionCreateLink=Create New Question +ViewQuestionShowAllLink=Show All Question Items +ViewQuestionIndexLink=Index +ViewQuestionLabel_id=Id: +ViewQuestionTitle_id=Id +ViewQuestionLabel_text=Text: +ViewQuestionTitle_text=Text +ViewQuestionLabel_node=Node: +ViewQuestionTitle_node=Node +ListQuestionTitle=List +ListQuestionEmpty=(No Question Items Found) +ListQuestionDestroyLink=Destroy +ListQuestionEditLink=Edit +ListQuestionViewLink=View +ListQuestionCreateLink=Create New Question +ListQuestionIndexLink=Index +ListQuestionTitle_id=Id +ListQuestionTitle_text=Text +ListQuestionTitle_node=Node diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/AnswerJpaController.java b/src/java/org/ufcspa/simdecs/bn/jpa/AnswerJpaController.java new file mode 100644 index 0000000..4dd2bcb --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/AnswerJpaController.java @@ -0,0 +1,190 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.bn.jpa; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import javax.transaction.UserTransaction; +import org.ufcspa.simdecs.bn.entity.Answer; +import org.ufcspa.simdecs.bn.entity.Question; +import org.ufcspa.simdecs.bn.jpa.exceptions.NonexistentEntityException; +import org.ufcspa.simdecs.bn.jpa.exceptions.RollbackFailureException; + +/** + * + * @author mchelem + */ +public class AnswerJpaController implements Serializable { + + public AnswerJpaController(UserTransaction utx, EntityManagerFactory emf) { + this.utx = utx; + this.emf = emf; + } + private UserTransaction utx = null; + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Answer answer) throws RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Question question = answer.getQuestion(); + if (question != null) { + question = em.getReference(question.getClass(), question.getId()); + answer.setQuestion(question); + } + em.persist(answer); + if (question != null) { + question.getAnswers().add(answer); + question = em.merge(question); + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Answer answer) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Answer persistentAnswer = em.find(Answer.class, answer.getId()); + Question questionOld = persistentAnswer.getQuestion(); + Question questionNew = answer.getQuestion(); + if (questionNew != null) { + questionNew = em.getReference(questionNew.getClass(), questionNew.getId()); + answer.setQuestion(questionNew); + } + answer = em.merge(answer); + if (questionOld != null && !questionOld.equals(questionNew)) { + questionOld.getAnswers().remove(answer); + questionOld = em.merge(questionOld); + } + if (questionNew != null && !questionNew.equals(questionOld)) { + questionNew.getAnswers().add(answer); + questionNew = em.merge(questionNew); + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Long id = answer.getId(); + if (findAnswer(id) == null) { + throw new NonexistentEntityException("The answer with id " + id + " no longer exists."); + } + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Long id) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Answer answer; + try { + answer = em.getReference(Answer.class, id); + answer.getId(); + } catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The answer with id " + id + " no longer exists.", enfe); + } + Question question = answer.getQuestion(); + if (question != null) { + question.getAnswers().remove(answer); + question = em.merge(question); + } + em.remove(answer); + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public List findAnswerEntities() { + return findAnswerEntities(true, -1, -1); + } + + public List findAnswerEntities(int maxResults, int firstResult) { + return findAnswerEntities(false, maxResults, firstResult); + } + + private List findAnswerEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Answer.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } finally { + em.close(); + } + } + + public Answer findAnswer(Long id) { + EntityManager em = getEntityManager(); + try { + return em.find(Answer.class, id); + } finally { + em.close(); + } + } + + public int getAnswerCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Answer.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } finally { + em.close(); + } + } + +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/BayesianNetworkJpaController.java b/src/java/org/ufcspa/simdecs/bn/jpa/BayesianNetworkJpaController.java new file mode 100644 index 0000000..68ec8df --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/BayesianNetworkJpaController.java @@ -0,0 +1,212 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.bn.jpa; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import org.ufcspa.simdecs.bn.entity.Node; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.transaction.UserTransaction; +import org.ufcspa.simdecs.bn.entity.BayesianNetwork; +import org.ufcspa.simdecs.bn.jpa.exceptions.NonexistentEntityException; +import org.ufcspa.simdecs.bn.jpa.exceptions.RollbackFailureException; + +/** + * + * @author mchelem + */ +public class BayesianNetworkJpaController implements Serializable { + + public BayesianNetworkJpaController(UserTransaction utx, EntityManagerFactory emf) { + this.utx = utx; + this.emf = emf; + } + private UserTransaction utx = null; + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(BayesianNetwork bayesianNetwork) throws RollbackFailureException, Exception { + if (bayesianNetwork.getNodes() == null) { + bayesianNetwork.setNodes(new ArrayList()); + } + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + List attachedNodes = new ArrayList(); + for (Node nodesNodeToAttach : bayesianNetwork.getNodes()) { + nodesNodeToAttach = em.getReference(nodesNodeToAttach.getClass(), nodesNodeToAttach.getId()); + attachedNodes.add(nodesNodeToAttach); + } + bayesianNetwork.setNodes(attachedNodes); + em.persist(bayesianNetwork); + for (Node nodesNode : bayesianNetwork.getNodes()) { + BayesianNetwork oldBayesianNetworkOfNodesNode = nodesNode.getBayesianNetwork(); + nodesNode.setBayesianNetwork(bayesianNetwork); + nodesNode = em.merge(nodesNode); + if (oldBayesianNetworkOfNodesNode != null) { + oldBayesianNetworkOfNodesNode.getNodes().remove(nodesNode); + oldBayesianNetworkOfNodesNode = em.merge(oldBayesianNetworkOfNodesNode); + } + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(BayesianNetwork bayesianNetwork) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + BayesianNetwork persistentBayesianNetwork = em.find(BayesianNetwork.class, bayesianNetwork.getId()); + List nodesOld = persistentBayesianNetwork.getNodes(); + List nodesNew = bayesianNetwork.getNodes(); + List attachedNodesNew = new ArrayList(); + for (Node nodesNewNodeToAttach : nodesNew) { + nodesNewNodeToAttach = em.getReference(nodesNewNodeToAttach.getClass(), nodesNewNodeToAttach.getId()); + attachedNodesNew.add(nodesNewNodeToAttach); + } + nodesNew = attachedNodesNew; + bayesianNetwork.setNodes(nodesNew); + bayesianNetwork = em.merge(bayesianNetwork); + for (Node nodesOldNode : nodesOld) { + if (!nodesNew.contains(nodesOldNode)) { + nodesOldNode.setBayesianNetwork(null); + nodesOldNode = em.merge(nodesOldNode); + } + } + for (Node nodesNewNode : nodesNew) { + if (!nodesOld.contains(nodesNewNode)) { + BayesianNetwork oldBayesianNetworkOfNodesNewNode = nodesNewNode.getBayesianNetwork(); + nodesNewNode.setBayesianNetwork(bayesianNetwork); + nodesNewNode = em.merge(nodesNewNode); + if (oldBayesianNetworkOfNodesNewNode != null && !oldBayesianNetworkOfNodesNewNode.equals(bayesianNetwork)) { + oldBayesianNetworkOfNodesNewNode.getNodes().remove(nodesNewNode); + oldBayesianNetworkOfNodesNewNode = em.merge(oldBayesianNetworkOfNodesNewNode); + } + } + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Long id = bayesianNetwork.getId(); + if (findBayesianNetwork(id) == null) { + throw new NonexistentEntityException("The bayesianNetwork with id " + id + " no longer exists."); + } + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Long id) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + BayesianNetwork bayesianNetwork; + try { + bayesianNetwork = em.getReference(BayesianNetwork.class, id); + bayesianNetwork.getId(); + } catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The bayesianNetwork with id " + id + " no longer exists.", enfe); + } + List nodes = bayesianNetwork.getNodes(); + for (Node nodesNode : nodes) { + nodesNode.setBayesianNetwork(null); + nodesNode = em.merge(nodesNode); + } + em.remove(bayesianNetwork); + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public List findBayesianNetworkEntities() { + return findBayesianNetworkEntities(true, -1, -1); + } + + public List findBayesianNetworkEntities(int maxResults, int firstResult) { + return findBayesianNetworkEntities(false, maxResults, firstResult); + } + + private List findBayesianNetworkEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(BayesianNetwork.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } finally { + em.close(); + } + } + + public BayesianNetwork findBayesianNetwork(Long id) { + EntityManager em = getEntityManager(); + try { + return em.find(BayesianNetwork.class, id); + } finally { + em.close(); + } + } + + public int getBayesianNetworkCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(BayesianNetwork.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } finally { + em.close(); + } + } + +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/NodeJpaController.java b/src/java/org/ufcspa/simdecs/bn/jpa/NodeJpaController.java new file mode 100644 index 0000000..54ec341 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/NodeJpaController.java @@ -0,0 +1,241 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.bn.jpa; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import org.ufcspa.simdecs.bn.entity.BayesianNetwork; +import org.ufcspa.simdecs.bn.entity.Question; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.transaction.UserTransaction; +import org.ufcspa.simdecs.bn.entity.Node; +import org.ufcspa.simdecs.bn.jpa.exceptions.NonexistentEntityException; +import org.ufcspa.simdecs.bn.jpa.exceptions.RollbackFailureException; + +/** + * + * @author mchelem + */ +public class NodeJpaController implements Serializable { + + public NodeJpaController(UserTransaction utx, EntityManagerFactory emf) { + this.utx = utx; + this.emf = emf; + } + private UserTransaction utx = null; + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Node node) throws RollbackFailureException, Exception { + if (node.getQuestions() == null) { + node.setQuestions(new ArrayList()); + } + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + BayesianNetwork bayesianNetwork = node.getBayesianNetwork(); + if (bayesianNetwork != null) { + bayesianNetwork = em.getReference(bayesianNetwork.getClass(), bayesianNetwork.getId()); + node.setBayesianNetwork(bayesianNetwork); + } + List attachedQuestions = new ArrayList(); + for (Question questionsQuestionToAttach : node.getQuestions()) { + questionsQuestionToAttach = em.getReference(questionsQuestionToAttach.getClass(), questionsQuestionToAttach.getId()); + attachedQuestions.add(questionsQuestionToAttach); + } + node.setQuestions(attachedQuestions); + em.persist(node); + if (bayesianNetwork != null) { + bayesianNetwork.getNodes().add(node); + bayesianNetwork = em.merge(bayesianNetwork); + } + for (Question questionsQuestion : node.getQuestions()) { + Node oldNodeOfQuestionsQuestion = questionsQuestion.getNode(); + questionsQuestion.setNode(node); + questionsQuestion = em.merge(questionsQuestion); + if (oldNodeOfQuestionsQuestion != null) { + oldNodeOfQuestionsQuestion.getQuestions().remove(questionsQuestion); + oldNodeOfQuestionsQuestion = em.merge(oldNodeOfQuestionsQuestion); + } + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Node node) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Node persistentNode = em.find(Node.class, node.getId()); + BayesianNetwork bayesianNetworkOld = persistentNode.getBayesianNetwork(); + BayesianNetwork bayesianNetworkNew = node.getBayesianNetwork(); + List questionsOld = persistentNode.getQuestions(); + List questionsNew = node.getQuestions(); + if (bayesianNetworkNew != null) { + bayesianNetworkNew = em.getReference(bayesianNetworkNew.getClass(), bayesianNetworkNew.getId()); + node.setBayesianNetwork(bayesianNetworkNew); + } + List attachedQuestionsNew = new ArrayList(); + for (Question questionsNewQuestionToAttach : questionsNew) { + questionsNewQuestionToAttach = em.getReference(questionsNewQuestionToAttach.getClass(), questionsNewQuestionToAttach.getId()); + attachedQuestionsNew.add(questionsNewQuestionToAttach); + } + questionsNew = attachedQuestionsNew; + node.setQuestions(questionsNew); + node = em.merge(node); + if (bayesianNetworkOld != null && !bayesianNetworkOld.equals(bayesianNetworkNew)) { + bayesianNetworkOld.getNodes().remove(node); + bayesianNetworkOld = em.merge(bayesianNetworkOld); + } + if (bayesianNetworkNew != null && !bayesianNetworkNew.equals(bayesianNetworkOld)) { + bayesianNetworkNew.getNodes().add(node); + bayesianNetworkNew = em.merge(bayesianNetworkNew); + } + for (Question questionsOldQuestion : questionsOld) { + if (!questionsNew.contains(questionsOldQuestion)) { + questionsOldQuestion.setNode(null); + questionsOldQuestion = em.merge(questionsOldQuestion); + } + } + for (Question questionsNewQuestion : questionsNew) { + if (!questionsOld.contains(questionsNewQuestion)) { + Node oldNodeOfQuestionsNewQuestion = questionsNewQuestion.getNode(); + questionsNewQuestion.setNode(node); + questionsNewQuestion = em.merge(questionsNewQuestion); + if (oldNodeOfQuestionsNewQuestion != null && !oldNodeOfQuestionsNewQuestion.equals(node)) { + oldNodeOfQuestionsNewQuestion.getQuestions().remove(questionsNewQuestion); + oldNodeOfQuestionsNewQuestion = em.merge(oldNodeOfQuestionsNewQuestion); + } + } + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Long id = node.getId(); + if (findNode(id) == null) { + throw new NonexistentEntityException("The node with id " + id + " no longer exists."); + } + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Long id) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Node node; + try { + node = em.getReference(Node.class, id); + node.getId(); + } catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The node with id " + id + " no longer exists.", enfe); + } + BayesianNetwork bayesianNetwork = node.getBayesianNetwork(); + if (bayesianNetwork != null) { + bayesianNetwork.getNodes().remove(node); + bayesianNetwork = em.merge(bayesianNetwork); + } + List questions = node.getQuestions(); + for (Question questionsQuestion : questions) { + questionsQuestion.setNode(null); + questionsQuestion = em.merge(questionsQuestion); + } + em.remove(node); + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public List findNodeEntities() { + return findNodeEntities(true, -1, -1); + } + + public List findNodeEntities(int maxResults, int firstResult) { + return findNodeEntities(false, maxResults, firstResult); + } + + private List findNodeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Node.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } finally { + em.close(); + } + } + + public Node findNode(Long id) { + EntityManager em = getEntityManager(); + try { + return em.find(Node.class, id); + } finally { + em.close(); + } + } + + public int getNodeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Node.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } finally { + em.close(); + } + } + +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/QuestionJpaController.java b/src/java/org/ufcspa/simdecs/bn/jpa/QuestionJpaController.java new file mode 100644 index 0000000..6d649ca --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/QuestionJpaController.java @@ -0,0 +1,241 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.bn.jpa; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import org.ufcspa.simdecs.bn.entity.Node; +import org.ufcspa.simdecs.bn.entity.Answer; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.transaction.UserTransaction; +import org.ufcspa.simdecs.bn.entity.Question; +import org.ufcspa.simdecs.bn.jpa.exceptions.NonexistentEntityException; +import org.ufcspa.simdecs.bn.jpa.exceptions.RollbackFailureException; + +/** + * + * @author mchelem + */ +public class QuestionJpaController implements Serializable { + + public QuestionJpaController(UserTransaction utx, EntityManagerFactory emf) { + this.utx = utx; + this.emf = emf; + } + private UserTransaction utx = null; + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Question question) throws RollbackFailureException, Exception { + if (question.getAnswers() == null) { + question.setAnswers(new ArrayList()); + } + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Node node = question.getNode(); + if (node != null) { + node = em.getReference(node.getClass(), node.getId()); + question.setNode(node); + } + List attachedAnswers = new ArrayList(); + for (Answer answersAnswerToAttach : question.getAnswers()) { + answersAnswerToAttach = em.getReference(answersAnswerToAttach.getClass(), answersAnswerToAttach.getId()); + attachedAnswers.add(answersAnswerToAttach); + } + question.setAnswers(attachedAnswers); + em.persist(question); + if (node != null) { + node.getQuestions().add(question); + node = em.merge(node); + } + for (Answer answersAnswer : question.getAnswers()) { + Question oldQuestionOfAnswersAnswer = answersAnswer.getQuestion(); + answersAnswer.setQuestion(question); + answersAnswer = em.merge(answersAnswer); + if (oldQuestionOfAnswersAnswer != null) { + oldQuestionOfAnswersAnswer.getAnswers().remove(answersAnswer); + oldQuestionOfAnswersAnswer = em.merge(oldQuestionOfAnswersAnswer); + } + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Question question) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Question persistentQuestion = em.find(Question.class, question.getId()); + Node nodeOld = persistentQuestion.getNode(); + Node nodeNew = question.getNode(); + List answersOld = persistentQuestion.getAnswers(); + List answersNew = question.getAnswers(); + if (nodeNew != null) { + nodeNew = em.getReference(nodeNew.getClass(), nodeNew.getId()); + question.setNode(nodeNew); + } + List attachedAnswersNew = new ArrayList(); + for (Answer answersNewAnswerToAttach : answersNew) { + answersNewAnswerToAttach = em.getReference(answersNewAnswerToAttach.getClass(), answersNewAnswerToAttach.getId()); + attachedAnswersNew.add(answersNewAnswerToAttach); + } + answersNew = attachedAnswersNew; + question.setAnswers(answersNew); + question = em.merge(question); + if (nodeOld != null && !nodeOld.equals(nodeNew)) { + nodeOld.getQuestions().remove(question); + nodeOld = em.merge(nodeOld); + } + if (nodeNew != null && !nodeNew.equals(nodeOld)) { + nodeNew.getQuestions().add(question); + nodeNew = em.merge(nodeNew); + } + for (Answer answersOldAnswer : answersOld) { + if (!answersNew.contains(answersOldAnswer)) { + answersOldAnswer.setQuestion(null); + answersOldAnswer = em.merge(answersOldAnswer); + } + } + for (Answer answersNewAnswer : answersNew) { + if (!answersOld.contains(answersNewAnswer)) { + Question oldQuestionOfAnswersNewAnswer = answersNewAnswer.getQuestion(); + answersNewAnswer.setQuestion(question); + answersNewAnswer = em.merge(answersNewAnswer); + if (oldQuestionOfAnswersNewAnswer != null && !oldQuestionOfAnswersNewAnswer.equals(question)) { + oldQuestionOfAnswersNewAnswer.getAnswers().remove(answersNewAnswer); + oldQuestionOfAnswersNewAnswer = em.merge(oldQuestionOfAnswersNewAnswer); + } + } + } + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Long id = question.getId(); + if (findQuestion(id) == null) { + throw new NonexistentEntityException("The question with id " + id + " no longer exists."); + } + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Long id) throws NonexistentEntityException, RollbackFailureException, Exception { + EntityManager em = null; + try { + utx.begin(); + em = getEntityManager(); + Question question; + try { + question = em.getReference(Question.class, id); + question.getId(); + } catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The question with id " + id + " no longer exists.", enfe); + } + Node node = question.getNode(); + if (node != null) { + node.getQuestions().remove(question); + node = em.merge(node); + } + List answers = question.getAnswers(); + for (Answer answersAnswer : answers) { + answersAnswer.setQuestion(null); + answersAnswer = em.merge(answersAnswer); + } + em.remove(question); + utx.commit(); + } catch (Exception ex) { + try { + utx.rollback(); + } catch (Exception re) { + throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); + } + throw ex; + } finally { + if (em != null) { + em.close(); + } + } + } + + public List findQuestionEntities() { + return findQuestionEntities(true, -1, -1); + } + + public List findQuestionEntities(int maxResults, int firstResult) { + return findQuestionEntities(false, maxResults, firstResult); + } + + private List findQuestionEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Question.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } finally { + em.close(); + } + } + + public Question findQuestion(Long id) { + EntityManager em = getEntityManager(); + try { + return em.find(Question.class, id); + } finally { + em.close(); + } + } + + public int getQuestionCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Question.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } finally { + em.close(); + } + } + +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/IllegalOrphanException.java b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/IllegalOrphanException.java new file mode 100644 index 0000000..15115fd --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/IllegalOrphanException.java @@ -0,0 +1,20 @@ +package org.ufcspa.simdecs.bn.jpa.exceptions; + +import java.util.ArrayList; +import java.util.List; + +public class IllegalOrphanException extends Exception { + private List messages; + public IllegalOrphanException(List messages) { + super((messages != null && messages.size() > 0 ? messages.get(0) : null)); + if (messages == null) { + this.messages = new ArrayList(); + } + else { + this.messages = messages; + } + } + public List getMessages() { + return messages; + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/NonexistentEntityException.java b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/NonexistentEntityException.java new file mode 100644 index 0000000..647c6a8 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/NonexistentEntityException.java @@ -0,0 +1,10 @@ +package org.ufcspa.simdecs.bn.jpa.exceptions; + +public class NonexistentEntityException extends Exception { + public NonexistentEntityException(String message, Throwable cause) { + super(message, cause); + } + public NonexistentEntityException(String message) { + super(message); + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/PreexistingEntityException.java b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/PreexistingEntityException.java new file mode 100644 index 0000000..4239666 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/PreexistingEntityException.java @@ -0,0 +1,10 @@ +package org.ufcspa.simdecs.bn.jpa.exceptions; + +public class PreexistingEntityException extends Exception { + public PreexistingEntityException(String message, Throwable cause) { + super(message, cause); + } + public PreexistingEntityException(String message) { + super(message); + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/RollbackFailureException.java b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/RollbackFailureException.java new file mode 100644 index 0000000..10227e5 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/jpa/exceptions/RollbackFailureException.java @@ -0,0 +1,10 @@ +package org.ufcspa.simdecs.bn.jpa.exceptions; + +public class RollbackFailureException extends Exception { + public RollbackFailureException(String message, Throwable cause) { + super(message, cause); + } + public RollbackFailureException(String message) { + super(message); + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/ui/AnswerController.java b/src/java/org/ufcspa/simdecs/bn/ui/AnswerController.java new file mode 100644 index 0000000..ccd3712 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/AnswerController.java @@ -0,0 +1,236 @@ +package org.ufcspa.simdecs.bn.ui; + +import org.ufcspa.simdecs.bn.entity.Answer; +import org.ufcspa.simdecs.bn.ui.util.JsfUtil; +import org.ufcspa.simdecs.bn.ui.util.PaginationHelper; +import org.ufcspa.simdecs.bn.jpa.AnswerJpaController; + +import java.io.Serializable; +import java.util.ResourceBundle; +import javax.annotation.Resource; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.UserTransaction; + +@ManagedBean(name = "answerController") +@SessionScoped +public class AnswerController implements Serializable { + + @Resource + private UserTransaction utx = null; + @PersistenceUnit(unitName = "simdecsEclipseLinkPU") + private EntityManagerFactory emf = null; + private Answer current; + private DataModel items = null; + private AnswerJpaController jpaController = null; + private PaginationHelper pagination; + private int selectedItemIndex; + + public AnswerController() { + } + + public Answer getSelected() { + if (current == null) { + current = new Answer(); + selectedItemIndex = -1; + } + return current; + } + + private AnswerJpaController getJpaController() { + if (jpaController == null) { + jpaController = new AnswerJpaController(utx, emf); + } + return jpaController; + } + + public PaginationHelper getPagination() { + if (pagination == null) { + pagination = new PaginationHelper(10) { + + @Override + public int getItemsCount() { + return getJpaController().getAnswerCount(); + } + + @Override + public DataModel createPageDataModel() { + return new ListDataModel(getJpaController().findAnswerEntities(getPageSize(), getPageFirstItem())); + } + }; + } + return pagination; + } + + public String prepareList() { + recreateModel(); + return "List"; + } + + public String prepareView() { + current = (Answer) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "View"; + } + + public String prepareCreate() { + current = new Answer(); + selectedItemIndex = -1; + return "Create"; + } + + public String create() { + try { + getJpaController().create(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("AnswerCreated")); + return prepareCreate(); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String prepareEdit() { + current = (Answer) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "Edit"; + } + + public String update() { + try { + getJpaController().edit(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("AnswerUpdated")); + return "View"; + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String destroy() { + current = (Answer) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + performDestroy(); + recreatePagination(); + recreateModel(); + return "List"; + } + + public String destroyAndView() { + performDestroy(); + recreateModel(); + updateCurrentItem(); + if (selectedItemIndex >= 0) { + return "View"; + } else { + // all items were removed - go back to list + recreateModel(); + return "List"; + } + } + + private void performDestroy() { + try { + getJpaController().destroy(current.getId()); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("AnswerDeleted")); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + } + } + + private void updateCurrentItem() { + int count = getJpaController().getAnswerCount(); + if (selectedItemIndex >= count) { + // selected index cannot be bigger than number of items: + selectedItemIndex = count - 1; + // go to previous page if last page disappeared: + if (pagination.getPageFirstItem() >= count) { + pagination.previousPage(); + } + } + if (selectedItemIndex >= 0) { + current = getJpaController().findAnswerEntities(1, selectedItemIndex).get(0); + } + } + + public DataModel getItems() { + if (items == null) { + items = getPagination().createPageDataModel(); + } + return items; + } + + private void recreateModel() { + items = null; + } + + private void recreatePagination() { + pagination = null; + } + + public String next() { + getPagination().nextPage(); + recreateModel(); + return "List"; + } + + public String previous() { + getPagination().previousPage(); + recreateModel(); + return "List"; + } + + public SelectItem[] getItemsAvailableSelectMany() { + return JsfUtil.getSelectItems(getJpaController().findAnswerEntities(), false); + } + + public SelectItem[] getItemsAvailableSelectOne() { + return JsfUtil.getSelectItems(getJpaController().findAnswerEntities(), true); + } + + @FacesConverter(forClass = Answer.class) + public static class AnswerControllerConverter implements Converter { + + public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { + if (value == null || value.length() == 0) { + return null; + } + AnswerController controller = (AnswerController) facesContext.getApplication().getELResolver(). + getValue(facesContext.getELContext(), null, "answerController"); + return controller.getJpaController().findAnswer(getKey(value)); + } + + java.lang.Long getKey(String value) { + java.lang.Long key; + key = Long.valueOf(value); + return key; + } + + String getStringKey(java.lang.Long value) { + StringBuffer sb = new StringBuffer(); + sb.append(value); + return sb.toString(); + } + + public String getAsString(FacesContext facesContext, UIComponent component, Object object) { + if (object == null) { + return null; + } + if (object instanceof Answer) { + Answer o = (Answer) object; + return getStringKey(o.getId()); + } else { + throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + AnswerController.class.getName()); + } + } + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/ui/BayesianNetworkController.java b/src/java/org/ufcspa/simdecs/bn/ui/BayesianNetworkController.java new file mode 100644 index 0000000..9dbe96f --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/BayesianNetworkController.java @@ -0,0 +1,236 @@ +package org.ufcspa.simdecs.bn.ui; + +import org.ufcspa.simdecs.bn.entity.BayesianNetwork; +import org.ufcspa.simdecs.bn.ui.util.JsfUtil; +import org.ufcspa.simdecs.bn.ui.util.PaginationHelper; +import org.ufcspa.simdecs.bn.jpa.BayesianNetworkJpaController; + +import java.io.Serializable; +import java.util.ResourceBundle; +import javax.annotation.Resource; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.UserTransaction; + +@ManagedBean(name = "bayesianNetworkController") +@SessionScoped +public class BayesianNetworkController implements Serializable { + + @Resource + private UserTransaction utx = null; + @PersistenceUnit(unitName = "simdecsEclipseLinkPU") + private EntityManagerFactory emf = null; + private BayesianNetwork current; + private DataModel items = null; + private BayesianNetworkJpaController jpaController = null; + private PaginationHelper pagination; + private int selectedItemIndex; + + public BayesianNetworkController() { + } + + public BayesianNetwork getSelected() { + if (current == null) { + current = new BayesianNetwork(); + selectedItemIndex = -1; + } + return current; + } + + private BayesianNetworkJpaController getJpaController() { + if (jpaController == null) { + jpaController = new BayesianNetworkJpaController(utx, emf); + } + return jpaController; + } + + public PaginationHelper getPagination() { + if (pagination == null) { + pagination = new PaginationHelper(10) { + + @Override + public int getItemsCount() { + return getJpaController().getBayesianNetworkCount(); + } + + @Override + public DataModel createPageDataModel() { + return new ListDataModel(getJpaController().findBayesianNetworkEntities(getPageSize(), getPageFirstItem())); + } + }; + } + return pagination; + } + + public String prepareList() { + recreateModel(); + return "List"; + } + + public String prepareView() { + current = (BayesianNetwork) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "View"; + } + + public String prepareCreate() { + current = new BayesianNetwork(); + selectedItemIndex = -1; + return "Create"; + } + + public String create() { + try { + getJpaController().create(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("BayesianNetworkCreated")); + return prepareCreate(); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String prepareEdit() { + current = (BayesianNetwork) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "Edit"; + } + + public String update() { + try { + getJpaController().edit(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("BayesianNetworkUpdated")); + return "View"; + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String destroy() { + current = (BayesianNetwork) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + performDestroy(); + recreatePagination(); + recreateModel(); + return "List"; + } + + public String destroyAndView() { + performDestroy(); + recreateModel(); + updateCurrentItem(); + if (selectedItemIndex >= 0) { + return "View"; + } else { + // all items were removed - go back to list + recreateModel(); + return "List"; + } + } + + private void performDestroy() { + try { + getJpaController().destroy(current.getId()); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("BayesianNetworkDeleted")); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + } + } + + private void updateCurrentItem() { + int count = getJpaController().getBayesianNetworkCount(); + if (selectedItemIndex >= count) { + // selected index cannot be bigger than number of items: + selectedItemIndex = count - 1; + // go to previous page if last page disappeared: + if (pagination.getPageFirstItem() >= count) { + pagination.previousPage(); + } + } + if (selectedItemIndex >= 0) { + current = getJpaController().findBayesianNetworkEntities(1, selectedItemIndex).get(0); + } + } + + public DataModel getItems() { + if (items == null) { + items = getPagination().createPageDataModel(); + } + return items; + } + + private void recreateModel() { + items = null; + } + + private void recreatePagination() { + pagination = null; + } + + public String next() { + getPagination().nextPage(); + recreateModel(); + return "List"; + } + + public String previous() { + getPagination().previousPage(); + recreateModel(); + return "List"; + } + + public SelectItem[] getItemsAvailableSelectMany() { + return JsfUtil.getSelectItems(getJpaController().findBayesianNetworkEntities(), false); + } + + public SelectItem[] getItemsAvailableSelectOne() { + return JsfUtil.getSelectItems(getJpaController().findBayesianNetworkEntities(), true); + } + + @FacesConverter(forClass = BayesianNetwork.class) + public static class BayesianNetworkControllerConverter implements Converter { + + public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { + if (value == null || value.length() == 0) { + return null; + } + BayesianNetworkController controller = (BayesianNetworkController) facesContext.getApplication().getELResolver(). + getValue(facesContext.getELContext(), null, "bayesianNetworkController"); + return controller.getJpaController().findBayesianNetwork(getKey(value)); + } + + java.lang.Long getKey(String value) { + java.lang.Long key; + key = Long.valueOf(value); + return key; + } + + String getStringKey(java.lang.Long value) { + StringBuffer sb = new StringBuffer(); + sb.append(value); + return sb.toString(); + } + + public String getAsString(FacesContext facesContext, UIComponent component, Object object) { + if (object == null) { + return null; + } + if (object instanceof BayesianNetwork) { + BayesianNetwork o = (BayesianNetwork) object; + return getStringKey(o.getId()); + } else { + throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + BayesianNetworkController.class.getName()); + } + } + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/ui/FileUploadController.java b/src/java/org/ufcspa/simdecs/bn/ui/FileUploadController.java new file mode 100644 index 0000000..aa5f25e --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/FileUploadController.java @@ -0,0 +1,106 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.bn.ui; + +import java.io.*; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.Resource; +import javax.faces.application.FacesMessage; +import javax.faces.bean.ApplicationScoped; +import javax.faces.bean.ManagedBean; +import javax.faces.context.FacesContext; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.UserTransaction; +import javax.xml.bind.JAXBException; +import org.primefaces.event.FileUploadEvent; +import org.primefaces.model.UploadedFile; +import org.ufcspa.simdecs.bn.entity.BayesianNetwork; +import org.ufcspa.simdecs.bn.entity.Node; +import unbbayes.io.exception.LoadException; +import unbbayes.io.xmlbif.version6.XMLBIFIO; +import unbbayes.prs.bn.ProbabilisticNetwork; + +/** + * + * @author mchelem + */ +@ManagedBean(name = "fileUploadController") +@ApplicationScoped +public class FileUploadController implements Serializable { + @Resource + private UserTransaction utx = null; + @PersistenceUnit(unitName = "simdecsEclipseLinkPU") + private EntityManagerFactory emf = null; + EntityManager em = null; + + private static final Logger logger = Logger.getLogger("" + FileUploadController.class); + + private File saveUploadedFile(UploadedFile uploadedFile) throws IOException{ + InputStream in = new BufferedInputStream(uploadedFile.getInputstream()); + File file = new File(uploadedFile.getFileName()); + FileOutputStream fout = new FileOutputStream(file); + while(in.available() != 0){ + fout.write(in.read()); + } + logger.log(Level.INFO, "Uploaded file saved in: {0}", file.getAbsolutePath()); + return file; + } + + private void persist(BayesianNetwork bayesianNetwork){ + em = emf.createEntityManager(); + try { + utx.begin(); + em.persist(bayesianNetwork); + utx.commit(); + } catch (Exception e) { + try { + utx.rollback(); + } catch (Exception ex) { + Logger.getLogger(FileUploadController.class.getName()).log(Level.SEVERE, null, ex); + } + Logger.getLogger(FileUploadController.class.getName()).log(Level.INFO, null, e); + } + logger.log(Level.INFO, "Bayesian Network {0} persisted.", bayesianNetwork.getName()); + + } + + + public void handleFileUpload(FileUploadEvent event) { + try { + File file = this.saveUploadedFile(event.getFile()); + // required to run unbbayes gui classes on server + System.setProperty("java.awt.headless", "false"); + + ProbabilisticNetwork bn = new ProbabilisticNetwork(null); + XMLBIFIO.loadXML(new File(file.getAbsolutePath()), bn); + BayesianNetwork bayesianNetwork = new BayesianNetwork(); + bayesianNetwork.setName(bn.getName()); + + ArrayList nodes = new ArrayList(); + for (unbbayes.prs.Node prs_node: bn.getNodes()){ + Node node = new Node(); + node.setName(prs_node.getName()); + node.setBayesianNetwork(bayesianNetwork); + nodes.add(node); + } + bayesianNetwork.setNodes(nodes); + persist(bayesianNetwork); + + FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded."); + FacesContext.getCurrentInstance().addMessage(null, msg); + } catch (LoadException ex) { + Logger.getLogger(FileUploadController.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(FileUploadController.class.getName()).log(Level.SEVERE, null, ex); + } catch (JAXBException ex) { + Logger.getLogger(FileUploadController.class.getName()).log(Level.SEVERE, null, ex); + } + } +} + \ No newline at end of file diff --git a/src/java/org/ufcspa/simdecs/bn/ui/NodeController.java b/src/java/org/ufcspa/simdecs/bn/ui/NodeController.java new file mode 100644 index 0000000..bd24dd9 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/NodeController.java @@ -0,0 +1,236 @@ +package org.ufcspa.simdecs.bn.ui; + +import org.ufcspa.simdecs.bn.entity.Node; +import org.ufcspa.simdecs.bn.ui.util.JsfUtil; +import org.ufcspa.simdecs.bn.ui.util.PaginationHelper; +import org.ufcspa.simdecs.bn.jpa.NodeJpaController; + +import java.io.Serializable; +import java.util.ResourceBundle; +import javax.annotation.Resource; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.UserTransaction; + +@ManagedBean(name = "nodeController") +@SessionScoped +public class NodeController implements Serializable { + + @Resource + private UserTransaction utx = null; + @PersistenceUnit(unitName = "simdecsEclipseLinkPU") + private EntityManagerFactory emf = null; + private Node current; + private DataModel items = null; + private NodeJpaController jpaController = null; + private PaginationHelper pagination; + private int selectedItemIndex; + + public NodeController() { + } + + public Node getSelected() { + if (current == null) { + current = new Node(); + selectedItemIndex = -1; + } + return current; + } + + private NodeJpaController getJpaController() { + if (jpaController == null) { + jpaController = new NodeJpaController(utx, emf); + } + return jpaController; + } + + public PaginationHelper getPagination() { + if (pagination == null) { + pagination = new PaginationHelper(10) { + + @Override + public int getItemsCount() { + return getJpaController().getNodeCount(); + } + + @Override + public DataModel createPageDataModel() { + return new ListDataModel(getJpaController().findNodeEntities(getPageSize(), getPageFirstItem())); + } + }; + } + return pagination; + } + + public String prepareList() { + recreateModel(); + return "List"; + } + + public String prepareView() { + current = (Node) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "View"; + } + + public String prepareCreate() { + current = new Node(); + selectedItemIndex = -1; + return "Create"; + } + + public String create() { + try { + getJpaController().create(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("NodeCreated")); + return prepareCreate(); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String prepareEdit() { + current = (Node) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "Edit"; + } + + public String update() { + try { + getJpaController().edit(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("NodeUpdated")); + return "View"; + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String destroy() { + current = (Node) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + performDestroy(); + recreatePagination(); + recreateModel(); + return "List"; + } + + public String destroyAndView() { + performDestroy(); + recreateModel(); + updateCurrentItem(); + if (selectedItemIndex >= 0) { + return "View"; + } else { + // all items were removed - go back to list + recreateModel(); + return "List"; + } + } + + private void performDestroy() { + try { + getJpaController().destroy(current.getId()); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("NodeDeleted")); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + } + } + + private void updateCurrentItem() { + int count = getJpaController().getNodeCount(); + if (selectedItemIndex >= count) { + // selected index cannot be bigger than number of items: + selectedItemIndex = count - 1; + // go to previous page if last page disappeared: + if (pagination.getPageFirstItem() >= count) { + pagination.previousPage(); + } + } + if (selectedItemIndex >= 0) { + current = getJpaController().findNodeEntities(1, selectedItemIndex).get(0); + } + } + + public DataModel getItems() { + if (items == null) { + items = getPagination().createPageDataModel(); + } + return items; + } + + private void recreateModel() { + items = null; + } + + private void recreatePagination() { + pagination = null; + } + + public String next() { + getPagination().nextPage(); + recreateModel(); + return "List"; + } + + public String previous() { + getPagination().previousPage(); + recreateModel(); + return "List"; + } + + public SelectItem[] getItemsAvailableSelectMany() { + return JsfUtil.getSelectItems(getJpaController().findNodeEntities(), false); + } + + public SelectItem[] getItemsAvailableSelectOne() { + return JsfUtil.getSelectItems(getJpaController().findNodeEntities(), true); + } + + @FacesConverter(forClass = Node.class) + public static class NodeControllerConverter implements Converter { + + public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { + if (value == null || value.length() == 0) { + return null; + } + NodeController controller = (NodeController) facesContext.getApplication().getELResolver(). + getValue(facesContext.getELContext(), null, "nodeController"); + return controller.getJpaController().findNode(getKey(value)); + } + + java.lang.Long getKey(String value) { + java.lang.Long key; + key = Long.valueOf(value); + return key; + } + + String getStringKey(java.lang.Long value) { + StringBuffer sb = new StringBuffer(); + sb.append(value); + return sb.toString(); + } + + public String getAsString(FacesContext facesContext, UIComponent component, Object object) { + if (object == null) { + return null; + } + if (object instanceof Node) { + Node o = (Node) object; + return getStringKey(o.getId()); + } else { + throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + NodeController.class.getName()); + } + } + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/ui/QuestionController.java b/src/java/org/ufcspa/simdecs/bn/ui/QuestionController.java new file mode 100644 index 0000000..711712f --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/QuestionController.java @@ -0,0 +1,236 @@ +package org.ufcspa.simdecs.bn.ui; + +import org.ufcspa.simdecs.bn.entity.Question; +import org.ufcspa.simdecs.bn.ui.util.JsfUtil; +import org.ufcspa.simdecs.bn.ui.util.PaginationHelper; +import org.ufcspa.simdecs.bn.jpa.QuestionJpaController; + +import java.io.Serializable; +import java.util.ResourceBundle; +import javax.annotation.Resource; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.UserTransaction; + +@ManagedBean(name = "questionController") +@SessionScoped +public class QuestionController implements Serializable { + + @Resource + private UserTransaction utx = null; + @PersistenceUnit(unitName = "simdecsEclipseLinkPU") + private EntityManagerFactory emf = null; + private Question current; + private DataModel items = null; + private QuestionJpaController jpaController = null; + private PaginationHelper pagination; + private int selectedItemIndex; + + public QuestionController() { + } + + public Question getSelected() { + if (current == null) { + current = new Question(); + selectedItemIndex = -1; + } + return current; + } + + private QuestionJpaController getJpaController() { + if (jpaController == null) { + jpaController = new QuestionJpaController(utx, emf); + } + return jpaController; + } + + public PaginationHelper getPagination() { + if (pagination == null) { + pagination = new PaginationHelper(10) { + + @Override + public int getItemsCount() { + return getJpaController().getQuestionCount(); + } + + @Override + public DataModel createPageDataModel() { + return new ListDataModel(getJpaController().findQuestionEntities(getPageSize(), getPageFirstItem())); + } + }; + } + return pagination; + } + + public String prepareList() { + recreateModel(); + return "List"; + } + + public String prepareView() { + current = (Question) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "View"; + } + + public String prepareCreate() { + current = new Question(); + selectedItemIndex = -1; + return "Create"; + } + + public String create() { + try { + getJpaController().create(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("QuestionCreated")); + return prepareCreate(); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String prepareEdit() { + current = (Question) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + return "Edit"; + } + + public String update() { + try { + getJpaController().edit(current); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("QuestionUpdated")); + return "View"; + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + return null; + } + } + + public String destroy() { + current = (Question) getItems().getRowData(); + selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex(); + performDestroy(); + recreatePagination(); + recreateModel(); + return "List"; + } + + public String destroyAndView() { + performDestroy(); + recreateModel(); + updateCurrentItem(); + if (selectedItemIndex >= 0) { + return "View"; + } else { + // all items were removed - go back to list + recreateModel(); + return "List"; + } + } + + private void performDestroy() { + try { + getJpaController().destroy(current.getId()); + JsfUtil.addSuccessMessage(ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("QuestionDeleted")); + } catch (Exception e) { + JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("org/ufcspa/simdecs/bn/Bundle").getString("PersistenceErrorOccured")); + } + } + + private void updateCurrentItem() { + int count = getJpaController().getQuestionCount(); + if (selectedItemIndex >= count) { + // selected index cannot be bigger than number of items: + selectedItemIndex = count - 1; + // go to previous page if last page disappeared: + if (pagination.getPageFirstItem() >= count) { + pagination.previousPage(); + } + } + if (selectedItemIndex >= 0) { + current = getJpaController().findQuestionEntities(1, selectedItemIndex).get(0); + } + } + + public DataModel getItems() { + if (items == null) { + items = getPagination().createPageDataModel(); + } + return items; + } + + private void recreateModel() { + items = null; + } + + private void recreatePagination() { + pagination = null; + } + + public String next() { + getPagination().nextPage(); + recreateModel(); + return "List"; + } + + public String previous() { + getPagination().previousPage(); + recreateModel(); + return "List"; + } + + public SelectItem[] getItemsAvailableSelectMany() { + return JsfUtil.getSelectItems(getJpaController().findQuestionEntities(), false); + } + + public SelectItem[] getItemsAvailableSelectOne() { + return JsfUtil.getSelectItems(getJpaController().findQuestionEntities(), true); + } + + @FacesConverter(forClass = Question.class) + public static class QuestionControllerConverter implements Converter { + + public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { + if (value == null || value.length() == 0) { + return null; + } + QuestionController controller = (QuestionController) facesContext.getApplication().getELResolver(). + getValue(facesContext.getELContext(), null, "questionController"); + return controller.getJpaController().findQuestion(getKey(value)); + } + + java.lang.Long getKey(String value) { + java.lang.Long key; + key = Long.valueOf(value); + return key; + } + + String getStringKey(java.lang.Long value) { + StringBuffer sb = new StringBuffer(); + sb.append(value); + return sb.toString(); + } + + public String getAsString(FacesContext facesContext, UIComponent component, Object object) { + if (object == null) { + return null; + } + if (object instanceof Question) { + Question o = (Question) object; + return getStringKey(o.getId()); + } else { + throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + QuestionController.class.getName()); + } + } + } +} diff --git a/src/java/org/ufcspa/simdecs/bn/ui/util/JsfUtil.java b/src/java/org/ufcspa/simdecs/bn/ui/util/JsfUtil.java new file mode 100644 index 0000000..8a83a97 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/util/JsfUtil.java @@ -0,0 +1,59 @@ +package org.ufcspa.simdecs.bn.ui.util; + +import java.util.List; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.model.SelectItem; + +public class JsfUtil { + + public static SelectItem[] getSelectItems(List entities, boolean selectOne) { + int size = selectOne ? entities.size() + 1 : entities.size(); + SelectItem[] items = new SelectItem[size]; + int i = 0; + if (selectOne) { + items[0] = new SelectItem("", "---"); + i++; + } + for (Object x : entities) { + items[i++] = new SelectItem(x, x.toString()); + } + return items; + } + + public static void addErrorMessage(Exception ex, String defaultMsg) { + String msg = ex.getLocalizedMessage(); + if (msg != null && msg.length() > 0) { + addErrorMessage(msg); + } else { + addErrorMessage(defaultMsg); + } + } + + public static void addErrorMessages(List messages) { + for (String message : messages) { + addErrorMessage(message); + } + } + + public static void addErrorMessage(String msg) { + FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg); + FacesContext.getCurrentInstance().addMessage(null, facesMsg); + } + + public static void addSuccessMessage(String msg) { + FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg); + FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg); + } + + public static String getRequestParameter(String key) { + return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key); + } + + public static Object getObjectFromRequestParameter(String requestParameterName, Converter converter, UIComponent component) { + String theId = JsfUtil.getRequestParameter(requestParameterName); + return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId); + } +} \ No newline at end of file diff --git a/src/java/org/ufcspa/simdecs/bn/ui/util/PaginationHelper.java b/src/java/org/ufcspa/simdecs/bn/ui/util/PaginationHelper.java new file mode 100644 index 0000000..c9da86b --- /dev/null +++ b/src/java/org/ufcspa/simdecs/bn/ui/util/PaginationHelper.java @@ -0,0 +1,57 @@ +package org.ufcspa.simdecs.bn.ui.util; + +import javax.faces.model.DataModel; + +public abstract class PaginationHelper { + + private int pageSize; + private int page; + + public PaginationHelper(int pageSize) { + this.pageSize = pageSize; + } + + public abstract int getItemsCount(); + + public abstract DataModel createPageDataModel(); + + public int getPageFirstItem() { + return page * pageSize; + } + + public int getPageLastItem() { + int i = getPageFirstItem() + pageSize - 1; + int count = getItemsCount() - 1; + if (i > count) { + i = count; + } + if (i < 0) { + i = 0; + } + return i; + } + + public boolean isHasNextPage() { + return (page + 1) * pageSize + 1 <= getItemsCount(); + } + + public void nextPage() { + if (isHasNextPage()) { + page++; + } + } + + public boolean isHasPreviousPage() { + return page > 0; + } + + public void previousPage() { + if (isHasPreviousPage()) { + page--; + } + } + + public int getPageSize() { + return pageSize; + } +} diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 662799e..6f0498f 100755 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -16,6 +16,10 @@ org.ufcspa.simdecs.resources.messages + + org/ufcspa/simdecs/bn/Bundle + bundle + editActor diff --git a/web/bn/answer/Create.xhtml b/web/bn/answer/Create.xhtml new file mode 100644 index 0000000..90e700c --- /dev/null +++ b/web/bn/answer/Create.xhtml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+
+ + diff --git a/web/bn/answer/Edit.xhtml b/web/bn/answer/Edit.xhtml new file mode 100644 index 0000000..e45407b --- /dev/null +++ b/web/bn/answer/Edit.xhtml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/answer/List.xhtml b/web/bn/answer/List.xhtml new file mode 100644 index 0000000..1378c38 --- /dev/null +++ b/web/bn/answer/List.xhtml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/answer/View.xhtml b/web/bn/answer/View.xhtml new file mode 100644 index 0000000..119c531 --- /dev/null +++ b/web/bn/answer/View.xhtml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+
+ + diff --git a/web/bn/bayesianNetwork/Create.xhtml b/web/bn/bayesianNetwork/Create.xhtml new file mode 100644 index 0000000..7219a62 --- /dev/null +++ b/web/bn/bayesianNetwork/Create.xhtml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+
+ + diff --git a/web/bn/bayesianNetwork/Edit.xhtml b/web/bn/bayesianNetwork/Edit.xhtml new file mode 100644 index 0000000..e2fe5d4 --- /dev/null +++ b/web/bn/bayesianNetwork/Edit.xhtml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/bayesianNetwork/List.xhtml b/web/bn/bayesianNetwork/List.xhtml new file mode 100644 index 0000000..8d00def --- /dev/null +++ b/web/bn/bayesianNetwork/List.xhtml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/bayesianNetwork/View.xhtml b/web/bn/bayesianNetwork/View.xhtml new file mode 100644 index 0000000..390f2b6 --- /dev/null +++ b/web/bn/bayesianNetwork/View.xhtml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+
+ + diff --git a/web/bn/node/Create.xhtml b/web/bn/node/Create.xhtml new file mode 100644 index 0000000..9c8ad32 --- /dev/null +++ b/web/bn/node/Create.xhtml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+
+ + diff --git a/web/bn/node/Edit.xhtml b/web/bn/node/Edit.xhtml new file mode 100644 index 0000000..076c337 --- /dev/null +++ b/web/bn/node/Edit.xhtml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/node/List.xhtml b/web/bn/node/List.xhtml new file mode 100644 index 0000000..65b92bf --- /dev/null +++ b/web/bn/node/List.xhtml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/node/View.xhtml b/web/bn/node/View.xhtml new file mode 100644 index 0000000..883acb5 --- /dev/null +++ b/web/bn/node/View.xhtml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+
+ + diff --git a/web/bn/question/Create.xhtml b/web/bn/question/Create.xhtml new file mode 100644 index 0000000..cdcbc6e --- /dev/null +++ b/web/bn/question/Create.xhtml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+
+ + diff --git a/web/bn/question/Edit.xhtml b/web/bn/question/Edit.xhtml new file mode 100644 index 0000000..d2c8f73 --- /dev/null +++ b/web/bn/question/Edit.xhtml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/question/List.xhtml b/web/bn/question/List.xhtml new file mode 100644 index 0000000..e4e827c --- /dev/null +++ b/web/bn/question/List.xhtml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+ + diff --git a/web/bn/question/View.xhtml b/web/bn/question/View.xhtml new file mode 100644 index 0000000..a116cdf --- /dev/null +++ b/web/bn/question/View.xhtml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+
+ + diff --git a/web/index.xhtml b/web/index.xhtml index 0acf6cf..9a5d5f9 100755 --- a/web/index.xhtml +++ b/web/index.xhtml @@ -5,14 +5,25 @@ xmlns:h="http://java.sun.com/jsf/html"> Facelet Title + - + - - - For more information visit http://primefaces.org. - + + + + + + + + + + + + + + diff --git a/web/resources/css/jsfcrud.css b/web/resources/css/jsfcrud.css new file mode 100644 index 0000000..4cf3660 --- /dev/null +++ b/web/resources/css/jsfcrud.css @@ -0,0 +1,87 @@ +root { + display: block; +} + +body { + font-family: Arial, Helvetica, sans-serif; + color: #000000; + background-color: #ffffff; + font-size: small; +} + +a { + color: #000000; +} + +table { + empty-cells: show; +} + +form.jsfcrud_list_form th, td th { + font-size: x-small; + color: #000000; + border-top-style: solid; + border-bottom-style: solid; + border-left-style: solid; + border-right-style: solid; + border-top-width: 1px; + border-bottom-width: 1px; + border-left-width: 1px; + border-right-width: 1px; + border-top-color: #404040; + border-bottom-color: #404040; + border-left-color: #404040; + border-right-color: #404040; + letter-spacing: 3px; + text-align: left; + padding-top: 6px; + padding-bottom: 6px; + padding-left: 6px; + padding-right: 6px; + background-color: #909090; +} + +td { + vertical-align: top; + padding-bottom: 8px; + font-size: small; +} + +form.jsfcrud_list_form td, td td { + border-top-style: solid; + border-bottom-style: solid; + border-left-style: solid; + border-right-style: solid; + border-top-width: 1px; + border-bottom-width: 1px; + border-left-width: 1px; + border-right-width: 1px; + border-top-color: #404040; + border-bottom-color: #404040; + border-left-color: #404040; + border-right-color: #404040; + vertical-align: baseline; + padding-bottom: 0px; +} + +tr.jsfcrud_odd_row { + background-color: #fefeff; + color: #303030; +} + + +tr.jsfcrud_even_row { + background-color: #eff5fa; + color: #303030; +} + +#busyImage { + position: absolute; + left: 50%; + top: 50%; +} + +.removeImage { + +background-image: url(‘/img/bayesianNetwork/remove.png’) !important; +} diff --git a/web/template.xhtml b/web/template.xhtml new file mode 100644 index 0000000..f83ce2e --- /dev/null +++ b/web/template.xhtml @@ -0,0 +1,21 @@ + + + + + + <ui:insert name="title">Default Title</ui:insert> + + + + +

+ Default Title +

+

+ Default Body +

+
+ +