Skip to content

Commit 3bc6499

Browse files
authored
Merge pull request #1101 from zfi/master
Release 0.97
2 parents 5fc0fed + ce6d8a3 commit 3bc6499

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2608
-817
lines changed

db-updates/0006-add-user-coach.sql

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/*
22
* Add coach email address field to support email cc option.
33
*/
4-
ALTER TABLE user ADD COLUMN coach_email VARCHAR(250) AFTER screen_name;
4+
5+
/*
6+
* This DDL has been moved to the Cloud Session Server project
7+
*/
8+
9+
-- ALTER TABLE user ADD COLUMN coach_email VARCHAR(250) AFTER screen_name;

db-updates/0007-coppa-support.sql

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
* Add fields to user table to support US COPPA compliance
9+
*
10+
* Author: Jim Ewald
11+
* Created: Apr 27, 2017A
12+
*
13+
* birth_month - is a range of [1 - 12]
14+
* birth_year - is a range from [1930 - current year]
15+
* parent_email - is used to register a child under the ae of 13. This is the
16+
* email address of the parent, guardian or instructor that is
17+
* creating the account on behalf of the child
18+
*
19+
* parent_email_source - is a integer designator to characterize the parent
20+
* email adress noted above. Current options are:
21+
* 0 - undefined
22+
* 1 - child's parent
23+
* 2 - child's guardian
24+
* 3 - child's instructor or teacher
25+
*/
26+
27+
/*
28+
* This DDL has been moved to the Cloud Session Server project
29+
*/
30+
31+
-- ALTER TABLE cloudsession.user ADD birth_month INT NOT NULL;
32+
-- ALTER TABLE cloudsession.user ADD birth_year INT NOT NULL;
33+
-- ALTER TABLE cloudsession.user ADD parent_email VARCHAR(250) NULL;
34+
-- ALTER TABLE cloudsession.user ADD parent_email_source INT DEFAULT 0 NULL;
35+
-- ALTER TABLE cloudsession.user DROP coach_email;

pom.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
<includes>.*</includes>
128128
<excludes></excludes>
129129
<inputSchema>blocklyprop</inputSchema>
130-
130+
131131
<customTypes>
132132
<customType>
133133
<name>GregorianCalendar</name>
@@ -361,6 +361,13 @@
361361
<artifactId>commons-io</artifactId>
362362
<version>1.3.2</version>
363363
</dependency>
364+
365+
<dependency>
366+
<groupId>commons-validator</groupId>
367+
<artifactId>commons-validator</artifactId>
368+
<version>1.6</version>
369+
</dependency>
370+
364371
<!-- END Apache commons Dependencies -->
365372

366373
<!-- Rest API -->

src/main/java/com/parallax/server/blocklyprop/config/ServletsModule.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.google.inject.servlet.ServletModule;
99
import com.parallax.server.blocklyprop.servlets.AuthenticationServlet;
10+
import com.parallax.server.blocklyprop.servlets.PrivacyPolicyServlet;
1011
import com.parallax.server.blocklyprop.servlets.ConfirmRequestServlet;
1112
import com.parallax.server.blocklyprop.servlets.ConfirmServlet;
1213
import com.parallax.server.blocklyprop.servlets.HelpSearchServlet;
@@ -32,7 +33,8 @@
3233
import com.parallax.server.blocklyprop.servlets.TextileLicenseServlet;
3334

3435
/**
35-
*
36+
* Map each URI to a class that will handle the request
37+
*
3638
* @author Michel
3739
*/
3840
public class ServletsModule extends ServletModule {
@@ -78,7 +80,10 @@ protected void configureServlets() {
7880

7981
// API Endpoints
8082
// Get the time left in a session
81-
serve("/sessionapi").with(SessionStateServlet.class);
83+
serve("/sessionapi").with(SessionStateServlet.class);
84+
85+
// COPPA support
86+
serve("/privacy-policy").with(PrivacyPolicyServlet.class);
8287
}
8388

8489
}

