com.formkiq.server.service.SystemPropertyServiceImpl Maven / Gradle / Ivy
package com.formkiq.server.service;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.formkiq.server.dao.SystemDao;
import com.formkiq.server.domain.SystemProperty;
import com.formkiq.server.domain.type.SystemPropertyListDTO;
/**
* Implementation of System Property Service.
*
*/
@Service
public class SystemPropertyServiceImpl implements SystemPropertyService {
/** System Properties that cannot be deleted. */
private static final Set CANNOT_DELETE_KEYS = new HashSet(
Arrays.asList(KEY_HOSTNAME, KEY_VERSION, INVITE_ONLY));
/** SystemDao. */
@Autowired
private SystemDao systemDao;
@Override
public void delete(final String key) {
if (CANNOT_DELETE_KEYS.contains(key)) {
throw new PreconditionFailedException(key + " cannot be deleted");
}
this.systemDao.delete(key);
}
@Override
public SystemPropertyListDTO getProperties() {
SystemPropertyListDTO dto = new SystemPropertyListDTO();
dto.setProperties(this.systemDao.getProperties());
return dto;
}
@Override
public String getSystemHostname() {
return this.systemDao.getValue(KEY_HOSTNAME);
}
@Override
public String getVersion() {
return this.systemDao.getValue(KEY_VERSION);
}
@Override
public boolean isInviteOnly() {
Boolean invite = Boolean.FALSE;
String value = this.systemDao.getValue(INVITE_ONLY);
if (!StringUtils.isEmpty(value)) {
invite = Boolean.valueOf(value);
}
return invite.booleanValue();
}
@Override
public void save(final String key, final String value) {
SystemProperty property = new SystemProperty(key, value);
this.systemDao.save(property);
}
@Override
public void setInviteOnly(final boolean inviteOnly) {
save(INVITE_ONLY, String.valueOf(inviteOnly));
}
@Override
public void setSystemHostname(final String hostname) {
save(KEY_HOSTNAME, hostname);
}
}