Initial import of DMP project modules.

1) dmp-backend : spring-hibernate webservice which allows dmp data
storing and fetching from a relational database.
2) dmp-javascript-engine: a simple wrapper for java's nashorn javascript
engine.
3) dmp-frontend: an angular based frontend app to serve dynamic
questionnaires to aid the formation of Digital Management Plans
merge-requests/1/head
Nikolaos Laskaris 7 years ago
commit 9f8b4a3cce

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

@ -0,0 +1 @@
/target/

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dmp-backend</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,3 @@
eclipse.preferences.version=1
org.eclipse.jpt.core.platform=generic2_1
org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="dmp-backend">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="java-output-path" value="/dmp-backend/target/classes"/>
<property name="context-root" value="dmp-backend"/>
</wb-module>
</project-modules>

@ -0,0 +1,7 @@
<root>
<facet id="jpt.jpa">
<node name="libprov">
<attribute name="provider-id" value="jpa-no-op-library-provider"/>
</node>
</facet>
</root>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="jpt.jpa" version="2.1"/>
</faceted-project>

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

@ -0,0 +1,5 @@
Manifest-Version: 1.0
Built-By: nikolas
Build-Jdk: 1.8.0_91
Created-By: Maven Integration for Eclipse

@ -0,0 +1,7 @@
#Generated by Maven Integration for Eclipse
#Thu Sep 14 13:20:15 EEST 2017
version=0.0.1-SNAPSHOT
groupId=dmp-backend
m2e.projectName=dmp-backend
m2e.projectLocation=/home/nikolas/git/OpenAIRE-EUDAT-DMP-service-pilot/dmp-backend
artifactId=dmp-backend

