Skip to content

Commit

Permalink
#117 created metadata view in experiment detail page, added template …
Browse files Browse the repository at this point in the history
…selection for metadata wizard page, implemented add/edit metadata process.
  • Loading branch information
rinkesj committed Jul 2, 2015
1 parent 7b82fb5 commit c187987
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import odml.core.Section;
import odml.core.Writer;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.ajax.json.JSONException;
Expand All @@ -25,14 +28,18 @@ public void serialize(Section value, JsonGenerator jgen, SerializerProvider prov
long start = System.currentTimeMillis();
try {

Writer wr = new Writer(value, true, false);
Writer wr = new Writer(value, true, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
wr.write(stream, false, false);

String xmlString = stream.toString("UTF-8"); // encoding is necessary

IOUtils.write(xmlString, new FileOutputStream(new File("D:\\tmp\\test.xml")));

JSONObject jsonObject = XML.toJSONObject(xmlString);
// String jsonString = jsonObject.toString(); /// XXX remove this - UTF8 encoding problem.
String jsonString = new String(jsonObject.toString().getBytes("UTF-8")); // encoding is necessary
IOUtils.write(jsonString, new FileOutputStream(new File("D:\\tmp\\test.json")));

jgen.writeRawValue(jsonString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ <h2>
<td wicket:id="paramValue"></td>
</tr>
</table>

<h2>
Metadata
</h2>
<div wicket:id="sections">
<div wicket:id="section"></div>
</div>

<h2>
<wicket:message key="dataTable.heading.licenses" />
Expand Down Expand Up @@ -261,6 +268,7 @@ <h2>
<a href="#" wicket:id="addParameterLink" class="lightButtonLink"><wicket:message:message key="button.addOptionalParameter"/></a>
<a href="#" wicket:id="addFileLink" class="lightButtonLink"><wicket:message:message key="button.addDataFile"/></a>
<a href="#" wicket:id="editExpLink" class="lightButtonLink"><wicket:message:message key="button.editExperiment"/></a>
<a href="#" wicket:id="metadataLink" class="lightButtonLink"><wicket:message:message key="button.metadataLink"/></a>
<span wicket:id="downloadExpLink" class="lightButtonLink" ></span>

<!-- XXX #66 Java Heap Space Exception : working with big data file in memory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
package cz.zcu.kiv.eegdatabase.wui.ui.experiments;

import java.util.ArrayList;
import java.util.List;

import odml.core.Section;

import cz.zcu.kiv.eegdatabase.data.pojo.*;
import cz.zcu.kiv.eegdatabase.wui.core.experimentLicense.ExperimentLicenseFacade;
Expand All @@ -41,6 +44,7 @@
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
Expand All @@ -51,7 +55,6 @@
import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu;
import cz.zcu.kiv.eegdatabase.wui.components.page.BasePage;
import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage;
import cz.zcu.kiv.eegdatabase.wui.components.page.UnderConstructPage;
import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampLabel;
import cz.zcu.kiv.eegdatabase.wui.components.table.ViewLinkPanel;
import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils;
Expand All @@ -64,6 +67,8 @@
import cz.zcu.kiv.eegdatabase.wui.ui.data.AddDataFilePage;
import cz.zcu.kiv.eegdatabase.wui.ui.data.DataFileDetailPage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentBuyDownloadLinkPanel;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.MetadataFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.ViewMetadataSectionPanel;
import cz.zcu.kiv.eegdatabase.wui.ui.people.PersonDetailPage;
import cz.zcu.kiv.eegdatabase.wui.ui.scenarios.ScenarioDetailPage;

Expand Down Expand Up @@ -133,9 +138,10 @@ private void setupComponents(final int experimentId) {
BookmarkablePageLink<Void> addParameterLink = new BookmarkablePageLink<Void>("addParameterLink", ExperimentOptParamValueFormPage.class, PageParametersUtils.getDefaultPageParameters(experimentId));
BookmarkablePageLink<Void> addFileLink = new BookmarkablePageLink<Void>("addFileLink", AddDataFilePage.class, PageParametersUtils.getDefaultPageParameters(experimentId));
BookmarkablePageLink<Void> editExpLink = new BookmarkablePageLink<Void>("editExpLink", ExperimentFormPage.class, PageParametersUtils.getDefaultPageParameters(experimentId));
BookmarkablePageLink<Void> metadataLink = new BookmarkablePageLink<Void>("metadataLink", MetadataFormPage.class, PageParametersUtils.getDefaultPageParameters(experimentId));
ExperimentBuyDownloadLinkPanel downloadExpLink = new ExperimentBuyDownloadLinkPanel("downloadExpLink", new Model<Experiment>(experiment));
downloadExpLink.setVisibilityAllowed(experiment.getExperimentPackageConnections().isEmpty());
add(addParameterLink.setVisibilityAllowed(coexperiment), addFileLink.setVisibilityAllowed(coexperiment), editExpLink.setVisibilityAllowed(coexperiment), downloadExpLink);
add(addParameterLink.setVisibilityAllowed(coexperiment), addFileLink.setVisibilityAllowed(coexperiment), editExpLink.setVisibilityAllowed(coexperiment), metadataLink.setVisibilityAllowed(coexperiment), downloadExpLink);

/* XXX #66 Java Heap Space Exception : working with big data file in memory.
final ExperimentSignalViewCanvasPanel experimentViewPanel = new ExperimentSignalViewCanvasPanel("view", experiment);
Expand Down Expand Up @@ -216,6 +222,18 @@ protected void populateItem(ListItem<ProjectType> item) {

}
};

PropertyListView<Section> metadata = new PropertyListView<Section>("sections", new PropertyModel<List<Section>>(experiment.getElasticExperiment().getMetadata(), "sections")) {

private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<Section> item) {
item.add(new ViewMetadataSectionPanel("section", item.getModel()));
}
};

add(metadata);

PropertyListView<License> licenseList = new PropertyListView<License>("licenseList", new ListModel<License>(licenseFacade.getLicensesForExperiment(experiment.getExperimentId()))) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.PropertyValueModel;

public class FormPropertyPanel extends Panel {

private static final long serialVersionUID = 1L;
Expand All @@ -55,7 +57,7 @@ private void setupFormComponents(IModel<Property> model) {
textField = new TextField("textfield", new PropertyModel(model.getObject(), "value"));
add(textField);

choice = new DropDownChoice<Value>("select", new Model<Value>(), new PropertyModel<List<Value>>(model.getObject(), "values"));
choice = new DropDownChoice("select", new PropertyValueModel(model.getObject(), 0), new PropertyModel<List<Value>>(model.getObject(), "values"));
add(choice);

boolean singleValue = model.getObject().getValues() != null ? model.getObject().getValues().size() == 1 : true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;

import odml.core.Reader;
Expand All @@ -33,15 +34,13 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.wizard.IWizardStep;
import org.apache.wicket.extensions.wizard.Wizard;
import org.apache.wicket.extensions.wizard.WizardModel;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.extensions.wizard.WizardStep;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
Expand All @@ -50,10 +49,12 @@

import com.sun.xml.messaging.saaj.util.ByteInputStream;

import cz.zcu.kiv.eegdatabase.data.pojo.Experiment;
import cz.zcu.kiv.eegdatabase.data.pojo.Template;
import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession;
import cz.zcu.kiv.eegdatabase.wui.components.form.input.AjaxDropDownChoice;
import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils;
import cz.zcu.kiv.eegdatabase.wui.core.experiments.ExperimentsFacade;
import cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata.TemplateFacade;

public class MetadataForm extends Panel {
Expand All @@ -64,35 +65,43 @@ public class MetadataForm extends Panel {

@SpringBean
private TemplateFacade templateFacade;

@SpringBean
private ExperimentsFacade expFacade;

private CompoundPropertyModel<Section> model;
private WizardModel wizardModel;
private Wizard wizard;

public MetadataForm(String id) {
this(id, new Model<Section>(new Section()));
public MetadataForm(String id, int experimentId) {
this(id, new Model<Section>(new Section()), experimentId);
}

public MetadataForm(String id, IModel<Section> model) {
public MetadataForm(String id, IModel<Section> model, final int experimentId) {
super(id);

this.model = new CompoundPropertyModel<Section>(model);
setDefaultModel(this.model);
setOutputMarkupId(true);

// TODO select template not work.
WizardModel wizardModel = new WizardModel();
for (Section section : model.getObject().getSections()) {
wizardModel.add(new MetadataWizardStep(new Model<Section>(section)));

wizardModel = new WizardModel();
if (model.getObject() != null) {
for (Section section : model.getObject().getSections()) {
wizardModel.add(new MetadataWizardStep(new Model<Section>(section)));
}
} else {
wizardModel.add(new WizardStep());
}

Wizard wizard = new Wizard("wizard", wizardModel, true) {
wizard = new Wizard("wizard", wizardModel, true) {

private static final long serialVersionUID = 1L;

@Override
public void onFinish() {
try {
Section data = MetadataForm.this.model.getObject();
FileOutputStream stream = new FileOutputStream(new File("D:\\trash\\"+ data.getName() + ".xml"));
FileOutputStream stream = new FileOutputStream(new File("D:\\trash\\" + data.getName() + ".xml"));

Writer writer = new Writer(data, true, true);
if (writer.write(stream)) {
Expand All @@ -104,15 +113,16 @@ public void onFinish() {
e.printStackTrace();
}
}

@Override
public void onCancel() {
throw new RestartResponseAtInterceptPageException(MetadataForm.this.getPage().getPageClass(), MetadataForm.this.getPage().getPageParameters());
}

};

add(wizard);
};
wizard.setOutputMarkupId(true);

add(wizard.setVisible(model.getObject() != null));

int personId = EEGDataBaseSession.get().getLoggedUser().getPersonId();
List<Template> templatesByPerson = templateFacade.getTemplatesByPerson(personId);
Expand All @@ -123,17 +133,59 @@ public void onCancel() {

@Override
protected void onSelectionChangeAjaxified(AjaxRequestTarget target, Template template) {

try {
Reader reader = new Reader();
Section section = reader.load(new ByteInputStream(template.getTemplate(), template.getTemplate().length));
section.setName(template.getName());
MetadataForm.this.model.setObject(section);

wizardModel = new WizardModel();
for (Section subsection : section.getSections()) {
wizardModel.add(new MetadataWizardStep(new Model<Section>(subsection)));
}

Wizard wiz = new Wizard("wizard", wizardModel, true){

private static final long serialVersionUID = 1L;

@Override
public void onFinish() {
try {
Section data = MetadataForm.this.model.getObject();
FileOutputStream stream = new FileOutputStream(new File("D:\\trash\\" + data.getName() + ".xml"));

Writer writer = new Writer(data, true, true);
if (writer.write(stream)) {
info("Save template done.");
} else {
error("Save template failed.");
}

Experiment experiment = expFacade.getExperimentForDetail(experimentId);
experiment.getElasticExperiment().setMetadata(data);
expFacade.update(experiment);

} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

@Override
public void onCancel() {
throw new RestartResponseAtInterceptPageException(MetadataForm.this.getPage().getPageClass(), MetadataForm.this.getPage().getPageParameters());
}

};

wizard = (Wizard) wizard.replaceWith(wiz);

log.error("Wizard reset...");
} catch (Exception e) {
log.error(e.getMessage(), e);
error(ResourceUtils.getString("text.template.error.load"));
}

target.add(MetadataForm.this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public MetadataFormPage() {
log.error(e.getMessage(), e);
}

add(new MetadataForm("metadata-form", new Model<Section>(section)));
add(new MetadataForm("metadata-form", new Model<Section>(section), 0));
getFeedback().setFilter(new ComponentFeedbackMessageFilter(this));
}

Expand All @@ -108,19 +108,19 @@ public MetadataFormPage(final PageParameters parameters) {

// templateFacade.migrateSQLToES();

int templateId = value.toInt();
Template template = templateFacade.read(templateId);
int experimentId = value.toInt();
Experiment exp = expFacade.getExperimentForDetail(experimentId);

Reader reader = new Reader();
try {
Section section = reader.load(new ByteInputStream(template.getTemplate(), template.getTemplate().length));
section.setName(template.getName());
add(new MetadataForm("metadata-form", new Model<Section>(section)));

} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
}
// try {
// Section section = reader.load(new ByteInputStream(template.getTemplate(), template.getTemplate().length));
// section.setName(template.getName());
add(new MetadataForm("metadata-form", new Model<Section>(exp.getElasticExperiment().getMetadata()), experimentId));

// } catch (Exception e) {
// log.error(e.getMessage(), e);
// throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
// }

getFeedback().setFilter(new ComponentFeedbackMessageFilter(this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
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.
***********************************************************************************************************************
ViewMetadataPropertyPanel.html, 2013/02/27 00:01 Jakub Rinkes
-->
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<!-- <span wicket:id="name"></span> -->
<!-- <p wicket:id="definition"></p> -->
<!-- <span wicket:id="value"></span> -->
<td wicket:id="name"></td>
<td wicket:id="value"></td>
</wicket:panel>
</body>
</html>
Loading

0 comments on commit c187987

Please sign in to comment.