Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
707ba88
Add a settings field for the user profile profile table.
pjewald Feb 20, 2019
9319570
Insert copyright notice.
pjewald Feb 20, 2019
8089bdb
Add inline documentation. Insert copyright notice.
pjewald Feb 20, 2019
a9adb38
Add support for a project settings field in a project. This is design…
pjewald Feb 20, 2019
13c146f
Add inline documentation. Insert copyright notice.
pjewald Feb 20, 2019
0753132
Implement project settings support. Arrange methods based on functional
pjewald Feb 21, 2019
27d3dcf
Refactor common code constructs into separate methods.
pjewald Feb 27, 2019
468f5f9
Create a Project V2 API draft.
pjewald Feb 28, 2019
5f3f895
Add inline documentation for the POST / endpoint.
pjewald Feb 28, 2019
001f034
Improve inline documentation. Add exception to trap case where logged in
pjewald Feb 28, 2019
614dc23
Add inline documentation.
pjewald Feb 28, 2019
ac73804
Refactor readSession to reduce code paths.
pjewald Mar 1, 2019
496ca58
Add version 2 Project REST endpoints. Work is still ongoing.
pjewald Mar 7, 2019
b65209a
Jooq generated updates for adding project settings to the application.
pjewald Mar 7, 2019
00853c3
Add support for version 2 Project REST endpoints.
pjewald Mar 7, 2019
4c1730a
Add code to support Project Update REST endpoint.
pjewald Mar 7, 2019
1d73749
Add inline documentation.
pjewald Mar 7, 2019
4d235e1
Implement project REST DELETE /{id} endpoint.
pjewald Mar 7, 2019
ed0b7f8
Add URL path for version 2 project REST API interface.
pjewald Mar 8, 2019
3298277
Merging patch 1522a into 1522
pjewald Mar 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions db-updates/0014-add-project-settings.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* 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.
*/
/**
* Author: Jim Ewald
* Created: Aug 27, 2018
*
* Add a field to the project table to store a JSON encoded group of project
* settings.
*
* Add a field to the user profile to store JSON encoded settings related to
* specific user.
*/

ALTER TABLE blocklyprop.project ADD settings TEXT NULL;
ALTER TABLE cloudsession.user ADD settings TEXT NULL;


Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import com.parallax.server.blocklyprop.rest.RestMotd;
import com.parallax.server.blocklyprop.rest.RestProfile;
import com.parallax.server.blocklyprop.rest.RestProject;
import com.parallax.server.blocklyprop.rest.RestV2Project;
import com.parallax.server.blocklyprop.rest.RestSharedProject;
import com.parallax.server.blocklyprop.rest.RestUser;

import com.sun.jersey.guice.JerseyServletModule;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;

