Commit c716e4c8 authored by Thomas Huster's avatar Thomas Huster

[17477] added home variable replacement to extern file path for docs

parent 438ac472
Pipeline #12515 passed with stages
in 4 minutes and 56 seconds
......@@ -33,8 +33,7 @@ public class BriefExternUtil {
*/
public static boolean isExternFile(){
if (CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE, false)) {
boolean ret = isValidExternPath(
CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE_PATH, null), true);
boolean ret = isValidExternPath(getExternFilePath(), true);
if (!ret) {
ElexisEventDispatcher.getInstance()
.fireMessageEvent(new MessageEvent(MessageType.WARN, "Brief Extern",
......@@ -52,7 +51,7 @@ public class BriefExternUtil {
* @return Brief or empty if no such file is found
*/
public static Optional<File> getExternFile(Brief brief){
String path = CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE_PATH, null);
String path = getExternFilePath();
if (isValidExternPath(path, true)) {
File dir = new File(path);
StringBuilder sb = new StringBuilder();
......@@ -83,7 +82,7 @@ public class BriefExternUtil {
* @return
*/
public static Optional<File> createExternFile(Brief brief){
String path = CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE_PATH, null);
String path = getExternFilePath();
if (isValidExternPath(path, true)) {
File dir = new File(path);
Person patient = brief.getPatient();
......@@ -112,6 +111,21 @@ public class BriefExternUtil {
return Optional.empty();
}
public static String getExternFilePath(){
return getAsExternFilePath(
CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE_PATH, null));
}
public static String getAsExternFilePath(String path){
if (path != null && path.contains("[home]")) {
path = path.replace("[home]", CoreHub.getWritableUserDir().getAbsolutePath());
LoggerFactory.getLogger(BriefExternUtil.class)
.warn("Replaced [home] -> [" + CoreHub.getWritableUserDir().getAbsolutePath()
+ "] in extern file path result is [" + path + "]");
}
return path;
}
private static String evaluateExtension(String input){
String ext = MimeTool.getExtension(input);
if (StringUtils.isEmpty(ext)) {
......
......@@ -38,6 +38,7 @@ import ch.elexis.core.services.INamedQuery;
import ch.elexis.core.services.IQuery;
import ch.elexis.core.services.IQuery.COMPARATOR;
import ch.elexis.core.services.IStoreToStringContribution;
import ch.elexis.core.utils.CoreUtil;
import ch.rgw.tools.MimeTool;
/**
......@@ -79,7 +80,7 @@ public class ModelUtil {
*/
public static boolean isExternFile(){
if (isConfig(Preferences.P_TEXT_EXTERN_FILE, false)) {
String path = getConfig(Preferences.P_TEXT_EXTERN_FILE_PATH, null);
String path = getExternFilePath();
if (path != null) {
return pathExistsAndCanWrite(path, true);
}
......@@ -87,6 +88,20 @@ public class ModelUtil {
return false;
}
public static String getExternFilePath(){
return getAsExternFilePath(getConfig(Preferences.P_TEXT_EXTERN_FILE_PATH, null));
}
private static String getAsExternFilePath(String path){
if (path != null && path.contains("[home]")) {
path = path.replace("[home]", CoreUtil.getWritableUserDir().getAbsolutePath());
LoggerFactory.getLogger(ModelUtil.class)
.warn("Replaced [home] -> [" + CoreUtil.getWritableUserDir().getAbsolutePath()
+ "] in extern file path result is [" + path + "]");
}
return path;
}
/**
* Read the configured {@value Preferences#P_TEXT_EXTERN_FILE_PATH} and return a {@link File}
* representation of the document.
......@@ -95,7 +110,7 @@ public class ModelUtil {
* @return
*/
public static Optional<File> getExternFile(DocumentLetter documentBrief){
String path = getConfig(Preferences.P_TEXT_EXTERN_FILE_PATH, null);
String path = getExternFilePath();
if (pathExistsAndCanWrite(path, true)) {
File dir = new File(path);
StringBuilder sb = new StringBuilder();
......@@ -126,7 +141,7 @@ public class ModelUtil {
* @return
*/
public static Optional<File> createExternFile(DocumentLetter documentBrief){
String path = getConfig(Preferences.P_TEXT_EXTERN_FILE_PATH, null);
String path = getExternFilePath();
if (pathExistsAndCanWrite(path, true)) {
File dir = new File(path);
IPatient patient = documentBrief.getPatient();
......
......@@ -43,10 +43,10 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
import org.slf4j.LoggerFactory;
import ch.elexis.core.constants.Preferences;
import ch.elexis.core.l10n.Messages;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.util.BriefExternUtil;
import ch.elexis.core.data.util.Extensions;
import ch.elexis.core.l10n.Messages;
import ch.elexis.core.services.ILocalDocumentService;
import ch.elexis.core.ui.constants.ExtensionPointConstantsUi;
import ch.elexis.core.ui.services.LocalDocumentServiceHolder;
......@@ -178,6 +178,7 @@ public class Texterstellung extends FieldEditorPreferencePage implements IWorkbe
}
private void updateExternPathDeco(String path){
path = BriefExternUtil.getAsExternFilePath(path);
if (BriefExternUtil.isValidExternPath(path, false)) {
externPathDeco.hide();
allExtern.setEnabled(true);
......@@ -211,7 +212,8 @@ public class Texterstellung extends FieldEditorPreferencePage implements IWorkbe
@Override
public boolean performOk(){
if (externPath != null && !externPath.isDisposed()
&& BriefExternUtil.isValidExternPath(externPath.getText(), false)) {
&& BriefExternUtil.isValidExternPath(
BriefExternUtil.getAsExternFilePath(externPath.getText()), false)) {
CoreHub.globalCfg.set(Preferences.P_TEXT_EXTERN_FILE_PATH, externPath.getText());
CoreHub.globalCfg.flush();
}
......
......@@ -15,8 +15,7 @@ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester
if ("documenteditlocal".equals(property)) { //$NON-NLS-1$
// no local copy / local edit if brief extern
if (CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE, false)
&& BriefExternUtil.isValidExternPath(
CoreHub.globalCfg.get(Preferences.P_TEXT_EXTERN_FILE_PATH, null), false)) {
&& BriefExternUtil.isValidExternPath(BriefExternUtil.getExternFilePath(), false)) {
return false;
}
return CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment