added caching and exception handling
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.account.boundary;
|
package de.muehlencord.shared.account.business.account.boundary;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.business.ControllerException;
|
||||||
import de.muehlencord.shared.account.business.account.control.AccountControl;
|
import de.muehlencord.shared.account.business.account.control.AccountControl;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
import de.muehlencord.shared.account.business.account.entity.ApiKeyEntity;
|
import de.muehlencord.shared.account.business.account.entity.ApiKeyEntity;
|
||||||
@ -89,7 +90,7 @@ public class ApiKeyService implements Serializable {
|
|||||||
password = configService.getConfigValue("rest.password");
|
password = configService.getConfigValue("rest.password");
|
||||||
issuer = configService.getConfigValue("rest.issuer");
|
issuer = configService.getConfigValue("rest.issuer");
|
||||||
expirationInMinutes = Short.parseShort(configService.getConfigValue("rest.expiration_in_minutes", "120", true));
|
expirationInMinutes = Short.parseShort(configService.getConfigValue("rest.expiration_in_minutes", "120", true));
|
||||||
} catch (ConfigException | NumberFormatException ex) {
|
} catch (ConfigException | NumberFormatException | ControllerException ex) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug(ex.toString(), ex);
|
LOGGER.debug(ex.toString(), ex);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.config.boundary;
|
package de.muehlencord.shared.account.business.config.boundary;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.business.ControllerException;
|
||||||
import de.muehlencord.shared.account.business.account.entity.Account;
|
import de.muehlencord.shared.account.business.account.entity.Account;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
@ -107,14 +108,14 @@ public class ConfigService implements Serializable {
|
|||||||
|
|
||||||
@Lock(LockType.READ)
|
@Lock(LockType.READ)
|
||||||
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
|
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
|
||||||
public String getConfigValue(String configKey, String defaultValue) throws ConfigException {
|
public String getConfigValue(String configKey, String defaultValue) throws ConfigException, ControllerException {
|
||||||
return getConfigValue(configKey, defaultValue, false);
|
return getConfigValue(configKey, defaultValue, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
@TransactionAttribute(REQUIRES_NEW)
|
@TransactionAttribute(REQUIRES_NEW)
|
||||||
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
|
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException, ControllerException {
|
||||||
// get configValue as usual
|
// get configValue as usual
|
||||||
String configValue = getConfigValue(configKey);
|
String configValue = getConfigValue(configKey);
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ public class ConfigService implements Serializable {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
@TransactionAttribute(REQUIRES_NEW)
|
@TransactionAttribute(REQUIRES_NEW)
|
||||||
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException {
|
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException, ControllerException {
|
||||||
String configValue = getConfigValue(configKey, account, fallbackToSystem);
|
String configValue = getConfigValue(configKey, account, fallbackToSystem);
|
||||||
|
|
||||||
if (configValue == null) {
|
if (configValue == null) {
|
||||||
@ -179,7 +180,7 @@ public class ConfigService implements Serializable {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
@TransactionAttribute(REQUIRES_NEW)
|
@TransactionAttribute(REQUIRES_NEW)
|
||||||
public boolean updateConfigValue(String configKey, String configValue) throws ConfigException {
|
public boolean updateConfigValue(String configKey, String configValue) throws ConfigException, ControllerException {
|
||||||
Account account = getAccount("system");
|
Account account = getAccount("system");
|
||||||
return updateConfigValue(configKey, account, configValue);
|
return updateConfigValue(configKey, account, configValue);
|
||||||
}
|
}
|
||||||
@ -187,7 +188,7 @@ public class ConfigService implements Serializable {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
@TransactionAttribute(REQUIRES_NEW)
|
@TransactionAttribute(REQUIRES_NEW)
|
||||||
public boolean updateConfigValue(String configKey, String accountName, String configValue) {
|
public boolean updateConfigValue(String configKey, String accountName, String configValue) throws ControllerException {
|
||||||
Account account = getAccount(accountName);
|
Account account = getAccount(accountName);
|
||||||
if (accountName == null) {
|
if (accountName == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -202,15 +203,14 @@ public class ConfigService implements Serializable {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
@TransactionAttribute(REQUIRES_NEW)
|
@TransactionAttribute(REQUIRES_NEW)
|
||||||
public boolean updateConfigValue(String configKey, Account account, String configValue) {
|
public boolean updateConfigValue(String configKey, Account account, String configValue) throws ControllerException {
|
||||||
if ((configKey == null) || (configKey.equals(""))) {
|
if ((configKey == null) || (configKey.equals(""))) {
|
||||||
// null or empty key
|
// null or empty key
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
LOGGER.error("Account must not be null, not updating");
|
throw new ControllerException(ControllerException.CAUSE_CANNOT_PERSIST, "Account must not be null, not updating");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountEntity accountEntity = getAccount(account.getUsername());
|
AccountEntity accountEntity = getAccount(account.getUsername());
|
||||||
@ -251,4 +251,11 @@ public class ConfigService implements Serializable {
|
|||||||
return accountList.get(0);
|
return accountList.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TransactionAttribute(TransactionAttributeType.REQUIRED)
|
||||||
|
@Transactional
|
||||||
|
@Lock(LockType.WRITE)
|
||||||
|
public void delete(ConfigEntity config) throws ControllerException {
|
||||||
|
em.remove(em.merge(config));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.instance.boundary;
|
package de.muehlencord.shared.account.business.instance.boundary;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.business.ControllerException;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
@ -55,7 +56,7 @@ public class StartupBean {
|
|||||||
configService.getConfigValue("account.maxFailedLogins", "5", true);
|
configService.getConfigValue("account.maxFailedLogins", "5", true);
|
||||||
|
|
||||||
LOGGER.info("Application startup complete");
|
LOGGER.info("Application startup complete");
|
||||||
} catch (ConfigException ex) {
|
} catch (ConfigException | ControllerException ex) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug(ex.toString(), ex);
|
LOGGER.debug(ex.toString(), ex);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -17,11 +17,13 @@ package de.muehlencord.shared.account.business.mail.entity;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Cacheable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.NamedQueries;
|
import javax.persistence.NamedQueries;
|
||||||
import javax.persistence.NamedQuery;
|
import javax.persistence.NamedQuery;
|
||||||
|
import javax.persistence.QueryHint;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
@ -32,16 +34,26 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
|
@Cacheable
|
||||||
@Table(name = "mail_template")
|
@Table(name = "mail_template")
|
||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "MailTemplateEntity.findAll", query = "SELECT m FROM MailTemplateEntity m"),
|
@NamedQuery(name = "MailTemplateEntity.findAll", query = "SELECT m FROM MailTemplateEntity m",
|
||||||
@NamedQuery(name = "MailTemplateEntity.findByTemplateName", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateName = :templateName"),
|
hints = {
|
||||||
@NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue")})
|
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||||
|
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||||
|
@NamedQuery(name = "MailTemplateEntity.findByTemplateName", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateName = :templateName",
|
||||||
|
hints = {
|
||||||
|
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||||
|
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||||
|
@NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue",
|
||||||
|
hints = {
|
||||||
|
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||||
|
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")})})
|
||||||
public class MailTemplateEntity implements Serializable {
|
public class MailTemplateEntity implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4527399247302581555L;
|
private static final long serialVersionUID = 4527399247302581555L;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Basic(optional = false)
|
@Basic(optional = false)
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -106,5 +118,5 @@ public class MailTemplateEntity implements Serializable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "de.muehlencord.shared.account.entity.MailTemplate[ templateName=" + templateName + " ]";
|
return "de.muehlencord.shared.account.entity.MailTemplate[ templateName=" + templateName + " ]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user