import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
Expand All @@ -45,6 +48,8 @@ protected void configureServlets() {
bind(RestCompile.class);
bind(RestUser.class);
bind(RestProject.class);
bind(RestV2Project.class);

bind(RestSharedProject.class);
bind(RestProfile.class);
bind(RestMotd.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;

import com.parallax.server.blocklyprop.SessionData;
import com.parallax.server.blocklyprop.jsp.Properties;
import com.parallax.server.blocklyprop.monitoring.Monitor;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import org.apache.commons.configuration.Configuration;
Expand All @@ -40,22 +41,25 @@
import org.slf4j.LoggerFactory;



/**
*
* @author Michel
*/
public class SetupConfig extends GuiceServletContextListener {

/**
* Application-specific configuration options
*/
// Application logging connector
private final Logger LOG = LoggerFactory.getLogger(SetupConfig.class);

// Application-specific configuration options
private Configuration configuration;



/**
* Application logging connector
* Create a Guice injector object
*
* @return a Guice injector object
*/
private final Logger LOG = LoggerFactory.getLogger(SetupConfig.class);

@Override
protected Injector getInjector() {
readConfiguration();
Expand All @@ -65,9 +69,9 @@ protected Injector getInjector() {
@Override
protected void configure() {

LOG.info("Binding Configuration class");
bind(Configuration.class).toInstance(configuration);

bind(SessionData.class);
bind(Properties.class).asEagerSingleton();

bind(Monitor.class).asEagerSingleton();
Expand All @@ -81,7 +85,6 @@ protected void configure() {
install(new ServletsModule());
install(new RestModule());
}

});
}

Expand Down Expand Up @@ -119,26 +122,16 @@ public void contextDestroyed(ServletContextEvent servletContextEvent) {
// This manually deregisters JDBC driver, which prevents Tomcat 7 from
// complaining about memory leaks into this class

/*
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
LOG.info("deregistering jdbc driver: {}",driver);
LOG.info("Deregister the jdbc driver: {}",driver);
} catch (SQLException sqlE) {
LOG.error("Error deregistering driver %s", driver);
LOG.error("Unable to deregister the jdbc driver {}", driver.toString());
LOG.error("{}", sqlE.getSQLState());
}

}

// Shut down the loggers. Assume SLF4J is bound to logback-classic
// in the current environment
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
if (loggerContext != null) {
loggerContext.stop();
}
*/
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
public class ProjectConverter {


/**
* Application logging facility
*/
// Application logging facility
private static final Logger LOG = LoggerFactory.getLogger(ProjectConverter.class);

private ProjectDao projectDao;
Expand All @@ -41,7 +39,6 @@ public class ProjectConverter {
// Internal flag to enable/disable parent project details
private Boolean includeParentProjectDetails = false;


@Inject
public void setProjectDao(ProjectDao projectDao) {
this.projectDao = projectDao;
Expand All @@ -61,48 +58,45 @@ public void setProjectSharingService(ProjectSharingService projectSharingService
/**
* Convert a ProjectRecord to a JSON object
*
* @param project
* @return
* @param project is the ProjectRecord object to convert
*
* @return a JsonObject. The JsonObject may be empty if the source project was null
*/
public JsonObject toListJson(ProjectRecord project) {

LOG.debug("Converting a ProjectRecord to a Json object");

JsonObject result = new JsonObject();

if (project != null) {
result.addProperty("id", project.getId());
result.addProperty("name", project.getName());
result.addProperty("description", project.getDescription());
result.addProperty("type", project.getType().name());
result.addProperty("board", project.getBoard());
result.addProperty("private", project.getPrivate());
result.addProperty("shared", project.getShared());
result.addProperty("created", DateConversion.toDateTimeString(project.getCreated().getTime()));
result.addProperty("modified", DateConversion.toDateTimeString(project.getModified().getTime()));

boolean isYours = project.getIdUser().equals(BlocklyPropSecurityUtils.getCurrentUserId());
result.addProperty("yours", isYours);
if (project == null) {
return new JsonObject();
}

// Get user screen name only if it's a registered user
if (project.getId() > 0) {
// Get the project owner's screen name
String screenName = userService.getUserScreenName(project.getIdUser());
result.addProperty("user",(screenName == "" ? "unknown" : screenName));
// Load the core project details
JsonObject result = addProjectRecordProperties(project);

// Add the project user's BP user id
result.addProperty("id-user", project.getIdUser());
}
else {
result.addProperty("user", "anonymous");
result.addProperty("id-user", 0);
}
boolean isYours = project.getIdUser().equals(BlocklyPropSecurityUtils.getCurrentUserId());
result.addProperty("yours", isYours);

// Get user screen name only if it's a registered user
if (project.getId() > 0) {
// Get the project owner's screen name
String screenName = userService.getUserScreenName(project.getIdUser());
result.addProperty("user",(screenName == "" ? "unknown" : screenName));

// Add the project user's BP user id
result.addProperty("id-user", project.getIdUser());
}
else {
result.addProperty("user", "anonymous");
result.addProperty("id-user", 0);
}

return result;
}



// TODO: Refactor code to eliminate the parent project details. We don't use it



// Overrride method to provide option to turn off parent project details
public JsonObject toJson(ProjectRecord project, Boolean includeParentDetails) {
includeParentProjectDetails = includeParentDetails;
Expand All @@ -119,38 +113,29 @@ public JsonObject toJson(Project project, Boolean includeParentDetails) {
/**
* Convert a project record to a JSON payload
*
* @param project
* @return
* @param project is te source ProjectRecord object to convert
*
* @return A Json object that contains a set of properties that represent
* the fields contained in the ProjectRecord object
*/
public JsonObject toJson(ProjectRecord project) {
LOG.debug("Converting a ProjectRecord object to JSON");

JsonObject result = null;

if (project == null) {
LOG.error("Recieved a null project. Unable to convert it to JSON");
return null;
LOG.error("Received a null project. Unable to convert it to JSON");
return new JsonObject();
}


JsonObject result = null;

try {
result = new JsonObject();

result.addProperty("id", project.getId());
result.addProperty("name", project.getName());
result.addProperty("description", project.getDescription());
result.addProperty("description-html", project.getDescriptionHtml());
result.addProperty("type", project.getType().name());
result.addProperty("board", project.getBoard());
result.addProperty("private", project.getPrivate());
result.addProperty("shared", project.getShared());
result.addProperty("created", DateConversion.toDateTimeString(project.getCreated().getTime()));
result.addProperty("modified", DateConversion.toDateTimeString(project.getModified().getTime()));

LOG.debug("Evaluating project owner");

// Load the project fields into the Json object
result = addProjectRecordProperties(project);


// Does current user own this project?
LOG.debug("Evaluating project owner");
boolean isYours = project.getIdUser().equals(BlocklyPropSecurityUtils.getCurrentUserId());

LOG.debug("isYours = {}", isYours);

result.addProperty("yours", isYours);
Expand Down Expand Up @@ -224,17 +209,10 @@ public JsonObject toJson(ProjectRecord project) {


private JsonObject toJson(Project project) {
JsonObject result = new JsonObject();
result.addProperty("id", project.getId());
result.addProperty("name", project.getName());
result.addProperty("description", project.getDescription());
result.addProperty("description-html", project.getDescriptionHtml());
result.addProperty("type", project.getType().name());
result.addProperty("board", project.getBoard());
result.addProperty("private", project.getPrivate());
result.addProperty("shared", project.getShared());
result.addProperty("modified", DateConversion.toDateTimeString(project.getModified().getTime()));

boolean isYours = project.getIdUser().equals(BlocklyPropSecurityUtils.getCurrentUserId());
JsonObject result = addProperties(project);

result.addProperty("yours", isYours);
result.addProperty("user", userService.getUserScreenName(project.getIdUser()));

Expand All @@ -258,4 +236,67 @@ private JsonObject toJson(Project project) {
return result;
}


/**
* Create a Json object representing a Project object.
*
* @param project is the Project object to translate
*
* @return a Json object that contains a collection of properties representing
* the fields in the source Project object
*/
private JsonObject addProperties(Project project) {

JsonObject result = new JsonObject();

try {
result.addProperty("id", project.getId());
result.addProperty("name", project.getName());
result.addProperty("description", project.getDescription());
result.addProperty("description-html", project.getDescriptionHtml());
result.addProperty("type", project.getType().name());
result.addProperty("board", project.getBoard());
result.addProperty("private", project.getPrivate());
result.addProperty("shared", project.getShared());
result.addProperty("modified", DateConversion.toDateTimeString(project.getModified().getTime()));
result.addProperty("settings", project.getSettings());
}
catch (Exception ex) {
LOG.error("Exception {} detected.", ex.toString());
}

return result;
}


/**
* Create a Json string representing a ProjectRecord object
*
* @param projectRecord is the ProjectRecord object to translate
*
* @return a Json object that contains a collection of properties representing
* the fields in the ProjectRecord object
*/
private JsonObject addProjectRecordProperties( ProjectRecord projectRecord) {

JsonObject result = new JsonObject();

try {
result.addProperty("id", projectRecord.getId());
result.addProperty("name", projectRecord.getName());
result.addProperty("description", projectRecord.getDescription());
result.addProperty("type", projectRecord.getType().name());
result.addProperty("board", projectRecord.getBoard());
result.addProperty("private", projectRecord.getPrivate());
result.addProperty("shared", projectRecord.getShared());
result.addProperty("created", DateConversion.toDateTimeString(projectRecord.getCreated().getTime()));
result.addProperty("modified", DateConversion.toDateTimeString(projectRecord.getModified().getTime()));
result.addProperty("settings", projectRecord.getSettings());
}
catch (Exception ex) {
LOG.error("Exception {} detected.", ex.toString());
}

return result;
}
}
Loading