Skip to content

Commit

Permalink
ALS-7882: Checkmarx related cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Dec 6, 2024
1 parent 5365a09 commit 4bc56c4
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,29 @@ public void put(K key, V value) {
index.put(key, recordIndex);
}

public void load(Iterable<V> values, Function<V, K> mapper) throws IOException {
public void load(Iterable<V> values, Function<V, K> mapper) {
//make sure we start fresh
if(this.storageFile.exists()) {
this.storageFile.delete();
}
this.storage = new RandomAccessFile(storageFile, "rw");
for(V value : values) {
put(mapper.apply(value), value);
}
this.storage.close();
complete();
}
try (RandomAccessFile storage = new RandomAccessFile(storageFile, "rw");) {
this.storage = storage;
for(V value : values) {
put(mapper.apply(value), value);
}
complete();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public void open() throws FileNotFoundException {
this.storage = new RandomAccessFile(this.storageFile, "rwd");
}
public void open() {
try {
this.storage = new RandomAccessFile(this.storageFile, "rwd");
} catch (FileNotFoundException e) {
throw new UncheckedIOException(e);
}
}

public void complete() {
this.completed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ public FileBackedJavaIndexedStorage(Class<K> keyClass, Class<V> valueClass, File

protected ByteArrayOutputStream writeObject(V value) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(out));
oos.writeObject(value);
oos.flush();
oos.close();
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(gzipOutputStream)) {
oos.writeObject(value);
oos.flush();
}
return out;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ protected ByteArrayOutputStream writeObject(V value) throws IOException {
}

protected V readObject(byte[] buffer) {
try {
return objectMapper.readValue(new GZIPInputStream(new ByteArrayInputStream(buffer)), getTypeReference());
try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(buffer))) {
return objectMapper.readValue(gzipInputStream, getTypeReference());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public List<String> search(String term) {
return new ArrayList<String>();
}else {
return allValues.keys().stream().filter((value)->{
String lowerTerm = term.toLowerCase();
return value.toLowerCase().contains(lowerTerm);
String lowerTerm = term.toLowerCase(Locale.ENGLISH);
return value.toLowerCase(Locale.ENGLISH).contains(lowerTerm);
}).collect(Collectors.toList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap.KeySetView;
import java.util.concurrent.ConcurrentSkipListSet;
Expand All @@ -22,8 +23,8 @@ public List<String> search(String term) {
return new ArrayList<String>();
}else {
return allValues.keySet().stream().filter((value)->{
String lowerTerm = term.toLowerCase();
return value.toLowerCase().contains(lowerTerm);
String lowerTerm = term.toLowerCase(Locale.ENGLISH);
return value.toLowerCase(Locale.ENGLISH).contains(lowerTerm);
}).collect(Collectors.toList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ public void setVariantSpecIndex(String[] variantSpecIndex) {
}

public static VariantStore readInstance(String genomicDataDirectory) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream(genomicDataDirectory + VARIANT_STORE_JAVABIN_FILENAME)));
VariantStore variantStore = (VariantStore) ois.readObject();
ois.close();
variantStore.getVariantMaskStorage().values().forEach(store -> {
store.updateStorageDirectory(new File(genomicDataDirectory));
});
variantStore.open();
variantStore.setVariantSpecIndex(loadVariantIndexFromFile(genomicDataDirectory));
return variantStore;
try (GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(genomicDataDirectory + VARIANT_STORE_JAVABIN_FILENAME));
ObjectInputStream ois = new ObjectInputStream(gzipInputStream)) {
VariantStore variantStore = (VariantStore) ois.readObject();
ois.close();
variantStore.getVariantMaskStorage().values().forEach(store -> {
store.updateStorageDirectory(new File(genomicDataDirectory));
});
variantStore.open();
variantStore.setVariantSpecIndex(loadVariantIndexFromFile(genomicDataDirectory));
return variantStore;
}
}

public void writeInstance(String genomicDirectory) {
Expand Down Expand Up @@ -125,11 +127,7 @@ public List<VariableVariantMasks> getMasksForDbSnpSpec(String variant) {
public void open() {
variantMaskStorage.values().stream().forEach((fbbis -> {
if (fbbis != null) {
try {
fbbis.open();
} catch (FileNotFoundException e) {
throw new UncheckedIOException(e);
}
fbbis.open();
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
//load each into observation store
for(String filename : inputFiles) {
log.info("Loading file " + filename);
if(filename.toLowerCase().endsWith("sql")) {
if(filename.toLowerCase(Locale.ENGLISH).endsWith("sql")) {
loadSqlFile(filename);
} else if(filename.toLowerCase().endsWith("csv")){
} else if(filename.toLowerCase(Locale.ENGLISH).endsWith("csv")){
loadCsvFile(filename);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,9 @@ public PhenoCube<?> load(String key) throws Exception {
byte[] buffer = new byte[length];
allObservationsStore.read(buffer);
allObservationsStore.close();
ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(Crypto.decryptData(buffer)));
PhenoCube<?> ret = (PhenoCube<?>)inStream.readObject();
inStream.close();
return ret;
try (ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(Crypto.decryptData(buffer)))) {
return (PhenoCube<?>)inStream.readObject();
}
}else {
log.warn("ColumnMeta not found for : [{}]", key);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public SearchResults search(@RequestBody QueryRequest searchJson) {

// Phenotype Values
Object phenotypeResults = searchJson.getQuery() != null ? allColumns.stream().filter((entry) -> {
String lowerCaseSearchTerm = searchJson.getQuery().toString().toLowerCase();
return entry.getKey().toLowerCase().contains(lowerCaseSearchTerm)
String lowerCaseSearchTerm = searchJson.getQuery().toString().toLowerCase(Locale.ENGLISH);
return entry.getKey().toLowerCase(Locale.ENGLISH).contains(lowerCaseSearchTerm)
|| (entry.getValue().isCategorical() && entry.getValue().getCategoryValues().stream()
.map(String::toLowerCase).collect(Collectors.toList()).contains(lowerCaseSearchTerm));
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue)) : allColumns;
Expand All @@ -154,10 +154,10 @@ public SearchResults search(@RequestBody QueryRequest searchJson) {
abstractProcessor.getInfoStoreMeta().stream().forEach(infoColumnMeta -> {
//FileBackedByteIndexedInfoStore store = abstractProcessor.getInfoStore(infoColumn);
String query = searchJson.getQuery().toString();
String lowerCase = query.toLowerCase();
String lowerCase = query.toLowerCase(Locale.ENGLISH);
boolean storeIsNumeric = infoColumnMeta.continuous();
if (infoColumnMeta.description().toLowerCase().contains(lowerCase)
|| infoColumnMeta.key().toLowerCase().contains(lowerCase)) {
if (infoColumnMeta.description().toLowerCase(Locale.ENGLISH).contains(lowerCase)
|| infoColumnMeta.key().toLowerCase(Locale.ENGLISH).contains(lowerCase)) {
infoResults.put(infoColumnMeta.key(),
ImmutableMap.of("description", infoColumnMeta.description(), "values",
storeIsNumeric ? new ArrayList<String>() : abstractProcessor.searchInfoConceptValues(infoColumnMeta.key(), ""), "continuous",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public enum BuildIntegrationTestEnvironment {
VariantMetadataLoader.main(new String[] {"./src/test/resources/test_vcfIndex.tsv", binFile, "target/VariantMetadataStorage.bin"});
VariantStore variantStore = VariantStore.readInstance(STORAGE_DIR);
BucketIndexBySample bucketIndexBySample = new BucketIndexBySample(variantStore, STORAGE_DIR);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}

Expand Down

0 comments on commit 4bc56c4

Please sign in to comment.