Skip to content

Commit

Permalink
Hotfix 0.5.5
Browse files Browse the repository at this point in the history
Hotfix 0.5.5
  • Loading branch information
sven1103 authored Feb 10, 2022
2 parents 05423f3 + 01f0937 commit e057f54
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 55 deletions.
128 changes: 92 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>life.qbic</groupId>
<artifactId>cli-parent-pom</artifactId>
<version>2.3.0</version>
</parent>
<groupId>life.qbic</groupId>
<artifactId>postman-cli</artifactId>
<version>0.5.4</version>
<name>Postman cli</name>
Expand All @@ -19,7 +15,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<groovy.version>2.5.15</groovy.version>
<groovy.version>3.0.8</groovy.version>
<log4j.version>2.17.1</log4j.version>
</properties>

Expand Down Expand Up @@ -51,32 +47,6 @@
<name>QBiC Releases</name>
<url>https://qbic-repo.qbic.uni-tuebingen.de/repository/maven-releases</url>
</repository>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>nexus-snapshots-old</id>
<name>QBiC Snapshots Old</name>
<url>https://qbic-repo.am10.uni-tuebingen.de/repository/maven-snapshots</url>
</repository>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>nexus-releases-old</id>
<name>QBiC Releases Old</name>
<url>https://qbic-repo.am10.uni-tuebingen.de/repository/maven-releases</url>
</repository>
<repository>
<id>vaadin-addons</id>
<name>Vaadin Addons</name>
Expand All @@ -91,6 +61,17 @@
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.6.2</version>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.14.6</version>
</dependency>


<dependency>
<groupId>org.codehaus.groovy</groupId>
Expand All @@ -99,17 +80,22 @@
<classifier>indy</classifier>
</dependency>


<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>

