Skip to content

Commit

Permalink
#142 - Added progress bar while downloading package
Browse files Browse the repository at this point in the history
  • Loading branch information
stebjan committed Feb 16, 2016
1 parent 88c7546 commit 253d83f
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cz.zcu.kiv.eegdatabase.wui.core.experiments;

import cz.zcu.kiv.eegdatabase.data.pojo.Experiment;
import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentPackage;
import cz.zcu.kiv.eegdatabase.data.pojo.License;
import cz.zcu.kiv.eegdatabase.data.pojo.Person;
import cz.zcu.kiv.eegdatabase.logic.controller.experiment.MetadataCommand;
import cz.zcu.kiv.eegdatabase.wui.core.file.FileDTO;

import java.io.Serializable;
import java.util.List;

/**
* Created by stebjan on 15.2.2016.
*/
public class DownloadPackageManager extends Thread implements Serializable{

private int numberOfExperiments;
private int numberOfDownloadedExperiments;
private FileDTO outputFile;
private ExperimentPackage expPackage;
private MetadataCommand command;
private License license;
private List<Experiment> selectList;
private ExperimentDownloadProvider downloadProvider;
private Person loggedUser;

public DownloadPackageManager(ExperimentPackage pckg, MetadataCommand mc, License license, List<Experiment> selectList,
ExperimentDownloadProvider provider, Person user) {
numberOfDownloadedExperiments = 0;
numberOfExperiments = 0;
expPackage = pckg;
command = mc;
this.license = license;
this.selectList = selectList;
downloadProvider = provider;
loggedUser = user;

}


@Override
public void run() {
numberOfExperiments = selectList.size();
outputFile = downloadProvider.generatePackageFile(expPackage, command, license, selectList, loggedUser, this);
}

public int getNumberOfExperiments() {
return numberOfExperiments;
}

public void setNumberOfExperiments(int numberOfExperiments) {
this.numberOfExperiments = numberOfExperiments;
}

public int getNumberOfDownloadedExperiments() {
return numberOfDownloadedExperiments;
}

public void setNumberOfDownloadedExperiments(int numberOfDownloadedExperiments) {
this.numberOfDownloadedExperiments = numberOfDownloadedExperiments;
}

public FileDTO getOutputFile() {
return outputFile;
}

public void setOutputFile(FileDTO outputFile) {
this.outputFile = outputFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public FileDTO generate(Experiment exp, MetadataCommand mc, Collection<DataFile>
Set<DataFile> newFiles = prepareDataFilesWithParameters(files, params);

// prepared history log
createHistoryRecordAboutDownload(experiment);
createHistoryRecordAboutDownload(experiment, personService.getLoggedPerson());

License license = licenseService.getLicenseForPurchasedExperiment(exp.getExperimentId(), EEGDataBaseSession.get().getLoggedUser().getPersonId());
byte[] licenseFile = licenseService.getLicenseAttachmentContent(license.getLicenseId());
Expand Down Expand Up @@ -154,7 +154,8 @@ public FileDTO generate(Experiment exp, MetadataCommand mc, Collection<DataFile>
}

@Transactional
public FileDTO generatePackageFile(ExperimentPackage pckg, MetadataCommand mc, License license, List<Experiment> selectList) {
public FileDTO generatePackageFile(ExperimentPackage pckg, MetadataCommand mc, License license, List<Experiment> selectList,
Person loggedUser, DownloadPackageManager manager) {

ZipOutputStream zipOutputStream = null;
FileOutputStream fileOutputStream = null;
Expand All @@ -175,6 +176,7 @@ public FileDTO generatePackageFile(ExperimentPackage pckg, MetadataCommand mc, L

for (Experiment tmp : selectList) {


Experiment exp = service.read(tmp.getExperimentId());
String experimentDirPrefix = "";

Expand Down Expand Up @@ -203,7 +205,10 @@ public FileDTO generatePackageFile(ExperimentPackage pckg, MetadataCommand mc, L
IOUtils.closeQuietly(in);
FileUtils.deleteQuietly(file);

createHistoryRecordAboutDownload(exp);
createHistoryRecordAboutDownload(exp, loggedUser);
synchronized (this) {
manager.setNumberOfDownloadedExperiments(manager.getNumberOfDownloadedExperiments() + 1);
}
}

dto.setFile(tempZipFile);
Expand Down Expand Up @@ -231,9 +236,8 @@ public FileDTO generatePackageFile(ExperimentPackage pckg, MetadataCommand mc, L
}
}

private void createHistoryRecordAboutDownload(Experiment experiment) {
private void createHistoryRecordAboutDownload(Experiment experiment, Person user) {

Person user = personService.getLoggedPerson();
Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime());
History history = new History();
log.debug("Setting downloading metadata");
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/cz/zcu/kiv/eegdatabase/wui/core/file/FileDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
******************************************************************************/
package cz.zcu.kiv.eegdatabase.wui.core.file;

import java.io.File;

import cz.zcu.kiv.eegdatabase.wui.core.dto.IdentifiDTO;

import java.io.File;

/**
* Object for file transfer in wicket.
*
Expand All @@ -39,6 +39,15 @@ public class FileDTO extends IdentifiDTO {
private String fileName;
private String mimetype;
private File file;
private boolean deleted;

public boolean isDeleted() {
return deleted;
}

public void setDeleted(boolean deleted) {
this.deleted = deleted;
}

public String getFileName() {
return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,35 @@ <h2>
<wicket:message key="label.chooseExperiments"></wicket:message>
</h2>
<!--<div wicket:id="navigator"></div>-->
<!-- progress bar -->

<div id="wrapper-panel-frame" class="ui-corner-all">

<table>
<tr>
<td width="240" colspan="2">
<wicket:message key="label.packageProgress" /><div wicket:id="progress"></div>
</td>
<!--<td>-->
<!--<div wicket:id="indicator"></div>-->
<!--</td>-->
</tr>
</table>
<br/>
<div wicket:id="feedback" style="width: 360px;"></div>

</div>
<div class="actionBox">
<input type="submit" wicket:id="submit" class="lightButtonLink" wicket:message="value:button.downloadPackage"/>
<a href='#' wicket:id="downloadLink"><wicket:message key="link.download"></wicket:message></a>
<a href="#" wicket:id="viewLicenseLink"><wicket:message key="link.license.view"/></a>
</div>


<span wicket:id="group">
<span><input type="checkbox" wicket:id="selectedAll"/><wicket:message key="label.chooseAll"></wicket:message></span>


<table class="standardValueTable" style="width: auto;">
<thead>
<tr>
Expand All @@ -155,10 +181,7 @@ <h2>
</table>
</span>

<div class="actionBox">
<input type="submit" wicket:id="submit" class="lightButtonLink" wicket:message="value:button.downloadPackage"/>
<a href="#" wicket:id="viewLicenseLink"><wicket:message key="link.license.view"/></a>
</div>

<div wicket:id="viewLicenseWindow"></div>
</form>
</div>
Expand Down
Loading

0 comments on commit 253d83f

Please sign in to comment.