Skip to content

Commit 559f41f

Browse files
Auto-refactor lint cleanup (#197)
SequencedCollections: get(0) -> getFirst(), etc Add missing @NotNull/@nullable Simplify test assertions Map operation simplification Remove redundant throws clause Switch to parameterized log message C-style array -> Java-style array declaration Delete overridden methods identical to parent Switch statement -> enhanced switch statement Remove redundant imports
1 parent fd0a34c commit 559f41f

14 files changed

Lines changed: 46 additions & 58 deletions

File tree

OConnorExperiments/src/org/labkey/oconnorexperiments/OConnorExperimentsController.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import org.labkey.api.util.URLHelper;
6161
import org.labkey.api.view.ActionURL;
6262
import org.labkey.api.view.HtmlView;
63-
import org.labkey.api.view.HttpView;
6463
import org.labkey.api.view.JspView;
6564
import org.labkey.api.view.NavTree;
6665
import org.labkey.api.view.NotFoundException;
@@ -85,6 +84,7 @@ public class OConnorExperimentsController extends SpringActionController
8584
{
8685
public static final String EXPERIMENTS = "Experiments";
8786
private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(OConnorExperimentsController.class);
87+
public static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger(OConnorExperimentsController.class);
8888

8989
public OConnorExperimentsController()
9090
{
@@ -110,7 +110,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
110110
{
111111
if (form.isFinalMigration())
112112
{
113-
LogManager.getLogger(OConnorExperimentsController.class).info("Final migration to be performed - file move events will be performed (irreversible).");
113+
LOG.info("Final migration to be performed - file move events will be performed (irreversible).");
114114
}
115115

116116
// global containers
@@ -160,7 +160,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
160160
newType.put("Name", currentType);
161161
newType.put("Enabled", true);
162162
List<Map<String, Object>> newTypes = typeUpdateService.insertRows(getUser(), getContainer(), Collections.singletonList(newType), new BatchValidationException(), null, null);
163-
targetType = (Integer) newTypes.get(0).get("RowId");
163+
targetType = (Integer) newTypes.getFirst().get("RowId");
164164
}
165165
}
166166

@@ -178,7 +178,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
178178
User user = UserManager.getUserByDisplayName((String) databaseMap.get("initials"));
179179
if (user == null)
180180
{
181-
LogManager.getLogger(OConnorExperimentsController.class).warn("User '" + databaseMap.get("initials") + "' not found for experiment " + databaseMap.get("expnumber"));
181+
LOG.warn("User '{}' not found for experiment {}", databaseMap.get("initials"), databaseMap.get("expnumber"));
182182
effectiveUser = getUser();
183183
}
184184
else
@@ -188,7 +188,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
188188
}
189189

190190
databaseMap.put("EffectiveUser", effectiveUser);
191-
LogManager.getLogger(OConnorExperimentsController.class).info("Insert on experiment " + databaseMap.get("expnumber"));
191+
LOG.info("Insert on experiment {}", databaseMap.get("expnumber"));
192192
List<Map<String, Object>> updateResult;
193193
try
194194
{
@@ -197,18 +197,18 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
197197
catch (Exception e)
198198
{
199199
// log the error to the logfile and continue
200-
LogManager.getLogger(OConnorExperimentsController.class).warn("Error inserting expNumber " + expNumber + " with exception " + e.getMessage());
200+
LOG.warn("Error inserting expNumber {} with exception {}", expNumber, e.getMessage());
201201
continue;
202202
}
203203
if (batchErrors.hasErrors())
204204
{
205205
// throw batchErrors.getLastRowError();
206-
LogManager.getLogger(OConnorExperimentsController.class).warn("Error inserting expNumber " + expNumber);
206+
LOG.warn("Error inserting expNumber {}", expNumber);
207207
}
208208

209-
Container workbookContainer = ContainerManager.getForId((String)updateResult.get(0).get("EntityId"));
209+
Container workbookContainer = ContainerManager.getForId((String)updateResult.getFirst().get("EntityId"));
210210
databaseMap.put("ContainerObj", workbookContainer);
211-
databaseMap.put("ContainerStr", updateResult.get(0).get("EntityId"));
211+
databaseMap.put("ContainerStr", updateResult.getFirst().get("EntityId"));
212212

213213
// We don't want these fields to be spoofable through the QueryUpdateService (and hence the Client API),
214214
// so preserve the value from the source data manually
@@ -218,7 +218,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
218218
// Move files
219219
File sourceFile = new File(fileContentService.getFileRoot(sourceContainer).getPath() + File.separator + "@files", databaseMap.get("expnumber").toString());
220220
File targetDir = new File(fileContentService.getFileRoot(targetContainer).getPath() + File.separator + databaseMap.get("expnumber").toString() + File.separator + "@files");
221-
LogManager.getLogger(OConnorExperimentsController.class).info("Copy from file '" + sourceFile + "' to directory '" + targetDir +"'" );
221+
LOG.info("Copy from file '{}' to directory '{}'", sourceFile, targetDir);
222222
if (sourceFile.exists())
223223
{
224224
FileUtils.copyDirectory(sourceFile, targetDir);
@@ -260,7 +260,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
260260
}
261261
else
262262
{
263-
LogManager.getLogger(OConnorExperimentsController.class).warn("child container not found: " + parents[i] + " for experiment " + databaseMap.get("expnumber") + " with username " + databaseMap.get("initials"));
263+
LOG.warn("child container not found: {} for experiment {} with username {}", parents[i], databaseMap.get("expnumber"), databaseMap.get("initials"));
264264
}
265265
}
266266
}
@@ -269,16 +269,15 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
269269
map.put("ParentExperiments", parentsEntityId.toArray(new String[0]));
270270

