Commit f6382725 authored by michael.simon's avatar michael.simon
Browse files

Merge branch '100-try-to-make-layout-templateable' into 'branch-2.7'

Resolve "Try to make layout templateable"

Closes #100

See merge request !20
parents 12c276de a74c0219
......@@ -136,6 +136,15 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -13,10 +13,10 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
<version>1.0.1.Final</version>
<type>pom</type>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-javaee8-with-tools</artifactId>
<version>17.0.1.Final</version>
<type>pom</type>
<scope>import</scope>
<optional>false</optional>
</dependency>
......@@ -46,11 +46,6 @@
<artifactId>hibernate-entitymanager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
@Entity(name = "VelocityTemplateEntity")
@Table(name = "velocity_template")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class VelocityTemplateEntity extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
@Column(name = "tpl_name", length=256)
private String name;
@Column(name = "tpl_content")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String template;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
}
package edu.kit.scc.webreg.entity;
import javax.annotation.Generated;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(VelocityTemplateEntity.class)
public abstract class VelocityTemplateEntity_ extends edu.kit.scc.webreg.entity.AbstractBaseEntity_ {
public static volatile SingularAttribute<EmailTemplateEntity, String> name;
public static volatile SingularAttribute<EmailTemplateEntity, String> template;
}
......@@ -20,19 +20,7 @@
<version>2.7.4</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
<version>1.0.1.Final</version>
<type>pom</type>
<scope>import</scope>
<optional>false</optional>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
......@@ -64,11 +52,6 @@
<artifactId>hibernate-entitymanager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao;
import edu.kit.scc.webreg.entity.VelocityTemplateEntity;
public interface VelocityTemplateDao extends BaseDao<VelocityTemplateEntity, Long> {
VelocityTemplateEntity findByName(String name);
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import edu.kit.scc.webreg.dao.VelocityTemplateDao;
import edu.kit.scc.webreg.entity.VelocityTemplateEntity;
@Named
@ApplicationScoped
public class JpaVelocityTemplateDao extends JpaBaseDao<VelocityTemplateEntity, Long> implements VelocityTemplateDao {
@Override
public VelocityTemplateEntity findByName(String name) {
try {
return (VelocityTemplateEntity) em.createQuery("select e from VelocityTemplateEntity e where e.name = :name")
.setParameter("name", name).getSingleResult();
} catch (NoResultException e) {
return null;
}
}
@Override
public Class<VelocityTemplateEntity> getEntityClass() {
return VelocityTemplateEntity.class;
}
}
......@@ -146,6 +146,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
......
package edu.kit.scc.nextcloud;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "ocs")
public class NextcloudAnswer {
......
......@@ -2,7 +2,7 @@ package edu.kit.scc.nextcloud;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElement;
public class NextcloudGroups {
......
package edu.kit.scc.nextcloud;
import javax.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElement;
public class NextcloudMeta {
......
package edu.kit.scc.nextcloud;
import javax.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElement;
public class NextcloudUser {
......
......@@ -7,9 +7,9 @@ import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.SSLException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Unmarshaller;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
......
......@@ -10,6 +10,9 @@
******************************************************************************/
package edu.kit.scc.webreg.bootstrap;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLStreamHandlerFactory;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -39,6 +42,7 @@ import edu.kit.scc.webreg.service.impl.HookManager;
import edu.kit.scc.webreg.service.mail.TemplateRenderer;
import edu.kit.scc.webreg.service.timer.ClusterSchedulerManager;
import edu.kit.scc.webreg.service.timer.StandardScheduler;
import edu.kit.scc.webreg.service.tpl.TemplateUrlStreamHandlerFactory;
@Singleton
@Startup
......@@ -89,6 +93,9 @@ public class ApplicationBootstrap {
logger.info("Initializing Application Configuration");
appConfig.init();
logger.info("Register Template URL Stream handler");
registerUrlHandler();
logger.info("Initializing Serials");
checkSerial("uid-number-serial", 900000L);
checkSerial("gid-number-serial", 500000L);
......@@ -154,6 +161,24 @@ public class ApplicationBootstrap {
standardScheduler.initialize();
clusterSchedulerManager.initialize();
}
private void registerUrlHandler() {
try {
final Field factoryField = URL.class.getDeclaredField("factory");
factoryField.setAccessible(true);
final Field lockField = URL.class.getDeclaredField("streamHandlerLock");
lockField.setAccessible(true);
synchronized (lockField.get(null)) {
final URLStreamHandlerFactory urlStreamHandlerFactory = (URLStreamHandlerFactory) factoryField.get(null);
factoryField.set(null, null);
URL.setURLStreamHandlerFactory(new TemplateUrlStreamHandlerFactory(urlStreamHandlerFactory));
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
logger.warn("Could not register Template URL Stream Handler");
}
}
private void checkGroup(String name, Integer createActual) {
......
package edu.kit.scc.webreg.service.tpl;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
public class TeamplateUrlStreamHandler extends URLStreamHandler {
@Override
protected URLConnection openConnection(URL url) throws IOException {
return new TemplateUrlConnection(url);
}
}
package edu.kit.scc.webreg.service.tpl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.entity.VelocityTemplateEntity;
public class TemplateUrlConnection extends URLConnection {
private static final Logger logger = LoggerFactory.getLogger(TemplateUrlConnection.class);
private VelocityTemplateService templateService;
private VelocityTemplateEntity tpl;
protected TemplateUrlConnection(URL url) {
super(url);
}
@Override
public void connect() throws IOException {
try {
InitialContext ic = new InitialContext();
templateService = (VelocityTemplateService) ic.lookup("global/bwreg/bwreg-service/VelocityTemplateServiceImpl!edu.kit.scc.webreg.service.tpl.VelocityTemplateService");
if (logger.isTraceEnabled())
logger.trace("Looking up template for url {}", url);
tpl = templateService.findByName(url.getHost() + url.getPath());
connected = true;
} catch (NamingException e) {
logger.warn("Could not load velocity template service: {}", e);
}
}
@Override
public InputStream getInputStream() throws IOException {
if (! connected) {
connect();
}
if (tpl == null) {
throw new IOException("Template not found!");
}
return new ByteArrayInputStream(tpl.getTemplate().getBytes("UTF-8"));
}
@Override
public long getLastModified() {
if (! connected) {
try {
connect();
} catch (IOException e) {
return -1L;
}
}
if (tpl == null) {
return -1L;
}
return tpl.getUpdatedAt().getTime();
}
}
package edu.kit.scc.webreg.service.tpl;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
public class TemplateUrlStreamHandler extends URLStreamHandler {
@Override
protected URLConnection openConnection(URL url) throws IOException {
return new TemplateUrlConnection(url);
}
}
package edu.kit.scc.webreg.service.tpl;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
public class TemplateUrlStreamHandlerFactory implements URLStreamHandlerFactory {
private URLStreamHandlerFactory originalFactory;
public TemplateUrlStreamHandlerFactory(URLStreamHandlerFactory originalFactory) {
this.originalFactory = originalFactory;
}
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
if ("tpl".equals(protocol)) {
return new TemplateUrlStreamHandler();
}
return originalFactory.createURLStreamHandler(protocol);
}
}
package edu.kit.scc.webreg.service.tpl;
public interface VelocityPageRenderer {
}
package edu.kit.scc.webreg.service.tpl;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.service.mail.TemplateRenderer;
@Stateless
public class VelocityPageRendererImpl implements VelocityPageRenderer {
@Inject
private Logger logger;
@Inject
private TemplateRenderer renderer;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment