Skip to content

Commit 879fa77

Browse files
authored
Migrate to new JSONObject/JSONArray library (#202)
1 parent b70afc4 commit 879fa77

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/SequenceAnalysisController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,17 +2075,17 @@ public static enum TYPE
20752075

20762076
public String getJobName()
20772077
{
2078-
return getJsonObject().optString("jobName");
2078+
return getNewJsonObject().optString("jobName");
20792079
}
20802080

20812081
public String getDescription()
20822082
{
2083-
return getJsonObject().optString("description");
2083+
return getNewJsonObject().optString("description");
20842084
}
20852085

20862086
public TYPE getType()
20872087
{
2088-
return !getJsonObject().containsKey("type") ? null : TYPE.valueOf(getJsonObject().getString("type"));
2088+
return !getNewJsonObject().has("type") ? null : TYPE.valueOf(getNewJsonObject().getString("type"));
20892089
}
20902090

20912091
public JSONObject getJobParameters()

jbrowse/src/org/labkey/jbrowse/JBrowseController.java

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -441,41 +441,36 @@ public ApiResponse execute(SimpleApiJsonForm form, BindException errors)
441441

442442
final Map<Container, List<Map<String, Object>>> rows = new HashMap<>();
443443
TableSelector ts = new TableSelector(JBrowseSchema.getInstance().getTable(JBrowseSchema.TABLE_JSONFILES), PageFlowUtil.set("objectid", "container", "trackJson"), new SimpleFilter(FieldKey.fromString("objectid"), objectIds, CompareType.IN), null);
444-
ts.forEachResults(new Selector.ForEachBlock<Results>()
445-
{
446-
@Override
447-
public void exec(Results rs) throws SQLException, StopIteratingException
444+
ts.forEachResults(rs -> {
445+
Container c = ContainerManager.getForId(rs.getString(FieldKey.fromString("container")));
446+
if (!c.hasPermission(getUser(), UpdatePermission.class))
448447
{
449-
Container c = ContainerManager.getForId(rs.getString(FieldKey.fromString("container")));
450-
if (!c.hasPermission(getUser(), UpdatePermission.class))
451-
{
452-
throw new UnauthorizedException("User does not have permission to update records in the folder: " + c.getPath());
453-
}
448+
throw new UnauthorizedException("User does not have permission to update records in the folder: " + c.getPath());
449+
}
454450

455-
JSONObject json = rs.getString("trackJson") == null ? new JSONObject() : new JSONObject(rs.getString("trackJson"));
456-
for (String key : attributes.keySet())
451+
JSONObject json = rs.getString("trackJson") == null ? new JSONObject() : new JSONObject(rs.getString("trackJson"));
452+
for (String key : attributes.keySet())
453+
{
454+
if (StringUtils.trimToNull(attributes.getString(key)) == null)
457455
{
458-
if (StringUtils.trimToNull(attributes.getString(key)) == null)
459-
{
460-
json.remove(key);
461-
}
462-
else
463-
{
464-
json.put(key, attributes.get(key));
465-
}
456+
json.remove(key);
466457
}
467-
468-
if (!rows.containsKey(c))
458+
else
469459
{
470-
rows.put(c, new ArrayList<>());
460+
json.put(key, attributes.get(key));
471461
}
462+
}
472463

473-
Map<String, Object> row = new CaseInsensitiveHashMap<>();
474-
row.put("objectid", rs.getString("objectid"));
475-
row.put("trackJson", json.isEmpty() ? null : json.toString());
476-
477-
rows.get(c).add(row);
464+
if (!rows.containsKey(c))
465+
{
466+
rows.put(c, new ArrayList<>());
478467
}
468+
469+
Map<String, Object> row = new CaseInsensitiveHashMap<>();
470+
row.put("objectid", rs.getString("objectid"));
471+
row.put("trackJson", json.isEmpty() ? null : json.toString());
472+
473+
rows.get(c).add(row);
479474
});
480475

481476
try (DbScope.Transaction transaction = DbScope.getLabKeyScope().ensureTransaction())

singlecell/src/org/labkey/singlecell/SingleCellController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private static void validateBarcodes(List<Map<String, Object>> readsetRows, Cont
345345

346346
private static List<Map<String, Object>> parseRows(SimpleApiJsonForm form, String propName, Container container) throws ApiUsageException
347347
{
348-
if (!form.getJsonObject().containsKey(propName))
348+
if (!form.getNewJsonObject().has(propName))
349349
{
350350
throw new ApiUsageException("Missing property: " + propName);
351351
}

0 commit comments

Comments
 (0)