Skip to content

Commit 3d255f1

Browse files
authored
Merge pull request #1006 from zfi/master
Release 0.96.383
2 parents 9f098c7 + 10cba00 commit 3d255f1

Some content is hidden

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

53 files changed

+2657
-638
lines changed

blocklyprop.properties.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ cloudcompiler.baseurl = http://localhost:5001
1919

2020
# Static files can be served from the BlocklyProp server directly or from a
2121
# content delivery network, such as Amazon's S3 CDN. Specify the location of
22-
# the static content here.
22+
# the static content here, for both HTTP and HTTPS protocols.
2323
cdnfiles.baseurl = http://localhost/blockly/cdn
24+
cdnfiles.baseurl.https = https://localhost/blockly/cdn
2425

2526
# BlocklyProp requires a software driver, loaded on the client's computer, to
2627
# pass the compiled code to a device attached to the client computer. The
2728
# drivers can be hosted on the BlocklyProp server or in a content delivery
2829
# network. Specify the URL to the download resource here.
29-
downloadfiles.baseurl = http://demo.blockly.parallax.com/download
30+
downloadfiles.baseurl = http://localhost/download
3031

3132
# OAuth support for Google users
3233
oauth.google.enabled = false

pom.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
<packaging>war</packaging>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10-
<maven.compiler.source>1.7</maven.compiler.source>
11-
<maven.compiler.target>1.7</maven.compiler.target>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
1212

1313
<!-- Adapt this to a version found on
1414
http://central.maven.org/maven2/org/eclipse/jetty/jetty-maven-plugin/
1515
-->
1616

17-
<jooq-version>3.6.1</jooq-version>
18-
<shiro-version>1.2.3</shiro-version>
17+
<!-- jOOQ version 3.7 and above requires Java 1.8.x JDK -->
18+
<jooq-version>3.7.4</jooq-version>
19+
20+
<shiro-version>1.3.2</shiro-version>
1921
<metrics-version>3.1.0</metrics-version>
2022
<jersey.version>1.19</jersey.version>
2123
</properties>
@@ -36,7 +38,12 @@
3638
<directory>src/main/config/${environment}</directory>
3739
</resource>
3840
</resources>
41+
3942
<plugins>
43+
<!--
44+
codehaus.org shut down on 6/2015.
45+
This is now the MojoHaus Project http://www.mojohaus.org/
46+
-->
4047
<plugin>
4148
<groupId>org.codehaus.mojo</groupId>
4249
<artifactId>properties-maven-plugin</artifactId>
@@ -60,15 +67,17 @@
6067
<artifactId>maven-compiler-plugin</artifactId>
6168
<version>3.3</version>
6269
<configuration>
63-
<source>1.7</source>
64-
<target>1.7</target>
70+
<source>1.8</source>
71+
<target>1.8</target>
6572
<showDeprecation>true</showDeprecation>
6673
</configuration>
6774
</plugin>
75+
6876
<plugin>
6977
<artifactId>maven-war-plugin</artifactId>
7078
<version>2.6</version>
7179
</plugin>
80+
7281
<plugin>
7382
<groupId>org.apache.tomcat.maven</groupId>
7483
<artifactId>tomcat7-maven-plugin</artifactId>
@@ -81,6 +90,7 @@
8190
<update>true</update>
8291
</configuration>
8392
</plugin>
93+
8494
<plugin>
8595
<groupId>org.jooq</groupId>
8696
<artifactId>jooq-codegen-maven</artifactId>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import com.parallax.server.blocklyprop.services.impl.UserServiceImpl;
2929

3030
/**
31-
*
31+
* Bind abstract service classes to their implementations
32+
*
3233
* @author Michel
3334
*/
3435
public class ServiceModule extends AbstractModule {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.parallax.server.blocklyprop.servlets.ProjectServlet;
2424
import com.parallax.server.blocklyprop.servlets.PublicProfileServlet;
2525
import com.parallax.server.blocklyprop.servlets.RegisterServlet;
26+
import com.parallax.server.blocklyprop.servlets.SessionStateServlet;
2627
import com.parallax.server.blocklyprop.servlets.TextileChangeLogServlet;
2728
import com.parallax.server.blocklyprop.servlets.TextileClientDownloadServlet;
2829
import com.parallax.server.blocklyprop.servlets.TextileClientInstructionsServlet;
@@ -74,6 +75,10 @@ protected void configureServlets() {
7475
serve("/oauth/newuser").with(NewOAuthUserServlet.class);
7576
// OAuth providers
7677
serve("/oauth/google").with(OAuthGoogleServlet.class);
78+
79+
// API Endpoints
80+
// Get the time left in a session
81+
serve("/sessionapi").with(SessionStateServlet.class);
7782
}
7883

7984
}

