Skip to content

Commit

Permalink
#117 metadata template implementation:
Browse files Browse the repository at this point in the history
- added odml sections into resource dir
- improve template form page - add/edit action
- store templates in db via Template entity
- loading existing odml section moved into template facade
- added link for testing created templates in wizard
  • Loading branch information
rinkesj committed Jul 2, 2015
1 parent 5809b6f commit ff805e2
Show file tree
Hide file tree
Showing 72 changed files with 7,392 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.converters.StimulusConverter;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.converters.WeatherConverter;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.MetadataFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.ListTemplatePage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.TemplateFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.groups.ListOfMembersGroupPage;
import cz.zcu.kiv.eegdatabase.wui.ui.groups.ListResearchGroupsPage;
Expand Down Expand Up @@ -253,6 +254,7 @@ private void mountPages() {
mountPage("experiments-package-download", ExperimentsPackageDownloadPage.class);
mountPage("experiments-add-file", AddDataFilePage.class);
mountPage("experiments-add-param", ExperimentOptParamValueFormPage.class);
mountPage("experiments-template-list", ListTemplatePage.class);
mountPage("experiments-add-template", TemplateFormPage.class);
mountPage("experiments-add-metadata", MetadataFormPage.class);
mountPage("file-detail", DataFileDetailPage.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;

import java.util.List;

import odml.core.Section;
import cz.zcu.kiv.eegdatabase.data.pojo.Template;
import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade;

import java.util.List;

/**
* ********************************************************************************************************************
* <p/>
Expand Down Expand Up @@ -49,4 +50,6 @@ public interface TemplateFacade extends GenericFacade<Template, Integer> {
public boolean isDefault(int id);

public boolean canSaveName(String name, int personId);

public List<Section> getListOfAvailableODMLSections();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;

import cz.zcu.kiv.eegdatabase.data.pojo.Template;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import odml.core.Reader;
import odml.core.Section;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.core.io.ClassPathResource;

import java.util.List;
import cz.zcu.kiv.eegdatabase.data.pojo.Template;

/**
* ********************************************************************************************************************
Expand All @@ -16,14 +26,12 @@
* <p/>
* **********************************************************************************************************************
* <p/>
* 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
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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.
* 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.
* <p/>
* **********************************************************************************************************************
* <p/>
Expand All @@ -33,7 +41,9 @@
*/
public class TemplateFacadeImpl implements TemplateFacade {

TemplateService service;
protected Log log = LogFactory.getLog(getClass());

private TemplateService service;

@Required
public void setService(TemplateService service) {
Expand All @@ -52,8 +62,9 @@ public List<Template> getDefaultTemplates() {

/**
* Finds all default and user's templates
*
* @param personId id of a user
*
* @param personId
* id of a user
* @return default + user's templates
*/
@Override
Expand Down Expand Up @@ -120,4 +131,37 @@ public int getCountRecords() {
public List<Template> getUnique(Template example) {
return service.getUnique(example);
}

@Override
public List<Section> getListOfAvailableODMLSections() {

// TODO add this in project.properties
String odmlSectionsPath = "./odML/odMLSections";
List<File> filteredFiles = new ArrayList<File>();
File[] paths;
try {
paths = new ClassPathResource(odmlSectionsPath).getFile().listFiles();
for (File path : paths) {
if (path.getName().endsWith(".xml")) {
filteredFiles.add(path);
}
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}

final List<Section> sections = new ArrayList<Section>();
Reader reader = new Reader();
for (File file : filteredFiles) {
Section section = null;
try {
section = reader.load(file.getAbsolutePath());
sections.addAll(section.getSections());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}

return sections;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import cz.zcu.kiv.eegdatabase.wui.components.page.UnderConstructPage;
import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.MetadataFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.ListTemplatePage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.TemplateFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.licenses.GrantedLicensesPage;
import cz.zcu.kiv.eegdatabase.wui.ui.licenses.ManageLicenseRequestsPage;
Expand All @@ -53,7 +54,7 @@ public enum ExperimentsPageLeftMenu implements IButtonPageMenu {
LIST_REVOKED_LICENSES(RevokedRequestPage.class, "menuItem.experiments.licenses.revoked", null),
SEARCH(UnderConstructPage.class, "menuItem.searchMeasuration", null),
ADD_EXPERIMENTS(ExperimentFormPage.class, "menuItem.experiments.addExperiment", null),
ADD_TEMPLATE(TemplateFormPage.class, "menuItem.template.new", null),
LIST_TEMPLATE(ListTemplatePage.class, "menuItem.template.list", null),
ADD_METADATA(MetadataFormPage.class, "menuItem.metadata.new", null),
RESULT(ResultListPage.class, "menuItem.serviceResult", null),
// XXX price list hidden for now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,77 @@
import odml.core.Reader;
import odml.core.Section;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.string.StringValue;

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

import cz.zcu.kiv.eegdatabase.data.pojo.Template;
import cz.zcu.kiv.eegdatabase.wui.app.EEGDataBaseApplication;
import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu;
import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage;
import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils;
import cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata.TemplateFacade;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentsPageLeftMenu;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.ListTemplatePage;

@AuthorizeInstantiation(value = { "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" })
public class MetadataFormPage extends MenuPage {

private static final long serialVersionUID = 1L;


private static final long serialVersionUID = -4170790197539589617L;
protected Log log = LogFactory.getLog(getClass());

@SpringBean
private TemplateFacade templateFacade;

public MetadataFormPage() {

setPageTitle(ResourceUtils.getModel("pageTitle.metadata.new"));
add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));

InputStream template = EEGDataBaseApplication.get().getServletContext().getResourceAsStream("/files/odML/testtemplate.xml");

Section section = null;
Reader reader = new Reader();
try {
section = reader.load(template);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

add(new MetadataForm("metadata-form", new Model<Section>(section)));
}

public MetadataFormPage(final PageParameters parameters) {

setPageTitle(ResourceUtils.getModel("pageTitle.metadata.new"));
add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));

InputStream template = EEGDataBaseApplication.get().getServletContext().getResourceAsStream("/files/odML/testtemplate.xml");

Section section = null;

StringValue value = parameters.get(DEFAULT_PARAM_ID);
if (value.isEmpty() || value.isNull()) {
throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
}

int templateId = value.toInt();
Template template = templateFacade.read(templateId);

Reader reader = new Reader();
try {
section = reader.load(template);

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

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage(), e);
throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
}

add(new MetadataForm("metadata-form", new Model<Section>(section)));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
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.
***********************************************************************************************************************
ListTemplatePage.html, 2013/02/27 00:01 Jakub Rinkes
-->
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="utf-8" />
<!-- <link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:regular,bold' rel='stylesheet' type='text/css' /> -->
<link rel="stylesheet" href="style.css" type="text/css" media="screen" title="Stylesheet" />
</head>
<body>
<wicket:extend>
<div class="leftMenu" wicket:id="leftMenu"></div>

<div class="mainContentWithMenu">
<h1>
<wicket:message key="pageTitle.template.list"></wicket:message>
</h1>

<a href="#" class="lightButtonLink" wicket:id="addTemplateLink"><wicket:message key="pageTitle.template.new"></wicket:message></a>
<table class="dataTable" wicket:id="list"></table>
</div>
</wicket:extend>
</body>
</html>
Loading

0 comments on commit ff805e2

Please sign in to comment.