From 8abc2863abc8020ff9f3ef6d75d32baaf56f7b73 Mon Sep 17 00:00:00 2001 From: Josh Eckels Date: Thu, 20 Mar 2025 13:12:31 -0700 Subject: [PATCH 1/3] Misc code cleanup - improve generics (#230) --- .../api/ldk/table/AbstractDataDefinedTable.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/LDK/api-src/org/labkey/api/ldk/table/AbstractDataDefinedTable.java b/LDK/api-src/org/labkey/api/ldk/table/AbstractDataDefinedTable.java index fe0cb3a8..a974a4d7 100644 --- a/LDK/api-src/org/labkey/api/ldk/table/AbstractDataDefinedTable.java +++ b/LDK/api-src/org/labkey/api/ldk/table/AbstractDataDefinedTable.java @@ -57,7 +57,7 @@ * Date: 4/2/13 * Time: 2:54 PM */ -abstract public class AbstractDataDefinedTable extends CustomPermissionsTable +abstract public class AbstractDataDefinedTable extends CustomPermissionsTable { protected String _pk; @@ -65,7 +65,7 @@ abstract public class AbstractDataDefinedTable extends CustomPermissionsTable protected String _filterValue; protected String _valueColumn; - public AbstractDataDefinedTable(UserSchema schema, SchemaTableInfo table, ContainerFilter cf, String filterColumn, String valueColumn, String tableName, String filterValue) + public AbstractDataDefinedTable(SchemaType schema, SchemaTableInfo table, ContainerFilter cf, String filterColumn, String valueColumn, String tableName, String filterValue) { super(schema, table, cf); _filterColumn = filterColumn; @@ -77,7 +77,7 @@ public AbstractDataDefinedTable(UserSchema schema, SchemaTableInfo table, Contai } @Override - public CustomPermissionsTable init() + public CustomPermissionsTable init() { super.init(); @@ -85,7 +85,7 @@ public CustomPermissionsTable init() addCondition(col, _filterValue); //enforce only showing rows from this category List pks = getRealTable().getPkColumnNames(); - assert pks.size() > 0; + assert !pks.isEmpty(); _pk = pks.get(0); var valueCol = getMutableColumn(_valueColumn); @@ -93,7 +93,7 @@ public CustomPermissionsTable init() valueCol.setKeyField(true); valueCol.setNullable(false); - getMutableColumn(_pk).setKeyField(false); + getMutableColumnOrThrow(_pk).setKeyField(false); ColumnInfo filterCol = getColumn(_filterColumn); assert filterCol != null; @@ -135,7 +135,7 @@ protected class UpdateService extends SimpleQueryUpdateService { private final ValuesManager _vm; - public UpdateService(SimpleUserSchema.SimpleTable ti) + public UpdateService(SimpleUserSchema.SimpleTable ti) { super(ti, ti.getRealTable()); @@ -217,8 +217,7 @@ public boolean testIfRowExists(String value) { boolean ret = _distinctValues.contains(value); - if (!_distinctValues.contains(value)) - _distinctValues.add(value); + _distinctValues.add(value); return ret; } From 07b249e28874cc9d865088c45f9857c9223891f2 Mon Sep 17 00:00:00 2001 From: bbimber Date: Wed, 2 Apr 2025 10:35:59 -0700 Subject: [PATCH 2/3] Make SQL select more specific (#237) (#238) --- .../schemas/dbscripts/postgresql/laboratory-12.305-12.306.sql | 2 +- .../schemas/dbscripts/sqlserver/laboratory-12.305-12.306.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/laboratory/resources/schemas/dbscripts/postgresql/laboratory-12.305-12.306.sql b/laboratory/resources/schemas/dbscripts/postgresql/laboratory-12.305-12.306.sql index df0e0a4b..880669e6 100644 --- a/laboratory/resources/schemas/dbscripts/postgresql/laboratory-12.305-12.306.sql +++ b/laboratory/resources/schemas/dbscripts/postgresql/laboratory-12.305-12.306.sql @@ -5,7 +5,7 @@ ALTER TABLE laboratory.species ADD createdby int; ALTER TABLE laboratory.species ADD modified timestamp; ALTER TABLE laboratory.species ADD modifiedby int; -UPDATE laboratory.species SET container = (SELECT entityid FROM core.containers WHERE name = 'Shared'); +UPDATE laboratory.species SET container = (SELECT entityid FROM core.containers c1 WHERE name = 'Shared' and (select parent from core.Containers c2 where c2.EntityId = c1.Parent) is null); ALTER TABLE laboratory.species DROP CONSTRAINT PK_species; ALTER TABLE laboratory.species ADD CONSTRAINT PK_species PRIMARY KEY (rowid); \ No newline at end of file diff --git a/laboratory/resources/schemas/dbscripts/sqlserver/laboratory-12.305-12.306.sql b/laboratory/resources/schemas/dbscripts/sqlserver/laboratory-12.305-12.306.sql index e64122d0..f149ac53 100644 --- a/laboratory/resources/schemas/dbscripts/sqlserver/laboratory-12.305-12.306.sql +++ b/laboratory/resources/schemas/dbscripts/sqlserver/laboratory-12.305-12.306.sql @@ -5,7 +5,7 @@ ALTER TABLE laboratory.species ADD createdby int; ALTER TABLE laboratory.species ADD modified datetime; ALTER TABLE laboratory.species ADD modifiedby int; GO -UPDATE laboratory.species SET container = (SELECT entityid FROM core.containers WHERE name = 'Shared'); +UPDATE laboratory.species SET container = (SELECT entityid FROM core.containers c1 WHERE name = 'Shared' and (select parent from core.Containers c2 where c2.EntityId = c1.Parent) is null); ALTER TABLE laboratory.species DROP CONSTRAINT PK_species; ALTER TABLE laboratory.species ADD CONSTRAINT PK_species PRIMARY KEY (rowid); \ No newline at end of file From 4ed505881f3b3aa25a28cb18df9acb95aa691ff9 Mon Sep 17 00:00:00 2001 From: labkey-danield Date: Thu, 1 May 2025 10:00:00 -0700 Subject: [PATCH 3/3] Backport test fix from develop. --- .../external/labModules/LabModulesTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java b/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java index 23cdbdf6..e31b1780 100644 --- a/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java +++ b/LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java @@ -16,12 +16,15 @@ package org.labkey.test.tests.external.labModules; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.labkey.api.util.DateUtil; import org.labkey.remoteapi.CommandException; import org.labkey.remoteapi.Connection; import org.labkey.remoteapi.collections.CaseInsensitiveHashMap; @@ -301,6 +304,9 @@ private void dateParseTest() throws ParseException String dateFormat3 = "MM/dd/yy"; checkDate("02/20/11", dateFormat3); checkDate("3/5/99", dateFormat3); + + String clientFormattedString = (String)executeScript("return Ext4.Date.format(LDK.ConvertUtils.parseDate('2024-01-01', 'c'), 'Y-m-d');"); + assertEquals("Incorrect date parsing", clientFormattedString, "2024-01-01"); } private void checkDate(String dateStr, String javaFormatStr) throws ParseException @@ -1415,6 +1421,7 @@ private void samplesTableTest() throws Exception columnLabels.add(getColumnLabel(srr, name)); } + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); List> rows = new ArrayList<>(); for (Map row : srr.getRows()) { @@ -1425,7 +1432,7 @@ private void samplesTableTest() throws Exception String val = row.get(name) == null ? "" : String.valueOf(row.get(name)); if (name.toLowerCase().contains("date")) { - val = StringUtils.isEmpty(val) ? "" : ExcelHelper.getDateTimeFormat().format(new Date(val)); + val = StringUtils.isEmpty(val) ? "" : dateFormat.format(Date.parse(val)); } target.add(val); @@ -1440,10 +1447,10 @@ private void samplesTableTest() throws Exception List> lines = ExcelHelper.getFirstNRows(sheet, 5); Assert.assertEquals(columnLabels, lines.get(0)); - Assert.assertEquals(rows.get(0), lines.get(1)); - Assert.assertEquals(rows.get(0), lines.get(2)); - Assert.assertEquals(rows.get(1), lines.get(3)); - Assert.assertEquals(rows.get(1), lines.get(4)); + Assert.assertEquals("Row did not match. ExcelHelper pattern: " + ExcelHelper.getDateTimeFormat().toPattern(), rows.get(0), lines.get(1)); + Assert.assertEquals("Row did not match. ExcelHelper pattern: " + ExcelHelper.getDateTimeFormat().toPattern(), rows.get(0), lines.get(2)); + Assert.assertEquals("Row did not match. ExcelHelper pattern: " + ExcelHelper.getDateTimeFormat().toPattern(), rows.get(1), lines.get(3)); + Assert.assertEquals("Row did not match. ExcelHelper pattern: " + ExcelHelper.getDateTimeFormat().toPattern(), rows.get(1), lines.get(4)); } refresh();