diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleTemplateDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleTemplateDao.java
new file mode 100644
index 00000000..a25a3abc
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleTemplateDao.java
@@ -0,0 +1,108 @@
+package cz.zcu.kiv.eegdatabase.data.dao;
+
+import cz.zcu.kiv.eegdatabase.data.pojo.Template;
+
+import java.util.List;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * SimpleTemplateDao, 2014/07/02 11:34 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+public class SimpleTemplateDao extends SimpleGenericDao implements TemplateDao {
+
+ public SimpleTemplateDao(){
+ super(Template.class);
+ }
+
+ @Override
+ public List getTemplatesByPerson(int personId) {
+ String hqlQuery = "from Template t where t.personByPersonId.personId = :personId";
+ List list = getSessionFactory().getCurrentSession().createQuery(hqlQuery).setParameter("personId", personId).list();
+
+ return list;
+ }
+
+ @Override
+ public List getDefaultTemplates() {
+ String hqlQuery = "from Template t where t.isDefault = true";
+ List list = getHibernateTemplate().find(hqlQuery);
+
+ return list;
+ }
+
+ /**
+ * Finds all default and user's templates.
+ * Distinct select and ordered by isDefault param (default templates first).
+ *
+ * @param personId id of a user
+ * @return default + user's templates
+ */
+ @Override
+ public List getUsableTemplates(int personId) {
+ String hqlQuery = "select distinct t from Template t where t.isDefault = true or t.personByPersonId.personId = :personId order by t.isDefault asc";
+ List list = getSessionFactory().getCurrentSession().
+ createQuery(hqlQuery).
+ setParameter("personId", personId).list();
+ return list;
+ }
+
+ @Override
+ public Template getTemplateByPersonAndName(int personId, String name) {
+ String hqlQuery = "from Template t where t.personByPersonId.personId = :personId and t.name=:name";
+ List list = getSessionFactory().getCurrentSession().
+ createQuery(hqlQuery).
+ setParameter("personId", personId).
+ setParameter("name", name).list();
+
+ if (list != null && !list.isEmpty()){
+ return list.get(0);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isDefault(int id) {
+ String hqlQuery = "select t.isDefault from Template t where t.templateId = :id";
+ List list = getSessionFactory().getCurrentSession().createQuery(hqlQuery).setParameter("id", id).list();
+ if (list.isEmpty()) {
+ return false;
+ }
+ if (list.get(0) == 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean canSaveName(String name, int personId) {
+ String hqlQuery = "from Template t where t.personByPersonId.personId = :personId and t.name=:name";
+ List list = getSessionFactory().getCurrentSession().
+ createQuery(hqlQuery).
+ setParameter("personId", personId).
+ setParameter("name", name).list();
+ return (list.size() == 0);
+ }
+}
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/TemplateDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/TemplateDao.java
new file mode 100644
index 00000000..7f4dbfd9
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/TemplateDao.java
@@ -0,0 +1,51 @@
+package cz.zcu.kiv.eegdatabase.data.dao;
+
+import cz.zcu.kiv.eegdatabase.data.pojo.Template;
+
+import java.util.List;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * TemplateDao, 2014/07/02 11:18 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+public interface TemplateDao extends GenericDao {
+
+ public List getTemplatesByPerson(int personId);
+
+ public List getDefaultTemplates();
+
+ /**
+ * Finds all default and user's templates
+ * @param personId id of a user
+ * @return default + user's templates
+ */
+ public List getUsableTemplates(int personId);
+
+ public Template getTemplateByPersonAndName(int personId, String name);
+
+ public boolean isDefault(int id);
+
+ public boolean canSaveName(String name, int personId);
+}
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Template.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Template.java
new file mode 100644
index 00000000..2f26e708
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Template.java
@@ -0,0 +1,126 @@
+package cz.zcu.kiv.eegdatabase.data.pojo;
+
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * Template, 2014/07/07 13:23 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+@Entity
+public class Template implements Serializable {
+ private int templateId;
+ private byte[] template;
+ private Person personByPersonId;
+ private Boolean isDefault;
+ private String name;
+
+ public Template() {
+ }
+
+ public Template(int templateId, byte[] template, Person personByPersonId) {
+ this.templateId = templateId;
+ this.template = template;
+ this.personByPersonId = personByPersonId;
+ }
+
+ @GenericGenerator(name = "generator", strategy = "increment")
+ @Id
+ @GeneratedValue(generator = "generator")
+ @Column(name = "template_id", nullable = false, insertable = true, updatable = true)
+ public int getTemplateId() {
+ return templateId;
+ }
+
+ public void setTemplateId(int templateId) {
+ this.templateId = templateId;
+ }
+
+ @Basic
+ @Column(name = "template", nullable = false, insertable = true, updatable = true)
+ public byte[] getTemplate() {
+ return template;
+ }
+
+ public void setTemplate(byte[] template) {
+ this.template = template;
+ }
+
+ @ManyToOne
+ @JoinColumn(name = "person_id", referencedColumnName = "person_id")
+ public Person getPersonByPersonId() {
+ return personByPersonId;
+ }
+
+ public void setPersonByPersonId(Person personByPersonId) {
+ this.personByPersonId = personByPersonId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Template)) return false;
+
+ Template template1 = (Template) o;
+
+ if (templateId != template1.templateId) return false;
+ if (personByPersonId != null ? !personByPersonId.equals(template1.personByPersonId) : template1.personByPersonId != null)
+ return false;
+ if (!Arrays.equals(template, template1.template)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = templateId;
+ result = 31 * result + (template != null ? Arrays.hashCode(template) : 0);
+ result = 31 * result + (personByPersonId != null ? personByPersonId.hashCode() : 0);
+ return result;
+ }
+
+ @Basic
+ @Column(name = "is_default", nullable = true, insertable = true, updatable = true)
+ public Boolean getIsDefault() {
+ return isDefault;
+ }
+
+ public void setIsDefault(Boolean isDefault) {
+ this.isDefault = isDefault;
+ }
+
+ @Basic
+ @Column(name = "name", nullable = false, insertable = true, updatable = true, length = 240)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacade.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacade.java
new file mode 100644
index 00000000..7250be73
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacade.java
@@ -0,0 +1,52 @@
+package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;
+
+import cz.zcu.kiv.eegdatabase.data.pojo.Template;
+import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade;
+
+import java.util.List;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * TemplateFacade, 2014/07/08 14:44 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+public interface TemplateFacade extends GenericFacade {
+
+ public List getTemplatesByPerson(int personId);
+
+ public List getDefaultTemplates();
+
+ /**
+ * Finds all default and user's templates
+ * @param personId id of a user
+ * @return default + user's templates
+ */
+ public List getUsableTemplates(int personId);
+
+ public Template getTemplateByPersonAndName(int personId, String name);
+
+ public boolean isDefault(int id);
+
+ public boolean canSaveName(String name, int personId);
+}
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java
new file mode 100644
index 00000000..454ed634
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateFacadeImpl.java
@@ -0,0 +1,123 @@
+package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;
+
+import cz.zcu.kiv.eegdatabase.data.pojo.Template;
+import org.springframework.beans.factory.annotation.Required;
+
+import java.util.List;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * TemplateFacadeImpl, 2014/07/08 14:48 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+public class TemplateFacadeImpl implements TemplateFacade {
+
+ TemplateService service;
+
+ @Required
+ public void setService(TemplateService service) {
+ this.service = service;
+ }
+
+ @Override
+ public List getTemplatesByPerson(int personId) {
+ return service.getTemplatesByPerson(personId);
+ }
+
+ @Override
+ public List getDefaultTemplates() {
+ return service.getDefaultTemplates();
+ }
+
+ /**
+ * Finds all default and user's templates
+ *
+ * @param personId id of a user
+ * @return default + user's templates
+ */
+ @Override
+ public List getUsableTemplates(int personId) {
+ return service.getUsableTemplates(personId);
+ }
+
+ @Override
+ public Template getTemplateByPersonAndName(int personId, String name) {
+ return service.getTemplateByPersonAndName(personId, name);
+ }
+
+ @Override
+ public boolean isDefault(int id) {
+ return service.isDefault(id);
+ }
+
+ @Override
+ public boolean canSaveName(String name, int personId) {
+ return service.canSaveName(name, personId);
+ }
+
+ @Override
+ public Integer create(Template newInstance) {
+ return service.create(newInstance);
+ }
+
+ @Override
+ public Template read(Integer id) {
+ return service.read(id);
+ }
+
+ @Override
+ public List readByParameter(String parameterName, Object parameterValue) {
+ return service.readByParameter(parameterName, parameterValue);
+ }
+
+ @Override
+ public void update(Template transientObject) {
+ service.update(transientObject);
+ }
+
+ @Override
+ public void delete(Template persistentObject) {
+ service.delete(persistentObject);
+ }
+
+ @Override
+ public List getAllRecords() {
+ return service.getAllRecords();
+ }
+
+ @Override
+ public List getRecordsAtSides(int first, int max) {
+ return service.getRecordsAtSides(first, max);
+ }
+
+ @Override
+ public int getCountRecords() {
+ return service.getCountRecords();
+ }
+
+ @Override
+ public List getUnique(Template example) {
+ return service.getUnique(example);
+ }
+}
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateService.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateService.java
new file mode 100644
index 00000000..7e188dd3
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateService.java
@@ -0,0 +1,52 @@
+package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;
+
+import cz.zcu.kiv.eegdatabase.data.pojo.Template;
+import cz.zcu.kiv.eegdatabase.wui.core.GenericService;
+
+import java.util.List;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * TemplateService, 2014/07/08 14:51 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+public interface TemplateService extends GenericService {
+
+ public List getTemplatesByPerson(int personId);
+
+ public List getDefaultTemplates();
+
+ /**
+ * Finds all default and user's templates
+ * @param personId id of a user
+ * @return default + user's templates
+ */
+ public List getUsableTemplates(int personId);
+
+ public Template getTemplateByPersonAndName(int personId, String name);
+
+ public boolean isDefault(int id);
+
+ public boolean canSaveName(String name, int personId);
+}
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateServiceImpl.java
new file mode 100644
index 00000000..66219b4a
--- /dev/null
+++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/metadata/TemplateServiceImpl.java
@@ -0,0 +1,140 @@
+package cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata;
+
+import cz.zcu.kiv.eegdatabase.data.dao.SimpleTemplateDao;
+import cz.zcu.kiv.eegdatabase.data.pojo.Template;
+import org.springframework.beans.factory.annotation.Required;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * ********************************************************************************************************************
+ *
+ * This file is part of the eegdatabase project
+ *
+ * ==========================================
+ *
+ * Copyright (C) 2014 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.
+ *
+ * **********************************************************************************************************************
+ *
+ * TemplateServiceImpl, 2014/07/08 14:52 Prokop
+ *
+ * ********************************************************************************************************************
+ */
+public class TemplateServiceImpl implements TemplateService {
+
+ SimpleTemplateDao templateDao;
+
+ @Required
+ public void setTemplateDao(SimpleTemplateDao templateDao) {
+ this.templateDao = templateDao;
+ }
+
+ @Override
+ @Transactional
+ public List getTemplatesByPerson(int personId) {
+ return templateDao.getTemplatesByPerson(personId);
+ }
+
+ @Override
+ @Transactional
+ public List getDefaultTemplates() {
+ return templateDao.getDefaultTemplates();
+ }
+
+ /**
+ * Finds all default and user's templates
+ *
+ * @param personId id of a user
+ * @return default + user's templates
+ */
+ @Override
+ @Transactional
+ public List getUsableTemplates(int personId) {
+ return templateDao.getUsableTemplates(personId);
+ }
+
+ @Override
+ @Transactional
+ public Template getTemplateByPersonAndName(int personId, String name) {
+ return templateDao.getTemplateByPersonAndName(personId, name);
+ }
+
+ @Override
+ @Transactional
+ public boolean isDefault(int id) {
+ return templateDao.isDefault(id);
+ }
+
+ @Override
+ @Transactional
+ public boolean canSaveName(String name, int personId){
+ return templateDao.canSaveName(name, personId);
+ }
+
+ @Override
+ @Transactional
+ public Integer create(Template newInstance) {
+ return templateDao.create(newInstance);
+ }
+
+ @Override
+ @Transactional
+ public Template read(Integer id) {
+ return templateDao.read(id);
+ }
+
+ @Override
+ @Transactional
+ public List readByParameter(String parameterName, Object parameterValue) {
+ return templateDao.readByParameter(parameterName, parameterValue);
+ }
+
+ @Override
+ @Transactional
+ public void update(Template transientObject) {
+ templateDao.update(transientObject);
+ }
+
+ @Override
+ @Transactional
+ public void delete(Template persistentObject) {
+ templateDao.delete(persistentObject);
+ }
+
+ @Override
+ @Transactional
+ public List getAllRecords() {
+ return templateDao.getAllRecords();
+ }
+
+ @Override
+ @Transactional
+ public List getRecordsAtSides(int first, int max) {
+ return templateDao.getRecordsAtSides(first, max);
+ }
+
+ @Override
+ @Transactional
+ public int getCountRecords() {
+ return templateDao.getCountRecords();
+ }
+
+ @Override
+ @Transactional
+ public List getUnique(Template example) {
+ return templateDao.findByExample(example);
+ }
+}