Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f03d8ff6
authored
Aug 31, 2013
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Random minor changes. Merge DbModel and bootstrapbean from talyn.
1 parent
dcaf6932
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
190 additions
and
17 deletions
check-mvn-versions.sh
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/BootstrapBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/DBModelFacade.java
code/MoyaDatabase/src/fi/codecrew/moya/model/DBModel.java
code/MoyaWeb/WebContent/WEB-INF/glassfish-web.xml
code/MoyaWeb/WebContent/WEB-INF/web.xml
code/MoyaWeb/WebContent/resources/templates/template1/template.xhtml
code/MoyaWeb/pom.xml
code/MoyaWeb/src/fi/codecrew/moya/HostnameFilter.java
code/MoyaWeb/src/fi/codecrew/moya/handler/NavigationHandler.java
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/menu/MenuView.java
check-mvn-versions.sh
0 → 100644
View file @
f03d8ff
#!/bin/bash
for
i
in
`
find code -type d -mindepth 1 -maxdepth 1 -name
"Moya*"
`
;
do
cd
$i
; mvn versions:display-dependency-updates;
cd
../.. ;
done
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/BootstrapBean.java
View file @
f03d8ff
package
fi
.
codecrew
.
moya
.
beans
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
javax.ejb.EJB
;
import
javax.ejb.
LocalBea
n
;
import
javax.ejb.Sta
teless
;
import
javax.ejb.
Singleto
n
;
import
javax.ejb.Sta
rtup
;
import
fi.codecrew.moya.facade.DBModelFacade
;
import
fi.codecrew.moya.facade.UserFacade
;
import
fi.codecrew.moya.model.DBModel
;
import
fi.codecrew.moya.model.User
;
@S
tateless
@
LocalBean
@S
ingleton
@
Startup
public
class
BootstrapBean
implements
BootstrapBeanLocal
{
@EJB
...
...
@@ -17,6 +23,63 @@ public class BootstrapBean implements BootstrapBeanLocal {
public
BootstrapBean
()
{
}
private
static
final
List
<
String
[]>
dbUpdates
=
new
ArrayList
<
String
[]>();
static
{
// {"Query1","Query2",...}
dbUpdates
.
add
(
new
String
[]
{
""
});
// first version, no changes
// dbUpdates.add(new String[] { "ALTER TABLE users ALTER COLUMN birthday TYPE date" });
}
@EJB
private
DBModelFacade
dbModelFacade
;
@PostConstruct
public
void
bootstrap
()
{
this
.
doDBUpdates
();
}
private
void
doDBUpdates
()
{
DBModel
dBm
=
dbModelFacade
.
findLastRevision
();
Integer
upIdx
=
(
dbUpdates
.
size
()
-
1
);
if
(
dBm
!=
null
)
{
Integer
revId
=
dBm
.
getRevision
();
// Check if we have unapplied updates
if
((
dbUpdates
.
size
()
-
1
)
>
revId
)
{
// Oh yes we do
this
.
executeUpdates
(
revId
,
upIdx
);
}
else
if
(
upIdx
<
revId
)
{
throw
new
RuntimeException
(
"Sanity check failed! DB is newer than the codebase!"
);
}
}
else
{
// DB is up to date by default! We need to mark the current version down though.
dBm
=
new
DBModel
();
dBm
.
setRevision
(
upIdx
);
dbModelFacade
.
create
(
dBm
);
}
}
private
void
executeUpdates
(
Integer
dbRev
,
Integer
targetRev
)
{
while
(
dbRev
<
targetRev
)
{
dbRev
++;
System
.
out
.
format
(
"attempt to upgrade db from version %d -> %d"
,
(
dbRev
-
1
),
dbRev
);
String
[]
queries
=
dbUpdates
.
get
(
dbRev
);
for
(
String
query
:
queries
)
{
if
(!
query
.
isEmpty
())
{
dbModelFacade
.
updateModel
(
query
);
}
}
System
.
out
.
println
(
"update ok!"
);
DBModel
dBm
=
new
DBModel
();
dBm
.
setRevision
(
dbRev
);
dbModelFacade
.
create
(
dBm
);
}
}
public
void
saneDefaults
()
{
User
adminUser
=
userFacade
.
findByLogin
(
"admin"
);
if
(
adminUser
==
null
)
{
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/DBModelFacade.java
0 → 100644
View file @
f03d8ff
package
fi
.
codecrew
.
moya
.
facade
;
import
javax.ejb.LocalBean
;
import
javax.ejb.Stateless
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.Query
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Root
;
import
fi.codecrew.moya.model.DBModel
;
import
fi.codecrew.moya.model.DBModel_
;
import
fi.codecrew.moya.utilities.jpa.GenericFacade
;
@Stateless
@LocalBean
public
class
DBModelFacade
extends
GenericFacade
<
DBModel
>
{
public
DBModelFacade
()
{
super
(
DBModel
.
class
);
}
public
void
updateModel
(
String
updateModelSQL
)
{
Query
q
=
getEm
().
createNativeQuery
(
updateModelSQL
);
q
.
executeUpdate
();
}
public
DBModel
findRevisionById
(
Integer
id
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
DBModel
>
cq
=
cb
.
createQuery
(
DBModel
.
class
);
Root
<
DBModel
>
root
=
cq
.
from
(
DBModel
.
class
);
cq
.
where
(
cb
.
equal
(
root
.
get
(
DBModel_
.
revision
),
id
));
return
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
}
public
DBModel
findLastRevision
()
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
DBModel
>
cq
=
cb
.
createQuery
(
DBModel
.
class
);
Root
<
DBModel
>
root
=
cq
.
from
(
DBModel
.
class
);
cq
.
orderBy
(
cb
.
desc
(
root
.
get
(
DBModel_
.
revision
)));
return
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
}
@PersistenceContext
private
EntityManager
em
;
protected
EntityManager
getEm
()
{
return
em
;
}
}
code/MoyaDatabase/src/fi/codecrew/moya/model/DBModel.java
0 → 100644
View file @
f03d8ff
package
fi
.
codecrew
.
moya
.
model
;
import
java.util.Date
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
javax.persistence.Temporal
;
import
javax.persistence.TemporalType
;
@Entity
@Table
(
name
=
"db_models"
)
public
class
DBModel
extends
GenericEntity
{
private
static
final
long
serialVersionUID
=
5073284536090477220L
;
@Column
(
name
=
"revision"
,
nullable
=
false
)
private
Integer
revision
;
@Column
(
name
=
"applied_at"
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Date
appliedAt
=
new
Date
();
public
Date
getAppliedAt
()
{
return
appliedAt
;
}
public
void
setAppliedAt
(
Date
appliedAt
)
{
this
.
appliedAt
=
appliedAt
;
}
public
Integer
getRevision
()
{
return
revision
;
}
public
void
setRevision
(
Integer
revision
)
{
this
.
revision
=
revision
;
}
}
code/MoyaWeb/WebContent/WEB-INF/glassfish-web.xml
View file @
f03d8ff
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN"
"http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app
error-url=
""
>
<context-root>
/MoyaWeb
</context-root>
<resource-ref>
<res-ref-name>
jsf/ProjectStage
</res-ref-name>
<jndi-name>
javax.faces.PROJECT_STAGE
</jndi-name>
</resource-ref>
<class-loader
delegate=
"true"
/>
<jsp-config>
<property
name=
"keepgenerated"
value=
"true"
>
<description>
Keep a copy of the generated servlet class java code.
</description>
</property>
</jsp-config>
<parameter-encoding
default-charset=
"UTF-8"
/>
</glassfish-web-app>
code/MoyaWeb/WebContent/WEB-INF/web.xml
View file @
f03d8ff
...
...
@@ -7,6 +7,11 @@
<param-name>
javax.faces.FACELETS_SKIP_COMMENTS
</param-name>
<param-value>
true
</param-value>
</context-param>
<!-- Asetetaan PROJECT_STAGE JNDI:llä, ja fallbackataan arvoon Development -->
<resource-ref>
<res-ref-name>
jsf/ProjectStage
</res-ref-name>
<res-type>
java.lang.String
</res-type>
</resource-ref>
<context-param>
<param-name>
javax.faces.PROJECT_STAGE
</param-name>
<param-value>
Development
</param-value>
...
...
@@ -36,7 +41,7 @@
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>
Faces Servlet
</servlet-name>
...
...
code/MoyaWeb/WebContent/resources/templates/template1/template.xhtml
View file @
f03d8ff
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:tools=
"http://java.sun.com/jsf/composite/cditools"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:p=
"http://primefaces.org/ui"
>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:tools=
"http://java.sun.com/jsf/composite/cditools"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:p=
"http://primefaces.org/ui"
>
<f:view
contentType=
"text/html"
locale=
"#{sessionHandler.locale}"
>
...
...
@@ -11,7 +12,7 @@
<meta
name=
"description"
content=
"Lippukauppa"
/>
<meta
name=
"author"
content=
"CodeCrew ry"
/>
<meta
http-equiv=
"Content-Language"
content=
"fi"
/>
<link
rel=
"icon"
href=
"#{request.contextPath}/favicon.ico"
type=
"image/x-icon"
/>
<link
rel=
"icon"
href=
"#{request.contextPath}/favicon.ico"
type=
"image/x-icon"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"#{request.contextPath}/resources/templates/template1/css/style.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"#{request.contextPath}/resources/templates/template1/css/general.css"
/>
<ui:insert
name=
"headerdata"
/>
...
...
@@ -99,9 +100,10 @@
<br
/>
<div
class=
"ui-widget-header"
>
Select Mode
</div>
<ui:fragment></ui:fragment>
<div
class=
"ui-widget-content"
style=
"text-align: center"
>
<h:form
render=
"#{menuview.viewChangeTopmenu.size() gt 1}"
>
Size: #{menuView.viewChangeTopmenu.size()}
<h:form
>
<p:selectOneMenu
value=
"#{menuView.menuChange}"
>
<p:ajax
listener=
"#{menuView.menuChangeEvent}"
/>
<f:selectItems
var=
"menuitem"
value=
"#{menuView.viewChangeTopmenu}"
itemLabel=
"#{i18n[menuitem.navigation.key]}"
itemValue=
"#{menuitem.outcome}"
/>
...
...
code/MoyaWeb/pom.xml
View file @
f03d8ff
...
...
@@ -76,7 +76,7 @@
<dependency>
<groupId>
net.bull.javamelody
</groupId>
<artifactId>
javamelody-core
</artifactId>
<version>
1.4
4
.0
</version>
<version>
1.4
6
.0
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
code/MoyaWeb/src/fi/codecrew/moya/HostnameFilter.java
View file @
f03d8ff
...
...
@@ -3,6 +3,7 @@ package fi.codecrew.moya;
import
java.io.IOException
;
import
javax.ejb.EJB
;
import
javax.faces.application.ProjectStage
;
import
javax.faces.context.FacesContext
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
...
...
@@ -153,15 +154,12 @@ public class HostnameFilter implements Filter {
public
void
init
(
FilterConfig
fConfig
)
throws
ServletException
{
// check if software is in development -mode
FacesContext
fc
=
FacesContext
.
getCurrentInstance
();
String
stage
=
fc
.
getExternalContext
().
getInitParameter
(
"javax.faces.PROJECT_STAGE"
);
if
(
stage
.
trim
().
equalsIgnoreCase
(
"Development"
))
{
if
(
ProjectStage
.
Development
.
equals
(
fc
.
getApplication
().
getProjectStage
()
))
{
developmentMode
=
true
;
}
}
// public static String getCurrentHostname(HttpSession sess) {
// String ret = null;
// if (sess != null) {
...
...
code/MoyaWeb/src/fi/codecrew/moya/handler/NavigationHandler.java
View file @
f03d8ff
...
...
@@ -62,4 +62,5 @@ public class NavigationHandler implements Serializable {
navihand
.
handleNavigation
(
fcont
,
null
,
navigation
);
}
}
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/menu/MenuView.java
View file @
f03d8ff
...
...
@@ -66,6 +66,11 @@ public class MenuView extends GenericCDIView {
return
contents
.
get
(
key
);
}
public
boolean
isRenderViewChange
()
{
return
viewchangeTopmenu
.
size
()
>
1
;
}
public
List
<
JsfMenuitem
>
getMenu
(
Integer
level
)
{
getMenus
();
...
...
@@ -81,7 +86,8 @@ public class MenuView extends GenericCDIView {
}
public
void
menuChangeEvent
()
{
super
.
navihandler
.
forward
(
menuChange
);
navihandler
.
forward
(
menuChange
);
// super.navihandler.forward(menuChange);
}
private
List
<
JsfMenuitem
>
viewchangeTopmenu
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment