Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: wjanssens/Aspekt-FDD
base: ddff2d8c15
...
head fork: wjanssens/Aspekt-FDD
compare: 7a5d787236
Checking mergeability… Don't worry, you can still create the pull request.
  • 7 commits
  • 33 files changed
  • 0 commit comments
  • 1 contributor
Showing with 520 additions and 307 deletions.
  1. +4 −4 WebContent/WEB-INF/template/html/include/menu.ftl
  2. +63 −45 src/aspekt/AspektApplication.java
  3. +31 −0 src/aspekt/db/maps/AccountMapper.java
  4. +13 −12 src/aspekt/db/maps/{account.xml → AccountMapper.xml}
  5. +28 −0 src/aspekt/db/maps/AspectMapper.java
  6. +9 −9 src/aspekt/db/maps/{aspect.xml → AspectMapper.xml}
  7. +19 −0 src/aspekt/db/maps/AuthMapper.java
  8. +3 −5 src/aspekt/db/maps/{auth.xml → AuthMapper.xml}
  9. +19 −0 src/aspekt/db/maps/FeatureMapper.java
  10. +16 −16 src/aspekt/db/maps/{feature.xml → FeatureMapper.xml}
  11. +13 −0 src/aspekt/db/maps/KeyMapper.java
  12. +7 −7 src/aspekt/db/maps/{key.xml → KeyMapper.xml}
  13. +28 −0 src/aspekt/db/maps/NodeMapper.java
  14. +13 −14 src/aspekt/db/maps/{node.xml → NodeMapper.xml}
  15. +13 −0 src/aspekt/db/maps/ParameterMapper.java
  16. +5 −5 src/aspekt/db/maps/{parameter.xml → ParameterMapper.xml}
  17. +17 −0 src/aspekt/db/maps/ReportMapper.java
  18. +9 −10 src/aspekt/db/maps/{report.xml → ReportMapper.xml}
  19. +0 −26 src/aspekt/db/maps/config.xml
  20. +11 −10 src/aspekt/resource/{DevelopmentView.java → DevelopmentViewResource.java}
  21. +9 −11 src/aspekt/resource/{Fddi.java → FddiResource.java}
  22. +11 −8 src/aspekt/resource/{Index.java → IndexResource.java}
  23. +80 −77 src/aspekt/resource/{Node.java → NodeResource.java}
  24. +11 −10 src/aspekt/resource/{ParkingLot.java → ParkingLotResource.java}
  25. +10 −9 src/aspekt/resource/{PlanView.java → PlanViewResource.java}
  26. +10 −9 src/aspekt/resource/{ProgressSummary.java → ProgressSummaryResource.java}
  27. +9 −5 src/aspekt/resource/{Search.java → SearchResource.java}
  28. +11 −10 src/aspekt/resource/{Trend.java → TrendResource.java}
  29. +1 −1  src/aspekt/security/AspektEnroler.java
  30. +4 −2 src/aspekt/security/AspektVerifier.java
  31. +4 −1 src/aspekt/service/ParameterService.java
  32. +37 −0 src/aspekt/service/StatusService.java
  33. +2 −1  src/aspekt/util/LocalizationUtil.java
View
8 WebContent/WEB-INF/template/html/include/menu.ftl
@@ -4,16 +4,16 @@
<li>
<a href="${urlBase}/node/0">Programs</a>
</li>
- <#if roles?seq_contains("admin") || roles?seq_contains("editparams") || roles?seq_contains("editusers")>
+ <#if roles?seq_contains("aspekt_editparams") || roles?seq_contains("aspekt_editusers")>
<li>
<a href="#">Administration</a>
<ul>
- <#if roles?seq_contains("admin") || roles?seq_contains("editusers")>
+ <#if roles?seq_contains("aspekt_editusers")>
<li>
<a href="${urlBase}/admin/accounts.html">Accounts</a>
</li>
</#if>
- <#if roles?seq_contains("admin") || roles?seq_contains("editparams")>
+ <#if roles?seq_contains("aspekt_editparams")>
<li>
<a href="${urlBase}/admin/parameters.html">Parameters</a>
</li>
@@ -27,7 +27,7 @@
<li>
<a href="${urlBase}/admin/accounts/${uid}.html">Name &amp; Password</a>
</li>
- <#if roles?seq_contains("admin") || roles?seq_contains("caninvite")>
+ <#if roles?seq_contains("aspekt_caninvite")>
<li>
<a href="${urlBase}/invite.html">Send Account Invitation</a>
</li>
View
108 src/aspekt/AspektApplication.java
@@ -12,9 +12,12 @@
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.ResourceAccessor;
+import org.apache.ibatis.datasource.pooled.PooledDataSource;
+import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.restlet.Application;
import org.restlet.Client;
import org.restlet.Context;
@@ -37,16 +40,16 @@
import org.restlet.routing.Router;
import org.restlet.security.ChallengeAuthenticator;
-import aspekt.resource.DevelopmentView;
-import aspekt.resource.Fddi;
-import aspekt.resource.Index;
+import aspekt.resource.DevelopmentViewResource;
+import aspekt.resource.FddiResource;
+import aspekt.resource.IndexResource;
import aspekt.resource.LoginResource;
-import aspekt.resource.Node;
-import aspekt.resource.ParkingLot;
-import aspekt.resource.PlanView;
-import aspekt.resource.ProgressSummary;
-import aspekt.resource.Search;
-import aspekt.resource.Trend;
+import aspekt.resource.NodeResource;
+import aspekt.resource.ParkingLotResource;
+import aspekt.resource.PlanViewResource;
+import aspekt.resource.ProgressSummaryResource;
+import aspekt.resource.SearchResource;
+import aspekt.resource.TrendResource;
import aspekt.resource.account.InviteResource;
import aspekt.resource.account.PasswordResetResource;
import aspekt.resource.admin.AccountResource;
@@ -58,6 +61,7 @@
import aspekt.service.KeyService;
import aspekt.service.NonceService;
import aspekt.service.ParameterService;
+import aspekt.service.StatusService;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateExceptionHandler;
@@ -71,6 +75,18 @@
private SqlSessionFactory sqlSessionFactory;
private final Configuration fmConfig = new Configuration();
+ public AspektApplication() {
+ setStatusService(new StatusService());
+
+ getMetadataService().setDefaultCharacterSet(CharacterSet.UTF_8);
+ getMetadataService().setDefaultLanguage(Language.ENGLISH);
+ getMetadataService().addExtension("html", MediaType.TEXT_HTML);
+ getTunnelService().setEnabled(true);
+ getTunnelService().setExtensionsTunnel(true);
+ getTunnelService().setMethodTunnel(true);
+ getTunnelService().setMethodParameter("method");
+ }
+
public synchronized void start() throws Exception {
final Object servletContext = getContext().getServerDispatcher().getContext().getAttributes().get("org.restlet.ext.servlet.ServletContext");
final Object contextPath = servletContext.getClass().getMethod("getContextPath").invoke(servletContext);
@@ -92,8 +108,17 @@ public synchronized void start() throws Exception {
org.apache.ibatis.logging.LogFactory.useJdkLogging();
+ final PooledDataSource dataSource = new PooledDataSource(
+ properties.getProperty("db.driver"),
+ properties.getProperty("db.url"),
+ properties.getProperty("db.username"),
+ properties.getProperty("db.password"));
+ dataSource.setPoolPingQuery(properties.getProperty("db.validationQuery"));
+ final Environment environment = new Environment("aspekt", new JdbcTransactionFactory(), dataSource);
+ final org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(environment);
+ configuration.addMappers("aspekt.db.maps");
final SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
- sqlSessionFactory = sqlSessionFactoryBuilder.build(getClass().getClassLoader().getResourceAsStream("aspekt/db/maps/config.xml"), properties);
+ sqlSessionFactory = sqlSessionFactoryBuilder.build(configuration);
migrate();
@@ -177,50 +202,43 @@ public void migrate() throws Exception {
@Override
public Restlet createRoot() {
- getMetadataService().setDefaultCharacterSet(CharacterSet.UTF_8);
- getMetadataService().setDefaultLanguage(Language.ENGLISH);
- getMetadataService().addExtension("html", MediaType.TEXT_HTML);
- getTunnelService().setEnabled(true);
- getTunnelService().setExtensionsTunnel(true);
- getTunnelService().setMethodTunnel(true);
- getTunnelService().setMethodParameter("method");
-
- final Router router = new Router(getContext());
+ final Router publicRouter = new Router(getContext());
final Router privateRouter = new Router(getContext());
final AspektVerifier verifier = new AspektVerifier(this);
final AspektEnroler enroler = new AspektEnroler(this);
final String realm = properties.getProperty("auth.realm", "Aspekt");
- final ChallengeAuthenticator authenticator = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, realm);
- authenticator.setVerifier(verifier);
- authenticator.setEnroler(enroler);
- authenticator.setNext(privateRouter);
+
+ final ChallengeAuthenticator publicAuthenticator = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, realm);
+ publicAuthenticator.setOptional(true);
+ publicAuthenticator.setVerifier(verifier);
+ publicAuthenticator.setEnroler(enroler);
+ publicAuthenticator.setNext(publicRouter);
- final ChallengeAuthenticator inviteAuthenticator = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, realm);
- inviteAuthenticator.setOptional(true);
- inviteAuthenticator.setVerifier(verifier);
- inviteAuthenticator.setEnroler(enroler);
- inviteAuthenticator.setNext(InviteResource.class);
+ final ChallengeAuthenticator privateAuthenticator = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, realm);
+ privateAuthenticator.setVerifier(verifier);
+ privateAuthenticator.setEnroler(enroler);
+ privateAuthenticator.setNext(privateRouter);
- router.attach("", new Redirector(getContext(), "/", Redirector.MODE_CLIENT_TEMPORARY));
- router.attach("/", Index.class);
- router.attach("/index", Index.class);
- router.attach("/media", new Directory(getContext(), "war:///media"));
- router.attach("/invite", inviteAuthenticator);
- router.attach("/passwordreset", PasswordResetResource.class);
- router.attachDefault(authenticator);
+ publicRouter.attach("", new Redirector(getContext(), "/", Redirector.MODE_CLIENT_TEMPORARY));
+ publicRouter.attach("/", IndexResource.class);
+ publicRouter.attach("/index", IndexResource.class);
+ publicRouter.attach("/media", new Directory(getContext(), "war:///media"));
+ publicRouter.attach("/invite", InviteResource.class);
+ publicRouter.attach("/passwordreset", PasswordResetResource.class);
+ publicRouter.attachDefault(privateAuthenticator);
privateRouter.attach("/login", LoginResource.class);
- privateRouter.attach("/search", Search.class);
+ privateRouter.attach("/search", SearchResource.class);
- privateRouter.attach("/node/{id}", Node.class);
- privateRouter.attach("/node/{id}/new", Node.class);
- privateRouter.attach("/node/{id}/plan", PlanView.class);
- privateRouter.attach("/node/{id}/development", DevelopmentView.class);
- privateRouter.attach("/node/{id}/summary", ProgressSummary.class);
- privateRouter.attach("/node/{id}/parkinglot", ParkingLot.class);
- privateRouter.attach("/node/{id}/trend", Trend.class);
- privateRouter.attach("/node/{id}/fddi", Fddi.class);
+ privateRouter.attach("/node/{id}", NodeResource.class);
+ privateRouter.attach("/node/{id}/new", NodeResource.class);
+ privateRouter.attach("/node/{id}/plan", PlanViewResource.class);
+ privateRouter.attach("/node/{id}/development", DevelopmentViewResource.class);
+ privateRouter.attach("/node/{id}/summary", ProgressSummaryResource.class);
+ privateRouter.attach("/node/{id}/parkinglot", ParkingLotResource.class);
+ privateRouter.attach("/node/{id}/trend", TrendResource.class);
+ privateRouter.attach("/node/{id}/fddi", FddiResource.class);
privateRouter.attach("/admin/accounts", AccountsResource.class);
privateRouter.attach("/admin/accounts/{uid}", AccountResource.class);
@@ -228,7 +246,7 @@ public Restlet createRoot() {
privateRouter.attach("/admin/parameters", ParametersResource.class);
final Encoder encoder = new Encoder(getContext());
- encoder.setNext(router);
+ encoder.setNext(publicAuthenticator);
return encoder;
}
}
View
31 src/aspekt/db/maps/AccountMapper.java
@@ -0,0 +1,31 @@
+package aspekt.db.maps;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface AccountMapper {
+ Map<String, Object> authenticate(@Param("mail") String email);
+ List<String> enrole(@Param("uid") String uid);
+ Map<String, Object> select(@Param("uid") String uid);
+ Map<String, Object> selectNodeCounts(@Param("uid") String uid);
+ List<Map<String, Object>> selectList();
+ void insert(
+ @Param("uid") String uid,
+ @Param("display_name") String displayName,
+ @Param("initials") String initials,
+ @Param("mail") String email,
+ @Param("credentials") String credentials,
+ @Param("tz") String timeZone,
+ @Param("locale") String locale);
+ void update(
+ @Param("uid") String uid,
+ @Param("display_name") String displayName,
+ @Param("initials") String initials,
+ @Param("mail") String email,
+ @Param("credentials") String credentials,
+ @Param("tz") String timeZone,
+ @Param("locale") String locale,
+ @Param("rev") String revision);
+}
View
25 src/aspekt/db/maps/account.xml → src/aspekt/db/maps/AccountMapper.xml
@@ -1,29 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="account">
+<mapper namespace="aspekt.db.maps.AccountMapper">
<cache/>
- <select id="authenticate" parameterType="string" resultType="hashmap">
+ <select id="authenticate" resultType="hashmap">
SELECT uid, credentials, display_name, initials, mail, tz, locale
FROM users
-WHERE lower(mail) = lower(#{value})
+WHERE lower(mail) = lower(#{mail})
</select>
- <select id="enrole" parameterType="string" resultType="string">
+ <select id="enrole" resultType="string">
SELECT role
FROM roles
-WHERE uid = #{value}
+WHERE uid = #{uid}
</select>
- <select id="select" parameterType="string" resultType="hashmap">
+ <select id="select" resultType="hashmap">
SELECT display_name, initials, mail, rev, created_at, modified_at
FROM users
-WHERE uid = #{value:INTEGER}
+WHERE uid = #{uid}
</select>
- <select id="select_node_counts" parameterType="string" resultType="hashmap">
+
+ <select id="selectNodeCounts" resultType="hashmap">
SELECT kind, COUNT(*) AS ct
FROM node
-WHERE owner = #{uid:INTEGER}
+WHERE owner = #{uid}
GROUP BY kind
ORDER BY kind
</select>
@@ -34,12 +35,12 @@ FROM users
ORDER BY mail
</select>
- <insert id="insert" parameterType="map">
+ <insert id="insert">
INSERT INTO users (uid, display_name, initials, mail, credentials, tz, locale, rev, created_at, modified_at)
VALUES (#{uid}, #{display_name}, #{initials}, #{mail}, #{credentials}, #{tz}, #{locale}, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
</insert>
- <update id="update" parameterType="map">
+ <update id="update">
UPDATE users
SET
<set><if test="display_name != null">display_name = #{display_name},</if></set>
@@ -49,7 +50,7 @@ SET
<set><if test="tz != null">tz = #{tz},</if></set>
<set><if test="locale != null">locale = #{locale}</if></set>
rev = rev + 1, modified_at = CURRENT_TIMESTAMP
-WHERE uid = #{uid:INTEGER} and rev = #{rev:INTEGER}
+WHERE uid = #{uid} and rev = #{rev:INTEGER}
</update>
</mapper>
View
28 src/aspekt/db/maps/AspectMapper.java
@@ -0,0 +1,28 @@
+package aspekt.db.maps;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface AspectMapper {
+
+ Map<String, Object> select(@Param("id") int id);
+ List<Map<String, Object>> selectMilestones(@Param("id") int id);
+ int selectMilestoneCount(@Param("id") int id);
+ void insert(
+ @Param("node_id") int nodeId,
+ @Param("subject_name") String subjectName,
+ @Param("activity_name") String activityName,
+ @Param("feature_name") String featureName,
+ @Param("milestone_name") String milestoneName);
+ void insertMilestones(@Param("list") List<Map<String, Object>> milestones);
+ void update(
+ @Param("node_id") int nodeId,
+ @Param("subject_name") String subjectName,
+ @Param("activity_name") String activityName,
+ @Param("feature_name") String featureName,
+ @Param("milestone_name") String milestoneName);
+ void updatetMilestones(@Param("list") List<Map<String, Object>> milestones);
+ void deleteMilestones(@Param("seq") int sequence);
+}
View
18 src/aspekt/db/maps/aspect.xml → src/aspekt/db/maps/AspectMapper.xml
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="aspect">
- <select id="select" parameterType="int" resultType="hashmap">
+<mapper namespace="aspekt.db.maps.AspectMapper">
+ <select id="select" resultType="hashmap">
SELECT subject_name, activity_name, feature_name, milestone_name
FROM aspect
WHERE node_id = #{id}
</select>
- <select id="select_milestones" parameterType="int" resultType="hashmap">
+ <select id="selectMilestones" resultType="hashmap">
SELECT id, seq, name, effort
FROM aspect_milestone
WHERE node_id = #{id}
ORDER BY seq
</select>
- <select id="select_milestone_count" parameterType="int" resultType="int">
+ <select id="selectMilestoneCount" resultType="int">
SELECT COUNT(*) FROM aspect_milestone WHERE node_id = #{id}
</select>
@@ -23,14 +23,14 @@
VALUES (#{node_id}, #{subject_name}, #{activity_name}, #{feature_name}, #{milestone_name})
</insert>
- <insert id="insert_milestones" parameterType="list">
+ <insert id="insertMilestones">
INSERT INTO aspect_milestone (node_id, seq, name, effort) VALUES
<foreach collection="list" item="m" separator=",">
(#{m.node_id}, #{m.seq}, #{m.name}, #{m.effort})
</foreach>
</insert>
- <update id="update" parameterType="map">
+ <update id="update">
UPDATE aspect
SET subject_name = #{subject_name},
activity_name = #{activity_name},
@@ -39,7 +39,7 @@
WHERE node_id = #{node_id}
</update>
- <update id="update_milestones" parameterType="list">
+ <update id="updateMilestones">
UPDATE aspect_milestone
SET name = CASE seq
<foreach collection="list" item="m">
@@ -57,9 +57,9 @@
</foreach>
</update>
- <delete id="delete_milestones" parameterType="integer">
+ <delete id="deleteMilestones">
DELETE aspect_milestone
- WHERE seq >= #{value}
+ WHERE seq >= #{seq}
</delete>
</mapper>
View
19 src/aspekt/db/maps/AuthMapper.java
@@ -0,0 +1,19 @@
+package aspekt.db.maps;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface AuthMapper {
+
+ /**
+ * Returns 'O', 'W', 'R', or ' ' depending on the type of access a user has to a node.
+ */
+ String authorization(@Param("uid") String uid, @Param("node") int nodeId);
+
+ /**
+ * Generates a summary of everyone who has access to a node.
+ */
+ List<Map<String, Object>> access(@Param("id") int nodeId);
+}
View
8 src/aspekt/db/maps/auth.xml → src/aspekt/db/maps/AuthMapper.xml
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="auth">
+<mapper namespace="aspekt.db.maps.AuthMapper">
- <!-- selects 'O', 'W', 'R', or ' ' depending on the type of access a user has to a node -->
- <select id="authorization" parameterType="map" resultType="string">
+ <select id="authorization" resultType="hashmap">
<!-- TODO DB2 does not like recursive keyword -->
WITH RECURSIVE w (id, owner) AS (
<!-- start with the parent of the node -->
@@ -31,8 +30,7 @@
FROM node n WHERE n.id = #{node};
</select>
- <!-- generates a summary of everyone who has access to a node -->
- <select id="access" parameterType="int" resultType="hashmap">
+ <select id="access" resultType="hashmap">
<!-- TODO DB2 does not like recursive keyword -->
WITH RECURSIVE w (id, owner) AS (
<!-- start with the parent of the node -->
View
19 src/aspekt/db/maps/FeatureMapper.java
@@ -0,0 +1,19 @@
+package aspekt.db.maps;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface FeatureMapper {
+
+ String selectNextNumber(@Param("id") int nodeId);
+ List<Map<String, Object>> selectRemarks(@Param("id") int nodeId);
+ List<Map<String, Object>> selectMilestones(@Param("id") int nodeId);
+ Map<String, Object> selectMilestoneTemplates(@Param("id") int nodeId);
+ Map<String, Object> selectCounts(@Param("id") int nodeId);
+ Map<String, Object> selectOwners(@Param("id") int nodeId);
+ void insertRemark(@Param("id") int nodeId, @Param("uid") String uid, @Param("value") String remark);
+ void updateMilestones(@Param("id") int nodeId, @Param("list") List<Map<String, Object>> milestones);
+
+}
View
32 src/aspekt/db/maps/feature.xml → src/aspekt/db/maps/FeatureMapper.xml
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="feature">
- <select id="next_number" parameterType="int" resultType="string">
+<mapper namespace="aspekt.db.maps.FeatureMapper">
+ <select id="selectNextNumber" resultType="string">
SELECT coalesce(to_char(max(cast(f.abbr as integer)) + 1, 'FM000'), '001') AS next
FROM node f
INNER JOIN node a ON f.parent_id = a.id
INNER JOIN node s ON a.parent_id = s.id
- WHERE a.id = #{parent}
+ WHERE a.id = #{id}
</select>
- <select id="select_remarks" parameterType="int" resultType="hashmap">
+ <select id="selectRemarks" resultType="hashmap">
SELECT r.id, r.node_id, r.uid, r.created_at, r.value, u.display_name, u.initials
FROM remark r
INNER JOIN users u ON r.uid = u.uid
- WHERE r.node_id = #{value:NUMERIC}
+ WHERE r.node_id = #{id}
ORDER BY created_at DESC
</select>
- <select id="select_milestones" parameterType="int" resultType="hashmap">
+ <select id="selectMilestones">
SELECT
fm.id, fm.seq,
fm.planned, fm.actual,
@@ -31,7 +31,7 @@
ORDER BY fm.seq
</select>
- <select id="select_milestone_templates" parameterType="int" resultType="hashmap">
+ <select id="selectMilestoneTemplates">
SELECT 'N' as status, am.name
FROM aspect_milestone am
INNER JOIN node s ON am.node_id = s.parent_id
@@ -39,12 +39,12 @@
WHERE a.id = #{id}
</select>
- <select id="select_counts" parameterType="int" resultType="hashmap">
+ <select id="selectCounts">
WITH RECURSIVE all_nodes (id, status, is_feature) AS (
SELECT
n.id, n.status, 0
FROM node n
- WHERE id = #{value}
+ WHERE id = #{id}
UNION ALL
SELECT
n.id, n.status,
@@ -62,21 +62,21 @@
WHERE is_feature = 1
</select>
- <select id="select_owners" parameterType="int">
+ <select id="selectOwners">
SELECT f.uid, initials
FROM feature_owner f
INNER JOIN users u USING uid
- where node_id = #{value}
+ where node_id = #{id}
</select>
- <insert id="insert_remark" parameterType="map">
- INSERT INTO remark (node_id, uid, value, created_at) VALUES (#{node_id}, #{uid}, #{value}, CURRENT_TIMESTAMP)
+ <insert id="insertRemark">
+ INSERT INTO remark (node_id, uid, value, created_at) VALUES (#{id}, #{uid}, #{value}, CURRENT_TIMESTAMP)
</insert>
- <update id="update_milestones" parameterType="map">
+ <update id="updateMilestones">
UPDATE feature_milestone
SET planned = CASE seq
- <foreach collection="milestones" item="m">
+ <foreach collection="list" item="m">
WHEN #{m.seq} THEN CAST (#{m.planned:CHAR} AS DATE)
</foreach>
END,
@@ -85,6 +85,6 @@
WHEN #{m.seq} THEN CAST (#{m.actual:CHAR} AS DATE)
</foreach>
END
- WHERE node_id = #{node_id}
+ WHERE node_id = #{id}
</update>
</mapper>
View
13 src/aspekt/db/maps/KeyMapper.java
@@ -0,0 +1,13 @@
+package aspekt.db.maps;
+
+import java.util.Date;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface KeyMapper {
+
+ String select(@Param("key") String key);
+ void insert(@Param("key") String key, @Param("data") String data, @Param("expires_at") Date expiresAt);
+ void delete(@Param("key") String key);
+ void deleteExpired();
+}
View
14 src/aspekt/db/maps/key.xml → src/aspekt/db/maps/KeyMapper.xml
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="key">
- <select id="select" parameterType="string" resultType="string">
- SELECT data FROM keys WHERE key = #{value}
+<mapper namespace="aspekt.db.maps.KeyMapper">
+ <select id="select">
+ SELECT data FROM keys WHERE key = #{key}
</select>
- <insert id="insert" parameterType="map">
+ <insert id="insert">
INSERT INTO keys (key, data, expires_at)
VALUES (#{key}, #{data}, #{expires_at})
</insert>
- <delete id="delete" parameterType="string">
+ <delete id="delete">
DELETE FROM keys
- WHERE key = #{value}
+ WHERE key = #{key}
</delete>
- <delete id="delete_expired">
+ <delete id="deleteExpired">
DELETE FROM keys
WHERE expires_at > CURRENT_TIMESTAMP
</delete>
View
28 src/aspekt/db/maps/NodeMapper.java
@@ -0,0 +1,28 @@
+package aspekt.db.maps;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface NodeMapper {
+
+ List<Map<String, Object>> selectPath(@Param("id") int nodeId);
+ Map<String, Object> select(@Param("id") int nodeId);
+ Map<String, Object> search(@Param("uid") String uid, @Param("term") String term);
+ List<Map<String, Object>> selectChildren(@Param("uid") String uid, @Param("id") Integer nodeId);
+ int insert(
+ @Param("parent") int parentNodeId,
+ @Param("owner") String uid,
+ @Param("kind") int kind,
+ @Param("name") String name,
+ @Param("abbr") String abbr);
+ int update(
+ @Param("id") int nodeId,
+ @Param("owner") String uid,
+ @Param("name") String name,
+ @Param("abbr") String abbr,
+ @Param("rev") int revision);
+ int updateOwner(@Param("id") int nodeId, @Param("owner") String uid, @Param("rev") int revision);
+ void delete(@Param("id") int nodeId);
+}
View
27 src/aspekt/db/maps/node.xml → src/aspekt/db/maps/NodeMapper.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="node">
+<mapper namespace="aspekt.db.maps.NodeMapper">
<resultMap type="hashmap" id="search">
<id property="kind" column="kind"/>
<collection property="nodes" javaType="list" ofType="hashmap">
@@ -11,12 +11,12 @@
</resultMap>
<!-- select the bread-crumb path -->
- <select id="select_path" parameterType="integer" resultType="hashmap">
+ <select id="selectPath" resultType="hashmap">
WITH RECURSIVE path (parent_id, id, name, c) AS (
<!-- start with the requested node-->
SELECT n.parent_id, n.id, n.name, 1
FROM node n
- WHERE n.id = #{id:NUMERIC}
+ WHERE n.id = #{id}
UNION ALL
<!-- walk up the tree -->
SELECT n.parent_id, n.id, n.name, c + 1
@@ -26,25 +26,23 @@
SELECT id, name FROM path ORDER BY c DESC
</select>
- <select id="select" parameterType="integer" resultType="hashmap">
+ <select id="select" resultType="hashmap">
SELECT
n.name, n.abbr, n.kind, n.percentage, n.status, n.rev,
- coalesce(to_char(n.complete_on, 'YYYY-MM-DD'), '') AS complete_on,
- to_char(n.created_at, 'YYYY-MM-DD HH:MI') AS created_at,
- to_char(n.modified_at, 'YYYY-MM-DD HH:MI') AS modified_at
+ n.complete_on, n.created_at, n.modified_at
FROM node n
INNER JOIN users u ON n.owner = u.uid
- WHERE id = #{value}
+ WHERE id = #{id}
</select>
- <select id="search" parameterType="map" resultMap="node.search">
+ <select id="search" resultMap="search">
WITH RECURSIVE visible (id, kind, name, abbr, is_owner) AS (
<!-- start at the top -->
SELECT n.id, kind, n.name, coalesce(n.abbr,''), 1
FROM node n
WHERE n.parent_id IS NULL
AND (
- n.owner = #{uid} <!-- is owner -->
+ n.owner = #{uid} <!-- is owner -->
OR IS_READER(#{uid}, n.id) = 1 <!-- is reader -->
)
UNION ALL
@@ -61,7 +59,7 @@
ORDER BY kind, abbr, name
</select>
- <select id="select_children" parameterType="map" resultType="hashmap">
+ <select id="selectChildren" resultType="hashmap">
SELECT id, kind, name
FROM node
<where>
@@ -73,7 +71,7 @@
parent_id IS NULL
</otherwise>
</choose>
- <if test="userId != null">
+ <if test="uid != null">
AND IS_READER(#{uid}, id) = 1
</if>
ORDER BY name
@@ -82,7 +80,7 @@
<insert id="insert">
INSERT INTO node (parent_id, owner, kind, name, abbr)
- VALUES (#{parent:INTEGER}, #{owner:VARCHAR}, #{kind}, #{name:VARCHAR}, #{abbr})
+ VALUES (#{parent}, #{owner}, #{kind}, #{name}, #{abbr})
<selectKey keyProperty="node_id" resultType="integer">
SELECT currval('node_id_seq')
</selectKey>
@@ -102,7 +100,8 @@
rev = rev + 1, modified_at = CURRENT_TIMESTAMP
WHERE id = #{id} AND rev = #{rev}
</update>
- <update id="assign">
+
+ <update id="updateOwner">
UPDATE node SET owner = #{owner} WHERE id = #{id} and rev = #{rev}
</update>
View
13 src/aspekt/db/maps/ParameterMapper.java
@@ -0,0 +1,13 @@
+package aspekt.db.maps;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface ParameterMapper {
+
+ String select(@Param("name") String name);
+ List<Map<String, Object>> selectList();
+ void update(@Param("name") String name, @Param("value") String value);
+}
View
10 src/aspekt/db/maps/parameter.xml → src/aspekt/db/maps/ParameterMapper.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="parameter">
+<mapper namespace="aspekt.db.maps.ParameterMapper">
<cache/>
- <select id="select" parameterType="string" resultType="string">
-SELECT value FROM parameters WHERE name = #{value}
+ <select id="select" resultType="string">
+SELECT value FROM parameters WHERE name = #{name}
</select>
- <select id="selectList" resultType="map">
-select name, value FROM parameters
+ <select id="selectList" resultType="hashmap">
+SELECT name, value FROM parameters
</select>
<update id="update" parameterType="map">
View
17 src/aspekt/db/maps/ReportMapper.java
@@ -0,0 +1,17 @@
+package aspekt.db.maps;
+
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
+public interface ReportMapper {
+
+ /**
+ * @param nodeId a project, aspect, subject, or activity node id
+ */
+ Map<String, Object> selectTrend(@Param("uid") String uid, @Param("id") int nodeId);
+ Map<String, Object> selectDevelopmentView(@Param("uid") String uid, @Param("id") int nodeId);
+ Map<String, Object> selectPlanView(@Param("uid") String uid, @Param("id") int nodeId);
+ Map<String, Object> selectProgressSummary(@Param("uid") String uid, @Param("id") int nodeId);
+ Map<String, Object> selectParkingLot(@Param("uid") String uid, @Param("id") int nodeId);
+}
View
19 src/aspekt/db/maps/report.xml → src/aspekt/db/maps/ReportMapper.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="report">
+<mapper namespace="aspekt.db.maps.ReportMapper">
<!-- program* | project | aspect | subject | activity | feature -->
- <resultMap type="hashmap" id="progress_summary_aspect">
+ <resultMap type="hashmap" id="progress_summary">
<id property="id" column="asp_id"></id>
<result property="name" column="asp_name"/>
<collection property="subjects" javaType="list" ofType="hashmap">
@@ -26,7 +26,7 @@
</collection>
</resultMap>
- <resultMap type="hashmap" id="parking_lot_aspect">
+ <resultMap type="hashmap" id="parking_lot">
<id property="id" column="asp_id"/>
<result property="name" column="sub_id"/>
<collection property="subjects" javaType="list" ofType="hashmap">
@@ -46,7 +46,7 @@
</collection>
</resultMap>
- <resultMap type="hashmap" id="plan_view_aspect">
+ <resultMap type="hashmap" id="plan_view">
<id property="id" column="asp_id"/>
<result property="name" column="asp_name"/>
<collection property="subjects" javaType="list" ofType="hashmap">
@@ -78,14 +78,13 @@
</collection>
</resultMap>
- <!-- input is a project, aspect, subject, or activity id -->
- <select id="trend" parameterType="map" resultType="hashmap">
+ <select id="selectTrend" parameterType="map" resultType="hashmap">
SELECT week, total, percentage, complete, not_started, underway, attention, inactive
FROM trend(#{id})
WHERE is_reader(#{uid}, #{id}) = 1
</select>
- <select id="development_view" parameterType="map" resultType="hashmap">
+ <select id="selectDevelopmentView" resultType="hashmap">
SELECT
f.id AS f_id, f.abbr AS f_abbr, f.name AS f_name,
a.id AS a_id, a.abbr AS a_abbr, a.name AS a_name,
@@ -102,7 +101,7 @@
OR f.parent_id = #{id})
</select>
- <select id="plan_view" parameterType="map" resultMap="report.plan_view_aspect">
+ <select id="selectPlanView" parameterType="map" resultMap="plan_view">
SELECT
asp.id AS asp_id, asp.name AS asp_name,
sub.id AS sub_id, sub.abbr AS sub_abbr, sub.name AS sub_name,
@@ -125,7 +124,7 @@
ORDER BY asp.name, sub.abbr, act.abbr, f.abbr, fm.seq
</select>
- <select id="progress_summary" parameterType="map" resultMap="report.progress_summary_aspect">
+ <select id="selectProgressSummary" resultMap="progress_summary">
SELECT
asp.id AS asp_id, asp.name AS asp_name,
sub.id AS sub_id, sub.abbr AS sub_abbr, sub.name AS sub_name,
@@ -142,7 +141,7 @@
OR act.parent_id = #{id})
</select>
- <select id="parking_lot" parameterType="map" resultMap="report.parking_lot_aspect">
+ <select id="selectParkingLot" resultMap="parking_lot">
SELECT
asp.id AS asp_id, asp.name AS asp_name,
sub.id AS sub_id, sub.abbr AS sub_abbr, sub.name AS sub_name,
View
26 src/aspekt/db/maps/config.xml
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
-<configuration>
- <environments default="prod">
- <environment id="prod">
- <transactionManager type="JDBC"/>
- <dataSource type="POOLED">
- <property name="driver" value="${db.driver}" />
- <property name="url" value="${db.url}" />
- <property name="username" value="${db.username}" />
- <property name="password" value="${db.password}" />
- </dataSource>
- </environment>
- </environments>
-
- <mappers>
- <mapper resource="aspekt/db/maps/auth.xml" />
- <mapper resource="aspekt/db/maps/node.xml" />
- <mapper resource="aspekt/db/maps/aspect.xml" />
- <mapper resource="aspekt/db/maps/feature.xml" />
- <mapper resource="aspekt/db/maps/report.xml" />
- <mapper resource="aspekt/db/maps/account.xml" />
- <mapper resource="aspekt/db/maps/key.xml" />
- <mapper resource="aspekt/db/maps/parameter.xml" />
- </mappers>
-</configuration>
View
21 src/aspekt/resource/DevelopmentView.java → src/aspekt/resource/DevelopmentViewResource.java
@@ -1,6 +1,5 @@
package aspekt.resource;
-import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;
@@ -14,12 +13,14 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
+import aspekt.db.maps.ReportMapper;
import aspekt.security.AspektEnroler;
import aspekt.util.LocalizationUtil;
-public class DevelopmentView extends ServerResource {
+public class DevelopmentViewResource extends ServerResource {
- public DevelopmentView() {
+ public DevelopmentViewResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -32,16 +33,16 @@ public Representation get(Variant variant) throws ResourceException {
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
final Integer id = new Integer((String) getRequestAttributes().get("id"));
+ final String uid = getClientInfo().getUser().getIdentifier();
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- params.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
-
- getRequestAttributes().put("path", sql.selectList("node.select_path", id));
- getRequestAttributes().put("features", sql.selectList("report.development_view", params));
- getRequestAttributes().put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final ReportMapper reportMapper = sql.getMapper(ReportMapper.class);
+
+ getRequestAttributes().put("path", nodeMapper.selectPath(id));
+ getRequestAttributes().put("features", reportMapper.selectDevelopmentView(uid, id));
+ getRequestAttributes().put("uid", uid);
getRequestAttributes().put("roles", AspektEnroler.toArray(getClientInfo().getRoles()));
getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
getRequestAttributes().put("bundle", bundle);
View
20 src/aspekt/resource/Fddi.java → src/aspekt/resource/FddiResource.java
@@ -26,13 +26,14 @@
import org.w3c.dom.Element;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
-public class Fddi extends ServerResource {
+public class FddiResource extends ServerResource {
private static final String NSURI = "http://www.nebulon.com/xml/2004/fddi";
private static final String[] STATUS_CODES = new String[] { "N", "U", "A", "C", "I" };
- public Fddi() {
+ public FddiResource() {
final Variant html = new Variant(MediaType.TEXT_XML);
html.getLanguages().add(Language.ALL);
getVariants().add(html);
@@ -67,16 +68,13 @@ public Representation get(Variant variant) throws ResourceException {
final Document document = parent instanceof Document ? (Document) parent : parent.getOwnerDocument();
final HashMap<String, Integer> result = new HashMap<String, Integer>();
try {
- final Map<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- if ("R".equals(getRequest().getAttributes().get("authorization"))) {
- params.put("userId", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
- }
- @SuppressWarnings("unchecked")
- final Map<String, Object> node = (Map<String, Object>) sql.selectOne("node.select", id);
+ final String uid = "R".equals(getRequest().getAttributes().get("authorization"))
+ ? getClientInfo().getUser().getIdentifier()
+ : null;
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final Map<String, Object> node = (Map<String, Object>) nodeMapper.select(id);
if (node == null) throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
- @SuppressWarnings("unchecked")
- final List<Map<String,Object>> children = sql.selectList("node.select_children", params);
+ final List<Map<String,Object>> children = nodeMapper.selectChildren(uid, id);
final Element e = (Element) parent.appendChild(document.createElementNS(NSURI, getNodeName((Integer) node.get("kind"))));
e.setAttribute("id", id.toString());
View
19 src/aspekt/resource/Index.java → src/aspekt/resource/IndexResource.java
@@ -6,6 +6,7 @@
import org.restlet.data.CookieSetting;
import org.restlet.data.MediaType;
import org.restlet.ext.freemarker.TemplateRepresentation;
+import org.restlet.representation.EmptyRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.Variant;
import org.restlet.resource.ResourceException;
@@ -15,7 +16,7 @@
import aspekt.util.LocalizationUtil;
-public class Index extends ServerResource {
+public class IndexResource extends ServerResource {
@Override
protected void doInit() throws ResourceException {
@@ -41,13 +42,15 @@ public Representation get(Variant variant) throws ResourceException {
getResponse().getCookieSettings().add(l);
}
-
- getRequestAttributes().put("bundle", bundle);
- getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
-
- final TemplateRepresentation result = new TemplateRepresentation("html/index.ftl", application.getFmConfig(), getRequestAttributes(), variant.getMediaType());
- LocalizationUtil.localize(result, locale);
- return result;
+ if (getClientInfo().getUser() == null || getQuery().getFirst("logout") != null) {
+ getRequestAttributes().put("bundle", bundle);
+ getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
+
+ return LocalizationUtil.localize(new TemplateRepresentation("html/index.ftl", application.getFmConfig(), getRequestAttributes(), variant.getMediaType()), locale);
+ } else {
+ redirectSeeOther(application.getUrlBase(getRequest()) + "/node/0.html");
+ return new EmptyRepresentation();
+ }
}
}
View
157 src/aspekt/resource/Node.java → src/aspekt/resource/NodeResource.java
@@ -29,14 +29,18 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.AspectMapper;
+import aspekt.db.maps.AuthMapper;
+import aspekt.db.maps.FeatureMapper;
+import aspekt.db.maps.NodeMapper;
import aspekt.security.AspektEnroler;
import aspekt.security.AspektUser;
import aspekt.util.CookieUtil;
import aspekt.util.LocalizationUtil;
-public class Node extends ServerResource {
+public class NodeResource extends ServerResource {
- public Node() {
+ public NodeResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -57,6 +61,11 @@ public Representation get(Variant variant) throws ResourceException {
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final AspectMapper aspectMapper = sql.getMapper(AspectMapper.class);
+ final FeatureMapper featureMapper = sql.getMapper(FeatureMapper.class);
+ final AuthMapper authMapper = sql.getMapper(AuthMapper.class);
+
if (id.equals(0)) {
// root
// create a dummy root node for the template to use
@@ -68,29 +77,24 @@ public Representation get(Variant variant) throws ResourceException {
getRequestAttributes().put("path", Collections.emptyList());
// find the programs that the user can see
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("uid", user.getIdentifier());
- getRequestAttributes().put("children", sql.selectList("node.select_children", params));
+ getRequestAttributes().put("children", nodeMapper.selectChildren(user.getIdentifier(), null));
} else {
// find the requested node
- @SuppressWarnings("unchecked")
- final Map<String, Object> node = (Map<String, Object>) sql.selectOne("node.select", id);
+ final NodeMapper mapper = nodeMapper;
+ final Map<String, Object> node = mapper.select(id);
if (node == null) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
}
node.put("id", id);
getRequestAttributes().put("node", node);
- getRequestAttributes().put("path", sql.selectList("node.select_path", id));
+ getRequestAttributes().put("path", mapper.selectPath(id));
// find the children of the requested node
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- if ("R".equals(getRequest().getAttributes().get("authorization"))) {
- params.put("userId", Integer.parseInt(user.getIdentifier()));
- }
-
+ final String uid = "R".equals(getRequest().getAttributes().get("authorization"))
+ ? getClientInfo().getUser().getIdentifier()
+ : null;
if (!node.get("kind").equals(6)) {
- getRequestAttributes().put("children", sql.selectList("node.select_children", params));
+ getRequestAttributes().put("children", mapper.selectChildren(uid, id));
@SuppressWarnings("unchecked")
final HashMap<String, Integer> counts = (HashMap<String, Integer>) sql.selectOne("feature.select_counts", id);
if (counts != null) {
@@ -99,14 +103,14 @@ public Representation get(Variant variant) throws ResourceException {
}
if (node.get("kind").equals(3)) {
- getRequestAttributes().put("aspect", sql.selectOne("aspect.select", id));
- getRequestAttributes().put("milestones", sql.selectList("aspect.select_milestones", id));
+ getRequestAttributes().put("aspect", aspectMapper.select(id));
+ getRequestAttributes().put("milestones", aspectMapper.selectMilestones(id));
} else if (node.get("kind").equals(6)) {
- getRequestAttributes().put("milestones", sql.selectList("feature.select_milestones", id));
- getRequestAttributes().put("remarks", sql.selectList("feature.select_remarks", id));
+ getRequestAttributes().put("milestones", featureMapper.selectMilestones(id));
+ getRequestAttributes().put("remarks", featureMapper.selectRemarks(id));
}
- getRequestAttributes().put("access", sql.selectList("auth.access", id));
+ getRequestAttributes().put("access", authMapper.access(id));
final String clipCookie = getRequest().getCookies().getFirstValue("clip");
if (clipCookie != null) {
@@ -142,7 +146,7 @@ public Representation get(Variant variant) throws ResourceException {
getRequestAttributes().put("aspect", getDefaultAspect(bundle));
getRequestAttributes().put("milestones", getDefaultAspectMilestones(bundle));
} else if (kind.equals(6)) {
- getRequestAttributes().put("milestones", sql.selectList("feature.select_milestone_templates", id));
+ getRequestAttributes().put("milestones", featureMapper.selectMilestoneTemplates(id));
getRequestAttributes().put("remarks", Collections.emptyList());
}
}
@@ -170,49 +174,47 @@ public Representation post(Representation entity, Variant variant) throws Resour
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
final Form form = new Form(entity);
- final Map<String, Object> params = new HashMap<String, Object>(form.getValuesMap());
- final Integer parent = new Integer((String) getRequest().getAttributes().get("id"));
-
final Integer id;
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- if (parent.equals(0) == false) {
- params.put("parent", parent);
- }
- final int kind = Integer.parseInt((String) params.get("kind"));
- params.put("owner", getRequest().getClientInfo().getUser().getIdentifier());
- params.put("kind", kind);
-
- if (kind == 6) {
- params.put("abbr", sql.selectOne("feature.next_number", parent));
- }
- sql.insert("node.insert", params);
- id = (Integer) params.get("node_id");
+ Integer parent = new Integer((String) getRequest().getAttributes().get("id"));
+ if (parent.equals(0)) parent = null;
+ final int kind = Integer.parseInt(form.getFirstValue("kind"));
+ final String uid = getClientInfo().getUser().getIdentifier();
+ final String name = form.getFirstValue("name");
+ final String abbr = kind == 6 ? sql.getMapper(FeatureMapper.class).selectNextNumber(parent) : null;
+ id = sql.getMapper(NodeMapper.class).insert(parent, uid, kind, name, abbr);
if (kind == 3) {
- sql.insert("aspect.insert", params);
+ final AspectMapper aspectMapper = sql.getMapper(AspectMapper.class);
+ final String subjectName = form.getFirstValue("subject_name");
+ final String activityName = form.getFirstValue("activity_name");
+ final String featureName = form.getFirstValue("feature_name");
+ final String milestoneName = form.getFirstValue("milestone_name");
+ aspectMapper.insert(id, subjectName, activityName, featureName, milestoneName);
final String[] names = form.getValuesArray("am_name");
final String[] efforts = form.getValuesArray("am_effort");
- final LinkedList<HashMap<String, Object>> insert = new LinkedList<HashMap<String,Object>>();
+ final List<Map<String, Object>> milestones = new LinkedList<Map<String,Object>>();
for (int i = 0; i < names.length; i++) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("node_id", id);
map.put("seq", i + 1);
map.put("name", names[i]);
map.put("effort", new Integer(efforts[i]));
-
- insert.add(map);
+ milestones.add(map);
}
- if (insert.size() > 0) {
- sql.insert("aspect.insert_milestones", insert);
+ if (milestones.size() > 0) {
+ aspectMapper.insertMilestones(milestones);
+ sql.insert("aspect.insert_milestones", milestones);
}
} else if (kind == 6) {
+ final FeatureMapper featureMapper = sql.getMapper(FeatureMapper.class);
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
final String[] plans = form.getValuesArray("fm_planned");
final String[] actuals = form.getValuesArray("fm_actual");
- final LinkedList<HashMap<String, Object>> milestones = new LinkedList<HashMap<String,Object>>();
+ final List<Map<String, Object>> milestones = new LinkedList<Map<String,Object>>();
for (int i = 0; i < plans.length; i++) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("seq", i + 1);
@@ -229,18 +231,15 @@ public Representation post(Representation entity, Variant variant) throws Resour
milestones.add(map);
}
// this is an update, because a trigger will have already inserted template milestones
- final HashMap<String, Object> milestoneParams = new HashMap<String, Object>();
- milestoneParams.put("node_id", id);
- milestoneParams.put("milestones", milestones);
- sql.update("feature.update_milestones", milestoneParams);
+ featureMapper.updateMilestones(id, milestones);
final String remark = form.getFirstValue("remark");
if (remark != null && remark.trim().length() > 0) {
final HashMap<String, Object> remarkParams = new HashMap<String, Object>();
remarkParams.put("node_id", id);
- remarkParams.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ remarkParams.put("uid", uid);
remarkParams.put("value", remark);
- sql.insert("feature.insert_remark", remarkParams);
+ featureMapper.insertRemark(id, uid, remark);
}
}
@@ -266,30 +265,38 @@ public Representation put(Representation entity, Variant variant) throws Resourc
final Locale locale = LocalizationUtil.getLocale(variant);
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
+ final String uid = getClientInfo().getUser().getIdentifier();
final Integer id = new Integer((String) getRequestAttributes().get("id"));
final Form form = new Form(entity);
- final Map<String, Object> params = new HashMap<String, Object>(form.getValuesMap());
- params.put("id", id);
- params.put("rev", new Integer(form.getFirstValue("rev")));
+ final String name = form.getFirstValue("name");
+ final String abbr = form.getFirstValue("abbr");
+ final int revision = Integer.parseInt(form.getFirstValue("rev"));
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final int affected = sql.update("node.update", params);
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ int affected = nodeMapper.update(id, uid, name, abbr, revision);
if (affected == 0) {
getLogger().log(Level.INFO, "Conflict");
throw new ResourceException(Status.CLIENT_ERROR_CONFLICT);
}
if ("3".equals(form.getFirstValue("kind"))) {
- sql.update("aspect.update", params);
- final Integer count = (Integer) sql.selectOne("aspect.select_milestone_count", id);
+ final String subjectName = form.getFirstValue("subject_name");
+ final String activityName = form.getFirstValue("activity_name");
+ final String featureName = form.getFirstValue("feature_name");
+ final String milestoneName = form.getFirstValue("milestone_name");
+
+ final AspectMapper aspectMapper = sql.getMapper(AspectMapper.class);
+ aspectMapper.update(id, subjectName, activityName, featureName, milestoneName);
+ final Integer count = aspectMapper.selectMilestoneCount(id);
final String[] names = form.getValuesArray("am_name");
final String[] efforts = form.getValuesArray("am_effort");
- final LinkedList<HashMap<String, Object>> insert = new LinkedList<HashMap<String,Object>>();
- final LinkedList<HashMap<String, Object>> update = new LinkedList<HashMap<String,Object>>();
+ final List<Map<String, Object>> insert = new LinkedList<Map<String,Object>>();
+ final List<Map<String, Object>> update = new LinkedList<Map<String,Object>>();
for (int i = 0; i < names.length; i++) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("node_id", id);
@@ -305,19 +312,21 @@ public Representation put(Representation entity, Variant variant) throws Resourc
}
if (insert.size() == 0 && update.size() < count.intValue()) {
- sql.delete("aspect.delete_milestones", update.size());
+ aspectMapper.deleteMilestones(update.size());
}
if (update.size() > 0) {
- sql.update("aspect.update_milestones", update);
+ aspectMapper.updatetMilestones(update);
}
if (insert.size() > 0) {
- sql.insert("aspect.insert_milestones", insert);
+ aspectMapper.insertMilestones(insert);
}
} else if ("6".equals(form.getFirstValue("kind"))) {
+ final FeatureMapper featureMapper = sql.getMapper(FeatureMapper.class);
+
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
final String[] plans = form.getValuesArray("fm_planned");
final String[] actuals = form.getValuesArray("fm_actual");
- final LinkedList<HashMap<String, Object>> milestones = new LinkedList<HashMap<String,Object>>();
+ final List<Map<String, Object>> milestones = new LinkedList<Map<String,Object>>();
for (int i = 0; i < plans.length; i++) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("seq", i + 1);
@@ -333,18 +342,11 @@ public Representation put(Representation entity, Variant variant) throws Resourc
}
milestones.add(map);
}
- final HashMap<String, Object> milestoneParams = new HashMap<String, Object>();
- milestoneParams.put("node_id", id);
- milestoneParams.put("milestones", milestones);
- sql.update("feature.update_milestones", milestoneParams);
+ featureMapper.updateMilestones(id, milestones);
final String remark = form.getFirstValue("remark");
if (remark != null && remark.trim().length() > 0) {
- final HashMap<String, Object> remarkParams = new HashMap<String, Object>();
- remarkParams.put("node_id", id);
- remarkParams.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
- remarkParams.put("value", remark);
- sql.insert("feature.insert_remark", remarkParams);
+ featureMapper.insertRemark(id, uid, remark);
}
}
@@ -401,8 +403,9 @@ public Representation delete(Variant variant) throws ResourceException {
final SqlSession sql = application.getSqlSessionFactory().openSession(true);
try {
- @SuppressWarnings("unchecked")
- final List<Map<String,Object>> path = sql.selectList("node.select_path", id);
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+
+ final List<Map<String,Object>> path = nodeMapper.selectPath(id);
final Integer parentId;
final Integer kind;
if (path.size() == 0) {
@@ -415,7 +418,7 @@ public Representation delete(Variant variant) throws ResourceException {
parentId = (Integer) current.get("id");
kind = (Integer) current.get("kind");
}
- sql.delete("node.delete", id);
+ nodeMapper.delete(id);
redirectSeeOther(application.getUrlBase(getRequest()) + "/node/" + parentId + ".html");
@@ -434,10 +437,10 @@ protected void authorize() throws ResourceException {
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("uid", getClientInfo().getUser().getIdentifier());
- params.put("node", Integer.parseInt(nodeId));
- final String authorization = (String) sql.selectOne("auth.authorization", params);
+ final AuthMapper authMapper = sql.getMapper(AuthMapper.class);
+
+ final String uid = getClientInfo().getUser().getIdentifier();
+ final String authorization = (String) authMapper.authorization(uid, Integer.parseInt(nodeId));
if (authorization == null) throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
if (" ".equals(authorization)) throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN);
getRequestAttributes().put("authorization", authorization);
View
21 src/aspekt/resource/ParkingLot.java → src/aspekt/resource/ParkingLotResource.java
@@ -1,6 +1,5 @@
package aspekt.resource;
-import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;
@@ -14,12 +13,14 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
+import aspekt.db.maps.ReportMapper;
import aspekt.security.AspektEnroler;
import aspekt.util.LocalizationUtil;
-public class ParkingLot extends ServerResource {
+public class ParkingLotResource extends ServerResource {
- public ParkingLot() {
+ public ParkingLotResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -32,16 +33,16 @@ public Representation get(Variant variant) throws ResourceException {
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
final Integer id = new Integer((String) getRequestAttributes().get("id"));
+ final String uid = getClientInfo().getUser().getIdentifier();
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- params.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
-
- getRequestAttributes().put("path", sql.selectList("node.select_path", id));
- getRequestAttributes().put("aspects", sql.selectList("report.parking_lot", params));
- getRequestAttributes().put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final ReportMapper reportMapper = sql.getMapper(ReportMapper.class);
+
+ getRequestAttributes().put("path", nodeMapper.selectPath(id));
+ getRequestAttributes().put("aspects", reportMapper.selectParkingLot(uid, id));
+ getRequestAttributes().put("uid", uid);
getRequestAttributes().put("roles", AspektEnroler.toArray(getClientInfo().getRoles()));
getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
getRequestAttributes().put("bundle", bundle);
View
19 src/aspekt/resource/PlanView.java → src/aspekt/resource/PlanViewResource.java
@@ -1,6 +1,5 @@
package aspekt.resource;
-import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;
@@ -14,12 +13,14 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
+import aspekt.db.maps.ReportMapper;
import aspekt.security.AspektEnroler;
import aspekt.util.LocalizationUtil;
-public class PlanView extends ServerResource {
+public class PlanViewResource extends ServerResource {
- public PlanView() {
+ public PlanViewResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -32,16 +33,16 @@ public Representation get(Variant variant) throws ResourceException {
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
final Integer id = new Integer((String) getRequestAttributes().get("id"));
+ final String uid = getClientInfo().getUser().getIdentifier();
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- params.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final ReportMapper reportMapper = sql.getMapper(ReportMapper.class);
- getRequestAttributes().put("path", sql.selectList("node.select_path", id));
- getRequestAttributes().put("aspects", sql.selectList("report.plan_view", params));
- getRequestAttributes().put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ getRequestAttributes().put("path", nodeMapper.selectPath(id));
+ getRequestAttributes().put("aspects", reportMapper.selectPlanView(uid, id));
+ getRequestAttributes().put("uid", uid);
getRequestAttributes().put("roles", AspektEnroler.toArray(getClientInfo().getRoles()));
getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
getRequestAttributes().put("bundle", bundle);
View
19 src/aspekt/resource/ProgressSummary.java → src/aspekt/resource/ProgressSummaryResource.java
@@ -1,6 +1,5 @@
package aspekt.resource;
-import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;
@@ -14,12 +13,14 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
+import aspekt.db.maps.ReportMapper;
import aspekt.security.AspektEnroler;
import aspekt.util.LocalizationUtil;
-public class ProgressSummary extends ServerResource {
+public class ProgressSummaryResource extends ServerResource {
- public ProgressSummary() {
+ public ProgressSummaryResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -32,16 +33,16 @@ public Representation get(Variant variant) throws ResourceException {
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
final Integer id = new Integer((String) getRequestAttributes().get("id"));
+ final String uid = getClientInfo().getUser().getIdentifier();
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- params.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final ReportMapper reportMapper = sql.getMapper(ReportMapper.class);
- getRequestAttributes().put("path", sql.selectList("node.select_path", id));
- getRequestAttributes().put("aspects", sql.selectList("report.progress_summary", params));
- getRequestAttributes().put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ getRequestAttributes().put("path", nodeMapper.selectPath(id));
+ getRequestAttributes().put("aspects", reportMapper.selectProgressSummary(uid, id));
+ getRequestAttributes().put("uid", uid);
getRequestAttributes().put("roles", AspektEnroler.toArray(getClientInfo().getRoles()));
getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
getRequestAttributes().put("bundle", bundle);
View
14 src/aspekt/resource/Search.java → src/aspekt/resource/SearchResource.java
@@ -15,12 +15,13 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
import aspekt.security.AspektEnroler;
import aspekt.util.LocalizationUtil;
-public class Search extends ServerResource {
+public class SearchResource extends ServerResource {
- public Search() {
+ public SearchResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -32,19 +33,22 @@ public Representation get(Variant variant) throws ResourceException {
final Locale locale = LocalizationUtil.getLocale(variant);
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
+ final String uid = getClientInfo().getUser().getIdentifier();
final Form form = getRequest().getResourceRef().getQueryAsForm();
final String term = form.getFirstValue("q");
final HashMap<String, Object> params = new HashMap<String, Object>();
params.put("term", "%" + term + "%");
- params.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ params.put("uid", uid);
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- getRequestAttributes().put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+
+ getRequestAttributes().put("uid", uid);
getRequestAttributes().put("roles", AspektEnroler.toArray(getClientInfo().getRoles()));
getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
- getRequestAttributes().put("kinds", sql.selectList("node.search", params));
+ getRequestAttributes().put("kinds", nodeMapper.search(uid, term));
getRequestAttributes().put("bundle", bundle);
final TemplateRepresentation result = new TemplateRepresentation("html/search.ftl", application.getFmConfig(), getRequest().getAttributes(), variant.getMediaType());
LocalizationUtil.localize(result, locale);
View
21 src/aspekt/resource/Trend.java → src/aspekt/resource/TrendResource.java
@@ -1,6 +1,5 @@
package aspekt.resource;
-import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;
@@ -14,12 +13,14 @@
import org.restlet.resource.ServerResource;
import aspekt.AspektApplication;
+import aspekt.db.maps.NodeMapper;
+import aspekt.db.maps.ReportMapper;
import aspekt.security.AspektEnroler;
import aspekt.util.LocalizationUtil;
-public class Trend extends ServerResource {
+public class TrendResource extends ServerResource {
- public Trend() {
+ public TrendResource() {
final Variant html = new Variant(MediaType.TEXT_HTML);
html.getLanguages().add(Language.ENGLISH);
getVariants().add(html);
@@ -32,16 +33,16 @@ public Representation get(Variant variant) throws ResourceException {
final ResourceBundle bundle = LocalizationUtil.getBundle(locale);
final Integer id = new Integer((String) getRequestAttributes().get("id"));
-
+ final String uid = getClientInfo().getUser().getIdentifier();
+
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final HashMap<String, Object> params = new HashMap<String, Object>();
- params.put("id", id);
- params.put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ final NodeMapper nodeMapper = sql.getMapper(NodeMapper.class);
+ final ReportMapper reportMapper = sql.getMapper(ReportMapper.class);
- getRequestAttributes().put("path", sql.selectList("node.select_path", id));
- getRequestAttributes().put("nodes", sql.selectList("report.trend", params));
- getRequestAttributes().put("uid", Integer.parseInt(getRequest().getClientInfo().getUser().getIdentifier()));
+ getRequestAttributes().put("path", nodeMapper.selectPath(id));
+ getRequestAttributes().put("nodes", reportMapper.selectTrend(uid, id));
+ getRequestAttributes().put("uid", uid);
getRequestAttributes().put("roles", AspektEnroler.toArray(getClientInfo().getRoles()));
getRequestAttributes().put("urlBase", application.getUrlBase(getRequest()));
getRequestAttributes().put("bundle", bundle);
View
2  src/aspekt/security/AspektEnroler.java
@@ -48,7 +48,7 @@ public void enrole(ClientInfo clientInfo) {
if (r != null) clientInfo.getRoles().add(r);
}
- if (clientInfo.getRoles().contains(application.getRole("admin"))) {
+ if (clientInfo.getRoles().contains(application.getRole("aspekt_admin"))) {
// implicitly have all roles if they have admin role
clientInfo.setRoles(application.getRoles());
}
View
6 src/aspekt/security/AspektVerifier.java
@@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Locale;
+import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -36,6 +37,7 @@
import org.restlet.security.Verifier;
import aspekt.AspektApplication;
+import aspekt.db.maps.AccountMapper;
import aspekt.util.LocalizationUtil;
public class AspektVerifier implements Verifier {
@@ -222,8 +224,8 @@ public boolean checkDb(Request request) {
public void findUser(String identifier, Request request) {
final SqlSession session = aspekt.getSqlSessionFactory().openSession();
try {
- @SuppressWarnings("unchecked")
- final HashMap<String, Object> user = (HashMap<String, Object>) session.selectOne("account.authenticate", identifier.toLowerCase());
+ final AccountMapper account = session.getMapper(AccountMapper.class);
+ final Map<String, Object> user = account.authenticate(identifier.toLowerCase());
if (user == null) return;
View
5 src/aspekt/service/ParameterService.java
@@ -3,6 +3,7 @@
import org.apache.ibatis.session.SqlSession;
import aspekt.AspektApplication;
+import aspekt.db.maps.ParameterMapper;
public class ParameterService {
@@ -15,7 +16,9 @@ public ParameterService(AspektApplication application) {
public String get(String name, String defaultValue) {
final SqlSession sql = application.getSqlSessionFactory().openSession();
try {
- final String value = (String) sql.selectOne("parameter.select", name);
+ final ParameterMapper parameterMapper = sql.getMapper(ParameterMapper.class);
+
+ final String value = parameterMapper.select(name);
if (value != null && value.trim().length() > 0) {
return value;
}
View
37 src/aspekt/service/StatusService.java
@@ -0,0 +1,37 @@
+package aspekt.service;
+
+import java.util.ArrayList;
+
+import org.restlet.Request;
+import org.restlet.Response;
+import org.restlet.data.MediaType;
+import org.restlet.data.Status;
+import org.restlet.representation.Representation;
+import org.restlet.representation.Variant;
+
+import aspekt.util.LocalizationUtil;
+
+public class StatusService extends org.restlet.service.StatusService {
+
+ @Override
+ public Representation getRepresentation(Status status, Request request, Response response) {
+ final ArrayList<Variant> variants = new ArrayList<Variant>();
+ variants.add(LocalizationUtil.addLanguages(new Variant(MediaType.TEXT_HTML)));
+
+ if (status.equals(Status.CLIENT_ERROR_UNAUTHORIZED)) {
+ if ("/login".equals(request.getResourceRef().getRemainingPart())) {
+ // only send back 401 when the Authentication header is missing
+ // otherwise change 401 to 400 so that AJAX login works correctly
+ if (request.getChallengeResponse() != null) {
+ response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
+ }
+ }
+ }
+
+ return super.getRepresentation(status, request, response);
+ // TODO add custom error page
+// final AspektApplication application = (AspektApplication) Application.getCurrent();
+// final Variant variant = request.getClientInfo().getPreferredVariant(variants, application.getMetadataService());
+// return getHtmlRepresentation(status, variant, application);
+ }
+}
View
3  src/aspekt/util/LocalizationUtil.java
@@ -60,7 +60,7 @@ public static ResourceBundle getBundle(Locale locale) {
return ResourceBundle.getBundle("aspekt.i18n", locale);
}
- public static void localize(TemplateRepresentation templateRepresentation, Locale locale) {
+ public static TemplateRepresentation localize(TemplateRepresentation templateRepresentation, Locale locale) {
final Template template = templateRepresentation.getTemplate();
final ResourceBundle bundle = getBundle(locale);
try {
@@ -72,6 +72,7 @@ public static void localize(TemplateRepresentation templateRepresentation, Local
}
template.setDateFormat(bundle.getString("dateFormat"));
template.setDateTimeFormat(bundle.getString("datetimeFormat"));
+ return templateRepresentation;
}
}

No commit comments for this range

Something went wrong with that request. Please try again.