Skip to content

Commit

Permalink
Merge pull request #1101 from zfi/master
Browse files Browse the repository at this point in the history
Release 0.97
  • Loading branch information
zfi authored Jul 19, 2017
2 parents 5fc0fed + ce6d8a3 commit 3bc6499
Show file tree
Hide file tree
Showing 66 changed files with 2,608 additions and 817 deletions.
7 changes: 6 additions & 1 deletion db-updates/0006-add-user-coach.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/*
* Add coach email address field to support email cc option.
*/
ALTER TABLE user ADD COLUMN coach_email VARCHAR(250) AFTER screen_name;

/*
* This DDL has been moved to the Cloud Session Server project
*/

-- ALTER TABLE user ADD COLUMN coach_email VARCHAR(250) AFTER screen_name;
35 changes: 35 additions & 0 deletions db-updates/0007-coppa-support.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Add fields to user table to support US COPPA compliance
*
* Author: Jim Ewald
* Created: Apr 27, 2017A
*
* birth_month - is a range of [1 - 12]
* birth_year - is a range from [1930 - current year]
* parent_email - is used to register a child under the ae of 13. This is the
* email address of the parent, guardian or instructor that is
* creating the account on behalf of the child
*
* parent_email_source - is a integer designator to characterize the parent
* email adress noted above. Current options are:
* 0 - undefined
* 1 - child's parent
* 2 - child's guardian
* 3 - child's instructor or teacher
*/

/*
* This DDL has been moved to the Cloud Session Server project
*/

-- ALTER TABLE cloudsession.user ADD birth_month INT NOT NULL;
-- ALTER TABLE cloudsession.user ADD birth_year INT NOT NULL;
-- ALTER TABLE cloudsession.user ADD parent_email VARCHAR(250) NULL;
-- ALTER TABLE cloudsession.user ADD parent_email_source INT DEFAULT 0 NULL;
-- ALTER TABLE cloudsession.user DROP coach_email;
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<includes>.*</includes>
<excludes></excludes>
<inputSchema>blocklyprop</inputSchema>

<customTypes>
<customType>
<name>GregorianCalendar</name>
Expand Down Expand Up @@ -361,6 +361,13 @@
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>

<!-- END Apache commons Dependencies -->

<!-- Rest API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.google.inject.servlet.ServletModule;
import com.parallax.server.blocklyprop.servlets.AuthenticationServlet;
import com.parallax.server.blocklyprop.servlets.PrivacyPolicyServlet;
import com.parallax.server.blocklyprop.servlets.ConfirmRequestServlet;
import com.parallax.server.blocklyprop.servlets.ConfirmServlet;
import com.parallax.server.blocklyprop.servlets.HelpSearchServlet;
Expand All @@ -32,7 +33,8 @@
import com.parallax.server.blocklyprop.servlets.TextileLicenseServlet;