271271
// workaround, pass user, container - databaseMap.get("Container"), singleton list
272-
LogManager.getLogger(OConnorExperimentsController.class).info("Update rows on experiment " + databaseMap.get("expnumber"));
272+
LOG.info("Update rows on experiment {}", databaseMap.get("expnumber"));
273273
try
274274
{
275275
queryUpdateService.updateRows(getUser(), targetContainer, Collections.singletonList(map), null, null, null);
276276
}
277277
catch (Exception e)
278278
{
279279
// log the error to the logfile and continue
280-
LogManager.getLogger(OConnorExperimentsController.class).warn("Error updating parent experiments for experiment number " + expNumber + " with exception " + e.getMessage());
281-
continue;
280+
LOG.warn("Error updating parent experiments for experiment number {} with exception {}", expNumber, e.getMessage());
282281
}
283282

284283
}
@@ -304,7 +303,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
304303
Container workbookContainer = targetContainer.getChild(databaseMap.get("expnumber").toString());
305304
if (workbookContainer == null)
306305
{
307-
LogManager.getLogger(OConnorExperimentsController.class).warn("Updating wiki, container not found: " + databaseMap.get("expnumber"));
306+
LOG.warn("Updating wiki, container not found: {}", databaseMap.get("expnumber"));
308307
}
309308
else
310309
{
@@ -320,14 +319,14 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
320319
catch (Exception e)
321320
{
322321
// log the error to the logfile and continue
323-
LogManager.getLogger(OConnorExperimentsController.class).warn("Error wiki for experiment number " + expNumber + " with exception " + e.getMessage());
322+
LOG.warn("Error wiki for experiment number {} with exception {}", expNumber, e.getMessage());
324323
continue;
325324
}
326325
finally
327326
{
328327
in.closeInputStream();
329328
}
330-
LogManager.getLogger(OConnorExperimentsController.class).info("Inserting wiki for experiment " + databaseMap.get("expnumber"));
329+
LOG.info("Inserting wiki for experiment {}", databaseMap.get("expnumber"));
331330
}
332331
}
333332
}
@@ -439,7 +438,7 @@ public boolean handlePost(Object o, BindException errors) throws Exception
439438

440439
if (result != null && !result.isEmpty())
441440
{
442-
String entityId = (String)result.get(0).get("Container");
441+
String entityId = (String)result.getFirst().get("Container");
443442
newExperiment = ContainerManager.getForId(entityId);
444443
return true;
445444
}
@@ -464,7 +463,7 @@ public ApiResponse execute(Object o, BindException errors) throws Exception
464463
ApiSimpleResponse resp = new ApiSimpleResponse();
465464
if (result != null && !result.isEmpty())
466465
{
467-
Map<String, Object> exp = result.get(0);
466+
Map<String, Object> exp = result.getFirst();
468467

469468
resp.put("success", true);
470469
resp.put("experiment", exp);

OConnorExperiments/src/org/labkey/oconnorexperiments/query/OConnorExperimentsUserSchema.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.labkey.oconnorexperiments.query;
1717

1818
import org.jetbrains.annotations.Nullable;
19+
import org.jetbrains.annotations.NotNull;
1920
import org.labkey.api.collections.Sets;
2021
import org.labkey.api.data.Container;
2122
import org.labkey.api.data.ContainerFilter;
@@ -139,7 +140,7 @@ private TableInfo createParentExperimentsTable(String name, ContainerFilter cf)
139140
}
140141

