added caching and exception handling

This commit is contained in:
2019-05-01 13:52:39 +02:00
parent 70a45b1919
commit 336e76f536
4 changed files with 36 additions and 15 deletions

View File

@ -15,6 +15,7 @@
*/
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.entity.AccountEntity;
import de.muehlencord.shared.account.business.account.entity.ApiKeyEntity;
@ -89,7 +90,7 @@ public class ApiKeyService implements Serializable {
password = configService.getConfigValue("rest.password");
issuer = configService.getConfigValue("rest.issuer");
expirationInMinutes = Short.parseShort(configService.getConfigValue("rest.expiration_in_minutes", "120", true));
} catch (ConfigException | NumberFormatException ex) {
} catch (ConfigException | NumberFormatException | ControllerException ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(ex.toString(), ex);
} else {

View File

@ -15,6 +15,7 @@
*/
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.AccountEntity;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
@ -107,14 +108,14 @@ public class ConfigService implements Serializable {
@Lock(LockType.READ)
@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);
}
@Transactional
@Lock(LockType.WRITE)
@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
String configValue = getConfigValue(configKey);
@ -160,7 +161,7 @@ public class ConfigService implements Serializable {
@Transactional
@Lock(LockType.WRITE)
@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);
if (configValue == null) {
@ -179,7 +180,7 @@ public class ConfigService implements Serializable {
@Transactional
@Lock(LockType.WRITE)
@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");
return updateConfigValue(configKey, account, configValue);
}
@ -187,7 +188,7 @@ public class ConfigService implements Serializable {
@Transactional
@Lock(LockType.WRITE)
@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);
if (accountName == null) {
return false;
@ -202,15 +203,14 @@ public class ConfigService implements Serializable {
@Transactional
@Lock(LockType.WRITE)
@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(""))) {
// null or empty key
return false;
}
if (account == null) {
LOGGER.error("Account must not be null, not updating");
return false;
throw new ControllerException(ControllerException.CAUSE_CANNOT_PERSIST, "Account must not be null, not updating");
}
AccountEntity accountEntity = getAccount(account.getUsername());
@ -251,4 +251,11 @@ public class ConfigService implements Serializable {
return accountList.get(0);
}
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Transactional
@Lock(LockType.WRITE)
public void delete(ConfigEntity config) throws ControllerException {
em.remove(em.merge(config));
}
}

View File

@ -15,6 +15,7 @@
*/
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.config.boundary.ConfigService;
import de.muehlencord.shared.account.business.config.entity.ConfigException;
@ -55,7 +56,7 @@ public class StartupBean {
configService.getConfigValue("account.maxFailedLogins", "5", true);
LOGGER.info("Application startup complete");
} catch (ConfigException ex) {
} catch (ConfigException | ControllerException ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(ex.toString(), ex);
} else {

View File

@ -17,11 +17,13 @@ package de.muehlencord.shared.account.business.mail.entity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.QueryHint;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@ -32,16 +34,26 @@ import javax.xml.bind.annotation.XmlRootElement;
* @author joern.muehlencord
*/
@Entity
@Cacheable
@Table(name = "mail_template")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "MailTemplateEntity.findAll", query = "SELECT m FROM MailTemplateEntity m"),
@NamedQuery(name = "MailTemplateEntity.findByTemplateName", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateName = :templateName"),
@NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue")})
@NamedQuery(name = "MailTemplateEntity.findAll", query = "SELECT m FROM MailTemplateEntity m",
hints = {
@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 {
private static final long serialVersionUID = 4527399247302581555L;
@Id
@Basic(optional = false)
@NotNull
@ -106,5 +118,5 @@ public class MailTemplateEntity implements Serializable {
public String toString() {
return "de.muehlencord.shared.account.entity.MailTemplate[ templateName=" + templateName + " ]";
}
}