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

Merge remote-tracking branch 'origin/branch-2.5' into issue-14

parents f89fd21f bf4337f5
......@@ -93,6 +93,11 @@
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<artifactId>dom4j</artifactId>
<groupId>dom4j</groupId>
......
......@@ -10,10 +10,14 @@
******************************************************************************/
package edu.kit.scc.webreg.dao;
import java.util.Date;
import edu.kit.scc.webreg.entity.ApplicationConfigEntity;
public interface ApplicationConfigDao extends BaseDao<ApplicationConfigEntity, Long> {
ApplicationConfigEntity findActive();
ApplicationConfigEntity findReloadActive(Date date);
}
/*******************************************************************************
* 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.TextPropertyEntity;
public interface TextPropertyDao extends BaseDao<TextPropertyEntity, Long> {
TextPropertyEntity findByKeyAndLang(String key, String language);
}
......@@ -10,12 +10,16 @@
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa;
import java.util.Date;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import edu.kit.scc.webreg.dao.ApplicationConfigDao;
import edu.kit.scc.webreg.entity.ApplicationConfigEntity;
import edu.kit.scc.webreg.entity.BusinessRulePackageEntity;
@Named
@ApplicationScoped
......@@ -33,6 +37,20 @@ public class JpaApplicationConfigDao extends JpaBaseDao<ApplicationConfigEntity,
}
}
@Override
@SuppressWarnings({"unchecked"})
public ApplicationConfigEntity findReloadActive(Date date) {
try {
return (ApplicationConfigEntity) em.createQuery("select e from ApplicationConfigEntity e "
+ "where e.activeConfig = :act and e.dirtyStamp > :date")
.setParameter("date", date).setParameter("act", true)
.getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public Class<ApplicationConfigEntity> getEntityClass() {
return ApplicationConfigEntity.class;
......
/*******************************************************************************
* 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.TextPropertyDao;
import edu.kit.scc.webreg.entity.TextPropertyEntity;
@Named
@ApplicationScoped
public class JpaTextPropertyDao extends JpaBaseDao<TextPropertyEntity, Long> implements TextPropertyDao {
@Override
public TextPropertyEntity findByKeyAndLang(String key, String language) {
try {
return (TextPropertyEntity) em.createQuery("select e from TextPropertyEntity e "
+ "where e.key = :key and e.language = :language")
.setParameter("key", key)
.setParameter("language", language)
.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
@Override
public Class<TextPropertyEntity> getEntityClass() {
return TextPropertyEntity.class;
}
}
package edu.kit.scc.webreg.entity;
import java.util.Date;
import java.util.Map;
import javax.persistence.Column;
......@@ -24,7 +25,10 @@ public class ApplicationConfigEntity extends AbstractBaseEntity {
@Column(name = "activeConfig")
private Boolean activeConfig;
@Column(name = "dirty_stamp")
private Date dirtyStamp;
@ElementCollection(fetch = FetchType.EAGER)
@JoinTable(name = "application_config_options")
@MapKeyColumn(name = "key_data", length = 128)
......@@ -61,6 +65,14 @@ public class ApplicationConfigEntity extends AbstractBaseEntity {
public void setConfigFormatVersion(String configFormatVersion) {
this.configFormatVersion = configFormatVersion;
}
public Date getDirtyStamp() {
return dirtyStamp;
}
public void setDirtyStamp(Date dirtyStamp) {
this.dirtyStamp = dirtyStamp;
}
}
/*******************************************************************************
* 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.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "text_property",
uniqueConstraints = @UniqueConstraint(columnNames = {"text_key", "text_lang"}))
public class TextPropertyEntity extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
@Column(name = "text_key", nullable = false, length = 256)
private String key;
@Column(name = "text_value", nullable = false, length = 2048)
private String value;
@Column(name = "text_lang", nullable = false, length = 32)
private String language;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
}
......@@ -33,12 +33,10 @@ import edu.kit.scc.webreg.entity.SerialEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.service.AdminUserService;
import edu.kit.scc.webreg.service.GroupService;
import edu.kit.scc.webreg.service.GroupServiceHook;
import edu.kit.scc.webreg.service.RoleService;
import edu.kit.scc.webreg.service.SerialService;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.UserService;
import edu.kit.scc.webreg.service.UserServiceHook;
import edu.kit.scc.webreg.service.impl.HookManager;
import edu.kit.scc.webreg.service.mail.TemplateRenderer;
import edu.kit.scc.webreg.service.timer.StandardScheduler;
......@@ -129,8 +127,7 @@ public class ApplicationBootstrap {
}
logger.info("Initializing Hooks");
addUserHooks();
addGroupHooks();
hookManager.reloadHooks();
userService.convertLegacyUsers();
......@@ -155,50 +152,6 @@ public class ApplicationBootstrap {
standardScheduler.initialize();
}
private void addUserHooks() {
String hooksString = appConfig.getConfigValue("user_hooks");
if (hooksString != null && hooksString.length() > 0) {
hooksString = hooksString.trim();
String[] hooks = hooksString.split(";");
for (String hook : hooks) {
hook = hook.trim();
try {
UserServiceHook h = (UserServiceHook) Class.forName(hook).newInstance();
h.setAppConfig(appConfig);
hookManager.addUserHook(h);
} catch (InstantiationException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (IllegalAccessException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (ClassNotFoundException e) {
logger.warn("Could not spawn hook " + hook, e);
}
}
}
}
private void addGroupHooks() {
String hooksString = appConfig.getConfigValue("group_hooks");
if (hooksString != null && hooksString.length() > 0) {
hooksString = hooksString.trim();
String[] hooks = hooksString.split(";");
for (String hook : hooks) {
hook = hook.trim();
try {
GroupServiceHook h = (GroupServiceHook) Class.forName(hook).newInstance();
h.setAppConfig(appConfig);
hookManager.addGroupHook(h);
} catch (InstantiationException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (IllegalAccessException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (ClassNotFoundException e) {
logger.warn("Could not spawn hook " + hook, e);
}
}
}
}
private void checkGroup(String name, Integer createActual) {
GroupEntity entity = groupService.findByName(name);
if (entity == null) {
......
......@@ -11,6 +11,7 @@
package edu.kit.scc.webreg.bootstrap;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -35,6 +36,8 @@ public class ApplicationConfig implements Serializable {
private ApplicationConfigEntity appConfig;
private Date lastLoad;
public void init() {
logger.debug("Checking for Active Configuration");
appConfig = dao.findActive();
......@@ -48,6 +51,28 @@ public class ApplicationConfig implements Serializable {
appConfig.setConfigOptions(new HashMap<String, String>());
appConfig = dao.persist(appConfig);
}
lastLoad = new Date();
}
public boolean reload() {
ApplicationConfigEntity newAppConfig = dao.findReloadActive(lastLoad);
if (newAppConfig != null) {
logger.info("Reloading Application Configuration");
appConfig = newAppConfig;
lastLoad = new Date();
return true;
}
else {
return false;
}
}
public void scheduleReload() {
appConfig.setDirtyStamp(new Date());
appConfig = dao.persist(appConfig);
}
public String getConfigValue(String key) {
......@@ -68,4 +93,12 @@ public class ApplicationConfig implements Serializable {
public Map<String, String> getConfigOptions() {
return appConfig.getConfigOptions();
}
public Date getLastLoad() {
return lastLoad;
}
public Date getNextScheduledReload() {
return appConfig.getDirtyStamp();
}
}
......@@ -179,7 +179,10 @@ public class KnowledgeSessionServiceImpl implements KnowledgeSessionService {
throw new MisconfiguredServiceException("Der Registrierungsprozess für den Dienst ist nicht korrekt konfiguriert (Keine Zugangsregel geladen)");
ksession.setGlobal("logger", logger);
ksession.insert(user);
ksession.insert(service);
ksession.insert(registry);
logger.debug("Test all Rules for service {}", service.getName());
ksession.fireAllRules();
......
/*******************************************************************************
* 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.service;
import edu.kit.scc.webreg.entity.TextPropertyEntity;
public interface TextPropertyService extends BaseService<TextPropertyEntity, Long> {
TextPropertyEntity findAllBySingleton(String key, String language);
}
......@@ -15,13 +15,23 @@ import java.util.Set;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.service.GroupServiceHook;
import edu.kit.scc.webreg.service.UserServiceHook;
@Singleton
public class HookManager {
@Inject
private Logger logger;
@Inject
private ApplicationConfig appConfig;
private Set<UserServiceHook> userHooks;
private Set<GroupServiceHook> groupHooks;
......@@ -31,14 +41,67 @@ public class HookManager {
userHooks = new HashSet<UserServiceHook>();
}
public void addGroupHook(GroupServiceHook hook) {
groupHooks.add(hook);
public void reloadHooks() {
logger.info("Reloading User Hooks");
reloadUserHooks();
logger.info("Reloading Group Hooks");
reloadGroupHooks();
}
public void reloadUserHooks() {
Set<UserServiceHook> newUserHooks = new HashSet<UserServiceHook>();
public void addUserHook(UserServiceHook hook) {
userHooks.add(hook);
String hooksString = appConfig.getConfigValue("user_hooks");
if (hooksString != null && hooksString.length() > 0) {
hooksString = hooksString.trim();
String[] hooks = hooksString.split(";");
for (String hook : hooks) {
hook = hook.trim();
try {
logger.debug("installing hook {}", hook);
UserServiceHook h = (UserServiceHook) Class.forName(hook).newInstance();
h.setAppConfig(appConfig);
newUserHooks.add(h);
} catch (InstantiationException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (IllegalAccessException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (ClassNotFoundException e) {
logger.warn("Could not spawn hook " + hook, e);
}
}
}
userHooks = newUserHooks;
}
public void reloadGroupHooks() {
Set<GroupServiceHook> newGroupHooks = new HashSet<GroupServiceHook>();
String hooksString = appConfig.getConfigValue("group_hooks");
if (hooksString != null && hooksString.length() > 0) {
hooksString = hooksString.trim();
String[] hooks = hooksString.split(";");
for (String hook : hooks) {
hook = hook.trim();
try {
logger.debug("installing hook {}", hook);
GroupServiceHook h = (GroupServiceHook) Class.forName(hook).newInstance();
h.setAppConfig(appConfig);
newGroupHooks.add(h);
} catch (InstantiationException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (IllegalAccessException e) {
logger.warn("Could not spawn hook " + hook, e);
} catch (ClassNotFoundException e) {
logger.warn("Could not spawn hook " + hook, e);
}
}
}
groupHooks = newGroupHooks;
}
public Set<GroupServiceHook> getGroupHooks() {
return groupHooks;
}
......
/*******************************************************************************
* 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.service.impl;
import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.TextPropertyDao;
import edu.kit.scc.webreg.entity.TextPropertyEntity;
import edu.kit.scc.webreg.service.TextPropertyService;
@Stateless
public class TextPropertyServiceImpl extends BaseServiceImpl<TextPropertyEntity, Long> implements TextPropertyService {
private static final long serialVersionUID = 1L;
@Inject
private TextPropertyDao dao;
@Override
public TextPropertyEntity findAllBySingleton(String key, String language) {
return dao.findByKeyAndLang(key, language);
}
@Override
protected BaseDao<TextPropertyEntity, Long> getDao() {
return dao;
}
}
......@@ -26,6 +26,7 @@ import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.bootstrap.NodeConfiguration;
import edu.kit.scc.webreg.drools.BpmProcessService;
import edu.kit.scc.webreg.entity.JobClassEntity;
......@@ -33,6 +34,7 @@ import edu.kit.scc.webreg.entity.JobScheduleEntity;
import edu.kit.scc.webreg.job.ExecutableJob;
import edu.kit.scc.webreg.service.JobClassService;
import edu.kit.scc.webreg.service.JobScheduleService;
import edu.kit.scc.webreg.service.impl.HookManager;
@Singleton
public class StandardSchedulerImpl implements StandardScheduler, Serializable {
......@@ -60,6 +62,12 @@ public class StandardSchedulerImpl implements StandardScheduler, Serializable {
@Inject
private BpmProcessService bpmProcessService;
@Inject
private ApplicationConfig appConfig;
@Inject
private HookManager hookManager;
@Override
public void initialize() {
......@@ -153,6 +161,15 @@ public class StandardSchedulerImpl implements StandardScheduler, Serializable {
// Reload rules here
bpmProcessService.reload();
// Reload App Config here
boolean reloaded = appConfig.reload();
// Reload Hooks if app config was reloaded
if (reloaded) {
hookManager.reloadHooks();
}
}
private void cancelTimer(Timer t) {
......
......@@ -93,6 +93,11 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
......
......@@ -10,24 +10,32 @@
******************************************************************************/
package edu.kit.scc.webreg.bean;
import java.util.List;
import java.io.Serializable;