src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,19 @@
3434
@Singleton
3535
public class ProjectDaoImpl implements ProjectDao {
3636

37+
/**
38+
*
39+
*/
3740
private static final int Min_BlocklyCodeSize = 48;
41+
42+
/**
43+
*
44+
*/
3845
private static final Logger LOG = LoggerFactory.getLogger(ProjectDao.class);
46+
47+
/**
48+
*
49+
*/
3950
private DSLContext create;
4051

4152
@Inject
@@ -97,8 +108,10 @@ public ProjectRecord createProject(
97108
LOG.info("Creating a new project with existing code.");
98109
Long idUser = BlocklyPropSecurityUtils.getCurrentUserId();
99110
Long idCloudUser = BlocklyPropSecurityUtils.getCurrentSessionUserId();
100-
101-
ProjectRecord record = create
111+
ProjectRecord record = null;
112+
try {
113+
114+
record = create
102115
.insertInto(Tables.PROJECT,
103116
Tables.PROJECT.ID_USER,
104117
Tables.PROJECT.ID_CLOUDUSER,
@@ -122,8 +135,13 @@ public ProjectRecord createProject(
122135
sharedProject)
123136
.returning()
124137
.fetchOne();
125-
126-
return record;
138+
}
139+
catch (org.jooq.exception.DataAccessException sqex) {
140+
LOG.error("Database error encountered {}", sqex.getMessage());
141+
}
142+
finally {
143+
return record;
144+
}
127145
}
128146

129147
/**
@@ -771,6 +789,12 @@ private String fixPropcProjectBlocks(String newCode, ProjectType projType) {
771789
newCode = newCode.replaceAll("field name=\"UNIT\">CM</field",
772790
"field name=\"UNIT\">_cm</field");
773791

792+
newCode = newCode.replaceAll("block type=\"spin_comment\"",
793+
"block type=\"comment\"");
794+
795+
newCode = newCode.replaceAll("field name=\"COMMENT\">",
796+
"field name=\"COMMENT_TEXT\">");
797+
774798
newCode = newCode.replaceAll("block type=\"controls_boolean_if\"",
775799
"block type=\"controls_if\"");
776800

src/main/java/com/parallax/server/blocklyprop/db/dao/impl/SessionDaoImpl.java

+93-44
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import java.util.Arrays;
1818
import java.util.Collection;
1919
import java.util.HashMap;
20-
//import java.util.logging.Level;
21-
//import java.util.logging.Logger;
2220
import org.apache.commons.configuration.Configuration;
2321
import org.jooq.DSLContext;
2422
import org.slf4j.Logger;
@@ -34,95 +32,146 @@ public class SessionDaoImpl implements SessionDao {
3432
// Get a logger instance
3533
private static final Logger LOG = LoggerFactory.getLogger(SessionDaoImpl.class);
3634

35+
/**
36+
*
37+
*/
3738
private DSLContext create;
3839

40+
/**
41+
* An instance of the application configuration settings
42+
*/
3943
private Configuration configuration;
4044

4145
@Inject
4246
public void setDSLContext(DSLContext dsl) {
4347
this.create = dsl;
4448
}
4549

50+
/**
51+
*
52+
* @param configuration
53+
*/
4654
@Inject
4755
public void setConfiguration(Configuration configuration) {
4856
this.configuration = configuration;
4957
}
5058

59+
/**
60+
*
61+
* @param session
62+
*/
5163
@Override
5264
public void create(SessionRecord session) {
5365
LOG.info("Create a session. Timeout set to: {}", session.getTimeout());
5466

5567
// Log session details if the configuration file permits it
5668
printSessionInfo("create", session);
5769

58-
create.insertInto(Tables.SESSION)
59-
.columns(
60-
Tables.SESSION.IDSESSION,
61-
Tables.SESSION.STARTTIMESTAMP,
62-
Tables.SESSION.LASTACCESSTIME,
63-
Tables.SESSION.TIMEOUT,
64-
Tables.SESSION.HOST,
65-
Tables.SESSION.ATTRIBUTES)
66-
.values(
67-
session.getIdsession(),
68-
session.getStarttimestamp(),
69-
session.getLastaccesstime(),
70-
session.getTimeout(),
71-
session.getHost(),
72-
session.getAttributes())
73-
.execute();
70+
try {
71+
create.insertInto(Tables.SESSION)
72+
.columns(
73+
Tables.SESSION.IDSESSION,
74+
Tables.SESSION.STARTTIMESTAMP,
75+
Tables.SESSION.LASTACCESSTIME,
76+
Tables.SESSION.TIMEOUT,
77+
Tables.SESSION.HOST,
78+
Tables.SESSION.ATTRIBUTES)
79+
.values(
80+
session.getIdsession(),
81+
session.getStarttimestamp(),
82+
session.getLastaccesstime(),
83+
session.getTimeout(),
84+
session.getHost(),
85+
session.getAttributes())
86+
.execute();
87+
}
88+
catch (org.jooq.exception.DataAccessException sqex) {
89+
LOG.error("Database exception {}", sqex.getMessage());
90+
}
7491
}
7592

93+
/**
94+
*
95+
* @param idSession
96+
* @return
97+
* @throws NullPointerException
98+
*/
7699
@Override
77100
public SessionRecord readSession(String idSession) throws NullPointerException {
78101
LOG.debug("Getting session details");
102+
SessionRecord sessionRecord = null;
103+
104+
try {
105+
sessionRecord = create.selectFrom(Tables.SESSION)
106+
.where(Tables.SESSION.IDSESSION.eq(idSession))
107+
.fetchOne();
79108

80-
SessionRecord sessionRecord
81-
= create.selectFrom(Tables.SESSION)
82-
.where(Tables.SESSION.IDSESSION
83-
.eq(idSession))
84-
.fetchOne();
85-
86-
// Log session details if the configuration file permits it
87-
printSessionInfo("read", sessionRecord);
88-
89-
return sessionRecord;
90-
}
109+
// Log session details if the configuration file permits it
110+
printSessionInfo("read", sessionRecord);
111+
}
112+
catch (org.jooq.exception.DataAccessException sqex) {
113+
LOG.error("Database exception {}", sqex.getMessage());
114+
}
115+
finally {
116+
return sessionRecord;
117+
}
118+
}
91119

120+
/**
121+
*
122+
* @param session
123+
* @throws NullPointerException
124+
*/
92125
@Override
93126
public void updateSession(SessionRecord session) throws NullPointerException {
94127
LOG.debug("Update a session");
128+
129+
try {
130+
// Get the current session record
131+
SessionRecord dbRecord = readSession(session.getIdsession());
132+
133+
if (dbRecord == null) {
134+
throw new NullPointerException("Session not found");
135+
}
136+
137+
dbRecord.setStarttimestamp(session.getStarttimestamp());
138+
dbRecord.setLastaccesstime(session.getLastaccesstime());
139+
dbRecord.setTimeout(session.getTimeout());
140+
dbRecord.setHost(session.getHost());
141+
dbRecord.setAttributes(session.getAttributes());
95142

96-
SessionRecord dbRecord = readSession(session.getIdsession());
143+
// Log session details if the configuration file permits it
144+
printSessionInfo("update from", session);
145+
printSessionInfo("update to", dbRecord);
97146

98-
if (dbRecord == null) {
99-
throw new NullPointerException();
147+
dbRecord.update();
148+
}
149+
catch (org.jooq.exception.DataAccessException sqex) {
150+
LOG.error("Database exception {}", sqex.getMessage());
151+
throw new NullPointerException("Database error");
100152
}
101-
102-
dbRecord.setStarttimestamp(session.getStarttimestamp());
103-
dbRecord.setLastaccesstime(session.getLastaccesstime());
104-
dbRecord.setTimeout(session.getTimeout());
105-
dbRecord.setHost(session.getHost());
106-
dbRecord.setAttributes(session.getAttributes());
107-
108-
// Log session details if the configuration file permits it
109-
printSessionInfo("update from", session);
110-
printSessionInfo("update to", dbRecord);
111-
112-
dbRecord.update();
113153
}
114154

155+
/**
156+
*
157+
* @param idSession
158+
*/
115159
@Override
116160
public void deleteSession(String idSession) {
117161
LOG.info("Deleting session {}", idSession);
118162
create.deleteFrom(Tables.SESSION).where(Tables.SESSION.IDSESSION.eq(idSession)).execute();
119163
}
120164

165+
/**
166+
*
167+
* @return
168+
*/
121169
@Override
122170
public Collection<SessionRecord> getActiveSessions() {
123171
return Arrays.asList(create.selectFrom(Tables.SESSION).fetchArray());
124172
}
125173

174+
126175
private void printSessionInfo(String action, SessionRecord session) {
127176
if (configuration.getBoolean("debug.session", false)) {
128177
try {

0 commit comments

Comments
 (0)