Skip to content

Commit

Permalink
Config rework (#312)
Browse files Browse the repository at this point in the history
* new configuration implementation

* add config for taxonomies

* update tests

* replace serverproperties with new config

* replace serverproperties with new config

* add test package

* remove old config

* update demo project

* update test projects fix some bugs

* remove sysout

* fix build readd demo project

* fix build readd demo project

* fix cli

* remove legacy events

---------
  • Loading branch information
thmarx authored Oct 24, 2024
1 parent 2a8ae7b commit 53f2b38
Show file tree
Hide file tree
Showing 138 changed files with 3,187 additions and 2,941 deletions.
2 changes: 1 addition & 1 deletion cms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.condation.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>6.4.0</version>
<version>7.0.0</version>
</parent>
<artifactId>cms-api</artifactId>
<packaging>jar</packaging>
Expand Down
25 changes: 5 additions & 20 deletions cms-api/src/main/java/com/condation/cms/api/APMProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,19 @@


import java.time.Duration;
import java.util.Map;
import lombok.RequiredArgsConstructor;

/**
* Application Performance Management Properties
*
* @author t.marx
*/
@RequiredArgsConstructor
public class APMProperties {
private final Map<String, Object> properties;
public interface APMProperties {

public boolean enabled () {
return (boolean) properties.getOrDefault("enabled", Boolean.FALSE);
}
public boolean enabled ();

public int max_requests () {
return (int) properties.getOrDefault("max_requests", 100);
}
public int max_requests ();

public int thread_limit () {
return (int) properties.getOrDefault("thread_limit", 10);
}
public int thread_limit ();

public Duration max_suspend () {
if (!properties.containsKey("max_suspend")) {
return Duration.ZERO;
}
return Duration.parse((String) properties.get("max_suspend"));
}
public Duration max_suspend ();
}
13 changes: 3 additions & 10 deletions cms-api/src/main/java/com/condation/cms/api/IPCProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,9 @@
*
* @author t.marx
*/
@RequiredArgsConstructor
public class IPCProperties {
private final Map<String, Object> properties;
public interface IPCProperties {
public int port ();

public int port () {
return (int) properties.getOrDefault("port", 6868);
}

public Optional<String> password () {
return Optional.ofNullable((String)properties.get("password"));
}
public Optional<String> password ();

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*
* @author thmar
*/
public class YamlProperties {
public class MapProperties {

protected final Map<String, Object> properties;

protected YamlProperties (final Map<String, Object> properties) {
protected MapProperties (final Map<String, Object> properties) {
this.properties = properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,23 @@
* #L%
*/


import com.condation.cms.api.annotations.Experimental;
import java.util.Map;
import lombok.RequiredArgsConstructor;

/**
* Application Performance Management Properties
*
* @author t.marx
*/
@Experimental(since = "5.3.0")
@RequiredArgsConstructor
public class PerformanceProperties {
private final Map<String, Object> properties;
public interface PerformanceProperties {

public boolean pool_enabled () {
return (boolean) properties.getOrDefault("pool_enabled", Boolean.FALSE);
}
public boolean pool_enabled ();
/**
* pool size per site
*
* @return
*/
public int pool_size () {
return (int) properties.getOrDefault("pool_size", 10);
}
public int pool_size ();


public int pool_expire () {
return (int) properties.getOrDefault("pool_expire", 10);
}
public int pool_expire ();

public int request_workers () {
return (int) properties.getOrDefault("request_workers", 200);
}
public int request_workers ();
}
61 changes: 17 additions & 44 deletions cms-api/src/main/java/com/condation/cms/api/ServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,28 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/


import java.nio.file.Path;
import java.util.Map;

/**
*
* @author t.marx
*/
public class ServerProperties extends YamlProperties {

public ServerProperties (final Map<String, Object> properties) {
super(properties);
}

public boolean dev () {
return !Constants.Environments.PROD.equals(env());
}

public String env () {
if (System.getenv().containsKey("CMS_ENV")) {
return System.getenv("CMS_ENV");
}
if (System.getProperties().containsKey("cms.env")) {
return System.getProperty("cms.env");
}
return (String) properties.getOrDefault("env", Constants.Environments.PROD);
}

public String serverIp () {
return (String)getSubMap("server").getOrDefault("ip", "127.0.0.1");
}
public int serverPort () {
return (int)getSubMap("server").getOrDefault("port", 8080);
}

public Path getThemesFolder () {
return Path.of("themes/");
}

public APMProperties apm () {
return new APMProperties(getSubMap("apm"));
}

public IPCProperties ipc () {
return new IPCProperties(getSubMap("ipc"));
}

public PerformanceProperties performance () {
return new PerformanceProperties(getSubMap("performance"));
}
public interface ServerProperties {

public boolean dev();

public String env();

public String serverIp();

public int serverPort();

public Path getThemesFolder();

public APMProperties apm();

public IPCProperties ipc();

public PerformanceProperties performance();
}
69 changes: 20 additions & 49 deletions cms-api/src/main/java/com/condation/cms/api/SiteProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,40 @@

import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
*
* @author t.marx
*/
public class SiteProperties extends ThemeProperties {
public interface SiteProperties {

public SiteProperties (final Map<String, Object> properties) {
super(properties);
}
public List<String> hostnames ();

public List<String> hostnames () {
var hostnames = properties.getOrDefault("hostname", "localhost");

if (hostnames instanceof String hostname) {
return List.of(hostname);
} else if (hostnames instanceof List) {
return (List<String>) hostnames;
} else {
return List.of("localhost");
}
}
public String markdownEngine ();

public String markdownEngine () {
return (String)getSubMap("markdown").get("engine");
}
public String contextPath ();

public String contextPath () {
return (String) properties.getOrDefault("context_path", "/");
}
public String id ();

public String id () {
return (String) properties.getOrDefault("id", "default");
}
public Object get (String field);

public String theme () {
return (String) properties.get("theme");
}
public String theme ();

public String queryIndexMode () {
return (String) getSubMap("index", getSubMap("query")).getOrDefault("mode", "MEMORY");
}
public String queryIndexMode ();

public Locale locale () {
if (properties.containsKey("language")) {
Locale.forLanguageTag((String)properties.get("language"));
}
return Locale.getDefault();
}
public Locale locale ();

public String defaultContentType () {
return (String)getSubMap("content").getOrDefault("type", Constants.DEFAULT_CONTENT_TYPE);
}
public String language();

public List<String> contentPipeline () {
return (List<String>)getSubMap("content").getOrDefault("pipeline", Constants.DEFAULT_CONTENT_PIPELINE);
}
public String defaultContentType ();

public String cacheEngine() {
return (String) getSubMap("cache").getOrDefault("engine", Constants.DEFAULT_CACHE_ENGINE);
}
public boolean cacheContent() {
return (boolean) getSubMap("cache").getOrDefault("content", Constants.DEFAULT_CONTENT_CACHE_ENABLED);
}
public List<String> contentPipeline ();

public String cacheEngine();

public boolean cacheContent();

public String templateEngine();

public List<String> activeModules();
}
58 changes: 9 additions & 49 deletions cms-api/src/main/java/com/condation/cms/api/ThemeProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,23 @@
*/


import com.condation.cms.api.media.MediaFormat;
import com.condation.cms.api.media.MediaUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;

/**
*
* @author t.marx
*/
@Slf4j
public class ThemeProperties extends YamlProperties {
public interface ThemeProperties {

public ThemeProperties(final Map<String, Object> properties) {
super(properties);
}

public Double version() {
return (Double)properties.get("version");
}

public String parent() {
return (String)properties.get("parent");
}
public String name();

public String templateEngine() {
return (String) getSubMap("template").get("engine");
}

public List<String> activeModules() {
return (List<String>) getSubMap("modules").getOrDefault("active", List.of());
}

public Map<String, MediaFormat> getMediaFormats() {
Map<String, MediaFormat> mediaFormats = new HashMap<>();
Map<String, Object> media = (Map<String, Object>) properties.getOrDefault("media", Collections.emptyMap());
List<Map<String, Object>> formats = (List<Map<String, Object>>) media.getOrDefault("formats", Collections.emptyList());
formats.forEach(map -> {
try {
var mediaFormat = new MediaFormat(
(String) map.get("name"),
(int) map.get("width"),
(int) map.get("height"),
MediaUtils.format4String((String) map.get("format")),
(boolean) map.get("compression"),
(boolean) map.getOrDefault("cropped", false)
);
mediaFormats.put(mediaFormat.name(), mediaFormat);
} catch (Exception e) {
log.error("error createing format " + map.get("name"), e);
}
public Double version();

});

return mediaFormats;
}
public String parent();

public String templateEngine();

public List<String> activeModules();

public Object get (String field);
}
Loading

0 comments on commit 53f2b38

Please sign in to comment.