Commit d0a516a0 authored by Thomas Huster's avatar Thomas Huster
Browse files

Merge remote-tracking branch 'origin/master' into f11106

parents ce0138f5 519fcf65
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ package ch.elexis.data;
import java.util.Objects;

import ch.elexis.core.constants.StringConstants;
import ch.elexis.core.model.IPersistentObject;
import ch.rgw.tools.JdbcLink;

/**
@@ -130,4 +131,16 @@ public class Mandant extends Anwender {
		return Kontakt.TABLENAME;
	}
	
	public IPersistentObject getReferencedObject(String fieldl){
		if (fieldl != null) {
			if ("Responsible".equals(fieldl)) {
				String responsibleId =
					(String) getExtInfoStoredObjectByKey("ch.elexis.tarmedprefs.responsible");
				if (responsibleId != null && !responsibleId.isEmpty()) {
					return Mandant.load(responsibleId);
				}
			}
		}
		return null;
	}
}
+55 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipInputStream;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -113,6 +114,9 @@ public class TextContainer {
		+ "]?[-a-zA-ZäöüÄÖÜéàè_ ]+(\\.[-a-zA-Z0-9äöüÄÖÜéàè_ ]+)+\\]";
	public static final String MATCH_GENDERIZE =
		"\\[[" + DONT_SHOW_REPLACEMENT_ERRORS + "]?[a-zA-Z]+:mwn?:[^\\[]+\\]"; //$NON-NLS-1$
	public static final String MATCH_EXISTS =
		"\\[[" + DONT_SHOW_REPLACEMENT_ERRORS //$NON-NLS-1$
			+ "]?[a-zA-Z\\.]+:exists?:[-a-zA-Z0-9\\.]:?[^\\]]*\\]";
	//public static final String MATCH_IDATACCESS = "\\[[-_a-zA-Z0-9]+:[-a-zA-Z0-9]+:[-a-zA-Z0-9\\.]+:[-a-zA-Z0-9\\.]:?.*\\]"; //$NON-NLS-1$
	public static final String MATCH_IDATACCESS = "\\[[" + DONT_SHOW_REPLACEMENT_ERRORS //$NON-NLS-1$
		+ "]?[-_a-zA-Z0-9]+:[-a-zA-Z0-9]+:[-a-zA-Z0-9\\.]+:[-a-zA-Z0-9\\.]:?[^\\]]*\\]";
@@ -272,6 +276,11 @@ public class TextContainer {
							in.replaceAll(MATCH_SQUARE_BRACKET, StringTool.leer));
					}
				});
				plugin.findOrReplace(MATCH_EXISTS, new ReplaceCallback() {
					public String replace(final String in){
						return exists(ret, in.replaceAll(MATCH_SQUARE_BRACKET, StringTool.leer));
					}
				});
				plugin.findOrReplace(MATCH_GENDERIZE, new ReplaceCallback() {
					public String replace(final String in){
						return genderize(ret, in.replaceAll(MATCH_SQUARE_BRACKET, StringTool.leer));
@@ -453,6 +462,14 @@ public class TextContainer {
			Fall fall = (Fall) parent;
			
			return fall.getReferencedObject(fieldl);
		} else if (parent instanceof Mandant) {
			String fieldl = field;
			if (fieldl.substring(0, 1).equalsIgnoreCase(DONT_SHOW_REPLACEMENT_ERRORS)) {
				fieldl = fieldl.substring(1);
			}
			Mandant mandant = (Mandant) parent;
			
			return mandant.getReferencedObject(fieldl);
		} else {
			// not yet supported
			return null;
@@ -485,6 +502,44 @@ public class TextContainer {
		}
	}
	
	/**
	 * Format für Exists: [Feld:exists:text]
	 */
	private String exists(Brief brief, String in){
		String inl = in;
		if (inl.substring(0, 1).equalsIgnoreCase(DONT_SHOW_REPLACEMENT_ERRORS)) {
			inl = inl.substring(1);
		}
		String[] q = inl.split(":"); //$NON-NLS-1$
		Object o = resolveObject(brief, q[0]);
		if (o == null) {
			String[] tokens = q[0].split("\\."); //$NON-NLS-1$
			if (tokens.length >= 2) {
				String firstToken = tokens[0];
				// resolve the first field
				IPersistentObject first = resolveObject(brief, firstToken);
				if (first != null) {
					IPersistentObject current = first;
					for (int i = 1; i < tokens.length; i++) {
						IPersistentObject next = resolveIndirectObject(current, tokens[i]);
						if (next == null && current instanceof PersistentObject) {
							String value = readFromPo((PersistentObject) current, tokens[i], false);
							if (StringUtils.isNotEmpty(value)) {
								break;
							}
						}
						current = next;
					}
					o = current;
				}
			}
		}
		if (o != null) {
			return q[2];
		}
		return "";
	}
	
	/**
	 * Format für Genderize: [Feld:mw:formulierung Mann/formulierung Frau] oder
	 * [Feld:mwn:mann/frau/neutral]