@ -0,0 +1,254 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dmp-backend</groupId>
<artifactId>dmp-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<dmp-backend-commons.version>0.0.1-SNAPSHOT</dmp-backend-commons.version>
<org.springframework.version>4.3.8.RELEASE</org.springframework.version>
<com.sun.jersey.version>1.19.1</com.sun.jersey.version>
<org.apache.tomcat.tomcat-jdbc.version>7.0.35</org.apache.tomcat.tomcat-jdbc.version>
<hibernate.version>5.2.9.Final</hibernate.version>
<commons-codec.version>1.9</commons-codec.version>
<org.junit.version>4.11</org.junit.version>
<log4j.version>1.2.17</log4j.version>
<slf4j.version>1.7.12</slf4j.version>
<jetty.version>9.0.7.v20131107</jetty.version> <!-- Adapt this to a version found on http://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-maven-plugin/ -->
<logback.version>1.1.1</logback.version>
<javax.inject.version>1</javax.inject.version>
<javax.servlet.servlet-api.version>3.0.1</javax.servlet.servlet-api.version>
<!-- <jcloverslf4j.version>1.7.6</jcloverslf4j.version> -->
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>dmp-backend</groupId> -->
<!-- <artifactId>dmp-backend-commons</artifactId> -->
<!-- <version>${dmp-backend-commons.version}</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- g/a spring -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- MY SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<!-- Jackson core and databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.4</version>
</dependency>
<!-- Json <-> XML transformations -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
<!-- tomcat jdbc -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>${org.apache.tomcat.tomcat-jdbc.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${org.junit.version}</version>
<scope>test</scope>
</dependency>
<!-- PostGreSql base libs dependencies -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
<!-- LogBack dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Various libs -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>false</failOnWarning>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>

@ -0,0 +1,254 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dmp-backend</groupId>
<artifactId>dmp-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<dmp-backend-commons.version>0.0.1-SNAPSHOT</dmp-backend-commons.version>
<org.springframework.version>4.3.8.RELEASE</org.springframework.version>
<com.sun.jersey.version>1.19.1</com.sun.jersey.version>
<org.apache.tomcat.tomcat-jdbc.version>7.0.35</org.apache.tomcat.tomcat-jdbc.version>
<hibernate.version>5.2.9.Final</hibernate.version>
<commons-codec.version>1.9</commons-codec.version>
<org.junit.version>4.11</org.junit.version>
<log4j.version>1.2.17</log4j.version>
<slf4j.version>1.7.12</slf4j.version>
<jetty.version>9.0.7.v20131107</jetty.version> <!-- Adapt this to a version found on http://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-maven-plugin/ -->
<logback.version>1.1.1</logback.version>
<javax.inject.version>1</javax.inject.version>
<javax.servlet.servlet-api.version>3.0.1</javax.servlet.servlet-api.version>
<!-- <jcloverslf4j.version>1.7.6</jcloverslf4j.version> -->
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>dmp-backend</groupId> -->
<!-- <artifactId>dmp-backend-commons</artifactId> -->
<!-- <version>${dmp-backend-commons.version}</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- g/a spring -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- MY SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<!-- Jackson core and databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.4</version>
</dependency>
<!-- Json <-> XML transformations -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
<!-- tomcat jdbc -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>${org.apache.tomcat.tomcat-jdbc.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${org.junit.version}</version>
<scope>test</scope>
</dependency>
<!-- PostGreSql base libs dependencies -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
<!-- LogBack dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Various libs -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>false</failOnWarning>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>

@ -0,0 +1,35 @@
package controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import entities.DMP;
@Controller
public class UIController {
@Autowired private DMPDao dMPDao;
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("DMPs", dMPDao.getAll());
return "home";
}
}

@ -0,0 +1,17 @@
package dao;
import java.io.Serializable;
import java.util.List;
public interface Dao<T, PK extends Serializable> {
public T create(T t);
public T read(PK id);
public T update(T t);
public void delete(T t);
public List<T> getAll();
public long count();
public T loadDetails(T t);
public boolean isLoaded(T t);
}

@ -0,0 +1,10 @@
package dao;
import java.util.Map;
public interface DaoFactory
{
public Dao getDao(Class<?> type) throws Exception;
public void overrideMappings(Map<String, String> mappings) throws Exception;
}

@ -0,0 +1,20 @@
package dao;
import java.io.Serializable;
import java.util.List;
public interface DaoI<T, Id extends Serializable> {
public void persist(T entity);
public void update(T entity);
public T findById(Id id);
public void delete(T entity);
public List<T> findAll();
public void deleteAll();
}

@ -0,0 +1,80 @@
package dao;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnitUtil;
import org.springframework.transaction.annotation.Transactional;
public abstract class JpaDao<T, PK extends Serializable> implements Dao<T, PK> {
protected Class<T> entityClass;
// protected static EntityManagerFactory entityManagerFactory = null;
@PersistenceContext
protected EntityManager entityManager;
protected PersistenceUnitUtil persistenceUnitUtil;
// public static void setEntityManagerFactory(EntityManagerFactory factory)
// {
// entityManagerFactory = factory;
// }
public JpaDao() {
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
this.entityClass = (Class<T>) genericSuperclass.getActualTypeArguments()[0];
// entityManager = entityManagerFactory.createEntityManager();
}
@PostConstruct
private void initPersistenceUnitUtil() {
this.persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
}
@Transactional
public T create(T t) {
entityManager.persist(t);
return t;
}
@Transactional(readOnly = true)
public T read(PK id) {
return entityManager.find(entityClass, id);
}
@Transactional
public T update(T t) {
return entityManager.merge(t);
}
@Transactional
public void delete(T t) {
t = entityManager.merge(t);
entityManager.remove(t);
}
public List<T> getAll() {
List<T> result = entityManager.createQuery("from " + entityClass.getSimpleName(), entityClass).getResultList();
return result == null ? new ArrayList<T>() : result;
}
public long count() {
return ((Number) entityManager.createQuery("select count(e) from " + entityClass.getSimpleName() + " e").getSingleResult()).longValue();
}
public boolean isLoaded(T t) {
return persistenceUnitUtil.isLoaded(t);
}
protected boolean isFieldLoaded(T t, String fieldName) {
return persistenceUnitUtil.isLoaded(t, fieldName);
}
}

@ -0,0 +1,84 @@
package dao;
import java.util.HashMap;
import java.util.Map;
import dao.entities.DMPDaoImpl;
import dao.entities.DMPProfileDaoImpl;
import dao.entities.DMPResearcherDaoImpl;
import dao.entities.DataRepositoryDaoImpl;
import dao.entities.DatasetDaoImpl;
import dao.entities.DatasetProfileDaoImpl;
import dao.entities.DatasetProfileRulesetDaoImpl;
import dao.entities.DatasetProfileViewstyleDaoImpl;
import dao.entities.DatasetRegistryDaoImpl;
import dao.entities.DatasetServiceDaoImpl;
import dao.entities.OrganisationDaoImpl;
import dao.entities.ProjectDaoImpl;
import dao.entities.RegistryDaoImpl;
import dao.entities.ResearcherDaoImpl;
import dao.entities.ServiceDaoImpl;
import entities.DMP;
import entities.DMPProfile;
import entities.DMPResearcher;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.DatasetRegistry;
import entities.DatasetService;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
/**
* A DAO factory for non-managed environments
*/
public class JpaDaoFactory implements DaoFactory
{
private static String persistenceUnit = null;
private static Map<String, String> daoImpls = null;
public static void setPersistenceContext(String persistenceUnit)
{
JpaDaoFactory.persistenceUnit = persistenceUnit;
}
private static void populateMappings()
{
daoImpls = new HashMap<String, String>();
daoImpls.put(Organisation.class.getName(), OrganisationDaoImpl.class.getName());
daoImpls.put(DataRepository.class.getName(), (DataRepositoryDaoImpl.class.getName()));
daoImpls.put(Dataset.class.getName(), (DatasetDaoImpl.class.getName()));
daoImpls.put(DatasetProfile.class.getName(), (DatasetProfileDaoImpl.class.getName()));
daoImpls.put(DatasetProfileRuleset.class.getName(), (DatasetProfileRulesetDaoImpl.class.getName()));
daoImpls.put(DatasetProfileViewstyle.class.getName(), (DatasetProfileViewstyleDaoImpl.class.getName()));
daoImpls.put(DatasetRegistry.class.getName(), (DatasetRegistryDaoImpl.class.getName()));
daoImpls.put(DatasetService.class.getName(), (DatasetServiceDaoImpl.class.getName()));
daoImpls.put(DMP.class.getName(), (DMPDaoImpl.class.getName()));
daoImpls.put(DMPProfile.class.getName(), (DMPProfileDaoImpl.class.getName()));
daoImpls.put(DMPResearcher.class.getName(), (DMPResearcherDaoImpl.class.getName()));
daoImpls.put(Organisation.class.getName(), (OrganisationDaoImpl.class.getName()));
daoImpls.put(Project.class.getName(), (ProjectDaoImpl.class.getName()));
daoImpls.put(Registry.class.getName(), (RegistryDaoImpl.class.getName()));
daoImpls.put(Researcher.class.getName(), (ResearcherDaoImpl.class.getName()));
daoImpls.put(Service.class.getName(), (ServiceDaoImpl.class.getName()));
}
@SuppressWarnings("rawtypes")
public Dao getDao(Class<?> type) throws Exception
{
if(daoImpls == null) populateMappings();
return (Dao)Class.forName(daoImpls.get(type.getName())).newInstance();
}
public void overrideMappings(Map<String, String> mappings)
{
populateMappings();
daoImpls.putAll(mappings);
}
}

@ -0,0 +1,120 @@
package dao;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import dao.entities.DMPDaoImpl;
import dao.entities.DMPProfileDaoImpl;
import dao.entities.DMPResearcherDaoImpl;
import dao.entities.DataRepositoryDaoImpl;
import dao.entities.DatasetDaoImpl;
import dao.entities.DatasetProfileDaoImpl;
import dao.entities.DatasetProfileRulesetDaoImpl;
import dao.entities.DatasetProfileViewstyleDaoImpl;
import dao.entities.DatasetRegistryDaoImpl;
import dao.entities.DatasetServiceDaoImpl;
import dao.entities.OrganisationDaoImpl;
import dao.entities.ProjectDaoImpl;
import dao.entities.RegistryDaoImpl;
import dao.entities.ResearcherDaoImpl;
import dao.entities.ServiceDaoImpl;
import entities.DMP;
import entities.DMPProfile;
import entities.DMPResearcher;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.DatasetRegistry;
import entities.DatasetService;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
/**
* A DAO factory for Spring managed environment
*/
public class SpringJpaDaoFactory implements DaoFactory
{
public static class SpringApplicationContext implements ApplicationContextAware {
private static ApplicationContext CONTEXT;
/**
* This method is called from within the ApplicationContext once it is
* done starting up, it will stick a reference to itself into this bean.
* @param context a reference to the ApplicationContext.
*/
public void setApplicationContext(ApplicationContext context) throws BeansException {
CONTEXT = context;
}
/**
* This is about the same as context.getBean("beanName"), except it has its
* own static handle to the Spring context, so calling this method statically
* will give access to the beans by name in the Spring application context.
* As in the context.getBean("beanName") call, the caller must cast to the
* appropriate target class. If the bean does not exist, then a Runtime error
* will be thrown.
* @param beanName the name of the bean to get.
* @return an Object reference to the named bean.
*/
public static Object getBean(String beanName) {
return CONTEXT.getBean(beanName);
}
}
private static String persistenceUnit = null;
private static Map<String, String> daoImpls = null;
public static void setPersistenceContext(String persistenceUnit)
{
SpringJpaDaoFactory.persistenceUnit = persistenceUnit;
}
private static String getBeanName(String className)
{
return Character.toLowerCase(className.charAt(0)) +
(className.length() > 1 ? className.substring(1) : "");
}
private static void populateMappings()
{
daoImpls = new HashMap<String, String>();
daoImpls.put(DataRepository.class.getName(), getBeanName(DataRepositoryDaoImpl.class.getSimpleName()));
daoImpls.put(Dataset.class.getName(), getBeanName(DatasetDaoImpl.class.getSimpleName()));
daoImpls.put(DatasetProfile.class.getName(), getBeanName(DatasetProfileDaoImpl.class.getSimpleName()));
daoImpls.put(DatasetProfileRuleset.class.getName(), getBeanName(DatasetProfileRulesetDaoImpl.class.getSimpleName()));
daoImpls.put(DatasetProfileViewstyle.class.getName(), getBeanName(DatasetProfileViewstyleDaoImpl.class.getSimpleName()));
daoImpls.put(DatasetRegistry.class.getName(), getBeanName(DatasetRegistryDaoImpl.class.getSimpleName()));
daoImpls.put(DatasetService.class.getName(), getBeanName(DatasetServiceDaoImpl.class.getSimpleName()));
daoImpls.put(DMP.class.getName(), getBeanName(DMPDaoImpl.class.getSimpleName()));
daoImpls.put(DMPProfile.class.getName(), getBeanName(DMPProfileDaoImpl.class.getSimpleName()));
daoImpls.put(DMPResearcher.class.getName(), getBeanName(DMPResearcherDaoImpl.class.getSimpleName()));
daoImpls.put(Organisation.class.getName(), getBeanName(OrganisationDaoImpl.class.getSimpleName()));
daoImpls.put(Project.class.getName(), getBeanName(ProjectDaoImpl.class.getSimpleName()));
daoImpls.put(Registry.class.getName(), getBeanName(RegistryDaoImpl.class.getSimpleName()));
daoImpls.put(Researcher.class.getName(), getBeanName(ResearcherDaoImpl.class.getSimpleName()));
daoImpls.put(Service.class.getName(), getBeanName(ServiceDaoImpl.class.getSimpleName()));
}
@SuppressWarnings("rawtypes")
public Dao getDao(Class<?> type) throws Exception
{
if(daoImpls == null) populateMappings();
return (Dao)SpringApplicationContext.getBean(daoImpls.get(type.getName()));
}
public void overrideMappings(Map<String, String> mappings)
{
populateMappings();
daoImpls.putAll(mappings);
}
}

@ -0,0 +1,16 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import dao.Dao;
import entities.DMP;
import entities.Organisation;
public interface DMPDao extends Dao<DMP, UUID> {
public List<UUID> listAllIDs();
}

@ -0,0 +1,26 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import javax.persistence.TypedQuery;
import dao.JpaDao;
import entities.DMP;
public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
public DMP loadDetails(DMP t) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT dmp.id FROM DMP dmp";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DMPProfile;
public interface DMPProfileDao extends Dao<DMPProfile, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DMPProfile;
public class DMPProfileDaoImpl extends JpaDao<DMPProfile, UUID> implements DMPProfileDao {
public DMPProfile loadDetails(DMPProfile t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DMPResearcher;
public interface DMPResearcherDao extends Dao<DMPResearcher, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DMPResearcher;
public class DMPResearcherDaoImpl extends JpaDao<DMPResearcher, UUID> implements DMPResearcherDao {
public DMPResearcher loadDetails(DMPResearcher t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DataRepository;
public interface DataRepositoryDao extends Dao<DataRepository, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DataRepository;
public class DataRepositoryDaoImpl extends JpaDao<DataRepository, UUID> implements DataRepositoryDao {
public DataRepository loadDetails(DataRepository t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,14 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import dao.Dao;
import entities.Dataset;
public interface DatasetDao extends Dao<Dataset, UUID> {
public List<UUID> listAllIDs();
}

@ -0,0 +1,26 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import dao.JpaDao;
import entities.Dataset;
public class DatasetDaoImpl extends JpaDao<Dataset, UUID> implements DatasetDao {
public Dataset loadDetails(Dataset t) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT dataset.id FROM Dataset dataset";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DatasetProfile;
public interface DatasetProfileDao extends Dao<DatasetProfile, UUID> {
}

@ -0,0 +1,18 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DatasetProfile;
public class DatasetProfileDaoImpl extends JpaDao<DatasetProfile, UUID> implements DatasetProfileDao {
public DatasetProfile loadDetails(DatasetProfile t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DatasetProfileRuleset;
public interface DatasetProfileRulesetDao extends Dao<DatasetProfileRuleset, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DatasetProfileRuleset;
public class DatasetProfileRulesetDaoImpl extends JpaDao<DatasetProfileRuleset, UUID> implements DatasetProfileRulesetDao {
public DatasetProfileRuleset loadDetails(DatasetProfileRuleset t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DatasetProfileViewstyle;
public interface DatasetProfileViewstyleDao extends Dao<DatasetProfileViewstyle, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DatasetProfileViewstyle;
public class DatasetProfileViewstyleDaoImpl extends JpaDao<DatasetProfileViewstyle, UUID> implements DatasetProfileViewstyleDao {
public DatasetProfileViewstyle loadDetails(DatasetProfileViewstyle t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DatasetRegistry;
public interface DatasetRegistryDao extends Dao<DatasetRegistry, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DatasetRegistry;
public class DatasetRegistryDaoImpl extends JpaDao<DatasetRegistry, UUID> implements DatasetRegistryDao {
public DatasetRegistry loadDetails(DatasetRegistry t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.DatasetService;
public interface DatasetServiceDao extends Dao<DatasetService, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.DatasetService;
public class DatasetServiceDaoImpl extends JpaDao<DatasetService, UUID> implements DatasetServiceDao {
public DatasetService loadDetails(DatasetService t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,11 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.Organisation;
public interface OrganisationDao extends Dao<Organisation, UUID> {
}

@ -0,0 +1,20 @@
package dao.entities;
import java.util.UUID;
import javax.persistence.Query;
import javax.transaction.Transactional;
import dao.JpaDao;
import entities.Organisation;
public class OrganisationDaoImpl extends JpaDao<Organisation, UUID> implements OrganisationDao {
public Organisation loadDetails(Organisation t) {
// TODO Auto-generated method stub
return null;
}
}

@ -0,0 +1,13 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import dao.Dao;
import entities.Project;
public interface ProjectDao extends Dao<Project, UUID> {
public List<UUID> listAllIDs();
}

@ -0,0 +1,26 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import javax.persistence.TypedQuery;
import dao.JpaDao;
import entities.Project;
public class ProjectDaoImpl extends JpaDao<Project, UUID> implements ProjectDao {
public Project loadDetails(Project t) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT project.id FROM Project project";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
}

@ -0,0 +1,10 @@
package dao.entities;
import java.util.UUID;
import dao.Dao;
import entities.Registry;
public interface RegistryDao extends Dao<Registry, UUID> {
}

@ -0,0 +1,17 @@
package dao.entities;
import java.util.UUID;
import dao.JpaDao;
import entities.Registry;
public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryDao {
public Registry loadDetails(Registry t) {
// TODO Auto-generated method stub
return null;
}