Skip to content

Commit

Permalink
refactor: Resolve some sonar and IntelliJ reported minor issues (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
ursjoss authored Jun 8, 2024
1 parent dc58c56 commit e64ee04
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ image:https://github.com/ursjoss/KRis/actions/workflows/codeql.yml/badge.svg?bra
KRis is a Kotlin implementation of RIS Format -- forked from fastlucas Java implementation https://github.com/fastluca/JRis[JRis].
KRis has the goal to give an easy way to parse RIS format stream and to build them.

From https://en.wikipedia.org/wiki/RIS_(file_format)[Wikipiedia]:
From https://en.wikipedia.org/wiki/RIS_(file_format)[Wikipedia]:

====
RIS is a standardized tag format developed by Research Information Systems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin

@Suppress("unused", "LackOfCohesionMethods")
@Suppress("LackOfCohesionMethods")
class CollectSarifPlugin : Plugin<Project> {

override fun apply(target: Project) {
Expand Down
4 changes: 2 additions & 2 deletions subprojects/kris-core/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ like writing to file or reading to file.

# Package ch.difty.kris

`KRis` is the object at the core of the KRis library. If offers a number of accessor methods
`KRis` is the object at the core of the KRis library. If provides a number of accessor methods
to Java Clients that offer to convert `String`s to `RisRecord`s or vice versa, in different
flavors of data input, non-blockingly using kotlin flows or RxJava observables or in a blocking
flavors of data input, non-blocking usage kotlin flows or RxJava observables or in a blocking
manner accepting lists.

`KrisExtensions` offers a number of handy extension functions to kotlin clients.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.reflect.KClass
* share the same value, resulting in either being sorted by tag name alphabetically
* or by a custom sort order specified by the caller.
*
* The class was composed from information available on
* The class was composed of information available on
* [Wikipedia](https://en.wikipedia.org/wiki/RIS_(file_format)).
*/
public enum class RisTag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ch.difty.kris.domain
/**
* Types of References - as used in [RisTag] `TY`.
*
* The class was composed from information available on
* The class was composed of information available on
* [Wikipedia](https://en.wikipedia.org/wiki/RIS_(file_format)).
*/
@Suppress("SpellCheckingInspection")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,85 +175,85 @@ void canFillAllFieldsIntoDataClassAppropriately() {

@Test
void emptyRecord() {
final RisRecord risRecord = new RisRecord.Builder().build();
assertThat(risRecord.getType()).isNull();
assertThat(risRecord.getFirstAuthors()).isEmpty();
assertThat(risRecord.getSecondaryAuthors()).isEmpty();
assertThat(risRecord.getTertiaryAuthors()).isEmpty();
assertThat(risRecord.getSubsidiaryAuthors()).isEmpty();
assertThat(risRecord.getAuthors()).isEmpty();
assertThat(risRecord.getAbstr()).isNull();
assertThat(risRecord.getAuthorAddress()).isNull();
assertThat(risRecord.getAccessionNumber()).isNull();
assertThat(risRecord.getArchivesLocation()).isNull();
assertThat(risRecord.getBt()).isNull();
assertThat(risRecord.getCustom1()).isNull();
assertThat(risRecord.getCustom2()).isNull();
assertThat(risRecord.getCustom3()).isNull();
assertThat(risRecord.getCustom4()).isNull();
assertThat(risRecord.getCustom5()).isNull();
assertThat(risRecord.getCustom6()).isNull();
assertThat(risRecord.getCustom7()).isNull();
assertThat(risRecord.getCustom8()).isNull();
assertThat(risRecord.getCaption()).isNull();
assertThat(risRecord.getCallNumber()).isNull();
assertThat(risRecord.getCp()).isNull();
assertThat(risRecord.getUnpublishedReferenceTitle()).isNull();
assertThat(risRecord.getPlacePublished()).isNull();
assertThat(risRecord.getDate()).isNull();
assertThat(risRecord.getDatabaseName()).isNull();
assertThat(risRecord.getDoi()).isNull();
assertThat(risRecord.getDatabaseProvider()).isNull();
assertThat(risRecord.getEditor()).isNull();
assertThat(risRecord.getEndPage()).isNull();
assertThat(risRecord.getEdition()).isNull();
assertThat(risRecord.getReferenceId()).isNull();
assertThat(risRecord.getIssue()).isNull();
assertThat(risRecord.getPeriodicalNameUserAbbrevation()).isNull();
assertThat(risRecord.getAlternativeTitle()).isNull();
assertThat(risRecord.getPeriodicalNameStandardAbbrevation()).isNull();
assertThat(risRecord.getPeriodicalNameFullFormatJF()).isNull();
assertThat(risRecord.getPeriodicalNameFullFormatJO()).isNull();
assertThat(risRecord.getKeywords()).isEmpty();
assertThat(risRecord.getPdfLinks()).isEmpty();
assertThat(risRecord.getFullTextLinks()).isEmpty();
assertThat(risRecord.getRelatedRecords()).isEmpty();
assertThat(risRecord.getImages()).isEmpty();
assertThat(risRecord.getLanguage()).isNull();
assertThat(risRecord.getLabel()).isNull();
assertThat(risRecord.getWebsiteLink()).isNull();
assertThat(risRecord.getMiscellaneous1()).isNull();
assertThat(risRecord.getMiscellaneous2()).isNull();
assertThat(risRecord.getMiscellaneous3()).isNull();
assertThat(risRecord.getNotes()).isNull();
assertThat(risRecord.getAbstr2()).isNull();
assertThat(risRecord.getNumberOfVolumes()).isNull();
assertThat(risRecord.getOriginalPublication()).isNull();
assertThat(risRecord.getPublisher()).isNull();
assertThat(risRecord.getPublishingPlace()).isNull();
assertThat(risRecord.getPublicationYear()).isNull();
assertThat(risRecord.getReviewedItem()).isNull();
assertThat(risRecord.getResearchNotes()).isNull();
assertThat(risRecord.getReprintEdition()).isNull();
assertThat(risRecord.getSection()).isNull();
assertThat(risRecord.getIsbnIssn()).isNull();
assertThat(risRecord.getStartPage()).isNull();
assertThat(risRecord.getShortTitle()).isNull();
assertThat(risRecord.getPrimaryTitle()).isNull();
assertThat(risRecord.getSecondaryTitle()).isNull();
assertThat(risRecord.getTertiaryTitle()).isNull();
assertThat(risRecord.getTranslatedAuthor()).isNull();
assertThat(risRecord.getTitle()).isNull();
assertThat(risRecord.getTranslatedTitle()).isNull();
assertThat(risRecord.getUserDefinable1()).isNull();
assertThat(risRecord.getUserDefinable2()).isNull();
assertThat(risRecord.getUserDefinable3()).isNull();
assertThat(risRecord.getUserDefinable4()).isNull();
assertThat(risRecord.getUserDefinable5()).isNull();
assertThat(risRecord.getUrl()).isNull();
assertThat(risRecord.getVolumeNumber()).isNull();
assertThat(risRecord.getPublisherStandardNumber()).isNull();
assertThat(risRecord.getPrimaryDate()).isNull();
assertThat(risRecord.getAccessDate()).isNull();
final RisRecord emptyRecord = new RisRecord.Builder().build();
assertThat(emptyRecord.getType()).isNull();
assertThat(emptyRecord.getFirstAuthors()).isEmpty();
assertThat(emptyRecord.getSecondaryAuthors()).isEmpty();
assertThat(emptyRecord.getTertiaryAuthors()).isEmpty();
assertThat(emptyRecord.getSubsidiaryAuthors()).isEmpty();
assertThat(emptyRecord.getAuthors()).isEmpty();
assertThat(emptyRecord.getAbstr()).isNull();
assertThat(emptyRecord.getAuthorAddress()).isNull();
assertThat(emptyRecord.getAccessionNumber()).isNull();
assertThat(emptyRecord.getArchivesLocation()).isNull();
assertThat(emptyRecord.getBt()).isNull();
assertThat(emptyRecord.getCustom1()).isNull();
assertThat(emptyRecord.getCustom2()).isNull();
assertThat(emptyRecord.getCustom3()).isNull();
assertThat(emptyRecord.getCustom4()).isNull();
assertThat(emptyRecord.getCustom5()).isNull();
assertThat(emptyRecord.getCustom6()).isNull();
assertThat(emptyRecord.getCustom7()).isNull();
assertThat(emptyRecord.getCustom8()).isNull();
assertThat(emptyRecord.getCaption()).isNull();
assertThat(emptyRecord.getCallNumber()).isNull();
assertThat(emptyRecord.getCp()).isNull();
assertThat(emptyRecord.getUnpublishedReferenceTitle()).isNull();
assertThat(emptyRecord.getPlacePublished()).isNull();
assertThat(emptyRecord.getDate()).isNull();
assertThat(emptyRecord.getDatabaseName()).isNull();
assertThat(emptyRecord.getDoi()).isNull();
assertThat(emptyRecord.getDatabaseProvider()).isNull();
assertThat(emptyRecord.getEditor()).isNull();
assertThat(emptyRecord.getEndPage()).isNull();
assertThat(emptyRecord.getEdition()).isNull();
assertThat(emptyRecord.getReferenceId()).isNull();
assertThat(emptyRecord.getIssue()).isNull();
assertThat(emptyRecord.getPeriodicalNameUserAbbrevation()).isNull();
assertThat(emptyRecord.getAlternativeTitle()).isNull();
assertThat(emptyRecord.getPeriodicalNameStandardAbbrevation()).isNull();
assertThat(emptyRecord.getPeriodicalNameFullFormatJF()).isNull();
assertThat(emptyRecord.getPeriodicalNameFullFormatJO()).isNull();
assertThat(emptyRecord.getKeywords()).isEmpty();
assertThat(emptyRecord.getPdfLinks()).isEmpty();
assertThat(emptyRecord.getFullTextLinks()).isEmpty();
assertThat(emptyRecord.getRelatedRecords()).isEmpty();
assertThat(emptyRecord.getImages()).isEmpty();
assertThat(emptyRecord.getLanguage()).isNull();
assertThat(emptyRecord.getLabel()).isNull();
assertThat(emptyRecord.getWebsiteLink()).isNull();
assertThat(emptyRecord.getMiscellaneous1()).isNull();
assertThat(emptyRecord.getMiscellaneous2()).isNull();
assertThat(emptyRecord.getMiscellaneous3()).isNull();
assertThat(emptyRecord.getNotes()).isNull();
assertThat(emptyRecord.getAbstr2()).isNull();
assertThat(emptyRecord.getNumberOfVolumes()).isNull();
assertThat(emptyRecord.getOriginalPublication()).isNull();
assertThat(emptyRecord.getPublisher()).isNull();
assertThat(emptyRecord.getPublishingPlace()).isNull();
assertThat(emptyRecord.getPublicationYear()).isNull();
assertThat(emptyRecord.getReviewedItem()).isNull();
assertThat(emptyRecord.getResearchNotes()).isNull();
assertThat(emptyRecord.getReprintEdition()).isNull();
assertThat(emptyRecord.getSection()).isNull();
assertThat(emptyRecord.getIsbnIssn()).isNull();
assertThat(emptyRecord.getStartPage()).isNull();
assertThat(emptyRecord.getShortTitle()).isNull();
assertThat(emptyRecord.getPrimaryTitle()).isNull();
assertThat(emptyRecord.getSecondaryTitle()).isNull();
assertThat(emptyRecord.getTertiaryTitle()).isNull();
assertThat(emptyRecord.getTranslatedAuthor()).isNull();
assertThat(emptyRecord.getTitle()).isNull();
assertThat(emptyRecord.getTranslatedTitle()).isNull();
assertThat(emptyRecord.getUserDefinable1()).isNull();
assertThat(emptyRecord.getUserDefinable2()).isNull();
assertThat(emptyRecord.getUserDefinable3()).isNull();
assertThat(emptyRecord.getUserDefinable4()).isNull();
assertThat(emptyRecord.getUserDefinable5()).isNull();
assertThat(emptyRecord.getUrl()).isNull();
assertThat(emptyRecord.getVolumeNumber()).isNull();
assertThat(emptyRecord.getPublisherStandardNumber()).isNull();
assertThat(emptyRecord.getPrimaryDate()).isNull();
assertThat(emptyRecord.getAccessDate()).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ class KRisUsageTest {

@Test
void whenProcessingRisLinesAsList_willReturnListOfRisRecords() {
final List<RisRecord> risRecords = KRis.processList(risLines);
assertThat(risRecords).hasSize(2);
final List<RisRecord> records = KRis.processList(risLines);
assertThat(records).hasSize(2);
}

@Test
void whenProcessingRisLinesAsObservable_willReturnObservableOfRisRecords() {
final List<RisRecord> risRecords = new ArrayList<>();
final List<RisRecord> records = new ArrayList<>();

final Observable<String> observable = Observable.fromIterable(risLines);

KRis
.processObservables(observable)
.blockingSubscribe(risRecords::add);
.blockingSubscribe(records::add);

assertThat(risRecords).hasSize(2);
assertThat(records).hasSize(2);
}

private final RisRecord risRecord = new RisRecord.Builder()
Expand All @@ -76,20 +76,20 @@ void whenProcessingRisLinesAsObservable_willReturnObservableOfRisRecords() {

@Test
void whenProcessingRisRecordsAsList_willReturnListOfRisLines() {
final List<String> risLines = KRis.buildFromList(risRecords);
assertThat(risLines).hasSize(expectedLineCount);
final List<String> lines = KRis.buildFromList(risRecords);
assertThat(lines).hasSize(expectedLineCount);
}

@Test
void whenProcessingRisRecordsAsObservable_willReturnObservableOfString() {
final List<String> risLines = new ArrayList<>();
final List<String> lines = new ArrayList<>();

final Observable<RisRecord> observable = Observable.fromIterable(risRecords);

KRis
.exportObservable(observable)
.blockingSubscribe(risLines::add);
.blockingSubscribe(lines::add);

assertThat(risLines).hasSize(expectedLineCount);
assertThat(lines).hasSize(expectedLineCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void fromList() {

List<String> lines = KRis.buildFromList(records);
// end::fromList[]
System.out.println(lines);
}

void fromListCustomSort() {
Expand All @@ -58,6 +59,7 @@ void fromListCustomSort() {

List<String> lines = KRis.buildFromList(records, sort);
// end::fromListCustomSort[]
System.out.println(lines);
}

// tag::fromObservable[]
Expand Down Expand Up @@ -91,7 +93,7 @@ void writerExport() throws IOException {
// end::writerExport[]
}

void fileExport() throws IOException {
void fileExport() {
// tag::fileExport[]
final List<RisRecord> records = List.of(record1, record2);

Expand All @@ -111,7 +113,7 @@ void streamExport() throws IOException {
// end::streamExport[]
}

void pathExport() throws IOException {
void pathExport() {
// tag::pathExport[]
final List<RisRecord> records = List.of(record1, record2);

Expand All @@ -135,6 +137,7 @@ void processFile() throws IOException {
final File file = new File("import.ris");
final List<RisRecord> records = KRisIO.process(file);
// end::processFile[]
System.out.println(records);
}

void processInputStream() throws IOException {
Expand All @@ -149,6 +152,7 @@ void processPath() throws IOException {
// tag::processPath[]
final List<RisRecord> records = KRisIO.process("import.ris");
// end::processPath[]
System.out.println(records);
}

void processReaderAsStream() throws IOException {
Expand All @@ -164,6 +168,7 @@ void processFileAsStream() throws IOException {
final File file = new File("import.ris");
final Stream<RisRecord> records = KRisIO.processToStream(file);
// end::processFileAsStream[]
System.out.println(records);
}

void processInputStreamAsStream() throws IOException {
Expand All @@ -178,13 +183,15 @@ void processPathAsStream() throws IOException {
// tag::processPathAsStream[]
final Stream<RisRecord> records = KRisIO.processToStream("import.ris");
// end::processPathAsStream[]
System.out.println(records);
}

void passRisLinesAsList() throws IOException {
// tag::passRisLinesAsList[]
final List<String> lines = List.of(); // TODO
List<RisRecord> records = KRis.processList(lines);
// end::passRisLinesAsList[]
System.out.println(records);
}

void processObservables() throws IOException {
Expand All @@ -205,5 +212,6 @@ void getListOfRisTagsAsString() {
// tag::getListOfRisTagsAsString[]
List<String> namesOfAllRisTags = KRis.risTagNames();
// end::getListOfRisTagsAsString[]
System.out.println(namesOfAllRisTags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.stream.Collectors.toList
private const val FILE_PATH = "src/integrationTest/resources/sample.ris"
private const val PAPER_COUNT = 4

@Suppress("FunctionName", "S100", "SpellCheckingInspection", "MaxLineLength", "TooManyFunctions")
@Suppress("FunctionName", "S100", "SpellCheckingInspection", "MaxLineLength", "TooManyFunctions", "RedundantSuppression")
internal class KRisIOIntegrationTest {

private val expectedLines = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.amshove.kluent.shouldHaveSize
import java.io.File
import kotlin.streams.toList

object KRisIoUsageImportSpec : DescribeSpec({

Expand All @@ -22,7 +21,7 @@ object KRisIoUsageImportSpec : DescribeSpec({
it.deleteOnExit()
}

describe("list mehtods") {
describe("list methods") {
it("can read from File") {
file.process() shouldHaveSize 1
}
Expand Down
5 changes: 4 additions & 1 deletion subprojects/kris-io/src/main/kotlin/ch/difty/kris/KRisIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.lastOrNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.BufferedReader
import java.io.File
import java.io.FileOutputStream
Expand Down Expand Up @@ -147,7 +148,9 @@ public object KRisIO {
KRis.build(records.asFlow(), sort)
.buffer(onBufferOverflow = BufferOverflow.SUSPEND)
.collect { line ->
w.write(line)
withContext(dispatchers.io) {
w.write(line)
}
}
}
}
Expand Down
Loading

0 comments on commit e64ee04

Please sign in to comment.