Skip to content

Commit

Permalink
#142 - migration to production
Browse files Browse the repository at this point in the history
  • Loading branch information
stebjan committed Feb 16, 2016
1 parent 983fc18 commit e583980
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 43 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 @@ -155,7 +155,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 Down Expand Up @@ -204,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 @@ -232,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 @@ -2,22 +2,22 @@
This file is part of the EEG-database project
==========================================
Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/)
***********************************************************************************************************************
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
***********************************************************************************************************************
ExperimentsPackageDownloadPage.html, 2014/11/13 00:01 Jakub Rinkes
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Expand All @@ -32,15 +32,15 @@
<h1>
<wicket:message key="pageTitle.downloadPackage" />
</h1>

<h2>
<wicket:message key="label.experimentPackage.name"></wicket:message> <wicket:container wicket:id="packageName"></wicket:container>
</h2>

<!--<h2 class="alert">-->
<!--<wicket:message key="pageTitle.chooseMetadata.hint"></wicket:message>-->
<!--</h2>-->


<form class="standardInputForm" wicket:id="form">
<!--<table style="width: 27%;" class="standardValueTable">-->
Expand Down Expand Up @@ -123,12 +123,36 @@ <h2>
<!--</tr>-->

<!--</table>-->

<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;">
Expand All @@ -154,11 +178,7 @@ <h2>
</tbody>
</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 e583980

Please sign in to comment.