/**
*
* Map each URI to a class that will handle the request
*
* @author Michel
*/
public class ServletsModule extends ServletModule {
Expand Down Expand Up @@ -78,7 +80,10 @@ protected void configureServlets() {

// API Endpoints
// Get the time left in a session
serve("/sessionapi").with(SessionStateServlet.class);
serve("/sessionapi").with(SessionStateServlet.class);

// COPPA support
serve("/privacy-policy").with(PrivacyPolicyServlet.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@
@Singleton
public class ProjectDaoImpl implements ProjectDao {

/**
*
*/
private static final int Min_BlocklyCodeSize = 48;

/**
*
*/
private static final Logger LOG = LoggerFactory.getLogger(ProjectDao.class);

/**
*
*/
private DSLContext create;

@Inject
Expand Down Expand Up @@ -97,8 +108,10 @@ public ProjectRecord createProject(
LOG.info("Creating a new project with existing code.");
Long idUser = BlocklyPropSecurityUtils.getCurrentUserId();
Long idCloudUser = BlocklyPropSecurityUtils.getCurrentSessionUserId();

ProjectRecord record = create
ProjectRecord record = null;
try {

record = create
.insertInto(Tables.PROJECT,
Tables.PROJECT.ID_USER,
Tables.PROJECT.ID_CLOUDUSER,
Expand All @@ -122,8 +135,13 @@ public ProjectRecord createProject(
sharedProject)
.returning()
.fetchOne();

return record;
}
catch (org.jooq.exception.DataAccessException sqex) {
LOG.error("Database error encountered {}", sqex.getMessage());
}
finally {
return record;
}
}

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

newCode = newCode.replaceAll("block type=\"spin_comment\"",
"block type=\"comment\"");

newCode = newCode.replaceAll("field name=\"COMMENT\">",
"field name=\"COMMENT_TEXT\">");

newCode = newCode.replaceAll("block type=\"controls_boolean_if\"",
"block type=\"controls_if\"");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
//import java.util.logging.Level;
//import java.util.logging.Logger;
import org.apache.commons.configuration.Configuration;
import org.jooq.DSLContext;
import org.slf4j.Logger;
Expand All @@ -34,95 +32,146 @@ public class SessionDaoImpl implements SessionDao {
// Get a logger instance
private static final Logger LOG = LoggerFactory.getLogger(SessionDaoImpl.class);

/**
*
*/
private DSLContext create;

/**
* An instance of the application configuration settings
*/
private Configuration configuration;

@Inject
public void setDSLContext(DSLContext dsl) {
this.create = dsl;
}

/**
*
* @param configuration
*/
@Inject
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}

/**
*
* @param session
*/
@Override
public void create(SessionRecord session) {
LOG.info("Create a session. Timeout set to: {}", session.getTimeout());

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

create.insertInto(Tables.SESSION)
.columns(
Tables.SESSION.IDSESSION,
Tables.SESSION.STARTTIMESTAMP,
Tables.SESSION.LASTACCESSTIME,
Tables.SESSION.TIMEOUT,
Tables.SESSION.HOST,
Tables.SESSION.ATTRIBUTES)
.values(
session.getIdsession(),
session.getStarttimestamp(),
session.getLastaccesstime(),
session.getTimeout(),
session.getHost(),
session.getAttributes())
.execute();
try {
create.insertInto(Tables.SESSION)
.columns(
Tables.SESSION.IDSESSION,
Tables.SESSION.STARTTIMESTAMP,
Tables.SESSION.LASTACCESSTIME,
Tables.SESSION.TIMEOUT,
Tables.SESSION.HOST,
Tables.SESSION.ATTRIBUTES)
.values(
session.getIdsession(),
session.getStarttimestamp(),
session.getLastaccesstime(),
session.getTimeout(),
session.getHost(),
session.getAttributes())
.execute();
}
catch (org.jooq.exception.DataAccessException sqex) {
LOG.error("Database exception {}", sqex.getMessage());
}
}

/**
*
* @param idSession
* @return
* @throws NullPointerException
*/
@Override
public SessionRecord readSession(String idSession) throws NullPointerException {
LOG.debug("Getting session details");
SessionRecord sessionRecord = null;

try {
sessionRecord = create.selectFrom(Tables.SESSION)
.where(Tables.SESSION.IDSESSION.eq(idSession))
.fetchOne();

SessionRecord sessionRecord
= create.selectFrom(Tables.SESSION)
.where(Tables.SESSION.IDSESSION
.eq(idSession))
.fetchOne();

// Log session details if the configuration file permits it
printSessionInfo("read", sessionRecord);

return sessionRecord;
}
// Log session details if the configuration file permits it
printSessionInfo("read", sessionRecord);
}
catch (org.jooq.exception.DataAccessException sqex) {
LOG.error("Database exception {}", sqex.getMessage());
}
finally {
return sessionRecord;
}
}

/**
*
* @param session
* @throws NullPointerException
*/
@Override
public void updateSession(SessionRecord session) throws NullPointerException {
LOG.debug("Update a session");

try {
// Get the current session record
SessionRecord dbRecord = readSession(session.getIdsession());

if (dbRecord == null) {
throw new NullPointerException("Session not found");
}

dbRecord.setStarttimestamp(session.getStarttimestamp());
dbRecord.setLastaccesstime(session.getLastaccesstime());
dbRecord.setTimeout(session.getTimeout());
dbRecord.setHost(session.getHost());
dbRecord.setAttributes(session.getAttributes());

SessionRecord dbRecord = readSession(session.getIdsession());
// Log session details if the configuration file permits it
printSessionInfo("update from", session);
printSessionInfo("update to", dbRecord);

if (dbRecord == null) {
throw new NullPointerException();
dbRecord.update();
}
catch (org.jooq.exception.DataAccessException sqex) {
LOG.error("Database exception {}", sqex.getMessage());
throw new NullPointerException("Database error");
}

dbRecord.setStarttimestamp(session.getStarttimestamp());
dbRecord.setLastaccesstime(session.getLastaccesstime());
dbRecord.setTimeout(session.getTimeout());
dbRecord.setHost(session.getHost());
dbRecord.setAttributes(session.getAttributes());

// Log session details if the configuration file permits it
printSessionInfo("update from", session);
printSessionInfo("update to", dbRecord);

dbRecord.update();
}

/**
*
* @param idSession
*/
@Override
public void deleteSession(String idSession) {
LOG.info("Deleting session {}", idSession);
create.deleteFrom(Tables.SESSION).where(Tables.SESSION.IDSESSION.eq(idSession)).execute();
}

/**
*
* @return
*/
@Override
public Collection<SessionRecord> getActiveSessions() {
return Arrays.asList(create.selectFrom(Tables.SESSION).fetchArray());
}


private void printSessionInfo(String action, SessionRecord session) {
if (configuration.getBoolean("debug.session", false)) {
try {
Expand Down
Loading

0 comments on commit 3bc6499

Please sign in to comment.