141142
@Override
142-
public QueryView createView(ViewContext context, QuerySettings settings, BindException errors)
143+
public @NotNull QueryView createView(ViewContext context, QuerySettings settings, BindException errors)
143144
{
144145
if (OConnorExperimentsController.EXPERIMENTS.equalsIgnoreCase(settings.getQueryName()))
145146
{

genotyping/src/org/labkey/genotyping/GenotypingController.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
import java.math.BigInteger;
126126
import java.net.MalformedURLException;
127127
import java.net.URL;
128-
import java.nio.file.Path;
129128
import java.nio.file.Paths;
130129
import java.sql.ResultSet;
131130
import java.sql.SQLException;
@@ -381,7 +380,7 @@ public boolean handlePost(ReturnUrlForm returnUrlForm, BindException errors)
381380
{
382381
long startTime = System.currentTimeMillis();
383382
SequenceManager.get().loadSequences(getContainer(), getUser());
384-
LOG.info(DateUtil.formatDuration(System.currentTimeMillis() - startTime) + " to load sequences");
383+
LOG.info("{} to load sequences", DateUtil.formatDuration(System.currentTimeMillis() - startTime));
385384

386385
return true;
387386
}
@@ -1299,7 +1298,7 @@ public void validateForm(ImportAnalysisForm form, Errors errors)
12991298
@Override
13001299
public Object execute(ImportAnalysisForm form, BindException errors) throws Exception
13011300
{
1302-
LOG.info("Galaxy signaled the completion of analysis " + form.getAnalysis());
1301+
LOG.info("Galaxy signaled the completion of analysis {}", form.getAnalysis());
13031302
String message;
13041303

13051304
// Send any exceptions back to the Galaxy task so it can log it as well.
@@ -1337,7 +1336,7 @@ public Object execute(ImportAnalysisForm form, BindException errors) throws Exce
13371336
message = FAILURE_PREFACE + "Analysis path doesn't match import path (see system log for more details)";
13381337

13391338
// But log more detail to the administrator so they're aware
1340-
LOG.error(FAILURE_PREFACE + fnf.getMessage());
1339+
LOG.error("{}{}", FAILURE_PREFACE, fnf.getMessage());
13411340
}
13421341
catch (Exception e)
13431342
{
@@ -1657,11 +1656,6 @@ public static class RunForm extends QueryExportForm
16571656
public enum Platforms{
16581657

16591658
LS454 {
1660-
@Override
1661-
public String getTableName()
1662-
{
1663-
return TableType.Reads.toString();
1664-
}
16651659
},
16661660
ILLUMINA {
16671661
@Override

genotyping/src/org/labkey/genotyping/GenotypingQuerySchema.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import org.apache.logging.log4j.Logger;
1919
import org.apache.logging.log4j.LogManager;
20-
import org.jetbrains.annotations.NotNull;
2120
import org.jetbrains.annotations.Nullable;
21+
import org.jetbrains.annotations.NotNull;
2222
import org.labkey.api.collections.CaseInsensitiveHashSet;
2323
import org.labkey.api.collections.Sets;
2424
import org.labkey.api.data.*;
@@ -952,7 +952,7 @@ public Set<String> getTableNames()
952952
}
953953

954954
@Override
955-
public QueryView createView(ViewContext context, QuerySettings settings, BindException errors)
955+
public @NotNull QueryView createView(ViewContext context, QuerySettings settings, BindException errors)
956956
{
957957
TableType type = findTableType(settings.getQueryName());
958958
return type == null ? super.createView(context, settings, errors) : type.createQueryView(context, settings, errors, this);

genotyping/src/org/labkey/genotyping/HaplotypeAssayProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.labkey.api.view.NavTree;
5656
import org.labkey.api.view.ViewContext;
5757

58-
import java.io.File;
5958
import java.util.Collections;
6059
import java.util.HashSet;
6160
import java.util.LinkedHashMap;

genotyping/src/org/labkey/genotyping/HaplotypeDataHandler.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.labkey.api.view.ViewBackgroundInfo;
5050
import org.labkey.vfs.FileLike;
5151

52-
import java.io.File;
5352
import java.io.IOException;
5453
import java.util.ArrayList;
5554
import java.util.Collections;
@@ -75,7 +74,7 @@ public void importFile(@NotNull ExpData data, @NotNull FileLike dataFile, @NotNu
7574
{
7675
if (!dataFile.exists())
7776
{
78-
log.warn("Could not find file " + dataFile + " on disk for data with LSID " + data.getLSID());
77+
log.warn("Could not find file {} on disk for data with LSID {}", dataFile, data.getLSID());
7978
return;
8079
}
8180
ExpRun expRun = data.getRun();
@@ -226,7 +225,7 @@ private Map<String, Integer> ensureAnimalIds(Map<String, String> ids, Map<String
226225
{
227226
throw new ExperimentException("Unable to insert a row into the Animal table for " + animalKey);
228227
}
229-
row.put("rowid", insertedRow.get(0).get("RowId"));
228+
row.put("rowid", insertedRow.getFirst().get("RowId"));
230229
}
231230
}
232231

@@ -299,7 +298,7 @@ private Map<HaplotypeIdentifier, Integer> ensureHaplotypeNames(List<HaplotypeIde
299298
{
300299
throw new ExperimentException("Unable to insert a row into the Haplotype table for " + haplotypeName);
301300
}
302-
row.put("rowid", insertedRow.get(0).get("RowId"));
301+
row.put("rowid", insertedRow.getFirst().get("RowId"));
303302
}
304303
}
305304

@@ -462,7 +461,7 @@ private void throwFirstError(BatchValidationException errors) throws ExperimentE
462461
{
463462
if (errors.hasErrors())
464463
{
465-
throw new ExperimentException(errors.getRowErrors().get(0));
464+
throw new ExperimentException(errors.getRowErrors().getFirst());
466465
}
467466
}
468467

genotyping/src/org/labkey/genotyping/IlluminaFastqParser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public Map<Pair<Integer, Integer>, FileInfo> parseFastqFiles(PipelineJob job) th
125125
long length = f.length();
126126
if (length == 0)
127127
{
128-
_logger.info("File " + f.getName() + " has no content to parse.");
128+
_logger.info("File {} has no content to parse.", f.getName());
129129
continue;
130130
}
131131

@@ -138,10 +138,10 @@ public Map<Pair<Integer, Integer>, FileInfo> parseFastqFiles(PipelineJob job) th
138138
// good way to check if a file is truly local
139139
tempFile = FileUtil.createTempFile(FileUtil.getBaseName(f) + ".", "." + FileUtil.getExtension(f));
140140
tempFile.deleteOnExit();
141-
_logger.debug("Copying to temp file " + tempFile + ", size is " + f.length() + " bytes");
141+
_logger.debug("Copying to temp file {}, size is {} bytes", tempFile, f.length());
142142
FileUtil.copyFile(f, tempFile);
143143

144-
_logger.info("Beginning to parse file: " + f.getName());
144+
_logger.info("Beginning to parse file: {}", f.getName());
145145
try (FastqReader reader = new FastqReader(tempFile))
146146
{
147147
File targetDir = f.getParentFile();
@@ -197,7 +197,7 @@ public Map<Pair<Integer, Integer>, FileInfo> parseFastqFiles(PipelineJob job) th
197197
}
198198
else if (reader.getLineNumber() == 1 && totalReads == 0 && !f.getName().contains("null"))//empty file
199199
{
200-
_logger.warn("File " + fileName + " has no content to parse.");
200+
_logger.warn("File {} has no content to parse.", fileName);
201201
reader.close();
202202
continue;
203203
}
@@ -223,7 +223,7 @@ else if (reader.getLineNumber() == 1 && totalReads == 0 && !f.getName().contains
223223
Pair<Integer, Integer> key = Pair.of(sampleId, pairNumber);
224224
_fileInfo.put(key, new FileInfo(newFile, totalReads));
225225

226-
_logger.info("Finished parsing file: " + f.getName());
226+
_logger.info("Finished parsing file: {}", f.getName());
227227
}
228228
}
229229
}
@@ -252,7 +252,7 @@ else if (reader.getLineNumber() == 1 && totalReads == 0 && !f.getName().contains
252252
File oldFile = entry.getKey();
253253
File newFile = entry.getValue();
254254
FileUtils.moveFile(oldFile, newFile);
255-
_logger.info("Moved file " + oldFile.getName() + " to " + newFile.getName() );
255+
_logger.info("Moved file {} to {}", oldFile.getName(), newFile.getName());
256256
}
257257
}
258258
catch (IOException e)
@@ -317,7 +317,7 @@ private void checkForDuplicateTargets(Map<File, File> filesToMove) throws Pipeli
317317
if (sourceFiles.size() > 1)
318318
{
319319
error = true;
320-
_logger.error("Multiple input files map to the target file " + targetFile + " - they are: " + sourceFiles);
320+
_logger.error("Multiple input files map to the target file {} - they are: {}", targetFile, sourceFiles);
321321
}
322322
}
323323
if (error)

0 commit comments

Comments
 (0)