Skip to content

Commit 625c588

Browse files
authored
Merge pull request #1055 from zfi/master
Release 0.96.410
2 parents 3d255f1 + 85f82d4 commit 625c588

36 files changed

+3183
-1860
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<dependency>
109109
<groupId>mysql</groupId>
110110
<artifactId>mysql-connector-java</artifactId>
111-
<version>5.1.40</version>
111+
<version>5.1.41</version>
112112
</dependency>
113113
</dependencies>
114114

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ protected void configure() {
7373
*/
7474
private void readConfiguration() {
7575
try {
76-
LOG.info("Looking for blocklyprop.properties in: {}", System.getProperty("user.home"));
77-
DefaultConfigurationBuilder configurationBuilder = new DefaultConfigurationBuilder(getClass().getResource("/config.xml"));
76+
LOG.info(
77+
"Looking for blocklyprop.properties in: {}",
78+
System.getProperty("user.home"));
79+
80+
DefaultConfigurationBuilder configurationBuilder
81+
= new DefaultConfigurationBuilder(getClass()
82+
.getResource("/config.xml"));
83+
7884
configuration = configurationBuilder.getConfiguration();
7985
} catch (ConfigurationException ce) {
8086
LOG.error("{}", ce.getMessage());
@@ -86,8 +92,11 @@ private void readConfiguration() {
8692
@Override
8793
public void contextDestroyed(ServletContextEvent servletContextEvent) {
8894
super.contextDestroyed(servletContextEvent);
89-
// This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks wrto this class
95+
9096
Enumeration<Driver> drivers = DriverManager.getDrivers();
97+
98+
// This manually deregisters JDBC driver, which prevents Tomcat 7 from
99+
// complaining about memory leaks into this class
91100
while (drivers.hasMoreElements()) {
92101
Driver driver = drivers.nextElement();
93102
try {

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

+99-12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@Singleton
3535
public class ProjectDaoImpl implements ProjectDao {
3636

37+
private static final int Min_BlocklyCodeSize = 48;
3738
private static final Logger LOG = LoggerFactory.getLogger(ProjectDao.class);
3839
private DSLContext create;
3940

@@ -63,9 +64,11 @@ public ProjectRecord getProject(Long idProject) {
6364
.where(Tables.PROJECT.ID.equal(idProject))
6465
.fetchOne();
6566

67+
if (record == null) {
68+
LOG.warn("Unable to retreive project {}", idProject);
69+
return null;
70+
}
6671
// Return the project after checking if for depricated blocks
67-
//
68-
// Todo: Verify that the record was fetched - it sometimes is not.
6972
return alterReadRecord(record);
7073
}
7174

@@ -210,7 +213,7 @@ public ProjectRecord createProject(
210213

211214
// Used by the randomString function
212215

213-
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*-+./:;=?@[]^_`{|}~";
216+
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#()*-+./:;=@[]^_`{|}~";
214217
static Random rnd = new Random();
215218

216219
/**
@@ -652,22 +655,26 @@ private ProjectRecord doProjectClone(ProjectRecord original) {
652655
// horribly wrong with the string conversions.
653656
//
654657
private ProjectRecord alterReadRecord(ProjectRecord record) {
655-
LOG.info("Verify project block characteristics");
656658
String currentCode, newCode;
657659

658660
if (record == null) {
659-
LOG.error("Null project record detected.");
660-
throw new NullPointerException("Cannot alter a null project record.");
661+
LOG.error("alterReadRecod detected a null project record.");
662+
return null;
661663
}
662664

663665
try {
666+
LOG.info("Verify project {} block characteristics", record.getId());
664667
currentCode = record.getCode();
665668

666669
// Return immediately if there is no code to adjust
667670
if (currentCode == null) {
668671
LOG.warn("Project () code block is empty.", record.getId());
669672
return record;
670673
}
674+
675+
if (currentCode.length() < Min_BlocklyCodeSize ) {
676+
LOG.warn("Project code appears to be missing");
677+
}
671678

672679
/*
673680
* Make a copy of the project. We will use this after the updates
@@ -676,12 +683,12 @@ private ProjectRecord alterReadRecord(ProjectRecord record) {
676683
*/
677684
newCode = currentCode;
678685

679-
if (record.getType() == ProjectType.SPIN) {
680-
newCode = fixSpinProjectBlocks(newCode);
686+
//if (record.getType() == ProjectType.SPIN) {
687+
// newCode = fixSpinProjectBlocks(newCode);
681688

682-
} else if (record.getType() == ProjectType.PROPC) {
683-
newCode = fixPropcProjectBlocks(newCode);
684-
}
689+
//} else if (record.getType() == ProjectType.PROPC) {
690+
newCode = fixPropcProjectBlocks(newCode, record.getType());
691+
//}
685692

686693
// Check for any difference from the original code
687694
if (!currentCode.equals(newCode)) {
@@ -716,7 +723,7 @@ private String fixSpinProjectBlocks(String newCode) {
716723
return newCode;
717724
}
718725

719-
private String fixPropcProjectBlocks(String newCode) {
726+
private String fixPropcProjectBlocks(String newCode, ProjectType projType) {
720727
LOG.info("Looking for depricated PropC blocks.");
721728

722729
newCode = newCode.replaceAll("field name=\"OP\">ADD</field",
@@ -775,11 +782,91 @@ private String fixPropcProjectBlocks(String newCode) {
775782

776783
newCode = newCode.replaceAll("block type=\"logic_boolean_negate\"",
777784
"block type=\"logic_negate\"");
785+
786+
newCode = newCode.replaceAll("_000 / ", "000 / ");
778787

779788
// Fix a small issue with calling the wrong project type.
780789
newCode = newCode.replaceAll("block type=\"spin_integer\"",
781790
"block type=\"math_number\"");
791+
792+
if (projType == ProjectType.SPIN) {
793+
// Change all math number blocks to the same kind
794+
newCode = newCode.replaceAll("block type=\"math_int_angle\"",
795+
"block type=\"math_number\"");
796+
newCode = newCode.replaceAll("block type=\"math_integer\"",
797+
"block type=\"math_number\"");
798+
newCode = newCode.replaceAll("block type=\"scribbler_random_number\"",
799+
"block type=\"math_random\"");
800+
newCode = newCode.replaceAll("field name=\"INT_VALUE\"",
801+
"field name=\"NUM\"");
802+
newCode = newCode.replaceAll("field name=\"ANGLE_VALUE\"",
803+
"field name=\"NUM\"");
804+
805+
newCode = newCode.replaceAll("block type=\"digital_input\"",
806+
"block type=\"check_pin\"");
807+
newCode = newCode.replaceAll("block type=\"digital_output\"",
808+
"block type=\"make_pin\"");
809+
newCode = newCode.replaceAll("block type=\"scribbler_servo\"",
810+
"block type=\"servo_move\"");
811+
newCode = newCode.replaceAll("field name=\"SERVO_PIN\"",
812+
"field name=\"PIN\"");
813+
newCode = newCode.replaceAll("field name=\"SERVO_ANGLE\"",
814+
"field name=\"ANGLE\"");
815+
newCode = newCode.replaceAll("<block type=\"serial_",
816+
"<block type=\"scribbler_serial_");
817+
newCode = newCode.replaceAll("field name=\"TIMESCALE\">1000<",
818+
"field name=\"TIMESCALE\">Z1<");
819+
newCode = newCode.replaceAll("field name=\"TIMESCALE\">1<",
820+
"field name=\"TIMESCALE\">Z1000<");
821+
newCode = newCode.replaceAll("field name=\"TIMESCALE\">10<",
822+
"field name=\"TIMESCALE\">100<");
823+
newCode = newCode.replaceAll("field name=\"TIMESCALE\">Z",
824+
"field name=\"TIMESCALE\">");
825+
826+
newCode = newCode.replaceAll("Scribbler#CS","256");
827+
newCode = newCode.replaceAll("Scribbler#NL","10");
828+
newCode = newCode.replaceAll("Scribbler#LF","13");
829+
newCode = newCode.replaceAll("Scribbler#BS","127");
830+
831+
newCode = newCode.replaceAll("block type=\"scribbler_loop\"",
832+
"block type=\"controls_repeat\"");
833+
newCode = newCode.replaceAll("statement name=\"LOOP\"",
834+
"statement name=\"DO\"");
835+
//newCode = newCode.replaceAll("<block type=\"scribbler_loop\" id=(.*)><statement name=\"LOOP\">",
836+
//"<block type=\"controls_repeat\" id=$1><mutation type=\"FOREVER\"></mutation><field name=\"TYPE\">FOREVER</field><statement name=\"DO\">");
837+
newCode = newCode.replaceAll("<block type=\"scribbler_limited_loop\" id=(.*)><field name=\"LOOP_COUNT\">(.*)</field><statement name=\"LOOP\">",
838+
"<block type=\"controls_repeat\" id=$1><mutation type=\"TIMES\"></mutation><field name=\"TYPE\">TIMES</field><value name=\"TIMES\"><block type=\"math_number\" id=\"" + randomString(20) + "\"><field name=\"NUM\">$2</field></block></value><statement name=\"DO\">");
782839

840+
/*
841+
// These aren't working consistently - so the fallback to to leave the old blocks alone,
842+
// Replace old "simple" s3 blocks with equavalent block combinations
843+
844+
newCode = newCode.replaceAll("scribbler_if_line\" id=(.*)><mutation state=\"(.*)\"></mutation><field name=\"LINE_CONDITION\">(.*)</field><field name=\"LINE_POSITION\">(.*)</field><field name=\"LINE_COLOR\">(.*)</field><statement name=\"IF_LINE",
845+
"controls_if\" id=$1><value name=\"IF0\"><block type=\"scribbler_simple_line\" id=\"" + randomString(20) + "\"><mutation state=\"$2\"></mutation><field name=\"LINE_CONDITION\">$3</field><field name=\"LINE_POSITION\">$4</field><field name=\"LINE_COLOR\">$5</field></block></value><statement name=\"DO0");
846+
847+
// Not sure if I need non-mutation replacers - if not included, they will likely get cleaned on the second save (first one adds them, second one replaces)
848+
//newCode = newCode.replaceAll("scribbler_if_obstacle\" id=(.*)><field name=\"OBSTACLE_CONDITION\">(.*)</field><field name=\"OBSTACLE_POSITION\">(.*)</field><statement name=\"IF_OBSTACLE",
849+
// "controls_if\" id=$1><value name=\"IF0\"><block type=\"scribbler_simple_obstacle\" id=\"" + randomString(20) + "\"><field name=\"OBSTACLE_CONDITION\">$2</field><field name=\"OBSTACLE_POSITION\">$3</field></block></value><statement name=\"DO0");
850+
851+
newCode = newCode.replaceAll("scribbler_if_obstacle\" id=(.*)><mutation state=\"(.*)\"></mutation><field name=\"OBSTACLE_CONDITION\">(.*)</field><field name=\"OBSTACLE_POSITION\">(.*)</field><statement name=\"IF_OBSTACLE",
852+
"controls_if\" id=$1><value name=\"IF0\"><block type=\"scribbler_simple_obstacle\" id=\"" + randomString(20) + "\"><mutation state=\"$2\"></mutation><field name=\"OBSTACLE_CONDITION\">$3</field><field name=\"OBSTACLE_POSITION\">$4</field></block></value><statement name=\"DO0");
853+
854+
newCode = newCode.replaceAll("<field name=\"OBSTACLE_SENSOR_CHOICE\">RIGHT</field>",
855+
"<mutation state=\"IS\"></mutation><field name=\"OBSTACLE_CONDITION\">IS</field><field name=\"OBSTACLE_POSITION\">RIGHT</field>");
856+
newCode = newCode.replaceAll("<field name=\"OBSTACLE_SENSOR_CHOICE\">LEFT</field>",
857+
"<mutation state=\"IS\"></mutation><field name=\"OBSTACLE_CONDITION\">IS</field><field name=\"OBSTACLE_POSITION\">LEFT</field>");
858+
newCode = newCode.replaceAll("<field name=\"OBSTACLE_SENSOR_CHOICE\">&amp;&amp;</field>",
859+
"<mutation state=\"IS\"></mutation><field name=\"OBSTACLE_CONDITION\">IS</field><field name=\"OBSTACLE_POSITION\">CENTER</field>");
860+
newCode = newCode.replaceAll("<field name=\"OBSTACLE_SENSOR_CHOICE\">\\|\\|</field>",
861+
"<mutation state=\"IS\"></mutation><field name=\"OBSTACLE_CONDITION\">IS</field><field name=\"OBSTACLE_POSITION\">DETECTED</field>");
862+
newCode = newCode.replaceAll("<block type=\"obstacle_sensor\"",
863+
"<block type=\"scribbler_simple_obstacle\"");
864+
865+
newCode = newCode.replaceAll("scribbler_if_light\" id=(.*)><mutation state=\"(.*)\"></mutation><field name=\"LIGHT_CONDITION\">(.*)</field><field name=\"LIGHT_POSITION\">(.*)</field><statement name=\"IF_LIGHT",
866+
"controls_if\" id=$1><value name=\"IF0\"><block type=\"scribbler_simple_light\" id=\"" + randomString(20) + "\"><mutation state=\"$2\"></mutation><field name=\"LIGHT_CONDITION\">$3</field><field name=\"LIGHT_POSITION\">$4</field></block></value><statement name=\"DO0");
867+
*/
868+
}
869+
783870
// Replace the Robot init block with two blocks, need to generate unique 20-digit blockID:
784871
newCode = newCode.replaceAll("</field><field name=\"RAMPING\">",
785872
"</field></block><block type=\"ab_drive_ramping\" id=\"" + randomString(20) + "\"><field name=\"RAMPING\">");

0 commit comments

Comments
 (0)