src/main/java/com/parallax/server/blocklyprop/converter/ProjectConverter.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,31 @@ public void setProjectSharingService(ProjectSharingService projectSharingService
5151

5252
public JsonObject toListJson(ProjectRecord project) {
5353
JsonObject result = new JsonObject();
54-
result.addProperty("id", project.getId());
55-
result.addProperty("name", project.getName());
56-
result.addProperty("description", project.getDescription());
57-
result.addProperty("type", project.getType().name());
58-
result.addProperty("board", project.getBoard());
59-
result.addProperty("private", project.getPrivate());
60-
result.addProperty("shared", project.getShared());
61-
result.addProperty("created", DateConversion.toDateTimeString(project.getCreated().getTime()));
62-
result.addProperty("modified", DateConversion.toDateTimeString(project.getModified().getTime()));
63-
boolean isYours = project.getIdUser().equals(BlocklyPropSecurityUtils.getCurrentUserId());
64-
result.addProperty("yours", isYours);
65-
// if (!isYours) {
66-
result.addProperty("user", userService.getUserScreenName(project.getIdUser()));
67-
result.addProperty("id-user", project.getIdUser());
68-
// }
6954

55+
if (project != null) {
56+
result.addProperty("id", project.getId());
57+
result.addProperty("name", project.getName());
58+
result.addProperty("description", project.getDescription());
59+
result.addProperty("type", project.getType().name());
60+
result.addProperty("board", project.getBoard());
61+
result.addProperty("private", project.getPrivate());
62+
result.addProperty("shared", project.getShared());
63+
result.addProperty("created", DateConversion.toDateTimeString(project.getCreated().getTime()));
64+
result.addProperty("modified", DateConversion.toDateTimeString(project.getModified().getTime()));
65+
66+
boolean isYours = project.getIdUser().equals(BlocklyPropSecurityUtils.getCurrentUserId());
67+
result.addProperty("yours", isYours);
68+
69+
// Get user screen name only if it's a registered user
70+
if (project.getId() > 0) {
71+
result.addProperty("user", userService.getUserScreenName(project.getIdUser()));
72+
result.addProperty("id-user", project.getIdUser());
73+
}
74+
else {
75+
result.addProperty("user", "anonymous");
76+
result.addProperty("id-user", 0);
77+
}
78+
}
7079
return result;
7180
}
7281

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

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@
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;
20+
//import java.util.logging.Level;
21+
//import java.util.logging.Logger;
2222
import org.apache.commons.configuration.Configuration;
2323
import org.jooq.DSLContext;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
2427

2528
/**
2629
*
2730
* @author Michel
2831
*/
2932
@Singleton
3033
public class SessionDaoImpl implements SessionDao {
34+
// Get a logger instance
35+
private static final Logger LOG = LoggerFactory.getLogger(SessionDaoImpl.class);
3136

3237
private DSLContext create;
3338

@@ -45,36 +50,71 @@ public void setConfiguration(Configuration configuration) {
4550

4651
@Override
4752
public void create(SessionRecord session) {
53+
LOG.info("Create a session. Timeout set to: {}", session.getTimeout());
54+
55+
// Log session details if the configuration file permits it
4856
printSessionInfo("create", session);
49-
create.insertInto(Tables.SESSION).columns(Tables.SESSION.IDSESSION, Tables.SESSION.STARTTIMESTAMP, Tables.SESSION.LASTACCESSTIME, Tables.SESSION.TIMEOUT, Tables.SESSION.HOST, Tables.SESSION.ATTRIBUTES)
50-
.values(session.getIdsession(), session.getStarttimestamp(), session.getLastaccesstime(), session.getTimeout(), session.getHost(), session.getAttributes()).execute();
57+
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();
5174
}
5275

5376
@Override
5477
public SessionRecord readSession(String idSession) throws NullPointerException {
55-
SessionRecord sessionRecord = create.selectFrom(Tables.SESSION).where(Tables.SESSION.IDSESSION.eq(idSession)).fetchOne();
78+
LOG.debug("Getting session details");
79+
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
5687
printSessionInfo("read", sessionRecord);
88+
5789
return sessionRecord;
5890
}
5991

6092
@Override
6193
public void updateSession(SessionRecord session) throws NullPointerException {
94+
LOG.debug("Update a session");
95+
6296
SessionRecord dbRecord = readSession(session.getIdsession());
97+
6398
if (dbRecord == null) {
6499
throw new NullPointerException();
65100
}
101+
66102
dbRecord.setStarttimestamp(session.getStarttimestamp());
67103
dbRecord.setLastaccesstime(session.getLastaccesstime());
68104
dbRecord.setTimeout(session.getTimeout());
69105
dbRecord.setHost(session.getHost());
70106
dbRecord.setAttributes(session.getAttributes());
107+
108+
// Log session details if the configuration file permits it
71109
printSessionInfo("update from", session);
72110
printSessionInfo("update to", dbRecord);
111+
73112
dbRecord.update();
74113
}
75114

76115
@Override
77116
public void deleteSession(String idSession) {
117+
LOG.info("Deleting session {}", idSession);
78118
create.deleteFrom(Tables.SESSION).where(Tables.SESSION.IDSESSION.eq(idSession)).execute();
79119
}
80120

@@ -87,20 +127,18 @@ private void printSessionInfo(String action, SessionRecord session) {
87127
if (configuration.getBoolean("debug.session", false)) {
88128
try {
89129
if (session == null || session.getAttributes() == null) {
90-
System.out.println(action + ": NO SESSION AVAILABLE");
130+
LOG.error("No sessions available.");
91131
} else {
92132
ByteArrayInputStream bis = new ByteArrayInputStream(session.getAttributes());
93133
ObjectInput in = new ObjectInputStream(bis);
94134
HashMap attributes = (HashMap) in.readObject();
95-
System.out.println(action + ": " + attributes);
135+
LOG.info("Session info: {}:{}", action, attributes);
96136
}
97137
} catch (IOException ex) {
98-
Logger.getLogger(SessionDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
138+
LOG.error("I/O error. {}",ex.getMessage());
99139
} catch (ClassNotFoundException cnfe) {
100-
Logger.getLogger(SessionDaoImpl.class.getName()).log(Level.SEVERE, null, cnfe);
140+
LOG.error("Class not found. {}", cnfe.getMessage());
101141
}
102142
}
103-
104143
}
105-
106144
}

src/main/java/com/parallax/server/blocklyprop/db/utils/DataSourceSetup.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@
2323
*/
2424
public class DataSourceSetup {
2525

26+
// SQL database source
2627
private static DataSource dataSource;
2728

29+
//
2830
private static List<NeedsDataSource> dataSourceUsers = new ArrayList<NeedsDataSource>();
2931

32+
/**
33+
* Get the static data source instance
34+
*
35+
* @return A static DataSource object. The object may be null.
36+
*/
3037
public static DataSource getDataSource() {
3138
return dataSource;
3239
}
3340

41+
/**
42+
*
43+
* @param dataSourceUser
44+
*/
3445
public static void registerDataSourceUsers(NeedsDataSource dataSourceUser) {
3546
if (dataSource != null) {
3647
dataSourceUser.setDataSource(dataSource);
@@ -39,12 +50,21 @@ public static void registerDataSourceUsers(NeedsDataSource dataSourceUser) {
3950
}
4051
}
4152

42-
public static PoolingDataSource connect(Configuration configuration) throws ClassNotFoundException {
53+
public static PoolingDataSource connect(Configuration configuration)
54+
throws ClassNotFoundException {
55+
4356
String driver = configuration.getString("database.driver");
4457
String url = configuration.getString("database.url");
4558
String username = configuration.getString("database.username");
4659
String password = configuration.getString("database.password");
4760

61+
//
62+
// Returns the Class object associated with the class or interface
63+
// with the given string name. Invoking this method is equivalent to:
64+
// Class.forName(className, true, currentLoader)
65+
// where currentLoader denotes the defining class loader of the
66+
// current class.
67+
//
4868
Class.forName(driver);
4969

5070
//
@@ -87,7 +107,9 @@ public static PoolingDataSource connect(Configuration configuration) throws Clas
87107
for (NeedsDataSource dataSourceUser : dataSourceUsers) {
88108
dataSourceUser.setDataSource(dataSourceInstance);
89109
}
110+
90111
DataSourceSetup.dataSource = dataSourceInstance;
112+
91113
return dataSourceInstance;
92114
}
93115

src/main/java/com/parallax/server/blocklyprop/jsp/Properties.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public static Configuration getConfiguration() {
2525
return configuration;
2626
}
2727

28+
/**
29+
* Retrieve the base path to the BlocklyProp Client download files
30+
* <p>
31+
* This method supports the "offline" mode which assumes that there is
32+
* no Internet connectivity available.
33+
*
34+
* @param file
35+
* @return
36+
*/
2837
public static String getDownloadFilesBaseUrl(String file) {
2938
if (configuration.getBoolean("offline.enabled") == true) {
3039
return configuration.getString("offline.downloadfiles.baseurl") + (file.startsWith("/") ? "" : "/") + file;
@@ -42,7 +51,20 @@ public static boolean isOauthEnabled(String oauthProvider) {
4251
}
4352
}
4453

45-
// Use experimental menu items in test environment
54+
//
55+
56+
/**
57+
* Obtain the state of experimental menu items.
58+
* <p>
59+
* Blocks that are not ready for production use can be placed within
60+
* and 'experimental block' pattern. The 'experimental.menu' option
61+
* contained in the application properties file will trigger the menu
62+
* system to expose experimental menu items. If this option is off or
63+
* missing, the experimental menu items will be disabled.
64+
*
65+
* @param state
66+
* @return
67+
*/
4668
public static boolean isExperimentalMenu(Boolean state) {
4769
try {
4870
if (configuration.getBoolean("experimental.menu") == true) {

0 commit comments

Comments
 (0)