<dependency>
<groupId>life.qbic.openbis</groupId>
<artifactId>openbis-api-with-deps</artifactId>
<version>18.06.5</version>
<groupId>life.qbic</groupId>
<artifactId>openbis-api</artifactId>
<version>18.06.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down Expand Up @@ -137,6 +123,76 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.13.1</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>compileTests</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
<execution>
<id>site</id>
<phase>site</phase>
<configuration><groovyDocOutputDirectory>${project.basedir}/target/site/gapidocs</groovyDocOutputDirectory></configuration>
<goals>
<goal>generateStubs</goal>
<goal>generateTestStubs</goal>
<goal>groovydoc</goal>
<goal>groovydocTests</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.*</exclude>
</excludes>
<includes>**/*Test.*</includes>
<includes>**/*Specification.*</includes>
<includes>**/*Spec.*</includes>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<!-- integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
16 changes: 10 additions & 6 deletions src/main/java/life/qbic/model/download/QbicDataDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import life.qbic.util.ProgressBar;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.remoting.RemoteConnectFailureException;

public class QbicDataDownloader {

Expand Down Expand Up @@ -125,7 +124,7 @@ public QbicDataDownloader setCredentials(String user, String password) {
public void login() throws ConnectionException, AuthenticationException {
try {
this.sessionToken = this.applicationServer.login(this.user, this.password);
} catch (RemoteConnectFailureException e) {
} catch (Exception e) {
throw new ConnectionException("Connection to openBIS server failed.");
}
if (sessionToken == null || sessionToken.isEmpty()) {
Expand Down Expand Up @@ -330,15 +329,17 @@ private void downloadFile(DataSetFile dataSetFile, Path prefix) throws IOExcepti
filePath.toString());
newFile.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(newFile);
String fileName = filePath.getFileName().toString();
ProgressBar progressBar =
new ProgressBar(
filePath.getFileName().toString(), file.getDataSetFile().getFileLength());
fileName, file.getDataSetFile().getFileLength());
int bufferSize =
(file.getDataSetFile().getFileLength() < defaultBufferSize)
? (int) file.getDataSetFile().getFileLength()
: defaultBufferSize;
byte[] buffer = new byte[bufferSize];
int bytesRead;
LOG.info(String.format("Download of %s is starting", fileName));
// read from is to buffer
while ((bytesRead = checkedInputStream.read(buffer)) != -1) {
progressBar.updateProgress(bufferSize);
Expand All @@ -351,6 +352,7 @@ private void downloadFile(DataSetFile dataSetFile, Path prefix) throws IOExcepti
initialStream.close();
// flush OutputStream to write any buffered data to file
os.flush();
LOG.info(String.format("Download of %s has finished", fileName));
os.close();
}
}
Expand Down Expand Up @@ -389,21 +391,23 @@ private Path determineFinalPathFromDataset(DataSetFile file) {
}

private int downloadFiles(DownloadRequest request) throws DownloadException {
Path pathPrefix = Paths.get(request.getSampleCode() + File.separator);
String sampleCode = request.getSampleCode();
LOG.info(String.format("Downloading file(s) for sample %s", sampleCode));
Path pathPrefix = Paths.get(sampleCode + File.separator);
request
.getDataSets()
.forEach(
dataSetFile -> {
try {
int downloadAttempt = 1;
while(downloadAttempt <= request.getMaxNumberOfAttempts()) {
while (downloadAttempt <= request.getMaxNumberOfAttempts()) {
try {
downloadFile(dataSetFile, pathPrefix);
writeCRC32Checksum(dataSetFile, pathPrefix);
return;
} catch (Exception e) {
LOG.error(String.format("Download attempt %d failed.", downloadAttempt));
LOG.error(String.format("Reason: %s", e.getMessage()));
LOG.error(String.format("Reason: %s", e.getMessage()), e);
downloadAttempt++;
if (downloadAttempt > request.getMaxNumberOfAttempts()) {
throw new IOException("Maximum number of download attempts reached.");
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/life/qbic/util/ProgressBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import jline.TerminalFactory;
import life.qbic.model.units.UnitConverterFactory;
import life.qbic.model.units.UnitDisplay;


public class ProgressBar {

private final int BARSIZE = jline.TerminalFactory.get().getWidth() / 3;
private final int MAXFILENAMESIZE = jline.TerminalFactory.get().getWidth() / 3;
private final int BARSIZE = TerminalFactory.get().getWidth() / 3;
private final int MAXFILENAMESIZE = TerminalFactory.get().getWidth() / 3;
private float nextProgressJump;
private float stepSize;
private String fileName;
private Long totalFileSize;
private Long downloadedSize;
private UnitDisplay unitDisplay;
private long start;
private long remainingTime;

public ProgressBar() {}

public ProgressBar(String fileName, long totalFileSize) {
this.fileName = shortenFileName(fileName);
this.totalFileSize = totalFileSize;
this.downloadedSize = 0L;
this.stepSize = totalFileSize / BARSIZE;
this.stepSize = (float) totalFileSize / (float) BARSIZE;
this.nextProgressJump = this.stepSize;
this.unitDisplay = UnitConverterFactory.determineBestUnitType(totalFileSize);
this.start = System.currentTimeMillis();
this.remainingTime = 0L;
}

public void updateProgress(int addDownloadedSize) {
Expand All @@ -56,8 +56,7 @@ private void checkForJump() {
}

private void drawProgress() {
System.out.print(
String.format("%-" + computeLeftPadding() + "s %s\r", this.fileName, buildProgressBar()));
System.out.printf("%-" + computeLeftPadding() + "s %s\r", this.fileName, buildProgressBar());
}

private int computeLeftPadding() {
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/life/qbic/util/StringUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package life.qbic.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

Expand All @@ -9,11 +10,11 @@ public class StringUtilTest {
@Test
public void endsWithIgnoreCase() {
// success with same case
assertEquals(true, StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomTESTBLA"));
assertEquals(true, StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomTESTBlA"));
assertEquals(true, StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomteSTBlA"));
assertTrue(StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomTESTBLA"));
assertTrue(StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomTESTBlA"));
assertTrue(StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomteSTBlA"));
// success with different case
assertEquals(true, StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomTESTbla"));
assertEquals(false, StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "ayyyyynope"));
assertTrue(StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "randomTESTbla"));
assertFalse(StringUtil.endsWithIgnoreCase("thisissomerandomTESTBLA", "ayyyyynope"));
}
}

0 comments on commit e057f54

Please sign in to comment.