2025-02-23 13:36:21 +00:00
|
|
|
package stirling.software.SPDF.config;
|
|
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
2025-02-25 22:31:20 +01:00
|
|
|
import java.nio.file.Path;
|
2025-02-23 13:36:21 +00:00
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties.CustomPaths.Operations;
|
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties.CustomPaths.Pipeline;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Configuration
|
|
|
|
|
@Getter
|
|
|
|
|
public class RuntimePathConfig {
|
|
|
|
|
private final ApplicationProperties properties;
|
|
|
|
|
private final String basePath;
|
|
|
|
|
private final String weasyPrintPath;
|
|
|
|
|
private final String unoConvertPath;
|
|
|
|
|
|
|
|
|
|
// Pipeline paths
|
|
|
|
|
private final String pipelineWatchedFoldersPath;
|
|
|
|
|
private final String pipelineFinishedFoldersPath;
|
|
|
|
|
private final String pipelineDefaultWebUiConfigs;
|
|
|
|
|
private final String pipelinePath;
|
|
|
|
|
|
|
|
|
|
public RuntimePathConfig(ApplicationProperties properties) {
|
|
|
|
|
this.properties = properties;
|
|
|
|
|
this.basePath = InstallationPathConfig.getPath();
|
|
|
|
|
|
2025-02-25 22:31:20 +01:00
|
|
|
this.pipelinePath = Path.of(basePath, "pipeline").toString();
|
|
|
|
|
String defaultWatchedFolders = Path.of(this.pipelinePath, "watchedFolders").toString();
|
|
|
|
|
String defaultFinishedFolders = Path.of(this.pipelinePath, "finishedFolders").toString();
|
|
|
|
|
String defaultWebUIConfigs = Path.of(this.pipelinePath, "defaultWebUIConfigs").toString();
|
2025-02-23 13:36:21 +00:00
|
|
|
|
|
|
|
|
Pipeline pipeline = properties.getSystem().getCustomPaths().getPipeline();
|
|
|
|
|
|
2025-02-25 22:31:20 +01:00
|
|
|
this.pipelineWatchedFoldersPath =
|
|
|
|
|
resolvePath(
|
|
|
|
|
defaultWatchedFolders,
|
|
|
|
|
pipeline != null ? pipeline.getWatchedFoldersDir() : null);
|
|
|
|
|
this.pipelineFinishedFoldersPath =
|
|
|
|
|
resolvePath(
|
|
|
|
|
defaultFinishedFolders,
|
|
|
|
|
pipeline != null ? pipeline.getFinishedFoldersDir() : null);
|
|
|
|
|
this.pipelineDefaultWebUiConfigs =
|
|
|
|
|
resolvePath(
|
|
|
|
|
defaultWebUIConfigs,
|
|
|
|
|
pipeline != null ? pipeline.getWebUIConfigsDir() : null);
|
2025-02-23 13:36:21 +00:00
|
|
|
|
|
|
|
|
boolean isDocker = isRunningInDocker();
|
2025-02-24 10:19:43 +00:00
|
|
|
|
2025-02-23 13:36:21 +00:00
|
|
|
// Initialize Operation paths
|
2025-02-25 22:31:20 +01:00
|
|
|
String defaultWeasyPrintPath = isDocker ? "/opt/venv/bin/weasyprint" : "weasyprint";
|
|
|
|
|
String defaultUnoConvertPath = isDocker ? "/opt/venv/bin/unoconvert" : "unoconvert";
|
2025-02-23 13:36:21 +00:00
|
|
|
|
|
|
|
|
Operations operations = properties.getSystem().getCustomPaths().getOperations();
|
2025-02-25 22:31:20 +01:00
|
|
|
this.weasyPrintPath =
|
|
|
|
|
resolvePath(
|
|
|
|
|
defaultWeasyPrintPath,
|
|
|
|
|
operations != null ? operations.getWeasyprint() : null);
|
|
|
|
|
this.unoConvertPath =
|
|
|
|
|
resolvePath(
|
|
|
|
|
defaultUnoConvertPath,
|
|
|
|
|
operations != null ? operations.getUnoconvert() : null);
|
|
|
|
|
}
|
2025-02-23 13:36:21 +00:00
|
|
|
|
2025-02-25 22:31:20 +01:00
|
|
|
private String resolvePath(String defaultPath, String customPath) {
|
|
|
|
|
return StringUtils.isNotBlank(customPath) ? customPath : defaultPath;
|
2025-02-23 13:36:21 +00:00
|
|
|
}
|
2025-02-24 10:19:43 +00:00
|
|
|
|
2025-02-23 13:36:21 +00:00
|
|
|
private boolean isRunningInDocker() {
|
2025-02-25 22:31:20 +01:00
|
|
|
return Files.exists(Path.of("/.dockerenv"));
|
2025-02-23 13:36:21 +00:00
|
|
|
}
|
|
|
|
|
}
|