├── settings.gradle ├── src ├── test │ ├── resources │ │ └── uk │ │ │ └── ac │ │ │ └── ebi │ │ │ └── ena │ │ │ └── webin │ │ │ └── cli │ │ │ ├── manifests │ │ │ └── json │ │ │ │ └── valid │ │ │ │ ├── simple-value.json │ │ │ │ ├── multi-value-no-attributes.json │ │ │ │ ├── object-value.json │ │ │ │ ├── multi-value-first-attributes.json │ │ │ │ ├── all-possible-field-formats.json │ │ │ │ ├── invalid-sample.json │ │ │ │ └── valid-sample.json │ │ │ ├── reads │ │ │ ├── valid.bam │ │ │ ├── invalid.bam │ │ │ ├── valid.cram │ │ │ ├── invalid.cram │ │ │ ├── valid.fastq.gz │ │ │ ├── invalid.fastq.gz │ │ │ ├── uracil-bases.fastq.gz │ │ │ ├── 10x │ │ │ │ ├── 3fastq │ │ │ │ │ ├── I1.fastq.gz │ │ │ │ │ ├── R1.fastq.gz │ │ │ │ │ └── R2.fastq.gz │ │ │ │ └── 4fastq │ │ │ │ │ ├── I1.fastq.gz │ │ │ │ │ ├── R1.fastq.gz │ │ │ │ │ ├── R2.fastq.gz │ │ │ │ │ └── R3.fastq.gz │ │ │ ├── valid_paired_1.fastq.gz │ │ │ ├── valid_paired_2.fastq.gz │ │ │ ├── invalid_not_paired_1.fastq.gz │ │ │ ├── invalid_not_paired_2.fastq.gz │ │ │ └── valid_paired_single_fastq.gz │ │ │ ├── genome │ │ │ ├── valid.agp.gz │ │ │ ├── invalid.agp.gz │ │ │ ├── valid.fasta.gz │ │ │ ├── invalid.fasta.gz │ │ │ ├── valid.flatfile.gz │ │ │ ├── invalid.flatfile.gz │ │ │ ├── valid-covid19.fasta.gz │ │ │ ├── single-sequence.fasta.gz │ │ │ ├── valid_chromosome_list.txt.gz │ │ │ ├── valid-covid19-chromosome.list.gz │ │ │ └── invalid_chromosome_list_sequenceless.txt.gz │ │ │ ├── sequence │ │ │ ├── invalid-sample.tsv.gz │ │ │ ├── invalid.flatfile.gz │ │ │ └── valid │ │ │ │ ├── valid.fasta.gz │ │ │ │ ├── valid.flatfile.gz │ │ │ │ ├── ERT000003-EST.tsv.gz │ │ │ │ ├── ERT000006-SCM.tsv.gz │ │ │ │ ├── ERT000009-ITS.tsv.gz │ │ │ │ ├── ERT000020-COI.tsv.gz │ │ │ │ ├── ERT000028-SVC.tsv.gz │ │ │ │ ├── ERT000035-IGS.tsv.gz │ │ │ │ ├── ERT000039-Sat.tsv.gz │ │ │ │ ├── ERT000050-ISR.tsv.gz │ │ │ │ ├── ERT000053-ETS.tsv.gz │ │ │ │ ├── ERT000055-STS.tsv.gz │ │ │ │ ├── ERT000002-rRNA.tsv.gz │ │ │ │ ├── ERT000003-EST-1.tsv.gz │ │ │ │ ├── ERT000024-GSS-1.tsv.gz │ │ │ │ ├── ERT000029-SCGD.tsv.gz │ │ │ │ ├── ERT000030-MHC1.tsv.gz │ │ │ │ ├── ERT000032-matK.tsv.gz │ │ │ │ ├── ERT000034-Dloop.tsv.gz │ │ │ │ ├── ERT000036-MHC2.tsv.gz │ │ │ │ ├── ERT000042-ncRNA.tsv.gz │ │ │ │ ├── ERT000051-poly.tsv.gz │ │ │ │ ├── ERT000052-ssRNA.tsv.gz │ │ │ │ ├── ERT000060-vUTR.tsv.gz │ │ │ │ ├── ERT000037-intron.tsv.gz │ │ │ │ ├── ERT000047-betasat.tsv.gz │ │ │ │ ├── ERT000056-mobele.tsv.gz │ │ │ │ ├── ERT000057-alphasat.tsv.gz │ │ │ │ ├── ERT000058-MLmarker.tsv.gz │ │ │ │ ├── ERT000038-hyloMarker.tsv.gz │ │ │ │ ├── ERT000061-polysample-tax_tsv.tsv.gz │ │ │ │ ├── ERT000002_rRNA-with-sample-field.tsv.gz │ │ │ │ └── ERT000061-polysample-sample_tsv.tsv.gz │ │ │ ├── transcriptome │ │ │ ├── valid.fasta.gz │ │ │ ├── valid.flatfile.gz │ │ │ └── invalid.flatfile.gz │ │ │ └── taxxrefset │ │ │ └── valid │ │ │ ├── valid.fasta.gz │ │ │ └── valid_w_customs.tsv.gz │ └── java │ │ └── uk │ │ └── ac │ │ └── ebi │ │ └── ena │ │ └── webin │ │ └── cli │ │ ├── upload │ │ └── FtpServiceTest.java │ │ ├── context │ │ ├── taxrefset │ │ │ ├── TaxRefSetManifestReaderFileCountTest.java │ │ │ └── TaxRefSetManifestReaderFileSuffixTest.java │ │ ├── sequence │ │ │ ├── SequenceManifestReaderFileCountTest.java │ │ │ ├── SequenceManifestReaderFileSuffixTest.java │ │ │ └── SequenceManifestReaderTest.java │ │ ├── transcriptome │ │ │ ├── TranscriptomeManifestReaderFileCountTest.java │ │ │ ├── TranscriptomeManifestReaderFileSuffixTest.java │ │ │ └── TranscriptomeManifestReaderTest.java │ │ ├── reads │ │ │ ├── ReadsManifestReaderFileSuffixTest.java │ │ │ └── ReadsManifestReaderFileCountTest.java │ │ ├── genome │ │ │ └── GenomeManifestReaderFileSuffixTest.java │ │ └── polysample │ │ │ └── PolySampleManifestReaderTest.java │ │ ├── manifest │ │ ├── TestManifestReader.java │ │ ├── processor │ │ │ ├── ProcessorTestUtils.java │ │ │ ├── FileSuffixProcessorTest.java │ │ │ ├── AssemblyTypeProcessorTest.java │ │ │ ├── metadata │ │ │ │ ├── StudyProcessorTest.java │ │ │ │ └── SampleXmlProcessorTest.java │ │ │ ├── ASCIIFileNameProcessorTest.java │ │ │ ├── CustomFieldProcessorTest.java │ │ │ ├── AuthorProcessorTest.java │ │ │ └── MetadataProcessorFactoryTest.java │ │ ├── ManifestReaderFileSuffixTester.java │ │ └── ManifestReaderTester.java │ │ ├── service │ │ ├── RatelimitServiceTest.java │ │ ├── IgnoreErrorsServiceTest.java │ │ ├── VersionServiceTest.java │ │ ├── LoginServiceTest.java │ │ ├── RunServiceTest.java │ │ ├── SampleXmlServiceTest.java │ │ ├── SampleServiceTest.java │ │ ├── AnalysisServiceTest.java │ │ └── StudyServiceTest.java │ │ ├── xml │ │ └── XmlWriterHelperTest.java │ │ ├── XmlTester.java │ │ └── WebinCliContextTest.java └── main │ ├── resources │ ├── uk │ │ └── ac │ │ │ └── ebi │ │ │ └── ena │ │ │ └── webin │ │ │ └── cli │ │ │ └── reads │ │ │ ├── source.properties │ │ │ ├── platform.properties │ │ │ ├── instrument.properties │ │ │ └── selection.properties │ └── logback.xml │ └── java │ └── uk │ └── ac │ └── ebi │ └── ena │ └── webin │ └── cli │ ├── manifest │ ├── ManifestFieldType.java │ ├── processor │ │ ├── MetadataProcessorParameters.java │ │ ├── AssemblyTypeProcessor.java │ │ ├── ASCIIFileNameProcessor.java │ │ ├── AuthorProcessor.java │ │ ├── FileSuffixProcessor.java │ │ ├── CustomFieldProcessor.java │ │ ├── CVFieldProcessor.java │ │ ├── metadata │ │ │ ├── StudyProcessor.java │ │ │ ├── SampleXmlProcessor.java │ │ │ ├── RunProcessor.java │ │ │ └── AnalysisProcessor.java │ │ └── MetadataProcessorFactory.java │ ├── ManifestReaderResult.java │ ├── ManifestFileGroup.java │ ├── ManifestFieldProcessor.java │ ├── ManifestFileSuffix.java │ ├── ManifestReaderBuilder.java │ ├── ManifestFieldValue.java │ ├── ManifestFieldGroup.java │ ├── ManifestFileCount.java │ └── ManifestCVList.java │ ├── ManifestValidationPolicy.java │ ├── WebinCliConfig.java │ ├── WebinSubmissionTool.java │ ├── upload │ └── UploadService.java │ ├── context │ ├── taxrefset │ │ └── PlaceHolderForTaxRefSetValidator.java │ ├── sequence │ │ └── SequenceXmlWriter.java │ └── transcriptome │ │ └── TranscriptomeXmlWriter.java │ ├── entity │ └── Version.java │ ├── xml │ ├── XmlWriter.java │ └── XmlWriterHelper.java │ ├── service │ ├── models │ │ └── RateLimitResult.java │ ├── utils │ │ ├── HttpHeaderBuilder.java │ │ └── HttpLoggingInterceptor.java │ ├── VersionService.java │ └── IgnoreErrorsService.java │ ├── utils │ ├── RemoteServiceUrlHelper.java │ └── ExceptionUtils.java │ └── spreadsheet │ └── SpreadsheetContext.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── Dockerfile ├── .gitlab-ci.yml ├── README.md └── gradlew.bat /settings.gradle: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/simple-value.json: -------------------------------------------------------------------------------- 1 | { 2 | "field1": "val1" 3 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/multi-value-no-attributes.json: -------------------------------------------------------------------------------- 1 | { 2 | "field": [ "val1", "val2" ] 3 | } -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/object-value.json: -------------------------------------------------------------------------------- 1 | { 2 | "field1": { 3 | "value": "val1" 4 | } 5 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .latest-version-check 2 | /build/ 3 | /.gradle/ 4 | /.classpath 5 | /.project 6 | /bin/ 7 | /.settings/ 8 | /.idea 9 | .idea -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eclipse-temurin:17-jre-alpine 2 | VOLUME /tmp 3 | ARG JAR_FILE 4 | COPY ${JAR_FILE} webin-cli.jar 5 | ENTRYPOINT ["java","-jar","/webin-cli.jar"] 6 | -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid.bam: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid.bam -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid.bam: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid.bam -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid.cram: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid.cram -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid.agp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid.agp.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid.cram: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid.cram -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid.agp.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid.agp.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid.flatfile.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid.flatfile.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid.flatfile.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid.flatfile.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/uracil-bases.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/uracil-bases.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid-covid19.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid-covid19.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/3fastq/I1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/3fastq/I1.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/3fastq/R1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/3fastq/R1.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/3fastq/R2.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/3fastq/R2.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/I1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/I1.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/R1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/R1.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/R2.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/R2.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/R3.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/10x/4fastq/R3.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid_paired_1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid_paired_1.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid_paired_2.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid_paired_2.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/invalid-sample.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/invalid-sample.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/invalid.flatfile.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/invalid.flatfile.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/valid.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/valid.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/transcriptome/valid.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/transcriptome/valid.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/single-sequence.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/single-sequence.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/valid.flatfile.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/valid.flatfile.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/taxxrefset/valid/valid.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/taxxrefset/valid/valid.fasta.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/transcriptome/valid.flatfile.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/transcriptome/valid.flatfile.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid_chromosome_list.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid_chromosome_list.txt.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid_not_paired_1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid_not_paired_1.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid_not_paired_2.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/invalid_not_paired_2.fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid_paired_single_fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/reads/valid_paired_single_fastq.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000003-EST.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000003-EST.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000006-SCM.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000006-SCM.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000009-ITS.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000009-ITS.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000020-COI.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000020-COI.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000028-SVC.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000028-SVC.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000035-IGS.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000035-IGS.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000039-Sat.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000039-Sat.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000050-ISR.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000050-ISR.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000053-ETS.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000053-ETS.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000055-STS.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000055-STS.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/transcriptome/invalid.flatfile.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/transcriptome/invalid.flatfile.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000002-rRNA.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000002-rRNA.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000003-EST-1.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000003-EST-1.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000024-GSS-1.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000024-GSS-1.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000029-SCGD.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000029-SCGD.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000030-MHC1.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000030-MHC1.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000032-matK.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000032-matK.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000034-Dloop.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000034-Dloop.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000036-MHC2.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000036-MHC2.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000042-ncRNA.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000042-ncRNA.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000051-poly.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000051-poly.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000052-ssRNA.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000052-ssRNA.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000060-vUTR.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000060-vUTR.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid-covid19-chromosome.list.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/valid-covid19-chromosome.list.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000037-intron.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000037-intron.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000047-betasat.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000047-betasat.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000056-mobele.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000056-mobele.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000057-alphasat.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000057-alphasat.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000058-MLmarker.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000058-MLmarker.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/taxxrefset/valid/valid_w_customs.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/taxxrefset/valid/valid_w_customs.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000038-hyloMarker.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000038-hyloMarker.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid_chromosome_list_sequenceless.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/genome/invalid_chromosome_list_sequenceless.txt.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000061-polysample-tax_tsv.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000061-polysample-tax_tsv.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000002_rRNA-with-sample-field.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000002_rRNA-with-sample-field.tsv.gz -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000061-polysample-sample_tsv.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enasequence/webin-cli/HEAD/src/test/resources/uk/ac/ebi/ena/webin/cli/sequence/valid/ERT000061-polysample-sample_tsv.tsv.gz -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/multi-value-first-attributes.json: -------------------------------------------------------------------------------- 1 | { 2 | "field": [ 3 | { 4 | "value": "val1", 5 | "attributes": { 6 | "attField": "attVal" 7 | } 8 | }, 9 | "val2" 10 | ] 11 | } -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/all-possible-field-formats.json: -------------------------------------------------------------------------------- 1 | { 2 | "field1": "val1", 3 | "field2": [ 4 | "val21", 5 | { 6 | "value": "val22" 7 | }, 8 | { 9 | "value": "val23", 10 | "attributes": { 11 | "attField1": [ "attVal11", "attVal12" ], 12 | "attField2": "attVal21" 13 | } 14 | } 15 | ], 16 | "field3": { 17 | "value": "val3" 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/resources/uk/ac/ebi/ena/webin/cli/reads/source.properties: -------------------------------------------------------------------------------- 1 | GENOMIC=Genomic DNA (includes PCR products from genomic DNA). 2 | GENOMIC\ SINGLE\ CELL= 3 | TRANSCRIPTOMIC=Transcription products or non genomic DNA (EST, cDNA, RT-PCR, screened libraries). 4 | TRANSCRIPTOMIC\ SINGLE\ CELL= 5 | METAGENOMIC=Mixed material from metagenome. 6 | METATRANSCRIPTOMIC=Transcription products from community targets 7 | SYNTHETIC=Synthetic DNA. 8 | VIRAL\ RNA=Viral RNA. 9 | OTHER=Other, unspecified, or unknown library source material. -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %-5level: %msg%nopex%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/invalid-sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "study": "sample-study", 3 | "sample": { 4 | "title": "human gastric microbiota, mucosal", 5 | "organism": { 6 | "taxonId": "1284369" 7 | }, 8 | "attributes": [ 9 | { 10 | "tag": "Geographic location (country and/or sea)", 11 | "value": "France" 12 | }, 13 | { 14 | "tag": "collection date", 15 | "value": "2010-01-20" 16 | }, 17 | { 18 | "tag": "ena-checklist", 19 | "value": "ERC000011" 20 | } 21 | ] 22 | 23 | 24 | }, 25 | "platform": "ILLUMINA" 26 | } -------------------------------------------------------------------------------- /src/test/resources/uk/ac/ebi/ena/webin/cli/manifests/json/valid/valid-sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "study": "sample-study", 3 | "sample": { 4 | "alias": "stomach_microbiota", 5 | "title": "human gastric microbiota, mucosal", 6 | "organism": { 7 | "taxonId": "1284369" 8 | }, 9 | "attributes": [ 10 | { 11 | "tag": "Geographic location (country and/or sea)", 12 | "value": "France" 13 | }, 14 | { 15 | "tag": "collection date", 16 | "value": "2010-01-20" 17 | }, 18 | { 19 | "tag": "ena-checklist", 20 | "value": "ERC000011" 21 | } 22 | ] 23 | 24 | 25 | }, 26 | "platform": "ILLUMINA" 27 | } -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFieldType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | public enum ManifestFieldType { 14 | META, 15 | FILE, 16 | ATTRIBUTE 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/ManifestValidationPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli; 12 | 13 | public enum ManifestValidationPolicy { 14 | VALIDATE_ALL_MANIFESTS, 15 | VALIDATE_UPDATED_MANIFESTS 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/uk/ac/ebi/ena/webin/cli/reads/platform.properties: -------------------------------------------------------------------------------- 1 | ILLUMINA=Illumina is 4-channel flowgram with 1-to-1 mapping between basecalls and flows 2 | PACBIO_SMRT=PacificBiosciences platform type for the single molecule real time (SMRT) technology. 3 | OXFORD_NANOPORE=Oxford Nanopore platform type. nanopore-based electronic single molecule analysis 4 | BGISEQ=BGI NGS Platform 5 | LS454=454 technology use 1-color sequential flows 6 | ION_TORRENT=Ion Torrent Personal Genome Machine (PGM) from Life Technologies. 7 | CAPILLARY=Sequencers based on capillary electrophoresis technology manufactured by LifeTech (formerly Applied BioSciences). 8 | DNBSEQ=Sequencers based on DNBSEQ by MGI Tech. 9 | ELEMENT=Element Biosciences 10 | ULTIMA=Ultima Genomics 11 | VELA_DIAGNOSTICS=Semi-conductor based sequencing technology. 12 | GENAPSYS=Chip based electronic sensing of polymerase extension reaction 13 | GENEMIND=Genemind Platform 14 | TAPESTRI=Tapestri Platform -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/WebinCliConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli; 12 | 13 | public interface WebinCliConfig { 14 | String VALIDATE_DIR = "validate"; 15 | String PROCESS_DIR = "process"; 16 | String SUBMIT_DIR = "submit"; 17 | String REPORT_FILE_SUFFIX = ".report"; 18 | String SUBMISSION_BUNDLE_FILE_NAME = "validate.json"; 19 | String SUBMISSION_STATUS_FILE_NAME = "submit.json"; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/WebinSubmissionTool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli; 12 | 13 | public enum WebinSubmissionTool { 14 | WEBIN_CLI("webin-cli"), 15 | WEBIN_CLI_REST("webin-cli-rest"); 16 | 17 | public String getToolName() { 18 | return toolName; 19 | } 20 | 21 | private String toolName; 22 | 23 | WebinSubmissionTool(String toolName) { 24 | this.toolName = toolName; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/upload/UploadService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.upload; 12 | 13 | import java.io.File; 14 | import java.nio.file.Path; 15 | import java.util.List; 16 | 17 | public interface UploadService { 18 | void connect(String userName, String password); 19 | 20 | void upload(List uploadFilesList, String uploadDir, Path inputDir); 21 | 22 | void disconnect(); 23 | 24 | boolean isAvailable(); 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/upload/FtpServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.upload; 12 | 13 | import org.junit.Test; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 15 | 16 | public class FtpServiceTest { 17 | @Test 18 | public void testFtpService() { 19 | FtpService ftpService = new FtpService(); 20 | ftpService.connect( 21 | WebinCliTestUtils.getTestWebinUsername(), WebinCliTestUtils.getTestWebinPassword()); 22 | ftpService.disconnect(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/context/taxrefset/PlaceHolderForTaxRefSetValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.taxrefset; 12 | 13 | import uk.ac.ebi.ena.webin.cli.validator.api.ValidationResponse; 14 | import uk.ac.ebi.ena.webin.cli.validator.api.Validator; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.Manifest; 16 | 17 | public class PlaceHolderForTaxRefSetValidator implements Validator { 18 | @Override 19 | public ValidationResponse validate(Manifest manifest) { 20 | return null; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/entity/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.entity; 12 | 13 | import com.fasterxml.jackson.databind.PropertyNamingStrategies; 14 | import com.fasterxml.jackson.databind.annotation.JsonNaming; 15 | import java.util.Date; 16 | 17 | @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) 18 | public class Version { 19 | public Boolean valid; 20 | public Boolean update; 21 | public Boolean expire; 22 | public String minVersion; 23 | public String latestVersion; 24 | public String nextMinVersion; 25 | public Date nextMinVersionDate; 26 | public String comment; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/xml/XmlWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.xml; 12 | 13 | import java.nio.file.Path; 14 | import java.util.Map; 15 | import uk.ac.ebi.ena.webin.cli.submit.SubmissionBundle; 16 | import uk.ac.ebi.ena.webin.cli.validator.api.ValidationResponse; 17 | import uk.ac.ebi.ena.webin.cli.validator.manifest.Manifest; 18 | 19 | public interface XmlWriter { 20 | Map createXml( 21 | M manifest, 22 | R response, 23 | String centerName, 24 | String submissionTitle, 25 | String submissionAlias, 26 | Path inputDir, 27 | Path uploadDir); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/MetadataProcessorParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import uk.ac.ebi.ena.webin.cli.manifest.processor.metadata.*; 14 | 15 | public interface MetadataProcessorParameters { 16 | String getWebinServiceUserName(); 17 | 18 | String getFileUploadServiceUserName(); 19 | 20 | String getPassword(); 21 | 22 | boolean isTest(); 23 | 24 | SampleProcessor getSampleProcessor(); 25 | 26 | StudyProcessor getStudyProcessor(); 27 | 28 | SampleXmlProcessor getSampleXmlProcessor(); 29 | 30 | RunProcessor getRunProcessor(); 31 | 32 | AnalysisProcessor getAnalysisProcessor(); 33 | 34 | boolean isSampleUpdate(); 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/taxrefset/TaxRefSetManifestReaderFileCountTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.taxrefset; 12 | 13 | import org.junit.Test; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileCountTester; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.TaxRefSetManifest; 16 | 17 | public class TaxRefSetManifestReaderFileCountTest { 18 | 19 | @Test 20 | public void testFileCount() { 21 | new ManifestReaderFileCountTester<>( 22 | TaxRefSetManifestReader.class, TaxRefSetManifest.FileType.values()) 23 | // Supported file groups 24 | .files(TaxRefSetManifest.FileType.TAB, TaxRefSetManifest.FileType.FASTA) 25 | .test(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/sequence/SequenceManifestReaderFileCountTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.sequence; 12 | 13 | import org.junit.Test; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileCountTester; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.SequenceManifest; 16 | 17 | public class SequenceManifestReaderFileCountTest { 18 | 19 | @Test 20 | public void testFileCount() { 21 | new ManifestReaderFileCountTester<>( 22 | SequenceManifestReader.class, SequenceManifest.FileType.values()) 23 | // Supported file groups 24 | .files(SequenceManifest.FileType.TAB) 25 | .files(SequenceManifest.FileType.FLATFILE) 26 | .test(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | # This file is a template, and might need editing before it works on your project. 2 | # This is the Gradle build system for JVM applications 3 | # https://gradle.org/ 4 | # https://github.com/gradle/gradle 5 | image: gradle:5.2.1-jdk8 6 | 7 | # Disable the Gradle daemon for Continuous Integration servers as correctness 8 | # is usually a priority over speed in CI environments. Using a fresh 9 | # runtime for each build is more reliable since the runtime is completely 10 | # isolated from any previous builds. 11 | variables: 12 | GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" 13 | 14 | before_script: 15 | - export GRADLE_USER_HOME=`pwd`/.gradle 16 | build: 17 | stage: build 18 | script: gradle --build-cache assemble 19 | cache: 20 | key: "$CI_COMMIT_REF_NAME" 21 | policy: push 22 | paths: 23 | - ./build 24 | - ./.gradle 25 | 26 | 27 | test: 28 | stage: test 29 | script: 30 | - wget http://download.asperasoft.com/download/sw/cli/3.9.1/ibm-aspera-cli-3.9.1.1401.be67d47-linux-64-release.sh 31 | - sh ./ibm-aspera-cli-3.9.1.1401.be67d47-linux-64-release.sh 32 | - export PATH=/home/gradle/.aspera/cli/bin:$PATH 33 | - gradle test --info 34 | cache: 35 | key: "$CI_COMMIT_REF_NAME" 36 | policy: pull 37 | paths: 38 | - ./build 39 | - ./.gradle 40 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/transcriptome/TranscriptomeManifestReaderFileCountTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.transcriptome; 12 | 13 | import org.junit.Test; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileCountTester; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.TranscriptomeManifest; 16 | 17 | public class TranscriptomeManifestReaderFileCountTest { 18 | 19 | @Test 20 | public void testFileCount() { 21 | new ManifestReaderFileCountTester<>( 22 | TranscriptomeManifestReader.class, TranscriptomeManifest.FileType.values()) 23 | // Supported file groups 24 | .files(TranscriptomeManifest.FileType.FASTA) 25 | .files(TranscriptomeManifest.FileType.FLATFILE) 26 | .test(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestReaderResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 16 | 17 | public class ManifestReaderResult { 18 | 19 | private final ValidationResult validationResult; 20 | 21 | private final Collection manifestFieldGroups = new ArrayList<>(); 22 | 23 | public ManifestReaderResult(ValidationResult validationResult) { 24 | this.validationResult = validationResult; 25 | } 26 | 27 | public ValidationResult getValidationResult() { 28 | return validationResult; 29 | } 30 | 31 | public Collection getManifestFieldGroups() { 32 | return manifestFieldGroups; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFileGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class ManifestFileGroup { 17 | 18 | private final List fileCounts = new ArrayList<>(); 19 | private final String description; 20 | 21 | public ManifestFileGroup(String description) { 22 | this.description = description; 23 | } 24 | 25 | public void addFileCount(ManifestFileCount fileCount) { 26 | fileCounts.add(fileCount); 27 | } 28 | 29 | public List getFileCounts() { 30 | return fileCounts; 31 | } 32 | 33 | public int getFileCountsSize() { 34 | return fileCounts.size(); 35 | } 36 | 37 | public String getDescription() { 38 | return description; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/TestManifestReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.Collection; 14 | import java.util.List; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.Manifest; 16 | 17 | public class TestManifestReader extends ManifestReader { 18 | 19 | public TestManifestReader(List fields) { 20 | super(null, fields); 21 | } 22 | 23 | public TestManifestReader( 24 | List fields, List fileGroups) { 25 | super(null, fields, fileGroups); 26 | } 27 | 28 | @Override 29 | protected void processManifest() {} 30 | 31 | @Override 32 | public Collection getManifests() { 33 | return null; 34 | } 35 | 36 | @Override 37 | protected Manifest createManifest() { 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/ProcessorTestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import java.util.ArrayList; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldDefinition; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 17 | 18 | public class ProcessorTestUtils { 19 | 20 | public static ManifestFieldValue createFieldValue( 21 | ManifestFieldType type, String name, String value) { 22 | return new ManifestFieldValue( 23 | new ManifestFieldDefinition.Builder() 24 | .type(type) 25 | .optional() 26 | .name(name) 27 | .desc(name) 28 | .build() 29 | .get(0), 30 | value, 31 | new ArrayList<>(), 32 | null); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFieldProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 14 | 15 | public interface ManifestFieldProcessor { 16 | /** Validates and fixes a manifest field. */ 17 | default void process( 18 | ValidationResult result, ManifestFieldGroup fieldGroup, ManifestFieldValue fieldValue) { 19 | process(result, fieldValue); 20 | } 21 | 22 | /** Validates and fixes a manifest field. */ 23 | default void process(ValidationResult result, ManifestFieldValue fieldValue) { 24 | process(result, null, fieldValue); 25 | } 26 | 27 | /** Interface to notify the user of the field processor. */ 28 | interface Callback { 29 | 30 | /** Callback to notify the user of the field processor. */ 31 | void notify(ManifestFieldGroup fieldGroup, T value); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/RatelimitServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.Test; 16 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 17 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 18 | 19 | public class RatelimitServiceTest { 20 | @Test 21 | public void testRatelimitFalse() { 22 | assertThat( 23 | new RatelimitService.Builder() 24 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(true)) 25 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 26 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 27 | .build() 28 | .ratelimit("GENOME", "Webin-1234", "ERP129098", "ERS11253593") 29 | .isRateLimited()) 30 | .isFalse(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/IgnoreErrorsServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.Test; 16 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 17 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 18 | 19 | public class IgnoreErrorsServiceTest { 20 | private static final boolean TEST = true; 21 | 22 | @Test 23 | public void testGetIgnoreErrorsFalse() { 24 | assertThat( 25 | new IgnoreErrorsService.Builder() 26 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 27 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 28 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 29 | .build() 30 | .getIgnoreErrors("UNKNOWN", "UNKNOWN")) 31 | .isFalse(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/AssemblyTypeProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import uk.ac.ebi.ena.webin.cli.context.genome.GenomeManifestReader; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 16 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 17 | 18 | public class AssemblyTypeProcessor implements ManifestFieldProcessor { 19 | 20 | @Override 21 | public void process(ValidationResult result, ManifestFieldValue fieldValue) { 22 | String value = fieldValue.getValue(); 23 | if (value == null) { 24 | return; 25 | } 26 | if (value.trim().toUpperCase().equals("CLONE") 27 | || value.trim().toUpperCase().equals("ISOLATE")) { 28 | fieldValue.setValue(GenomeManifestReader.ASSEMBLY_TYPE_PRIMARY_CLONE_OR_ISOLATE); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/service/models/RateLimitResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service.models; 12 | 13 | import java.time.Duration; 14 | 15 | public class RateLimitResult { 16 | 17 | private boolean rateLimited; 18 | 19 | private Duration rateLimiDuration; 20 | 21 | private String lastSubmittedAnalysisId; 22 | 23 | public RateLimitResult() {} 24 | 25 | public boolean isRateLimited() { 26 | return rateLimited; 27 | } 28 | 29 | public void setRateLimited(boolean rateLimited) { 30 | this.rateLimited = rateLimited; 31 | } 32 | 33 | public Duration getRateLimiDuration() { 34 | return rateLimiDuration; 35 | } 36 | 37 | public void setRateLimiDuration(Duration rateLimiDuration) { 38 | this.rateLimiDuration = rateLimiDuration; 39 | } 40 | 41 | public String getLastSubmittedAnalysisId() { 42 | return lastSubmittedAnalysisId; 43 | } 44 | 45 | public void setLastSubmittedAnalysisId(String lastSubmittedAnalysisId) { 46 | this.lastSubmittedAnalysisId = lastSubmittedAnalysisId; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/service/utils/HttpHeaderBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service.utils; 12 | 13 | import java.util.Base64; 14 | import org.springframework.http.HttpHeaders; 15 | import org.springframework.http.MediaType; 16 | 17 | public class HttpHeaderBuilder { 18 | 19 | private final HttpHeaders headers = new HttpHeaders(); 20 | 21 | private HttpHeaderBuilder set(String headerName, String headerValue) { 22 | headers.set(headerName, headerValue); 23 | return this; 24 | } 25 | 26 | public HttpHeaderBuilder basicAuth(String userName, String password) { 27 | return set("Authorization", basicAuthHeaderValue(userName, password)); 28 | } 29 | 30 | public static String basicAuthHeaderValue(String userName, String password) { 31 | String auth = userName + ":" + password; 32 | return "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()); 33 | } 34 | 35 | public HttpHeaderBuilder multipartFormData() { 36 | headers.setContentType(MediaType.MULTIPART_FORM_DATA); 37 | return this; 38 | } 39 | 40 | public HttpHeaders build() { 41 | return headers; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/ASCIIFileNameProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import java.util.regex.Pattern; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 17 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 18 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 19 | 20 | public class ASCIIFileNameProcessor implements ManifestFieldProcessor { 21 | static final Pattern pattern = 22 | Pattern.compile( 23 | "^([\\p{Alnum}]|\\\\|\\]|\\[|#|-|_|\\.|,|\\/|:|@|\\+| |\\(|\\)|'|~|<|%|\\?)+$"); 24 | 25 | @Override 26 | public void process(ValidationResult result, ManifestFieldValue fieldValue) { 27 | if (!pattern.matcher(fieldValue.getValue()).matches()) 28 | result.add( 29 | ValidationMessage.error( 30 | WebinCliMessage.ASCII_FILE_NAME_PROCESSOR_ERROR, 31 | fieldValue.getName(), 32 | fieldValue.getValue(), 33 | pattern.pattern())); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestReaderFileSuffixTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import uk.ac.ebi.ena.webin.cli.ManifestBuilder; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 15 | 16 | public class ManifestReaderFileSuffixTester { 17 | public static , T extends ManifestReader> void invalid( 18 | Class manifestReaderClass, FileType fileType, String fileName) { 19 | ManifestReaderTester tester = new ManifestReaderTester(manifestReaderClass); 20 | ManifestBuilder manifestBuilder = 21 | new ManifestBuilder().field("NAME", "TEST").file(fileType, fileName); 22 | tester.testError(manifestBuilder, WebinCliMessage.FILE_SUFFIX_PROCESSOR_ERROR); 23 | } 24 | 25 | public static , T extends ManifestReader> void valid( 26 | Class manifestReaderClass, FileType fileType, String fileName) { 27 | ManifestReaderTester tester = new ManifestReaderTester(manifestReaderClass); 28 | ManifestBuilder manifestBuilder = 29 | new ManifestBuilder().field("NAME", "TEST").file(fileType, fileName); 30 | tester.test(manifestBuilder); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFileSuffix.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | public interface ManifestFileSuffix { 17 | 18 | String GZIP_FILE_SUFFIX = ".gz"; 19 | String BZIP2_FILE_SUFFIX = ".bz2"; 20 | 21 | List GZIP_OR_BZIP_FILE_SUFFIX = Arrays.asList(GZIP_FILE_SUFFIX, BZIP2_FILE_SUFFIX); 22 | 23 | List BAM_FILE_SUFFIX = Arrays.asList(".bam"); 24 | 25 | List CRAM_FILE_SUFFIX = Arrays.asList(".cram"); 26 | 27 | List FASTA_FILE_SUFFIX = 28 | Arrays.asList( 29 | ".fasta" + GZIP_FILE_SUFFIX, 30 | ".fas" + GZIP_FILE_SUFFIX, 31 | ".fsa" + GZIP_FILE_SUFFIX, 32 | ".fna" + GZIP_FILE_SUFFIX, 33 | ".fa" + GZIP_FILE_SUFFIX, 34 | ".fasta" + BZIP2_FILE_SUFFIX, 35 | ".fas" + BZIP2_FILE_SUFFIX, 36 | ".fsa" + BZIP2_FILE_SUFFIX, 37 | ".fna" + BZIP2_FILE_SUFFIX, 38 | ".fa" + BZIP2_FILE_SUFFIX); 39 | 40 | List TAB_FILE_SUFFIX = 41 | Arrays.asList( 42 | ".tab" + GZIP_FILE_SUFFIX, 43 | ".tsv" + GZIP_FILE_SUFFIX, 44 | ".tab" + BZIP2_FILE_SUFFIX, 45 | ".tsv" + BZIP2_FILE_SUFFIX); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/AuthorProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import java.util.regex.Pattern; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 16 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 17 | 18 | public class AuthorProcessor implements ManifestFieldProcessor { 19 | 20 | @Override 21 | public void process(ValidationResult result, ManifestFieldValue fieldValue) { 22 | if (null != fieldValue.getValue()) { 23 | fieldValue.setValue( 24 | replaceMultiplePeriods(replaceMultipleSpaces(fieldValue.getValue().replaceAll(";", "")))); 25 | } 26 | } 27 | 28 | private String replaceMultipleSpaces(String string) { 29 | if (string == null) { 30 | return null; 31 | } 32 | string = string.trim(); 33 | Pattern pattern = Pattern.compile(" {2,}"); 34 | return pattern.matcher(string).replaceAll(" "); 35 | } 36 | 37 | private String replaceMultiplePeriods(String string) { 38 | if (string == null) { 39 | return null; 40 | } 41 | string = string.trim(); 42 | Pattern pattern = Pattern.compile("\\.{2,}"); 43 | return pattern.matcher(string).replaceAll("."); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/FileSuffixProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import java.util.List; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 17 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 18 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 19 | 20 | public class FileSuffixProcessor implements ManifestFieldProcessor { 21 | private final List suffixes; 22 | 23 | public FileSuffixProcessor(List suffixes) { 24 | this.suffixes = suffixes; 25 | } 26 | 27 | @Override 28 | public void process(ValidationResult result, ManifestFieldValue fieldValue) { 29 | if (null == suffixes || suffixes.isEmpty()) { 30 | return; 31 | } 32 | 33 | for (String suffix : suffixes) { 34 | if (fieldValue.getValue().endsWith(suffix)) { 35 | return; 36 | } 37 | } 38 | 39 | result.add( 40 | ValidationMessage.error( 41 | WebinCliMessage.FILE_SUFFIX_PROCESSOR_ERROR, 42 | fieldValue.getName(), 43 | fieldValue.getValue(), 44 | String.join(", ", suffixes))); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/transcriptome/TranscriptomeManifestReaderFileSuffixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.transcriptome; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.invalid; 14 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.valid; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.validator.manifest.TranscriptomeManifest; 18 | 19 | public class TranscriptomeManifestReaderFileSuffixTest { 20 | 21 | @Test 22 | public void testValidFileSuffix() { 23 | Class manifestReader = TranscriptomeManifestReader.class; 24 | valid(manifestReader, TranscriptomeManifest.FileType.FASTA, ".fasta.gz"); 25 | valid(manifestReader, TranscriptomeManifest.FileType.FLATFILE, ".txt.gz"); 26 | } 27 | 28 | @Test 29 | public void testInvalidFileSuffix() { 30 | Class manifestReader = TranscriptomeManifestReader.class; 31 | // Invalid suffix before .gz 32 | invalid(manifestReader, TranscriptomeManifest.FileType.FASTA, ".INVALID.gz"); 33 | // No .gz 34 | invalid(manifestReader, TranscriptomeManifest.FileType.FASTA, ".fasta"); 35 | invalid(manifestReader, TranscriptomeManifest.FileType.FLATFILE, ".txt"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/FileSuffixProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.processor.ProcessorTestUtils.createFieldValue; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 18 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFileSuffix; 20 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 21 | 22 | public class FileSuffixProcessorTest { 23 | @Test 24 | public void test() { 25 | ValidationResult result = new ValidationResult(); 26 | 27 | FileSuffixProcessor processor = new FileSuffixProcessor(ManifestFileSuffix.BAM_FILE_SUFFIX); 28 | 29 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "a.bam"); 30 | processor.process(result, fieldValue); 31 | Assert.assertTrue(result.isValid()); 32 | Assert.assertEquals("a.bam", fieldValue.getValue()); 33 | 34 | fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "a.cram"); 35 | processor.process(result, fieldValue); 36 | Assert.assertFalse(result.isValid()); 37 | Assert.assertEquals("a.cram", fieldValue.getValue()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/xml/XmlWriterHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.xml; 12 | 13 | import java.io.IOException; 14 | import java.nio.file.Files; 15 | import java.nio.file.Path; 16 | import java.nio.file.Paths; 17 | import org.jdom2.Element; 18 | import org.junit.Assert; 19 | import org.junit.Test; 20 | import uk.ac.ebi.ena.webin.cli.utils.FileUtils; 21 | 22 | public class XmlWriterHelperTest { 23 | 24 | @Test 25 | public void testFileNameDoesNotHaveExtraDirectories() throws IOException { 26 | Path inputDir = Files.createTempDirectory("test-dir-"); 27 | Path uploadDir = Paths.get("webin-cli/context/submission-01"); 28 | Path file = 29 | Files.createTempFile( 30 | Files.createDirectories(inputDir.resolve("dir1").resolve("dir2")), 31 | "test-file-", 32 | ".temp"); 33 | 34 | Element fileElement = 35 | XmlWriterHelper.createFileElement( 36 | inputDir, uploadDir, file, FileUtils.calculateDigest("MD5", file.toFile()), "FASTQ"); 37 | 38 | String expectedFileName = 39 | FileUtils.replaceIncompatibleFileSeparators( 40 | uploadDir.resolve(file.getFileName()).toString()); 41 | 42 | String actualFileName = fileElement.getAttribute("filename").getValue(); 43 | 44 | Assert.assertEquals(expectedFileName, actualFileName); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/sequence/SequenceManifestReaderFileSuffixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.sequence; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.invalid; 14 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.valid; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.validator.manifest.SequenceManifest; 18 | 19 | public class SequenceManifestReaderFileSuffixTest { 20 | 21 | @Test 22 | public void testValidFileSuffix() { 23 | Class manifestReader = SequenceManifestReader.class; 24 | valid(manifestReader, SequenceManifest.FileType.TAB, ".tsv.gz"); 25 | valid(manifestReader, SequenceManifest.FileType.TAB, ".tab.gz"); 26 | valid(manifestReader, SequenceManifest.FileType.FLATFILE, ".txt.gz"); 27 | } 28 | 29 | @Test 30 | public void testInvalidFileSuffix() { 31 | Class manifestReader = SequenceManifestReader.class; 32 | // Invalid suffix before .gz 33 | invalid(manifestReader, SequenceManifest.FileType.TAB, ".INVALID.gz"); 34 | // No .gz 35 | invalid(manifestReader, SequenceManifest.FileType.TAB, ".tsv"); 36 | invalid(manifestReader, SequenceManifest.FileType.TAB, ".tab"); 37 | invalid(manifestReader, SequenceManifest.FileType.FLATFILE, ".txt"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/reads/ReadsManifestReaderFileSuffixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.reads; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.invalid; 14 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.valid; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.validator.manifest.ReadsManifest; 18 | 19 | public class ReadsManifestReaderFileSuffixTest { 20 | 21 | @Test 22 | public void testValidFileSuffix() { 23 | Class manifestReader = ReadsManifestReader.class; 24 | valid(manifestReader, ReadsManifest.FileType.BAM, ".bam"); 25 | valid(manifestReader, ReadsManifest.FileType.CRAM, ".cram"); 26 | valid(manifestReader, ReadsManifest.FileType.FASTQ, ".fastq.gz"); 27 | } 28 | 29 | @Test 30 | public void testInvalidFileSuffix() { 31 | Class manifestReader = ReadsManifestReader.class; 32 | // Invalid suffix 33 | invalid(manifestReader, ReadsManifest.FileType.BAM, ".INVALID"); 34 | invalid(manifestReader, ReadsManifest.FileType.CRAM, ".INVALID"); 35 | // Not allowed .gz 36 | invalid(manifestReader, ReadsManifest.FileType.BAM, ".bam.gz"); 37 | invalid(manifestReader, ReadsManifest.FileType.CRAM, ".cram.gz"); 38 | // No .gz 39 | invalid(manifestReader, ReadsManifest.FileType.FASTQ, ".fastq"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/taxrefset/TaxRefSetManifestReaderFileSuffixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.taxrefset; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.invalid; 14 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.valid; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.validator.manifest.TaxRefSetManifest; 18 | 19 | public class TaxRefSetManifestReaderFileSuffixTest { 20 | 21 | @Test 22 | public void testValidFileSuffix() { 23 | Class manifestReader = TaxRefSetManifestReader.class; 24 | valid(manifestReader, TaxRefSetManifest.FileType.TAB, ".tsv.gz"); 25 | valid(manifestReader, TaxRefSetManifest.FileType.TAB, ".tab.gz"); 26 | valid(manifestReader, TaxRefSetManifest.FileType.FASTA, ".fasta.gz"); 27 | valid(manifestReader, TaxRefSetManifest.FileType.FASTA, ".fa.gz"); 28 | } 29 | 30 | @Test 31 | public void testInvalidFileSuffix() { 32 | Class manifestReader = TaxRefSetManifestReader.class; 33 | // Invalid suffix before .gz 34 | invalid(manifestReader, TaxRefSetManifest.FileType.TAB, ".INVALID.gz"); 35 | // No .gz 36 | invalid(manifestReader, TaxRefSetManifest.FileType.TAB, ".tsv"); 37 | invalid(manifestReader, TaxRefSetManifest.FileType.TAB, ".tab"); 38 | invalid(manifestReader, TaxRefSetManifest.FileType.FASTA, ".txt"); 39 | invalid(manifestReader, TaxRefSetManifest.FileType.FASTA, ".fasta"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/genome/GenomeManifestReaderFileSuffixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.genome; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.invalid; 14 | import static uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileSuffixTester.valid; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.validator.manifest.GenomeManifest; 18 | 19 | public class GenomeManifestReaderFileSuffixTest { 20 | 21 | @Test 22 | public void testValidFileSuffix() { 23 | Class manifestReader = GenomeManifestReader.class; 24 | valid(manifestReader, GenomeManifest.FileType.FASTA, ".fasta.gz"); 25 | valid(manifestReader, GenomeManifest.FileType.FLATFILE, ".txt.gz"); 26 | valid(manifestReader, GenomeManifest.FileType.CHROMOSOME_LIST, ".txt.gz"); 27 | valid(manifestReader, GenomeManifest.FileType.UNLOCALISED_LIST, ".txt.gz"); 28 | } 29 | 30 | @Test 31 | public void testInvalidFileSuffix() { 32 | Class manifestReader = GenomeManifestReader.class; 33 | // Invalid suffix before .gz 34 | invalid(manifestReader, GenomeManifest.FileType.FASTA, ".INVALID.gz"); 35 | // No .gz 36 | invalid(manifestReader, GenomeManifest.FileType.FASTA, ".fasta"); 37 | invalid(manifestReader, GenomeManifest.FileType.FLATFILE, ".txt"); 38 | invalid(manifestReader, GenomeManifest.FileType.CHROMOSOME_LIST, ".txt"); 39 | invalid(manifestReader, GenomeManifest.FileType.UNLOCALISED_LIST, ".txt"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestReaderBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import uk.ac.ebi.ena.webin.cli.WebinCliParameters; 14 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorFactory; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.Manifest; 16 | 17 | public class ManifestReaderBuilder { 18 | private final Class> manifestReaderClass; 19 | private final MetadataProcessorFactory metadataProcessorFactory; 20 | private final WebinCliParameters webinCliParameters; 21 | 22 | public ManifestReaderBuilder(Class> manifestReaderClass) { 23 | this.manifestReaderClass = manifestReaderClass; 24 | this.webinCliParameters = null; 25 | this.metadataProcessorFactory = new MetadataProcessorFactory(null); 26 | } 27 | 28 | public ManifestReaderBuilder( 29 | Class> manifestReaderClass, WebinCliParameters webinCliParameters) { 30 | this.manifestReaderClass = manifestReaderClass; 31 | this.webinCliParameters = webinCliParameters; 32 | this.metadataProcessorFactory = new MetadataProcessorFactory(webinCliParameters); 33 | } 34 | 35 | public ManifestReader build() { 36 | try { 37 | return manifestReaderClass 38 | .getDeclaredConstructor(WebinCliParameters.class, MetadataProcessorFactory.class) 39 | .newInstance(webinCliParameters, metadataProcessorFactory); 40 | } catch (Exception ex) { 41 | throw new RuntimeException(ex); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/AssemblyTypeProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.processor.ProcessorTestUtils.createFieldValue; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.context.genome.GenomeManifestReader; 18 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 20 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 21 | 22 | public class AssemblyTypeProcessorTest { 23 | @Test 24 | public void test() { 25 | AssemblyTypeProcessor processor = new AssemblyTypeProcessor(); 26 | 27 | for (String value : new String[] {"clone", "CLONE", "isolate", "ISOLATE"}) { 28 | ManifestFieldValue fieldValue = 29 | createFieldValue(ManifestFieldType.META, GenomeManifestReader.Field.ASSEMBLY_TYPE, value); 30 | ValidationResult result = new ValidationResult(); 31 | processor.process(result, fieldValue); 32 | Assert.assertEquals(0, result.count()); 33 | Assert.assertEquals( 34 | GenomeManifestReader.ASSEMBLY_TYPE_PRIMARY_CLONE_OR_ISOLATE, fieldValue.getValue()); 35 | } 36 | ManifestFieldValue fieldValue = 37 | createFieldValue(ManifestFieldType.META, GenomeManifestReader.Field.ASSEMBLY_TYPE, "test"); 38 | ValidationResult result = new ValidationResult(); 39 | processor.process(result, fieldValue); 40 | Assert.assertEquals(0, result.count()); 41 | Assert.assertEquals("test", fieldValue.getValue()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/utils/RemoteServiceUrlHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.utils; 12 | 13 | public class RemoteServiceUrlHelper { 14 | public static final String WEBIN_REST_V1_TEST_URL = 15 | "https://wwwdev.ebi.ac.uk/ena/submit/drop-box/"; 16 | public static final String WEBIN_REST_V1_PROD_URL = "https://www.ebi.ac.uk/ena/submit/drop-box/"; 17 | 18 | public static final String WEBIN_REST_V2_TEST_URL = 19 | "https://wwwdev.ebi.ac.uk/ena/submit/webin-v2/"; 20 | public static final String WEBIN_REST_V2_PROD_URL = "https://www.ebi.ac.uk/ena/submit/webin-v2/"; 21 | 22 | public static final String WEBIN_AUTH_TEST_URL = 23 | "https://wwwdev.ebi.ac.uk/ena/submit/webin/auth/token"; 24 | public static final String WEBIN_AUTH_PROD_URL = 25 | "https://www.ebi.ac.uk/ena/submit/webin/auth/token"; 26 | 27 | public static final String BIOSAMPLES_TEST_URL = "https://wwwdev.ebi.ac.uk/biosamples/"; 28 | public static final String BIOSAMPLES_PROD_URL = "https://www.ebi.ac.uk/biosamples/"; 29 | 30 | public static String getWebinRestV1Url(boolean isTestMode) { 31 | return isTestMode ? WEBIN_REST_V1_TEST_URL : WEBIN_REST_V1_PROD_URL; 32 | } 33 | 34 | public static String getWebinRestV2Url(boolean isTestMode) { 35 | return isTestMode ? WEBIN_REST_V2_TEST_URL : WEBIN_REST_V2_PROD_URL; 36 | } 37 | 38 | public static String getWebinAuthUrl(boolean isTestMode) { 39 | return isTestMode ? WEBIN_AUTH_TEST_URL : WEBIN_AUTH_PROD_URL; 40 | } 41 | 42 | public static String getBiosamplesUrl(boolean isTestMode) { 43 | return isTestMode ? BIOSAMPLES_TEST_URL : BIOSAMPLES_PROD_URL; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/XmlTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli; 12 | 13 | import java.util.Arrays; 14 | import java.util.stream.Collectors; 15 | import org.junit.Assert; 16 | 17 | public class XmlTester { 18 | public static void assertXml(String xml, String expectedXml) { 19 | xml = xml.replaceAll("<\\?xml.*", ""); 20 | xml = xml.replaceAll("\\r\\n?", "\n"); 21 | xml = 22 | Arrays.stream(xml.split("\n")) 23 | .filter(line -> !line.trim().isEmpty()) 24 | .map(line -> line.replaceAll("^\\s+", "")) 25 | .map(line -> line.replaceAll("\\s+$", "")) 26 | .collect(Collectors.joining("\n")); 27 | xml = xml.replaceAll("<\\s+", "<"); 28 | xml = xml.replaceAll("\\s+/>", "/>"); 29 | xml = 30 | xml.replaceAll( 31 | "\\s*alias=\"[^\"]+\"", ""); // TODO ask why alias attribute is being stripped off. 32 | expectedXml = expectedXml.replaceAll("<\\?xml.*", ""); 33 | expectedXml = expectedXml.replaceAll("\\r\\n?", "\n"); 34 | expectedXml = 35 | Arrays.stream(expectedXml.split("\n")) 36 | .filter(line -> !line.trim().isEmpty()) 37 | .map(line -> line.replaceAll("^\\s+", "")) 38 | .map(line -> line.replaceAll("\\s+$", "")) 39 | .collect(Collectors.joining("\n")); 40 | expectedXml = expectedXml.replaceAll("<\\s+", "<"); 41 | expectedXml = expectedXml.replaceAll("\\s+/>", "/>"); 42 | expectedXml = expectedXml.replaceAll("\\s*alias=\"[^\"]+\"", ""); 43 | Assert.assertFalse(xml.isEmpty()); 44 | Assert.assertFalse(expectedXml.isEmpty()); 45 | Assert.assertEquals(expectedXml, xml); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/VersionServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.BeforeClass; 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.entity.Version; 18 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 19 | 20 | public class VersionServiceTest { 21 | 22 | private static final boolean TEST = true; 23 | 24 | private static Version validVersion; 25 | private static Version invalidVersion; 26 | 27 | @BeforeClass 28 | public static void setup() { 29 | VersionService versionService = 30 | new VersionService.Builder() 31 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 32 | .build(); 33 | validVersion = versionService.getVersion("10.0.0"); 34 | invalidVersion = versionService.getVersion("1.0.0"); 35 | } 36 | 37 | @Test 38 | public void testValidVersion() { 39 | assertThat(validVersion.valid).isTrue(); 40 | assertThat(validVersion.expire).isNotNull(); 41 | assertThat(validVersion.update).isNotNull(); 42 | assertThat(validVersion.minVersion).matches("\\d+\\.\\d+\\.\\d+"); 43 | assertThat(validVersion.latestVersion).matches("\\d+\\.\\d+\\.\\d+"); 44 | } 45 | 46 | @Test 47 | public void testInvalidVersion() { 48 | assertThat(invalidVersion.valid).isFalse(); 49 | assertThat(invalidVersion.expire).isNotNull(); 50 | assertThat(invalidVersion.update).isNotNull(); 51 | assertThat(invalidVersion.minVersion).matches("\\d+\\.\\d+\\.\\d+"); 52 | assertThat(invalidVersion.latestVersion).matches("\\d+\\.\\d+\\.\\d+"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/reads/ReadsManifestReaderFileCountTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.reads; 12 | 13 | import org.junit.Test; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderFileCountTester; 15 | import uk.ac.ebi.ena.webin.cli.validator.manifest.ReadsManifest; 16 | 17 | public class ReadsManifestReaderFileCountTest { 18 | 19 | @Test 20 | public void testFileCount() { 21 | new ManifestReaderFileCountTester<>(ReadsManifestReader.class, ReadsManifest.FileType.values()) 22 | // Supported file groups 23 | .files(ReadsManifest.FileType.BAM) 24 | .files(ReadsManifest.FileType.CRAM) 25 | // The way this test is written, all possible combinations up until the desired maximum must 26 | // be provided for it to pass. 27 | // That is why all following combinations of fastq files (1, 2, 3, 4) up until the maximum 28 | // of 4 are defined. 29 | // Skipping a combination e.g. 3 from (1, 2, 4) will fail the test. 30 | // If we decide to increase the number to, say 7 from 4, then the combinations will turn out 31 | // to be 32 | // (1, 2, 3, 4, 5, 6, 7) i.e. 5 and 6 must then be added explicitly as well. 33 | .files(ReadsManifest.FileType.FASTQ) 34 | .files(ReadsManifest.FileType.FASTQ, ReadsManifest.FileType.FASTQ) 35 | .files( 36 | ReadsManifest.FileType.FASTQ, 37 | ReadsManifest.FileType.FASTQ, 38 | ReadsManifest.FileType.FASTQ) 39 | .files( 40 | ReadsManifest.FileType.FASTQ, 41 | ReadsManifest.FileType.FASTQ, 42 | ReadsManifest.FileType.FASTQ, 43 | ReadsManifest.FileType.FASTQ) 44 | .test(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/resources/uk/ac/ebi/ena/webin/cli/reads/instrument.properties: -------------------------------------------------------------------------------- 1 | HiSeq\ X\ Five=ILLUMINA 2 | HiSeq\ X\ Ten=ILLUMINA 3 | Illumina\ Genome\ Analyzer=ILLUMINA 4 | Illumina\ Genome\ Analyzer\ II=ILLUMINA 5 | Illumina\ Genome\ Analyzer\ IIx=ILLUMINA 6 | Illumina\ HiScanSQ=ILLUMINA 7 | Illumina\ HiSeq\ 1000=ILLUMINA 8 | Illumina\ HiSeq\ 1500=ILLUMINA 9 | Illumina\ HiSeq\ 2000=ILLUMINA 10 | Illumina\ HiSeq\ 2500=ILLUMINA 11 | Illumina\ HiSeq\ 3000=ILLUMINA 12 | Illumina\ HiSeq\ 4000=ILLUMINA 13 | Illumina\ HiSeq\ X=ILLUMINA 14 | Illumina\ iSeq\ 100=ILLUMINA 15 | Illumina\ MiSeq=ILLUMINA 16 | Illumina\ MiniSeq=ILLUMINA 17 | Illumina\ NovaSeq\ 6000=ILLUMINA 18 | Illumina\ NovaSeq\ X=ILLUMINA 19 | Illumina\ NovaSeq\ X\ Plus=ILLUMINA 20 | NextSeq\ 500=ILLUMINA 21 | NextSeq\ 550=ILLUMINA 22 | NextSeq\ 1000=ILLUMINA 23 | NextSeq\ 2000=ILLUMINA 24 | MinION=OXFORD_NANOPORE 25 | GridION=OXFORD_NANOPORE 26 | PromethION=OXFORD_NANOPORE 27 | Onso=PACBIO_SMRT 28 | PacBio\ RS=PACBIO_SMRT 29 | PacBio\ RS\ II=PACBIO_SMRT 30 | Revio=PACBIO_SMRT 31 | Sequel=PACBIO_SMRT 32 | Sequel\ II=PACBIO_SMRT 33 | Sequel\ IIe=PACBIO_SMRT 34 | BGISEQ-50=BGISEQ 35 | BGISEQ-500=BGISEQ 36 | MGISEQ-2000RS=BGISEQ 37 | 454\ GS=LS454 38 | 454\ GS\ 20=LS454 39 | 454\ GS\ FLX=LS454 40 | 454\ GS\ FLX+=LS454 41 | 454\ GS\ FLX\ Titanium=LS454 42 | 454\ GS\ Junior=LS454 43 | Ion\ Torrent\ Genexus=ION_TORRENT 44 | Ion\ Torrent\ PGM=ION_TORRENT 45 | Ion\ Torrent\ Proton=ION_TORRENT 46 | Ion\ Torrent\ S5=ION_TORRENT 47 | Ion\ Torrent\ S5\ XL=ION_TORRENT 48 | Ion\ GeneStudio\ S5=ION_TORRENT 49 | Ion\ GeneStudio\ S5\ Plus=ION_TORRENT 50 | Ion\ GeneStudio\ S5\ Prime=ION_TORRENT 51 | AB\ 3730xL\ Genetic\ Analyzer=CAPILLARY 52 | AB\ 3730\ Genetic\ Analyzer=CAPILLARY 53 | AB\ 3500xL\ Genetic\ Analyzer=CAPILLARY 54 | AB\ 3500\ Genetic\ Analyzer=CAPILLARY 55 | AB\ 3130xL\ Genetic\ Analyzer=CAPILLARY 56 | AB\ 3130\ Genetic\ Analyzer=CAPILLARY 57 | AB\ 310\ Genetic\ Analyzer=CAPILLARY 58 | DNBSEQ-T7=DNBSEQ 59 | DNBSEQ-G400=DNBSEQ 60 | DNBSEQ-G50=DNBSEQ 61 | DNBSEQ-G400\ FAST=DNBSEQ 62 | DNBSEQ-T10x4RS=DNBSEQ 63 | Element\ AVITI=ELEMENT 64 | UG\ 100=ULTIMA 65 | Sentosa\ SQ301=VELA_DIAGNOSTICS 66 | GENIUS=GENAPSYS 67 | Genapsys\ Sequencer=GENAPSYS 68 | GS111=GENAPSYS 69 | GenoCare\ 1600=GENEMIND 70 | GenoLab\ M=GENEMIND 71 | FASTASeq 300=GENEMIND 72 | Tapestri=TAPESTRI 73 | unspecified=LS454,ILLUMINA,PACBIO_SMRT,ION_TORRENT,OXFORD_NANOPORE,DNBSEQ,ELEMENT,ULTIMA,VELA_DIAGNOSTICS,GENAPSYS,GENEMIND,TAPESTRI -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/service/VersionService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.web.client.HttpServerErrorException; 16 | import org.springframework.web.client.ResourceAccessException; 17 | import org.springframework.web.client.RestTemplate; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 19 | import uk.ac.ebi.ena.webin.cli.entity.Version; 20 | import uk.ac.ebi.ena.webin.cli.utils.ExceptionUtils; 21 | import uk.ac.ebi.ena.webin.cli.utils.RetryUtils; 22 | 23 | public class VersionService extends WebinService { 24 | private static final Logger log = LoggerFactory.getLogger(VersionService.class); 25 | 26 | public static class Builder extends AbstractBuilder { 27 | public VersionService build() { 28 | return new VersionService(this); 29 | } 30 | } 31 | 32 | protected VersionService(Builder builder) { 33 | super(builder); 34 | } 35 | 36 | public Version getVersion(String version) { 37 | RestTemplate restTemplate = new RestTemplate(); 38 | 39 | return ExceptionUtils.executeWithRestExceptionHandling( 40 | () -> 41 | RetryUtils.executeWithRetry( 42 | retryContext -> 43 | restTemplate.getForObject( 44 | resolveAgainstWebinRestV1Uri("/cli/{version}"), Version.class, version), 45 | retryContext -> log.warn("Retrying version retrieval from server."), 46 | HttpServerErrorException.class, 47 | ResourceAccessException.class), 48 | WebinCliMessage.SERVICE_AUTHENTICATION_ERROR.format("Version"), 49 | null, 50 | WebinCliMessage.VERSION_SERVICE_SYSTEM_ERROR.text()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/CustomFieldProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import org.apache.commons.lang3.tuple.ImmutablePair; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldGroup; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 17 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 18 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 19 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 20 | 21 | public class CustomFieldProcessor implements ManifestFieldProcessor { 22 | 23 | private ManifestFieldProcessor.Callback> callback; 24 | 25 | public void setCallback(Callback> callback) { 26 | this.callback = callback; 27 | } 28 | 29 | @Override 30 | public void process( 31 | ValidationResult result, ManifestFieldGroup fieldGroup, ManifestFieldValue fieldValue) { 32 | String value = fieldValue.getValue(); 33 | 34 | if (value == null || value.trim().isEmpty()) { 35 | result.add( 36 | ValidationMessage.error( 37 | WebinCliMessage.CUSTOM_FIELD_PROCESSOR_INCORRECT_FIELD_VALUE, 38 | fieldValue.getName(), 39 | value)); 40 | return; 41 | } 42 | 43 | String keyVal[] = value.split(":"); 44 | if (keyVal.length == 2) { 45 | ImmutablePair pair = new ImmutablePair<>(keyVal[0], keyVal[1]); 46 | callback.notify(fieldGroup, pair); 47 | } else { 48 | result.add( 49 | ValidationMessage.error( 50 | WebinCliMessage.CUSTOM_FIELD_PROCESSOR_INCORRECT_FIELD_VALUE, 51 | fieldValue.getName(), 52 | value)); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/metadata/StudyProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor.metadata; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.processor.ProcessorTestUtils.createFieldValue; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.WebinCliParameters; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 20 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 21 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 22 | 23 | public class StudyProcessorTest { 24 | private final WebinCliParameters parameters = WebinCliTestUtils.getTestWebinCliParameters(); 25 | 26 | @Test 27 | public void testCorrect() { 28 | StudyProcessor processor = 29 | new StudyProcessor( 30 | parameters, 31 | (fieldGroup, study) -> Assert.assertEquals("PRJNA28545", study.getBioProjectId())); 32 | 33 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "STUDY", "SRP000392"); 34 | ValidationResult result = new ValidationResult(); 35 | processor.process(result, fieldValue); 36 | Assert.assertTrue(result.isValid()); 37 | Assert.assertEquals("PRJNA28545", fieldValue.getValue()); 38 | } 39 | 40 | @Test 41 | public void testIncorrect() { 42 | StudyProcessor processor = 43 | new StudyProcessor(parameters, (fieldGroup, study) -> Assert.assertNull(study)); 44 | 45 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "STUDY", "ERS000002"); 46 | ValidationResult result = new ValidationResult(); 47 | processor.process(result, fieldValue); 48 | Assert.assertFalse(result.isValid()); 49 | Assert.assertEquals("ERS000002", fieldValue.getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/LoginServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | 21 | public class LoginServiceTest { 22 | 23 | @Test 24 | public void testValidLoginProd() { 25 | String userName = 26 | new LoginService( 27 | WebinCliTestUtils.getTestWebinUsername(), 28 | WebinCliTestUtils.getTestWebinPassword(), 29 | false) 30 | .login(); 31 | 32 | assertThat(userName).matches("Webin-\\d+"); 33 | } 34 | 35 | @Test 36 | public void testValidLoginTest() { 37 | String userName = 38 | new LoginService( 39 | WebinCliTestUtils.getTestWebinUsername(), 40 | WebinCliTestUtils.getTestWebinPassword(), 41 | true) 42 | .login(); 43 | 44 | assertThat(userName).matches("Webin-\\d+"); 45 | } 46 | 47 | @Test 48 | public void testInvalidLoginProd() { 49 | assertThatThrownBy( 50 | () -> 51 | new LoginService(WebinCliTestUtils.getTestWebinUsername(), "INVALID", false) 52 | .login()) 53 | .isInstanceOf(WebinCliException.class) 54 | .hasMessage(WebinCliMessage.CLI_AUTHENTICATION_ERROR.text()); 55 | } 56 | 57 | @Test 58 | public void testInvalidLoginTest() { 59 | assertThatThrownBy( 60 | () -> 61 | new LoginService(WebinCliTestUtils.getTestWebinUsername(), "INVALID", true).login()) 62 | .isInstanceOf(WebinCliException.class) 63 | .hasMessage(WebinCliMessage.CLI_AUTHENTICATION_ERROR.text()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/CVFieldProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import java.util.List; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestCVList; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 17 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 18 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 19 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 20 | 21 | public class CVFieldProcessor implements ManifestFieldProcessor { 22 | public static final CVFieldProcessor CV_BOOLEAN = 23 | new CVFieldProcessor(new ManifestCVList("yes", "no", "true", "false", "Y", "N")); 24 | 25 | private final ManifestCVList cvList; 26 | 27 | public CVFieldProcessor(String... values) { 28 | this.cvList = new ManifestCVList(values); 29 | } 30 | 31 | public CVFieldProcessor(ManifestCVList cvList) { 32 | this.cvList = cvList; 33 | } 34 | 35 | @Override 36 | public void process(ValidationResult result, ManifestFieldValue fieldValue) { 37 | String value = fieldValue.getValue(); 38 | 39 | if (!cvList.contains(value)) { 40 | result.add( 41 | ValidationMessage.error( 42 | WebinCliMessage.CV_FIELD_PROCESSOR_ERROR, 43 | fieldValue.getName(), 44 | value, 45 | cvList.keyList())); 46 | return; 47 | } 48 | 49 | String corrected = cvList.getKey(value); 50 | 51 | if (!value.equals(corrected)) { 52 | fieldValue.setValue(corrected); 53 | result.add( 54 | ValidationMessage.info( 55 | WebinCliMessage.CV_FIELD_PROCESSOR_FIELD_VALUE_CORRECTED, 56 | fieldValue.getName(), 57 | value, 58 | corrected)); 59 | } 60 | } 61 | 62 | public List getValues() { 63 | return cvList.keyList(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/ASCIIFileNameProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.processor.ProcessorTestUtils.createFieldValue; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 18 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 19 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 20 | 21 | public class ASCIIFileNameProcessorTest { 22 | @Test 23 | public void test() { 24 | ASCIIFileNameProcessor processor = new ASCIIFileNameProcessor(); 25 | 26 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "a.bam"); 27 | ValidationResult result = new ValidationResult(); 28 | processor.process(result, fieldValue); 29 | Assert.assertEquals(0, result.count()); 30 | Assert.assertEquals("a.bam", fieldValue.getValue()); 31 | 32 | fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "/a/b/c.bam"); 33 | result = new ValidationResult(); 34 | processor.process(result, fieldValue); 35 | Assert.assertEquals(0, result.count()); 36 | 37 | fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "a:\\B\\c.bam"); 38 | result = new ValidationResult(); 39 | processor.process(result, fieldValue); 40 | Assert.assertEquals(0, result.count()); 41 | 42 | fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "a|b.cram"); 43 | result = new ValidationResult(); 44 | processor.process(result, fieldValue); 45 | Assert.assertEquals(false, result.isValid()); 46 | 47 | fieldValue = createFieldValue(ManifestFieldType.META, "FIELD1", "a&b.cram"); 48 | result = new ValidationResult(); 49 | processor.process(result, fieldValue); 50 | Assert.assertEquals(false, result.isValid()); 51 | Assert.assertEquals("a&b.cram", fieldValue.getValue()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Webin command line submission interface (Webin-CLI) 2 | 3 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c4fa2bcf5593436da9ea27149f84ee6e)](https://app.codacy.com/app/enasequence/webin-cli?utm_source=github.com&utm_medium=referral&utm_content=enasequence/webin-cli&utm_campaign=badger) 4 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 5 | 6 | ## Introduction 7 | 8 | Data submissions to ENA can be made using the Webin command line submission interface (Webin-CLI). Webin submission account credentials are required to use the program. 9 | 10 | The following types of submissions are supported: 11 | 12 | - genome assemblies 13 | - transcriptome assemblies 14 | - annotated sequences 15 | - read data submissions (Fastq, BAM, CRAM) 16 | - taxonomy reference sets 17 | - environmental sequence sets (polysample) 18 | 19 | For further information about Webin-CLI please refer to: 20 | 21 | 22 | 23 | ## Executable Java JAR 24 | 25 | The latest version of the Webin-CLI can be downloaded from: 26 | 27 | 28 | 29 | The program requires Java 1.8 or a newer which can be downloaded from: 30 | 31 | 32 | 33 | 34 | The program is run using the java command: 35 | 36 | ``` 37 | java -jar webin-cli-.jar 38 | ``` 39 | 40 | for example: 41 | 42 | ``` 43 | java -jar webin-cli-2.0.0.jar -help 44 | ``` 45 | 46 | To increase the memory available to Webin-CLI please use the -Xms java option: 47 | 48 | ``` 49 | java -Xms2G -jar webin-cli-2.0.0.jar -help 50 | ``` 51 | 52 | ## Docker 53 | 54 | ### Run 55 | 56 | Since version 1.8.12 Webin-CLI is available as a docker image: 57 | 58 | ``` 59 | docker pull enasequence/webin-cli 60 | docker run --rm -v :/data enasequence/webin-cli -help 61 | ``` 62 | 63 | To increase the memory available to Webin-CLI please set the JAVA_TOOL_OPTIONS environment variable: 64 | 65 | ``` 66 | docker run --rm -v :/data -e JAVA_TOOL_OPTIONS="-Xms2G" enasequence/webin-cli -help 67 | ``` 68 | 69 | ### Publishing 70 | 71 | - Create docker image with default tags by running `gradle dockerTag` 72 | 73 | ## Testing 74 | 75 | Testing requires the following environmental variables to be set: 76 | - webin-cli-username or webinCliUsername 77 | - webin-cli-password or webinCliPassword 78 | 79 | ## Library Jar Publishing 80 | 81 | To publish webin-cli as a library : 82 | 83 | ``` 84 | gradle publish 85 | ``` 86 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFieldValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationOrigin; 16 | 17 | public class ManifestFieldValue { 18 | private final ManifestFieldDefinition definition; 19 | private String value; 20 | private List attributes; 21 | private final List origin = new ArrayList<>(); 22 | private boolean validFieldValueOrFileSuffix = true; 23 | 24 | public ManifestFieldValue( 25 | ManifestFieldDefinition definition, 26 | String value, 27 | List attributes, 28 | ValidationOrigin origin) { 29 | 30 | assert (definition != null); 31 | assert (value != null); 32 | this.definition = definition; 33 | this.value = value; 34 | this.attributes = attributes; 35 | this.origin.add(origin); 36 | this.origin.add(new ValidationOrigin("field", definition.getName())); 37 | this.origin.add(new ValidationOrigin("value", value)); 38 | } 39 | 40 | public String getName() { 41 | return definition.getName(); 42 | } 43 | 44 | public ManifestFieldDefinition getDefinition() { 45 | return definition; 46 | } 47 | 48 | public String getValue() { 49 | return value; 50 | } 51 | 52 | public void setValue(String value) { 53 | this.value = value; 54 | } 55 | 56 | public boolean isValidFieldValueOrFileSuffix() { 57 | return validFieldValueOrFileSuffix; 58 | } 59 | 60 | public void setValidFieldValueOrFileSuffix(boolean validFieldValueOrFileSuffix) { 61 | this.validFieldValueOrFileSuffix = validFieldValueOrFileSuffix; 62 | } 63 | 64 | public List getOrigin() { 65 | return origin; 66 | } 67 | 68 | public List getAttributes() { 69 | return attributes; 70 | } 71 | 72 | public void setAttributes(List attributes) { 73 | this.attributes = attributes; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFieldGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | import java.util.stream.Collectors; 18 | import org.apache.commons.lang.StringUtils; 19 | 20 | /** 21 | * A manifest field group is a collection of fields read from a manifest file. A single manifest 22 | * file can have multiple groups of fields. Each group is considered as an independent submission 23 | * manifest. 24 | */ 25 | public class ManifestFieldGroup extends ArrayList { 26 | 27 | public ManifestFieldValue getField(String fieldName) { 28 | return this.stream() 29 | .filter(field -> field.getName().equalsIgnoreCase(fieldName)) 30 | .findFirst() 31 | .orElse(null); 32 | } 33 | 34 | public String getValue(String fieldName) { 35 | return this.stream() 36 | .filter(field -> field.getName().equalsIgnoreCase(fieldName)) 37 | .findFirst() 38 | .map(field -> field.getValue()) 39 | .orElse(null); 40 | } 41 | 42 | public Map getNonEmptyValues(String... fieldNames) { 43 | Map nameValues = new HashMap<>(); 44 | 45 | this.forEach( 46 | field -> { 47 | for (String fieldName : fieldNames) { 48 | if (field.getName().equalsIgnoreCase(fieldName) 49 | && StringUtils.isNotBlank(field.getValue())) { 50 | nameValues.put(fieldName, field.getValue()); 51 | } 52 | } 53 | }); 54 | 55 | return nameValues; 56 | } 57 | 58 | public Collection getValues(String fieldName) { 59 | return this.stream() 60 | .filter(field -> field.getName().equalsIgnoreCase(fieldName)) 61 | .map(field -> field.getValue()) 62 | .collect(Collectors.toList()); 63 | } 64 | 65 | public int getCount(String fieldName) { 66 | return (int) this.stream().filter(field -> field.getName().equalsIgnoreCase(fieldName)).count(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/resources/uk/ac/ebi/ena/webin/cli/reads/selection.properties: -------------------------------------------------------------------------------- 1 | RANDOM=No Selection or Random selection 2 | PCR=target enrichment via PCR 3 | RANDOM\ PCR=Source material was selected by randomly generated primers. 4 | RT-PCR=target enrichment via 5 | HMPR=Hypo-methylated partial restriction digest 6 | MF=Methyl Filtrated 7 | repeat\ fractionation=Selection for less repetitive (and more gene rich) sequence through Cot filtration (CF) or other fractionation techniques based on DNA kinetics. 8 | size\ fractionation=Physical selection of size appropriate targets. 9 | MSLL=Methylation Spanning Linking Library 10 | cDNA=PolyA selection or enrichment for messenger RNA (mRNA); synonymize with PolyA 11 | cDNA_randomPriming= 12 | cDNA_oligo_dT= 13 | PolyA=PolyA selection or enrichment for messenger RNA (mRNA); should replace cDNA enumeration. 14 | Oligo-dT=enrichment of messenger RNA (mRNA) by hybridization to Oligo-dT. 15 | Inverse\ rRNA=depletion of ribosomal RNA by oligo hybridization. 16 | Inverse\ rRNA\ selection=depletion of ribosomal RNA by inverse oligo hybridization. 17 | ChIP=Chromatin immunoprecipitation 18 | ChIP-Seq=Chromatin immunoPrecipitation, reveals binding sites of specific proteins, typically transcription factors (TFs) using antibodies to extract DNA fragments bound to the target protein. 19 | MNase=Identifies well-positioned nucleosomes. uses Micrococcal Nuclease (MNase) is an endo-exonuclease that processively digests DNA until an obstruction, such as a nucleosome, is reached. 20 | DNase=DNase I endonuclease digestion and size selection reveals regions of chromatin where the DNA is highly sensitive to DNase I. 21 | Hybrid\ Selection=Selection by hybridization in array or solution. 22 | Reduced\ Representation=Reproducible genomic subsets, often generated by restriction fragment size selection, containing a manageable number of loci to facilitate re-sampling. 23 | Restriction\ Digest=DNA fractionation using restriction enzymes. 24 | 5-methylcytidine\ antibody=Selection of methylated DNA fragments using an antibody raised against 5-methylcytosine or 5-methylcytidine (m5C). 25 | MBD2\ protein\ methyl-CpG\ binding\ domain=Enrichment by methyl-CpG binding domain. 26 | CAGE=Cap-analysis gene expression. 27 | RACE=Rapid Amplification of cDNA Ends. 28 | MDA=Multiple Displacement Amplification, a non-PCR based DNA amplification technique that amplifies a minute quantifies of DNA to levels suitable for genomic analysis. 29 | padlock\ probes\ capture\ method=Targeted sequence capture protocol covering an arbitrary set of nonrepetitive genomics targets. An example is capture bisulfite sequencing using padlock probes (BSPP). 30 | other=Other library enrichment, screening, or selection process. 31 | unspecified=Library enrichment, screening, or selection is not specified. -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/WebinCliContextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.Test; 16 | import uk.ac.ebi.ena.webin.cli.context.genome.GenomeManifestReader; 17 | import uk.ac.ebi.ena.webin.cli.context.genome.GenomeXmlWriter; 18 | import uk.ac.ebi.ena.webin.cli.context.reads.ReadsManifestReader; 19 | import uk.ac.ebi.ena.webin.cli.context.reads.ReadsXmlWriter; 20 | import uk.ac.ebi.ena.webin.cli.context.sequence.SequenceManifestReader; 21 | import uk.ac.ebi.ena.webin.cli.context.sequence.SequenceXmlWriter; 22 | import uk.ac.ebi.ena.webin.cli.context.transcriptome.TranscriptomeManifestReader; 23 | import uk.ac.ebi.ena.webin.cli.context.transcriptome.TranscriptomeXmlWriter; 24 | 25 | public class WebinCliContextTest { 26 | 27 | @Test 28 | public void testCreateExecutor() { 29 | WebinCliParameters parameters = WebinCliTestUtils.getTestWebinCliParameters(); 30 | 31 | assertThat(WebinCliContext.genome.createExecutor(parameters).getManifestReader()) 32 | .isInstanceOf(GenomeManifestReader.class); 33 | assertThat(WebinCliContext.genome.createExecutor(parameters).getXmlWriter()) 34 | .isInstanceOf(GenomeXmlWriter.class); 35 | 36 | assertThat(WebinCliContext.transcriptome.createExecutor(parameters).getManifestReader()) 37 | .isInstanceOf(TranscriptomeManifestReader.class); 38 | assertThat(WebinCliContext.transcriptome.createExecutor(parameters).getXmlWriter()) 39 | .isInstanceOf(TranscriptomeXmlWriter.class); 40 | 41 | assertThat(WebinCliContext.sequence.createExecutor(parameters).getManifestReader()) 42 | .isInstanceOf(SequenceManifestReader.class); 43 | assertThat(WebinCliContext.sequence.createExecutor(parameters).getXmlWriter()) 44 | .isInstanceOf(SequenceXmlWriter.class); 45 | 46 | assertThat(WebinCliContext.reads.createExecutor(parameters).getManifestReader()) 47 | .isInstanceOf(ReadsManifestReader.class); 48 | assertThat(WebinCliContext.reads.createExecutor(parameters).getXmlWriter()) 49 | .isInstanceOf(ReadsXmlWriter.class); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/CustomFieldProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.manifest.processor.ProcessorTestUtils.createFieldValue; 14 | 15 | import org.apache.commons.lang3.tuple.ImmutablePair; 16 | import org.junit.Assert; 17 | import org.junit.Before; 18 | import org.junit.Test; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 20 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 21 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 22 | 23 | public class CustomFieldProcessorTest { 24 | 25 | private ImmutablePair parsedValue; 26 | private CustomFieldProcessor processor = new CustomFieldProcessor(); 27 | 28 | @Before 29 | public void init() { 30 | processor.setCallback( 31 | (fieldGroup, keyVal) -> parsedValue = new ImmutablePair<>(keyVal.left, keyVal.right)); 32 | } 33 | 34 | @Test 35 | public void testValid() { 36 | ManifestFieldValue fieldValue = 37 | createFieldValue(ManifestFieldType.META, "CUSTOM_FIELD", "TEST_KEY:TEST_VAL"); 38 | ValidationResult result = new ValidationResult(); 39 | processor.process(result, fieldValue); 40 | Assert.assertTrue(result.isValid()); 41 | Assert.assertEquals("TEST_KEY", parsedValue.left); 42 | Assert.assertEquals("TEST_VAL", parsedValue.right); 43 | } 44 | 45 | @Test 46 | public void testInValidValueFormat() { 47 | ManifestFieldValue fieldValue = 48 | createFieldValue(ManifestFieldType.META, "CUSTOM_FIELD", "TEST_KEYTEST_VAL"); 49 | ValidationResult result = new ValidationResult(); 50 | processor.process(result, fieldValue); 51 | Assert.assertFalse(result.isValid()); 52 | } 53 | 54 | @Test 55 | public void testInValidEmptyValue() { 56 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "CUSTOM_FIELD", " "); 57 | ValidationResult result = new ValidationResult(); 58 | processor.process(result, fieldValue); 59 | Assert.assertFalse(result.isValid()); 60 | } 61 | 62 | @Test(expected = AssertionError.class) 63 | public void testInValidNullValue() { 64 | createFieldValue(ManifestFieldType.META, "CUSTOM_FIELD", null); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/metadata/StudyProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor.metadata; 12 | 13 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 14 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldGroup; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 17 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorParameters; 18 | import uk.ac.ebi.ena.webin.cli.service.StudyService; 19 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 20 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 21 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 22 | import uk.ac.ebi.ena.webin.cli.validator.reference.Study; 23 | 24 | public class StudyProcessor implements ManifestFieldProcessor { 25 | 26 | private final MetadataProcessorParameters parameters; 27 | private ManifestFieldProcessor.Callback callback; 28 | 29 | public StudyProcessor( 30 | MetadataProcessorParameters parameters, ManifestFieldProcessor.Callback callback) { 31 | this.parameters = parameters; 32 | this.callback = callback; 33 | } 34 | 35 | public StudyProcessor(MetadataProcessorParameters parameters) { 36 | this.parameters = parameters; 37 | } 38 | 39 | public void setCallback(Callback callback) { 40 | this.callback = callback; 41 | } 42 | 43 | public Callback getCallback() { 44 | return callback; 45 | } 46 | 47 | @Override 48 | public void process( 49 | ValidationResult result, ManifestFieldGroup fieldGroup, ManifestFieldValue fieldValue) { 50 | String value = fieldValue.getValue(); 51 | 52 | try { 53 | StudyService studyService = 54 | new StudyService.Builder() 55 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(parameters.isTest())) 56 | .setCredentials(parameters.getWebinServiceUserName(), parameters.getPassword()) 57 | .build(); 58 | Study study = studyService.getStudy(value); 59 | fieldValue.setValue(study.getBioProjectId()); 60 | callback.notify(fieldGroup, study); 61 | 62 | } catch (WebinCliException e) { 63 | result.add(ValidationMessage.error(e)); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/sequence/SequenceManifestReaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.sequence; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.junit.Assert.*; 15 | import static uk.ac.ebi.ena.webin.cli.context.reads.ReadsManifestReader.Field; 16 | 17 | import java.nio.file.Paths; 18 | import java.util.Locale; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | import uk.ac.ebi.ena.webin.cli.ManifestBuilder; 22 | import uk.ac.ebi.ena.webin.cli.TempFileBuilder; 23 | import uk.ac.ebi.ena.webin.cli.WebinCliParameters; 24 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 25 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReader; 26 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorFactory; 27 | import uk.ac.ebi.ena.webin.cli.validator.manifest.SequenceManifest; 28 | 29 | public class SequenceManifestReaderTest { 30 | private static SequenceManifestReader createManifestReader() { 31 | WebinCliParameters parameters = WebinCliTestUtils.getTestWebinCliParameters(); 32 | return new SequenceManifestReader(parameters, new MetadataProcessorFactory(parameters)); 33 | } 34 | 35 | @Before 36 | public void before() { 37 | Locale.setDefault(Locale.UK); 38 | } 39 | 40 | @Test 41 | public void testValidSequenceFlatFileManifest() { 42 | SequenceManifestReader manifestReader = createManifestReader(); 43 | 44 | manifestReader.readManifest( 45 | Paths.get("."), 46 | new ManifestBuilder() 47 | .field(ManifestReader.Fields.NAME, " SOME-FANCY-NAME") 48 | .field(Field.DESCRIPTION, " description") 49 | .file("FLATFILE", TempFileBuilder.empty("csv")) 50 | .field(ManifestReader.Fields.SUBMISSION_TOOL, "ST-001") 51 | .field(ManifestReader.Fields.SUBMISSION_TOOL_VERSION, "STV-001") 52 | .build()); 53 | 54 | SequenceManifest manifest = manifestReader.getManifests().stream().findFirst().get(); 55 | 56 | assertEquals("SOME-FANCY-NAME", manifest.getName()); 57 | assertThat(manifest.files().files()).size().isOne(); 58 | assertEquals("description", manifest.getDescription()); 59 | assertEquals("ST-001", manifest.getSubmissionTool()); 60 | assertEquals("STV-001", manifest.getSubmissionToolVersion()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/spreadsheet/SpreadsheetContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.spreadsheet; 12 | 13 | import uk.ac.ebi.ena.webin.cli.context.genome.GenomeManifestReader; 14 | import uk.ac.ebi.ena.webin.cli.context.reads.ReadsManifestReader; 15 | import uk.ac.ebi.ena.webin.cli.context.sequence.SequenceManifestReader; 16 | import uk.ac.ebi.ena.webin.cli.context.transcriptome.TranscriptomeManifestReader; 17 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReader; 18 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReaderBuilder; 19 | 20 | public enum SpreadsheetContext { 21 | GENOME( 22 | new ManifestReaderBuilder(GenomeManifestReader.class).build(), 23 | "genome", 24 | "Additionally, primary and binned metagenomes and clinical isolate assembly must have " 25 | + ManifestReader.getFileGroupText( 26 | GenomeManifestReader 27 | .PRIMARY_AND_BINNED_METAGENOME_AND_CLINICAL_ISOLATE_ASSEMBLY_FILE_GROUPS) 28 | + " files."), 29 | TRANSCRIPTOME( 30 | new ManifestReaderBuilder(TranscriptomeManifestReader.class).build(), "transcriptome", null), 31 | SEQUENCE(new ManifestReaderBuilder(SequenceManifestReader.class).build(), "sequence", null), 32 | READ(new ManifestReaderBuilder(ReadsManifestReader.class).build(), "read", null); 33 | 34 | SpreadsheetContext(ManifestReader manifest, String name, String extraFileGroupText) { 35 | this.fileName = name + ".xlsx"; 36 | this.sheetName = name; 37 | this.manifest = manifest; 38 | this.extraFileGroupText = extraFileGroupText; 39 | } 40 | 41 | private final String fileName; 42 | private final String sheetName; 43 | private final ManifestReader manifest; 44 | private final String extraFileGroupText; 45 | 46 | public ManifestReader getManifest() { 47 | return manifest; 48 | } 49 | 50 | public String getFileName() { 51 | return fileName; 52 | } 53 | 54 | public String getSheetName() { 55 | return sheetName; 56 | } 57 | 58 | public String getFileGroupText() { 59 | String fileGroupText = 60 | "Submission must have " 61 | + ManifestReader.getFileGroupText(manifest.getFileGroups()) 62 | + " files."; 63 | if (extraFileGroupText != null) { 64 | fileGroupText += " " + extraFileGroupText; 65 | } 66 | return fileGroupText; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestReaderTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import java.io.File; 16 | import java.nio.file.Path; 17 | import uk.ac.ebi.ena.webin.cli.ManifestBuilder; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.validator.manifest.Manifest; 21 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 22 | import uk.ac.ebi.ena.webin.cli.validator.message.listener.MessageCounter; 23 | 24 | /** Creates the validator and reads the manifest file without using the command line parser. */ 25 | public class ManifestReaderTester { 26 | private final Class> manifestReaderClass; 27 | 28 | public ManifestReaderTester(Class> manifestReaderClass) { 29 | this.manifestReaderClass = manifestReaderClass; 30 | } 31 | 32 | private ManifestReader create() { 33 | return new ManifestReaderBuilder( 34 | manifestReaderClass, WebinCliTestUtils.getTestWebinCliParameters()) 35 | .build(); 36 | } 37 | 38 | public ManifestReader test(ManifestBuilder manifest) { 39 | return test(manifest, WebinCliTestUtils.createTempDir()); 40 | } 41 | 42 | public ManifestReader test(ManifestBuilder manifest, File inputDir) { 43 | return test(manifest, inputDir.toPath()); 44 | } 45 | 46 | public ManifestReader test(ManifestBuilder manifest, Path inputDir) { 47 | ManifestReader reader = create(); 48 | reader.readManifest(inputDir, manifest.build(inputDir)); 49 | return reader; 50 | } 51 | 52 | public ManifestReader testError(ManifestBuilder manifest, WebinCliMessage message) { 53 | return testError(manifest, WebinCliTestUtils.createTempDir(), message); 54 | } 55 | 56 | public ManifestReader testError( 57 | ManifestBuilder manifest, File inputDir, WebinCliMessage message) { 58 | MessageCounter counter = 59 | MessageCounter.regex(ValidationMessage.Severity.ERROR, message.regex()); 60 | ManifestReader reader = create(); 61 | reader.addListener(counter); 62 | reader.readManifest(inputDir.toPath(), manifest.build(inputDir)); 63 | assertThat(counter.getCount()).isGreaterThanOrEqualTo(1); 64 | return reader; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/utils/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.utils; 12 | 13 | import java.util.function.Supplier; 14 | import org.springframework.web.client.HttpClientErrorException; 15 | import org.springframework.web.client.RestClientException; 16 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 17 | 18 | public class ExceptionUtils { 19 | 20 | /** 21 | * Runs given code and translates any {@link RestClientException} to {@link WebinCliException} if 22 | * thrown. Mapping rules are:
23 | *
24 | * HttpClientErrorException.Unauthorized or HttpClientErrorException.Forbidden -> 25 | * WebinCliException.userError
26 | * HttpClientErrorException.NotFound -> WebinCliException.validationError
27 | * RestClientException -> WebinCliException.systemError 28 | * 29 | * @param supplier 30 | * @param authenticationUserErrorMessage Message to use for WebinCliException.userError in case of 31 | * authentication failure. 32 | * @param validationErrorMessage Message to use for WebinCliException.validationError thrown in 33 | * case of validation error. If this is null and validation error occurs then 34 | * WebinCliException.systemError is thrown instead. 35 | * @param systemErrorMessage Message to use for WebinCliException.systemError thrown in case of 36 | * server error. 37 | * @return Returns back what the given supplier returns. 38 | * @param 39 | * @throws WebinCliException 40 | */ 41 | public static T executeWithRestExceptionHandling( 42 | Supplier supplier, 43 | String authenticationUserErrorMessage, 44 | String validationErrorMessage, 45 | String systemErrorMessage) 46 | throws WebinCliException { 47 | 48 | try { 49 | return supplier.get(); 50 | } catch (HttpClientErrorException.Unauthorized | HttpClientErrorException.Forbidden ex) { 51 | throw WebinCliException.userError(ex, authenticationUserErrorMessage); 52 | } catch (HttpClientErrorException.NotFound ex) { 53 | if (validationErrorMessage != null) { 54 | throw WebinCliException.validationError(ex, validationErrorMessage); 55 | } else { 56 | throw WebinCliException.systemError(ex, systemErrorMessage); 57 | } 58 | } catch (RestClientException ex) { 59 | throw WebinCliException.systemError(ex, systemErrorMessage); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/metadata/SampleXmlProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor.metadata; 12 | 13 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; 14 | import static uk.ac.ebi.ena.webin.cli.manifest.processor.ProcessorTestUtils.createFieldValue; 15 | 16 | import org.junit.Assert; 17 | import org.junit.Test; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliParameters; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 21 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 22 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 23 | import uk.ac.ebi.ena.webin.cli.validator.reference.Attribute; 24 | 25 | public class SampleXmlProcessorTest { 26 | 27 | private final WebinCliParameters parameters = WebinCliTestUtils.getTestWebinCliParameters(); 28 | 29 | private static final String STRAIN_NAME = "SK1"; 30 | 31 | @Test 32 | public void testCorrect() { 33 | SampleXmlProcessor processor = 34 | new SampleXmlProcessor( 35 | parameters, 36 | (fieldGroup, sample) -> { 37 | Assert.assertNotNull(sample); 38 | 39 | boolean assertStrain = false; 40 | for (Attribute attribute : sample.getAttributes()) { 41 | if (attribute.getName().equals("strain") 42 | && attribute.getValue().equals(STRAIN_NAME)) { 43 | assertStrain = true; 44 | } 45 | } 46 | assertThat(assertStrain); 47 | }); 48 | 49 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "SAMPLE", "ERS000002"); 50 | ValidationResult result = new ValidationResult(); 51 | processor.process(result, fieldValue); 52 | Assert.assertTrue(result.isValid()); 53 | } 54 | 55 | @Test 56 | public void testIncorrect() { 57 | SampleXmlProcessor processor = 58 | new SampleXmlProcessor(parameters, (fieldGroup, sample) -> Assert.assertNull(sample)); 59 | ManifestFieldValue fieldValue = createFieldValue(ManifestFieldType.META, "SAMPLE", "SRP000392"); 60 | ValidationResult result = new ValidationResult(); 61 | processor.process(result, fieldValue); 62 | Assert.assertFalse(result.isValid()); 63 | Assert.assertEquals("SRP000392", fieldValue.getValue()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestFileCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.util.ArrayList; 14 | 15 | public class ManifestFileCount { 16 | private final String fileType; 17 | private final int minCount; 18 | private final Integer maxCount; 19 | 20 | public ManifestFileCount(String fileType, int minCount, Integer maxCount) { 21 | this.fileType = fileType; 22 | this.minCount = minCount; 23 | this.maxCount = maxCount; 24 | } 25 | 26 | public String getFileType() { 27 | return fileType; 28 | } 29 | 30 | public int getMinCount() { 31 | return minCount; 32 | } 33 | 34 | public Integer getMaxCount() { 35 | return maxCount; 36 | } 37 | 38 | public static class Builder { 39 | private final ArrayList fileGroups = new ArrayList<>(); 40 | 41 | public static class Group { 42 | private final Builder builder; 43 | private final ManifestFileGroup fileGroup; 44 | 45 | private Group(Builder builder, String description) { 46 | this.builder = builder; 47 | this.fileGroup = new ManifestFileGroup(description); 48 | builder.fileGroups.add(this.fileGroup); 49 | } 50 | 51 | public Group required(String fieldName) { 52 | fileGroup.addFileCount(new ManifestFileCount(fieldName, 1, 1)); 53 | return this; 54 | } 55 | 56 | public Group required(String fieldName, int maxCount) { 57 | fileGroup.addFileCount(new ManifestFileCount(fieldName, 1, maxCount)); 58 | return this; 59 | } 60 | 61 | public Group required(String fieldName, int minCount, int maxCount) { 62 | fileGroup.addFileCount(new ManifestFileCount(fieldName, minCount, maxCount)); 63 | return this; 64 | } 65 | 66 | public Group optional(String fieldName) { 67 | fileGroup.addFileCount(new ManifestFileCount(fieldName, 0, 1)); 68 | return this; 69 | } 70 | 71 | public Group optional(String fieldName, int maxCount) { 72 | fileGroup.addFileCount(new ManifestFileCount(fieldName, 0, maxCount)); 73 | return this; 74 | } 75 | 76 | public Builder and() { 77 | return builder; 78 | } 79 | 80 | public ArrayList build() { 81 | return builder.fileGroups; 82 | } 83 | } 84 | 85 | public Group group(String description) { 86 | return new Group(this, description); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/service/utils/HttpLoggingInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service.utils; 12 | 13 | import java.io.IOException; 14 | import java.nio.charset.Charset; 15 | import java.nio.charset.StandardCharsets; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | import org.springframework.http.HttpRequest; 19 | import org.springframework.http.client.ClientHttpRequestExecution; 20 | import org.springframework.http.client.ClientHttpRequestInterceptor; 21 | import org.springframework.http.client.ClientHttpResponse; 22 | import org.springframework.util.StreamUtils; 23 | 24 | public class HttpLoggingInterceptor implements ClientHttpRequestInterceptor { 25 | 26 | private final Logger log = LoggerFactory.getLogger(this.getClass()); 27 | 28 | @Override 29 | public ClientHttpResponse intercept( 30 | HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { 31 | logRequest(request, body); 32 | ClientHttpResponse response = execution.execute(request, body); 33 | logResponse(response); 34 | return response; 35 | } 36 | 37 | private void logRequest(HttpRequest request, byte[] body) { 38 | if (log.isDebugEnabled()) { 39 | log.debug( 40 | "===========================request begin================================================"); 41 | log.debug("URI : {}", request.getURI()); 42 | log.debug("Method : {}", request.getMethod()); 43 | log.debug("Headers : {}", request.getHeaders()); 44 | log.debug("Request body: {}", new String(body, StandardCharsets.UTF_8)); 45 | log.debug( 46 | "==========================request end================================================"); 47 | } 48 | } 49 | 50 | private void logResponse(ClientHttpResponse response) throws IOException { 51 | if (log.isDebugEnabled()) { 52 | log.debug( 53 | "============================response begin=========================================="); 54 | log.debug("Status code : {}", response.getStatusCode()); 55 | log.debug("Status text : {}", response.getStatusText()); 56 | log.debug("Headers : {}", response.getHeaders()); 57 | log.debug( 58 | "Response body: {}", 59 | StreamUtils.copyToString(response.getBody(), Charset.defaultCharset())); 60 | log.debug( 61 | "=======================response end================================================="); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/transcriptome/TranscriptomeManifestReaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.transcriptome; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static uk.ac.ebi.ena.webin.cli.context.reads.ReadsManifestReader.Field; 15 | 16 | import java.nio.file.Paths; 17 | import java.util.Locale; 18 | import org.junit.Assert; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | import uk.ac.ebi.ena.webin.cli.ManifestBuilder; 22 | import uk.ac.ebi.ena.webin.cli.TempFileBuilder; 23 | import uk.ac.ebi.ena.webin.cli.WebinCliParameters; 24 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 25 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReader; 26 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorFactory; 27 | import uk.ac.ebi.ena.webin.cli.validator.manifest.TranscriptomeManifest; 28 | 29 | public class TranscriptomeManifestReaderTest { 30 | 31 | private static TranscriptomeManifestReader createManifestReader() { 32 | WebinCliParameters parameters = WebinCliTestUtils.getTestWebinCliParameters(); 33 | return new TranscriptomeManifestReader(parameters, new MetadataProcessorFactory(parameters)); 34 | } 35 | 36 | @Before 37 | public void before() { 38 | Locale.setDefault(Locale.UK); 39 | } 40 | 41 | @Test 42 | public void testValidManifest() { 43 | TranscriptomeManifestReader manifestReader = createManifestReader(); 44 | 45 | manifestReader.readManifest( 46 | Paths.get("."), 47 | new ManifestBuilder() 48 | .field(Field.PLATFORM, " illumina") 49 | .field(ManifestReader.Fields.NAME, " SOME-FANCY-NAME") 50 | .field(Field.DESCRIPTION, " description") 51 | .file("FASTA", TempFileBuilder.empty("fasta")) 52 | .field(ManifestReader.Fields.SUBMISSION_TOOL, "ST-001") 53 | .field(ManifestReader.Fields.SUBMISSION_TOOL_VERSION, "STV-001") 54 | .build()); 55 | 56 | TranscriptomeManifest manifest = manifestReader.getManifests().stream().findFirst().get(); 57 | 58 | Assert.assertEquals("illumina", manifest.getPlatform()); 59 | Assert.assertEquals("SOME-FANCY-NAME", manifest.getName()); 60 | assertThat(manifest.files().files()).size().isOne(); 61 | Assert.assertEquals("description", manifest.getDescription()); 62 | Assert.assertEquals("ST-001", manifest.getSubmissionTool()); 63 | Assert.assertEquals("STV-001", manifest.getSubmissionToolVersion()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/context/sequence/SequenceXmlWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.sequence; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.validator.manifest.SequenceManifest.FileType; 14 | import static uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createFileElement; 15 | import static uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createTextElement; 16 | 17 | import java.nio.file.Path; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import org.jdom2.Element; 21 | import uk.ac.ebi.ena.webin.cli.context.SequenceToolsXmlWriter; 22 | import uk.ac.ebi.ena.webin.cli.utils.FileUtils; 23 | import uk.ac.ebi.ena.webin.cli.validator.api.ValidationResponse; 24 | import uk.ac.ebi.ena.webin.cli.validator.manifest.SequenceManifest; 25 | 26 | public class SequenceXmlWriter 27 | extends SequenceToolsXmlWriter { 28 | 29 | @Override 30 | protected Element createXmlAnalysisTypeElement(SequenceManifest manifest) { 31 | String analysisType = "SEQUENCE_FLATFILE"; 32 | Element element = new Element(analysisType); 33 | 34 | if (null != manifest.getAuthors() && null != manifest.getAddress()) { 35 | element.addContent(createTextElement("AUTHORS", manifest.getAuthors())); 36 | element.addContent(createTextElement("ADDRESS", manifest.getAddress())); 37 | return element; 38 | } 39 | return element; 40 | } 41 | 42 | @Override 43 | protected List createXmlFileElements( 44 | SequenceManifest manifest, Path inputDir, Path uploadDir) { 45 | List list = new ArrayList<>(); 46 | 47 | manifest.files(FileType.FLATFILE).stream() 48 | .map(file -> file.getFile().toPath()) 49 | .forEach( 50 | file -> 51 | list.add( 52 | createFileElement( 53 | inputDir, 54 | uploadDir, 55 | file, 56 | FileUtils.calculateDigest("MD5", file.toFile()), 57 | "flatfile"))); 58 | manifest.files(FileType.TAB).stream() 59 | .map(file -> file.getFile().toPath()) 60 | .forEach( 61 | file -> 62 | list.add( 63 | createFileElement( 64 | inputDir, 65 | uploadDir, 66 | file, 67 | FileUtils.calculateDigest("MD5", file.toFile()), 68 | "tab"))); 69 | 70 | return list; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/AuthorProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import static org.junit.Assert.*; 14 | 15 | import java.util.ArrayList; 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.context.genome.GenomeManifestReader; 18 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldDefinition; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldType; 20 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 21 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 22 | 23 | public class AuthorProcessorTest { 24 | 25 | @Test 26 | public void testProcess() { 27 | ValidationResult result = new ValidationResult(); 28 | 29 | ManifestFieldDefinition fieldDef = 30 | new ManifestFieldDefinition.Builder() 31 | .type(ManifestFieldType.META) 32 | .name(GenomeManifestReader.Field.AUTHORS) 33 | .desc(GenomeManifestReader.Description.AUTHORS) 34 | .optional() 35 | .build() 36 | .get(0); 37 | ManifestFieldValue manifestField = 38 | new ManifestFieldValue(fieldDef, "Senthil .V", new ArrayList<>(), null); 39 | new AuthorProcessor().process(result, manifestField); 40 | assertEquals("Senthil .V", manifestField.getValue()); 41 | 42 | manifestField = 43 | new ManifestFieldValue(fieldDef, "Senthil .V, nathan vijay.", new ArrayList<>(), null); 44 | new AuthorProcessor().process(result, manifestField); 45 | assertEquals("Senthil .V, nathan vijay.", manifestField.getValue()); 46 | 47 | manifestField = 48 | new ManifestFieldValue(fieldDef, "Senthil .V...,nathan", new ArrayList<>(), null); 49 | new AuthorProcessor().process(result, manifestField); 50 | assertEquals("Senthil .V.,nathan", manifestField.getValue()); 51 | 52 | manifestField = new ManifestFieldValue(fieldDef, "Senthil .V.", new ArrayList<>(), null); 53 | new AuthorProcessor().process(result, manifestField); 54 | assertEquals("Senthil .V.", manifestField.getValue()); 55 | 56 | manifestField = 57 | new ManifestFieldValue(fieldDef, "..Senthil Vija. vija; nathan", new ArrayList<>(), null); 58 | new AuthorProcessor().process(result, manifestField); 59 | assertEquals(".Senthil Vija. vija nathan", manifestField.getValue()); 60 | 61 | manifestField = new ManifestFieldValue(fieldDef, "", new ArrayList<>(), null); 62 | new AuthorProcessor().process(result, manifestField); 63 | assertEquals("", manifestField.getValue()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/xml/XmlWriterHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.xml; 12 | 13 | import java.nio.file.Path; 14 | import java.util.List; 15 | import java.util.Objects; 16 | import org.jdom2.Element; 17 | import uk.ac.ebi.ena.webin.cli.utils.FileUtils; 18 | import uk.ac.ebi.ena.webin.cli.validator.file.SubmissionFileAttribute; 19 | 20 | public class XmlWriterHelper { 21 | 22 | public static Element createTextElement(String name, String text) { 23 | Element e = new Element(name); 24 | e.setText(text); 25 | return e; 26 | } 27 | 28 | private static Element createFileElement( 29 | String fileName, 30 | String fileType, 31 | String digest, 32 | String checksum, 33 | List attributes) { 34 | if (checksum == null) { 35 | throw new IllegalArgumentException("File checksum cannot be null."); 36 | } 37 | 38 | Element e = new Element("FILE"); 39 | e.setAttribute("filename", fileName); 40 | e.setAttribute("filetype", String.valueOf(fileType)); 41 | e.setAttribute("checksum_method", digest); 42 | e.setAttribute("checksum", checksum); 43 | 44 | if (attributes != null && !attributes.isEmpty()) { 45 | attributes.stream() 46 | .map(att -> createAttributeElement(att.getName(), att.getValue())) 47 | .filter(Objects::nonNull) 48 | .forEach(attElement -> e.addContent(attElement)); 49 | } 50 | 51 | return e; 52 | } 53 | 54 | public static Element createFileElement( 55 | Path inputDir, Path uploadDir, Path file, String fileMd5, String fileType) { 56 | return createFileElement(inputDir, uploadDir, file, fileMd5, fileType, null); 57 | } 58 | 59 | public static Element createFileElement( 60 | Path inputDir, 61 | Path uploadDir, 62 | Path file, 63 | String fileMd5, 64 | String fileType, 65 | List attributes) { 66 | String fileName = file.toFile().getName(); 67 | 68 | return createFileElement( 69 | FileUtils.replaceIncompatibleFileSeparators(String.valueOf(uploadDir.resolve(fileName))), 70 | String.valueOf(fileType), 71 | "MD5", 72 | fileMd5, 73 | attributes); 74 | } 75 | 76 | private static Element createAttributeElement(String attName, String attValue) { 77 | switch (attName) { 78 | case "READ_TYPE": 79 | { 80 | Element e = new Element(attName); 81 | e.addContent(attValue); 82 | 83 | return e; 84 | } 85 | 86 | default: 87 | return null; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/context/polysample/PolySampleManifestReaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.polysample; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertFalse; 16 | import static uk.ac.ebi.ena.webin.cli.context.reads.ReadsManifestReader.Field; 17 | 18 | import java.nio.file.Paths; 19 | import java.util.Locale; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | import uk.ac.ebi.ena.webin.cli.ManifestBuilder; 23 | import uk.ac.ebi.ena.webin.cli.TempFileBuilder; 24 | import uk.ac.ebi.ena.webin.cli.WebinCliParameters; 25 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 26 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestReader; 27 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorFactory; 28 | import uk.ac.ebi.ena.webin.cli.validator.manifest.PolySampleManifest; 29 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 30 | 31 | public class PolySampleManifestReaderTest { 32 | private static PolySampleManifestReader createManifestReader() { 33 | WebinCliParameters parameters = WebinCliTestUtils.getTestWebinCliParameters(); 34 | return new PolySampleManifestReader(parameters, new MetadataProcessorFactory(parameters)); 35 | } 36 | 37 | @Before 38 | public void before() { 39 | Locale.setDefault(Locale.UK); 40 | } 41 | 42 | @Test 43 | public void testValidSequenceSetManifest() { 44 | PolySampleManifestReader manifestReader = createManifestReader(); 45 | 46 | manifestReader.readManifest( 47 | Paths.get("."), 48 | new ManifestBuilder() 49 | .field(ManifestReader.Fields.NAME, " SOME-FANCY-NAME") 50 | .field(Field.DESCRIPTION, " description") 51 | .file("FASTA", TempFileBuilder.empty(".fasta.gz")) 52 | .field(ManifestReader.Fields.SUBMISSION_TOOL, "ST-001") 53 | .field(ManifestReader.Fields.SUBMISSION_TOOL_VERSION, "STV-001") 54 | .field("ANALYSIS_TYPE", "SEQUENCE_SET") 55 | .build()); 56 | ValidationResult validationResult = manifestReader.getValidationResult(); 57 | 58 | assertFalse(validationResult.isValid()); 59 | 60 | PolySampleManifest manifest = manifestReader.getManifests().stream().findFirst().get(); 61 | 62 | assertEquals("SOME-FANCY-NAME", manifest.getName()); 63 | assertThat(manifest.files().files()).size().isOne(); 64 | assertEquals("description", manifest.getDescription()); 65 | assertEquals("ST-001", manifest.getSubmissionTool()); 66 | assertEquals("STV-001", manifest.getSubmissionToolVersion()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/RunServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 21 | import uk.ac.ebi.ena.webin.cli.validator.reference.Run; 22 | 23 | public class RunServiceTest { 24 | 25 | private static final boolean TEST = true; 26 | 27 | @Test 28 | public void testGetRunUsingPublicRunId() { 29 | Run run = getRunUsingValidId("ERR2486461"); 30 | assertThat(run.getRunId()).isEqualTo("ERR2486461"); 31 | } 32 | 33 | @Test 34 | public void testGetRunUsingPrivateRunId() { 35 | Run run = getRunUsingValidId("ERR6111314"); 36 | assertThat(run.getRunId()).isEqualTo("ERR6111314"); 37 | } 38 | 39 | private Run getRunUsingValidId(String id) { 40 | 41 | RunService runService = 42 | new RunService.Builder() 43 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 44 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 45 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 46 | .build(); 47 | Run run = runService.getRun(id); 48 | assertThat(run).isNotNull(); 49 | assertThat(run.getName()).isNotNull(); 50 | return run; 51 | } 52 | 53 | @Test 54 | public void testGetRunUsingInvalidId() { 55 | String runId = "INVALID"; 56 | RunService runService = 57 | new RunService.Builder() 58 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 59 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 60 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 61 | .build(); 62 | 63 | assertThatThrownBy(() -> runService.getRun(runId)) 64 | .isInstanceOf(WebinCliException.class) 65 | .hasMessageContaining(WebinCliMessage.RUN_SERVICE_VALIDATION_ERROR.format(runId)); 66 | } 67 | 68 | @Test 69 | public void testGetRunUsingInvalidCredentials() { 70 | String runId = "INVALID"; 71 | RunService runService = 72 | new RunService.Builder() 73 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 74 | .setUserName("INVALID") 75 | .setPassword("INVALID") 76 | .build(); 77 | 78 | assertThatThrownBy(() -> runService.getRun(runId)) 79 | .isInstanceOf(WebinCliException.class) 80 | .hasMessageContaining(WebinCliMessage.CLI_AUTHENTICATION_ERROR.text()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/metadata/SampleXmlProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor.metadata; 12 | 13 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 14 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 15 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldGroup; 16 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 17 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 18 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorParameters; 19 | import uk.ac.ebi.ena.webin.cli.service.SampleXmlService; 20 | import uk.ac.ebi.ena.webin.cli.service.exception.ServiceException; 21 | import uk.ac.ebi.ena.webin.cli.utils.ExceptionUtils; 22 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 23 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 24 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 25 | import uk.ac.ebi.ena.webin.cli.validator.reference.Sample; 26 | 27 | public class SampleXmlProcessor implements ManifestFieldProcessor { 28 | 29 | private final MetadataProcessorParameters parameters; 30 | private ManifestFieldProcessor.Callback callback; 31 | 32 | public SampleXmlProcessor( 33 | MetadataProcessorParameters parameters, ManifestFieldProcessor.Callback callback) { 34 | this.parameters = parameters; 35 | this.callback = callback; 36 | } 37 | 38 | public SampleXmlProcessor(MetadataProcessorParameters parameters) { 39 | this.parameters = parameters; 40 | } 41 | 42 | public void setCallback(Callback callback) { 43 | this.callback = callback; 44 | } 45 | 46 | @Override 47 | public void process( 48 | ValidationResult result, ManifestFieldGroup fieldGroup, ManifestFieldValue fieldValue) { 49 | String value = fieldValue.getValue(); 50 | 51 | try { 52 | SampleXmlService sampleXmlService = 53 | new SampleXmlService.Builder() 54 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(parameters.isTest())) 55 | .setCredentials(parameters.getWebinServiceUserName(), parameters.getPassword()) 56 | .build(); 57 | 58 | Sample source = 59 | ExceptionUtils.executeWithRestExceptionHandling( 60 | () -> sampleXmlService.getSample(value), 61 | WebinCliMessage.SERVICE_AUTHENTICATION_ERROR.format(SampleXmlService.SERVICE_NAME), 62 | WebinCliMessage.SAMPLE_SERVICE_VALIDATION_ERROR.format(value), 63 | WebinCliMessage.SAMPLE_SERVICE_SYSTEM_ERROR.format(value)); 64 | 65 | callback.notify(fieldGroup, source); 66 | 67 | } catch (WebinCliException | ServiceException e) { 68 | result.add(ValidationMessage.error(e)); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/metadata/RunProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor.metadata; 12 | 13 | import java.util.ArrayList; 14 | import java.util.HashSet; 15 | import java.util.List; 16 | import java.util.Set; 17 | import java.util.stream.Collectors; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldGroup; 20 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 21 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 22 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorParameters; 23 | import uk.ac.ebi.ena.webin.cli.service.RunService; 24 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 25 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 26 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 27 | import uk.ac.ebi.ena.webin.cli.validator.reference.Run; 28 | 29 | public class RunProcessor implements ManifestFieldProcessor { 30 | private final MetadataProcessorParameters parameters; 31 | private ManifestFieldProcessor.Callback> callback; 32 | 33 | public RunProcessor( 34 | MetadataProcessorParameters parameters, ManifestFieldProcessor.Callback> callback) { 35 | this.parameters = parameters; 36 | this.callback = callback; 37 | } 38 | 39 | public RunProcessor(MetadataProcessorParameters parameters) { 40 | this.parameters = parameters; 41 | } 42 | 43 | public void setCallback(Callback> callback) { 44 | this.callback = callback; 45 | } 46 | 47 | @Override 48 | public void process( 49 | ValidationResult result, ManifestFieldGroup fieldGroup, ManifestFieldValue fieldValue) { 50 | String value = fieldValue.getValue(); 51 | String[] ids = value.split(", *"); 52 | Set idsSet = new HashSet<>(); 53 | List run_list = new ArrayList<>(ids.length); 54 | 55 | for (String r : ids) { 56 | String id = r.trim(); 57 | if (id.isEmpty()) continue; 58 | 59 | if (!idsSet.add(id)) continue; 60 | try { 61 | RunService runService = 62 | new RunService.Builder() 63 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(parameters.isTest())) 64 | .setCredentials(parameters.getWebinServiceUserName(), parameters.getPassword()) 65 | .build(); 66 | run_list.add(runService.getRun(id)); 67 | 68 | } catch (WebinCliException e) { 69 | result.add(ValidationMessage.error(e)); 70 | } 71 | } 72 | 73 | if (result.isValid()) { 74 | fieldValue.setValue( 75 | run_list.stream().map(e -> e.getRunId()).collect(Collectors.joining(", "))); 76 | 77 | callback.notify(fieldGroup, run_list); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/MetadataProcessorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import uk.ac.ebi.ena.webin.cli.manifest.processor.metadata.*; 14 | 15 | public class MetadataProcessorFactory { 16 | 17 | private MetadataProcessorParameters parameters; 18 | 19 | public MetadataProcessorFactory(MetadataProcessorParameters parameters) { 20 | this.parameters = parameters; 21 | } 22 | 23 | private SampleProcessor sampleProcessor; 24 | private StudyProcessor studyProcessor; 25 | private SampleXmlProcessor sampleXmlProcessor; 26 | private RunProcessor runProcessor; 27 | private AnalysisProcessor analysisProcessor; 28 | private CustomFieldProcessor customFieldProcessor; 29 | 30 | public SampleProcessor getSampleProcessor() { 31 | if (parameters != null && parameters.getSampleProcessor() != null) { 32 | return parameters.getSampleProcessor(); 33 | } 34 | if (parameters != null && sampleProcessor == null) { 35 | sampleProcessor = new SampleProcessor(parameters); 36 | } 37 | return sampleProcessor; 38 | } 39 | 40 | public StudyProcessor getStudyProcessor() { 41 | if (parameters != null && parameters.getStudyProcessor() != null) { 42 | return parameters.getStudyProcessor(); 43 | } 44 | if (parameters != null && studyProcessor == null) { 45 | studyProcessor = new StudyProcessor(parameters); 46 | } 47 | return studyProcessor; 48 | } 49 | 50 | public SampleXmlProcessor getSampleXmlProcessor() { 51 | if (parameters != null && parameters.getSampleXmlProcessor() != null) { 52 | return parameters.getSampleXmlProcessor(); 53 | } 54 | if (parameters != null && sampleXmlProcessor == null) { 55 | sampleXmlProcessor = new SampleXmlProcessor(parameters); 56 | } 57 | return sampleXmlProcessor; 58 | } 59 | 60 | public RunProcessor getRunProcessor() { 61 | if (parameters != null && parameters.getRunProcessor() != null) { 62 | return parameters.getRunProcessor(); 63 | } 64 | if (parameters != null && runProcessor == null) { 65 | runProcessor = new RunProcessor(parameters); 66 | } 67 | return runProcessor; 68 | } 69 | 70 | public AnalysisProcessor getAnalysisProcessor() { 71 | if (parameters != null && parameters.getAnalysisProcessor() != null) { 72 | return parameters.getAnalysisProcessor(); 73 | } 74 | if (parameters != null && analysisProcessor == null) { 75 | analysisProcessor = new AnalysisProcessor(parameters); 76 | } 77 | return analysisProcessor; 78 | } 79 | 80 | public CustomFieldProcessor getCustomFieldProcessor() { 81 | 82 | if (customFieldProcessor == null) { 83 | customFieldProcessor = new CustomFieldProcessor(); 84 | } 85 | return customFieldProcessor; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/SampleXmlServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; 14 | 15 | import org.junit.Rule; 16 | import org.junit.Test; 17 | import org.junit.rules.ExpectedException; 18 | import org.springframework.web.client.HttpClientErrorException; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 21 | import uk.ac.ebi.ena.webin.cli.validator.reference.Attribute; 22 | import uk.ac.ebi.ena.webin.cli.validator.reference.Sample; 23 | 24 | public class SampleXmlServiceTest { 25 | 26 | private static final boolean TEST = true; 27 | 28 | private static final String BIO_SAMPLE_ID = "SAMEA749881"; 29 | private static final String SAMPLE_ID = "ERS000002"; 30 | private static final String SCIENTIFIC_NAME = "Saccharomyces cerevisiae SK1"; 31 | private static final String STRAIN_NAME = "SK1"; 32 | private static final int TAX_ID = 580239; 33 | 34 | @Rule public ExpectedException exceptionRule = ExpectedException.none(); 35 | 36 | @Test 37 | public void testGetSourceFeatureUsingPublicBioSampleId() { 38 | testGetSourceFeatureUsingValidId(BIO_SAMPLE_ID); 39 | } 40 | 41 | @Test 42 | public void testGetSourceFeatureUsingPublicSampleId() { 43 | testGetSourceFeatureUsingValidId(SAMPLE_ID); 44 | } 45 | 46 | @Test 47 | public void testGetSourceFeatureUsingInvalidId() { 48 | String id = "INVALID"; 49 | exceptionRule.expect(HttpClientErrorException.NotFound.class); 50 | SampleXmlService sampleService = 51 | new SampleXmlService.Builder() 52 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 53 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 54 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 55 | .build(); 56 | sampleService.getSample(id); 57 | } 58 | 59 | private void testGetSourceFeatureUsingValidId(String id) { 60 | SampleXmlService sampleService = 61 | new SampleXmlService.Builder() 62 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 63 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 64 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 65 | .build(); 66 | Sample sample = sampleService.getSample(id); 67 | assertThat(sample).isNotNull(); 68 | assertThat(sample.getTaxId()).isEqualTo(TAX_ID); 69 | assertThat(sample.getOrganism()).isEqualTo(SCIENTIFIC_NAME); 70 | boolean assertStrain = false; 71 | for (Attribute attribute : sample.getAttributes()) { 72 | if (attribute.getName().equals("strain") && attribute.getValue().equals(STRAIN_NAME)) { 73 | assertStrain = true; 74 | } 75 | } 76 | assertThat(assertStrain); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/manifest/processor/MetadataProcessorFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.Test; 16 | import org.mockito.Mockito; 17 | import uk.ac.ebi.ena.webin.cli.manifest.processor.metadata.*; 18 | 19 | public class MetadataProcessorFactoryTest { 20 | 21 | @Test 22 | public void testDefaultProcessor() { 23 | MetadataProcessorParameters parameters = Mockito.mock(MetadataProcessorParameters.class); 24 | MetadataProcessorFactory factory = new MetadataProcessorFactory(parameters); 25 | assertThat(factory.getSampleProcessor()).isNotNull(); 26 | assertThat(factory.getStudyProcessor()).isNotNull(); 27 | assertThat(factory.getSampleXmlProcessor()).isNotNull(); 28 | assertThat(factory.getAnalysisProcessor()).isNotNull(); 29 | assertThat(factory.getRunProcessor()).isNotNull(); 30 | } 31 | 32 | @Test 33 | public void testParameterProcessor() { 34 | MetadataProcessorParameters parameters = Mockito.mock(MetadataProcessorParameters.class); 35 | StudyProcessor studyProcessor = new StudyProcessor(parameters); 36 | SampleProcessor sampleProcessor = new SampleProcessor(parameters); 37 | SampleXmlProcessor sampleXmlProcessor = new SampleXmlProcessor(parameters); 38 | RunProcessor runProcessor = new RunProcessor(parameters); 39 | AnalysisProcessor analysisProcessor = new AnalysisProcessor(parameters); 40 | 41 | Mockito.when(parameters.getStudyProcessor()).thenReturn(studyProcessor); 42 | Mockito.when(parameters.getSampleProcessor()).thenReturn(sampleProcessor); 43 | Mockito.when(parameters.getSampleXmlProcessor()).thenReturn(sampleXmlProcessor); 44 | Mockito.when(parameters.getRunProcessor()).thenReturn(runProcessor); 45 | Mockito.when(parameters.getAnalysisProcessor()).thenReturn(analysisProcessor); 46 | 47 | MetadataProcessorFactory factory = new MetadataProcessorFactory(parameters); 48 | assertThat(factory.getSampleProcessor()).isSameAs(sampleProcessor); 49 | assertThat(factory.getStudyProcessor()).isSameAs(studyProcessor); 50 | assertThat(factory.getSampleXmlProcessor()).isSameAs(sampleXmlProcessor); 51 | assertThat(factory.getAnalysisProcessor()).isSameAs(analysisProcessor); 52 | assertThat(factory.getRunProcessor()).isSameAs(runProcessor); 53 | } 54 | 55 | @Test 56 | public void testNullParameters() { 57 | MetadataProcessorParameters parameters = null; 58 | MetadataProcessorFactory factory = new MetadataProcessorFactory(parameters); 59 | assertThat(factory.getSampleProcessor()).isNull(); 60 | assertThat(factory.getStudyProcessor()).isNull(); 61 | assertThat(factory.getSampleXmlProcessor()).isNull(); 62 | assertThat(factory.getAnalysisProcessor()).isNull(); 63 | assertThat(factory.getRunProcessor()).isNull(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/SampleServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; 14 | 15 | import org.junit.Rule; 16 | import org.junit.Test; 17 | import org.junit.rules.ExpectedException; 18 | import org.springframework.web.client.HttpClientErrorException; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 21 | import uk.ac.ebi.ena.webin.cli.validator.reference.Sample; 22 | 23 | public class SampleServiceTest { 24 | 25 | private static final boolean TEST = true; 26 | 27 | private static final String BIO_SAMPLE_ID = "SAMEA749881"; 28 | private static final String SAMPLE_ID = "ERS000002"; 29 | private static final String SCIENTIFIC_NAME = "Saccharomyces cerevisiae SK1"; 30 | private static final int TAX_ID = 580239; 31 | 32 | @Rule public ExpectedException exceptionRule = ExpectedException.none(); 33 | 34 | @Test 35 | public void testGetSampleUsingPublicBioSampleId() { 36 | testGetSampleUsingValidId(BIO_SAMPLE_ID); 37 | } 38 | 39 | @Test 40 | public void testGetSampleUsingPublicSampleId() { 41 | testGetSampleUsingValidId(SAMPLE_ID); 42 | } 43 | 44 | @Test 45 | public void testGetSampleUsingInvalidId() { 46 | String id = "INVALID"; 47 | exceptionRule.expect(HttpClientErrorException.NotFound.class); 48 | SampleService sampleService = 49 | new SampleService.Builder() 50 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 51 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 52 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 53 | .setBiosamplesUri(RemoteServiceUrlHelper.getBiosamplesUrl(TEST)) 54 | .build(); 55 | sampleService.getSample(id); 56 | } 57 | 58 | private void testGetSampleUsingValidId(String id) { 59 | SampleService sampleService = 60 | new SampleService.Builder() 61 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 62 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 63 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 64 | .setWebinAuthUri(RemoteServiceUrlHelper.getWebinAuthUrl(TEST)) 65 | .setBiosamplesUri(RemoteServiceUrlHelper.getBiosamplesUrl(TEST)) 66 | .setBiosamplesWebinUserName(WebinCliTestUtils.getTestWebinUsername()) 67 | .setBiosamplesWebinPassword(WebinCliTestUtils.getTestWebinPassword()) 68 | .build(); 69 | Sample sample = sampleService.getSample(id); 70 | assertThat(sample).isNotNull(); 71 | assertThat(sample.getBioSampleId()).isEqualTo(BIO_SAMPLE_ID); 72 | assertThat(sample.getOrganism()).isEqualTo(SCIENTIFIC_NAME); 73 | assertThat(sample.getTaxId()).isEqualTo(TAX_ID); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/ManifestCVList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest; 12 | 13 | import java.io.*; 14 | import java.nio.charset.StandardCharsets; 15 | import java.util.AbstractMap; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.Properties; 19 | import java.util.stream.Collectors; 20 | 21 | public class ManifestCVList { 22 | private final Properties cvMap = new Properties(); 23 | private final ArrayList cvList = new ArrayList(); 24 | 25 | private static InputStream getResourceAsStream(File resource) { 26 | return ManifestCVList.class 27 | .getClassLoader() 28 | .getResourceAsStream(resource.getPath().replaceAll("\\\\+", "/")); 29 | } 30 | 31 | public ManifestCVList(File resource) { 32 | try (InputStream in = getResourceAsStream(resource)) { 33 | this.cvMap.load(in); 34 | } catch (IOException e) { 35 | throw new RuntimeException(e); 36 | } 37 | 38 | try (InputStream in = getResourceAsStream(resource)) { 39 | new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)) 40 | .lines() 41 | .forEach(line -> cvList.add(line.split("\\s*=\\s*")[0].replaceAll("\\\\", ""))); 42 | } catch (IOException e) { 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | 47 | public ManifestCVList(String... values) { 48 | for (String value : values) { 49 | cvMap.setProperty(value, value); 50 | cvList.add(value); 51 | } 52 | } 53 | 54 | private static String normalizeString(Object s) { 55 | return String.valueOf(s).toLowerCase().replaceAll("[ _-]+", ""); 56 | } 57 | 58 | public boolean contains(String key) { 59 | return cvMap.keySet().stream().anyMatch(e -> normalizeString(e).equals(normalizeString(key))); 60 | } 61 | 62 | public String getKey(String key) { 63 | return cvMap.entrySet().stream() 64 | .map( 65 | e -> 66 | new AbstractMap.SimpleEntry<>( 67 | normalizeString(e.getKey()), String.valueOf(e.getKey()))) 68 | .filter(e -> e.getKey().equals(normalizeString(key))) 69 | .findFirst() 70 | .orElse(new AbstractMap.SimpleEntry<>(null, null)) 71 | .getValue(); 72 | } 73 | 74 | public String getValue(String key) { 75 | return cvMap.entrySet().stream() 76 | .map( 77 | e -> 78 | new AbstractMap.SimpleEntry<>( 79 | normalizeString(e.getKey()), String.valueOf(e.getValue()))) 80 | .filter(e -> e.getKey().equals(normalizeString(key))) 81 | .findFirst() 82 | .orElse(new AbstractMap.SimpleEntry<>(null, null)) 83 | .getValue(); 84 | } 85 | 86 | public List keyList() { 87 | return cvList.stream().collect(Collectors.toList()); 88 | } 89 | 90 | public String toString() { 91 | return String.valueOf(cvMap.entrySet()); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/manifest/processor/metadata/AnalysisProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.manifest.processor.metadata; 12 | 13 | import java.util.ArrayList; 14 | import java.util.HashSet; 15 | import java.util.List; 16 | import java.util.Set; 17 | import java.util.stream.Collectors; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 19 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldGroup; 20 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldProcessor; 21 | import uk.ac.ebi.ena.webin.cli.manifest.ManifestFieldValue; 22 | import uk.ac.ebi.ena.webin.cli.manifest.processor.MetadataProcessorParameters; 23 | import uk.ac.ebi.ena.webin.cli.service.AnalysisService; 24 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 25 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationMessage; 26 | import uk.ac.ebi.ena.webin.cli.validator.message.ValidationResult; 27 | import uk.ac.ebi.ena.webin.cli.validator.reference.Analysis; 28 | 29 | public class AnalysisProcessor implements ManifestFieldProcessor { 30 | private final MetadataProcessorParameters parameters; 31 | private ManifestFieldProcessor.Callback> callback; 32 | 33 | public AnalysisProcessor( 34 | MetadataProcessorParameters parameters, 35 | ManifestFieldProcessor.Callback> callback) { 36 | this.parameters = parameters; 37 | this.callback = callback; 38 | } 39 | 40 | public AnalysisProcessor(MetadataProcessorParameters parameters) { 41 | this.parameters = parameters; 42 | } 43 | 44 | public void setCallback(Callback> callback) { 45 | this.callback = callback; 46 | } 47 | 48 | @Override 49 | public void process( 50 | ValidationResult result, ManifestFieldGroup fieldGroup, ManifestFieldValue fieldValue) { 51 | String value = fieldValue.getValue(); 52 | String[] ids = value.split(", *"); 53 | Set idsSet = new HashSet<>(); 54 | List analysis_list = new ArrayList<>(ids.length); 55 | 56 | for (String a : ids) { 57 | String id = a.trim(); 58 | if (id.isEmpty()) continue; 59 | if (!idsSet.add(id)) continue; 60 | try { 61 | AnalysisService analysisService = 62 | new AnalysisService.Builder() 63 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(parameters.isTest())) 64 | .setCredentials(parameters.getWebinServiceUserName(), parameters.getPassword()) 65 | .build(); 66 | analysis_list.add(analysisService.getAnalysis(id)); 67 | 68 | } catch (WebinCliException e) { 69 | result.add(ValidationMessage.error(e)); 70 | } 71 | } 72 | 73 | if (result.isValid()) { 74 | fieldValue.setValue( 75 | analysis_list.stream().map(e -> e.getAnalysisId()).collect(Collectors.joining(", "))); 76 | callback.notify(fieldGroup, analysis_list); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/AnalysisServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 21 | import uk.ac.ebi.ena.webin.cli.validator.reference.Analysis; 22 | 23 | public class AnalysisServiceTest { 24 | 25 | private static final boolean TEST = true; 26 | 27 | @Test 28 | public void testGetAnalysisUsingPublicAnalysisId() { 29 | Analysis analysis = getAnalysisUsingValidId("ERZ000865"); 30 | assertThat(analysis.getAnalysisId()).isEqualTo("ERZ000865"); 31 | } 32 | 33 | @Test 34 | public void testGetAnalysisUsingPrivateAnalysisId() { 35 | Analysis analysis = getAnalysisUsingValidId("ERZ2661588"); 36 | assertThat(analysis.getAnalysisId()).isEqualTo("ERZ2661588"); 37 | } 38 | 39 | private Analysis getAnalysisUsingValidId(String id) { 40 | 41 | AnalysisService analysisService = 42 | new AnalysisService.Builder() 43 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 44 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 45 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 46 | .build(); 47 | Analysis analysis = analysisService.getAnalysis(id); 48 | assertThat(analysis).isNotNull(); 49 | assertThat(analysis.getName()).isNotNull(); 50 | return analysis; 51 | } 52 | 53 | @Test 54 | public void testGetAnalysisUsingInvalidId() { 55 | String analysisId = "INVALID"; 56 | AnalysisService analysisService = 57 | new AnalysisService.Builder() 58 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 59 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 60 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 61 | .build(); 62 | 63 | assertThatThrownBy(() -> analysisService.getAnalysis(analysisId)) 64 | .isInstanceOf(WebinCliException.class) 65 | .hasMessageContaining(WebinCliMessage.ANALYSIS_SERVICE_VALIDATION_ERROR.format(analysisId)); 66 | } 67 | 68 | @Test 69 | public void testGetAnalysisUsingInvalidCredentials() { 70 | String analysisId = "INVALID"; 71 | AnalysisService analysisService = 72 | new AnalysisService.Builder() 73 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 74 | .setUserName("INVALID") 75 | .setPassword("INVALID") 76 | .build(); 77 | 78 | assertThatThrownBy(() -> analysisService.getAnalysis(analysisId)) 79 | .isInstanceOf(WebinCliException.class) 80 | .hasMessageContaining(WebinCliMessage.CLI_AUTHENTICATION_ERROR.text()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/context/transcriptome/TranscriptomeXmlWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.context.transcriptome; 12 | 13 | import static uk.ac.ebi.ena.webin.cli.validator.manifest.TranscriptomeManifest.FileType; 14 | import static uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createFileElement; 15 | import static uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createTextElement; 16 | 17 | import java.nio.file.Path; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import org.jdom2.Element; 21 | import uk.ac.ebi.ena.webin.cli.context.SequenceToolsXmlWriter; 22 | import uk.ac.ebi.ena.webin.cli.utils.FileUtils; 23 | import uk.ac.ebi.ena.webin.cli.validator.api.ValidationResponse; 24 | import uk.ac.ebi.ena.webin.cli.validator.manifest.TranscriptomeManifest; 25 | 26 | public class TranscriptomeXmlWriter 27 | extends SequenceToolsXmlWriter { 28 | 29 | @Override 30 | protected Element createXmlAnalysisTypeElement(TranscriptomeManifest manifest) { 31 | Element e = new Element("TRANSCRIPTOME_ASSEMBLY"); 32 | 33 | e.addContent(createTextElement("NAME", manifest.getName())); 34 | e.addContent(createTextElement("PROGRAM", manifest.getProgram())); 35 | e.addContent(createTextElement("PLATFORM", manifest.getPlatform())); 36 | 37 | if (manifest.isTpa()) e.addContent(createTextElement("TPA", String.valueOf(manifest.isTpa()))); 38 | 39 | if (null != manifest.getAuthors() && null != manifest.getAddress()) { 40 | e.addContent(createTextElement("AUTHORS", manifest.getAuthors())); 41 | e.addContent(createTextElement("ADDRESS", manifest.getAddress())); 42 | } 43 | if (null != manifest.getAssemblyType() && !manifest.getAssemblyType().isEmpty()) 44 | e.addContent(createTextElement("TYPE", manifest.getAssemblyType())); 45 | return e; 46 | } 47 | 48 | @Override 49 | protected List createXmlFileElements( 50 | TranscriptomeManifest manifest, Path inputDir, Path uploadDir) { 51 | 52 | List list = new ArrayList<>(); 53 | 54 | manifest.files(FileType.FASTA).stream() 55 | .map(file -> file.getFile().toPath()) 56 | .forEach( 57 | file -> 58 | list.add( 59 | createFileElement( 60 | inputDir, 61 | uploadDir, 62 | file, 63 | FileUtils.calculateDigest("MD5", file.toFile()), 64 | "fasta"))); 65 | 66 | manifest.files(FileType.FLATFILE).stream() 67 | .map(file -> file.getFile().toPath()) 68 | .forEach( 69 | file -> 70 | list.add( 71 | createFileElement( 72 | inputDir, 73 | uploadDir, 74 | file, 75 | FileUtils.calculateDigest("MD5", file.toFile()), 76 | "flatfile"))); 77 | 78 | return list; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/uk/ac/ebi/ena/webin/cli/service/IgnoreErrorsService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.http.HttpEntity; 16 | import org.springframework.http.HttpHeaders; 17 | import org.springframework.http.HttpMethod; 18 | import org.springframework.http.ResponseEntity; 19 | import org.springframework.web.client.HttpServerErrorException; 20 | import org.springframework.web.client.ResourceAccessException; 21 | import org.springframework.web.client.RestTemplate; 22 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 23 | import uk.ac.ebi.ena.webin.cli.service.utils.HttpHeaderBuilder; 24 | import uk.ac.ebi.ena.webin.cli.utils.ExceptionUtils; 25 | import uk.ac.ebi.ena.webin.cli.utils.RetryUtils; 26 | 27 | public class IgnoreErrorsService extends WebinService { 28 | 29 | private static final Logger log = LoggerFactory.getLogger(IgnoreErrorsService.class); 30 | 31 | protected IgnoreErrorsService(AbstractBuilder builder) { 32 | super(builder); 33 | } 34 | 35 | public static class Builder extends AbstractBuilder { 36 | @Override 37 | public IgnoreErrorsService build() { 38 | return new IgnoreErrorsService(this); 39 | } 40 | } 41 | 42 | private static class IgnoreErrorsRequest { 43 | public final String context; 44 | public final String name; 45 | 46 | public IgnoreErrorsRequest(String context, String name) { 47 | this.context = context; 48 | this.name = name; 49 | } 50 | } 51 | 52 | public boolean getIgnoreErrors(String context, String name) { 53 | return getIgnoreErrors(getUserName(), getPassword(), context, name); 54 | } 55 | 56 | private boolean getIgnoreErrors(String userName, String password, String context, String name) { 57 | 58 | RestTemplate restTemplate = new RestTemplate(); 59 | 60 | HttpHeaders headers = new HttpHeaderBuilder().basicAuth(userName, password).build(); 61 | 62 | ResponseEntity response = 63 | ExceptionUtils.executeWithRestExceptionHandling( 64 | () -> 65 | RetryUtils.executeWithRetry( 66 | retryContext -> 67 | restTemplate.exchange( 68 | resolveAgainstWebinRestV1Uri("cli/ignore_errors/"), 69 | HttpMethod.POST, 70 | new HttpEntity<>(new IgnoreErrorsRequest(context, name), headers), 71 | String.class), 72 | retryContext -> log.warn("Retrying getting ignore error status from server."), 73 | HttpServerErrorException.class, 74 | ResourceAccessException.class), 75 | WebinCliMessage.SERVICE_AUTHENTICATION_ERROR.format("IgnoreError"), 76 | null, 77 | WebinCliMessage.IGNORE_ERRORS_SERVICE_SYSTEM_ERROR.text()); 78 | 79 | return "true".equals(response.getBody()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/uk/ac/ebi/ena/webin/cli/service/StudyServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2023 EMBL - European Bioinformatics Institute 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 4 | * file except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the 7 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | */ 11 | package uk.ac.ebi.ena.webin.cli.service; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 15 | 16 | import org.junit.Test; 17 | import uk.ac.ebi.ena.webin.cli.WebinCliException; 18 | import uk.ac.ebi.ena.webin.cli.WebinCliMessage; 19 | import uk.ac.ebi.ena.webin.cli.WebinCliTestUtils; 20 | import uk.ac.ebi.ena.webin.cli.utils.RemoteServiceUrlHelper; 21 | import uk.ac.ebi.ena.webin.cli.validator.reference.Study; 22 | 23 | public class StudyServiceTest { 24 | 25 | private static final boolean TEST = true; 26 | 27 | private static final String BIO_PROJECT_ID = "PRJEB12332"; 28 | private static final String STUDY_ID = "ERP013798"; 29 | private static final String LOCUS_TAG = "BN3616"; 30 | 31 | @Test 32 | public void testGetStudyUsingPublicBioProjectId() { 33 | testGetStudyUsingValidId(BIO_PROJECT_ID); 34 | } 35 | 36 | @Test 37 | public void testGetStudyUsingPublicStudyId() { 38 | testGetStudyUsingValidId(STUDY_ID); 39 | } 40 | 41 | private void testGetStudyUsingValidId(String id) { 42 | 43 | StudyService studyService = 44 | new StudyService.Builder() 45 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 46 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 47 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 48 | .build(); 49 | Study study = studyService.getStudy(id); 50 | assertThat(study).isNotNull(); 51 | assertThat(study.getBioProjectId()).isEqualTo(BIO_PROJECT_ID); 52 | assertThat(study.getLocusTags()).hasSize(1); 53 | assertThat(study.getLocusTags()).first().isEqualTo(LOCUS_TAG); 54 | } 55 | 56 | @Test 57 | public void testGetStudyUsingInvalidId() { 58 | String studyId = "INVALID"; 59 | StudyService studyService = 60 | new StudyService.Builder() 61 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 62 | .setUserName(WebinCliTestUtils.getTestWebinUsername()) 63 | .setPassword(WebinCliTestUtils.getTestWebinPassword()) 64 | .build(); 65 | assertThatThrownBy(() -> studyService.getStudy(studyId)) 66 | .isInstanceOf(WebinCliException.class) 67 | .hasMessageContaining(WebinCliMessage.STUDY_SERVICE_VALIDATION_ERROR.format(studyId)); 68 | } 69 | 70 | @Test 71 | public void testGetStudyUsingInvalidCredentials() { 72 | String studyId = "INVALID"; 73 | StudyService studyService = 74 | new StudyService.Builder() 75 | .setWebinRestV1Uri(RemoteServiceUrlHelper.getWebinRestV1Url(TEST)) 76 | .setUserName("INVALID") 77 | .setPassword("INVALID") 78 | .build(); 79 | 80 | assertThatThrownBy(() -> studyService.getStudy(studyId)) 81 | .isInstanceOf(WebinCliException.class) 82 | .hasMessageContaining(WebinCliMessage.CLI_AUTHENTICATION_ERROR.text()); 83 | } 84 | } 85 | --------------------------------------------------------------------------------