package ch.elexis.core.model.issue;

import java.util.ResourceBundle;

import ch.elexis.core.interfaces.ILocalizedEnum;
import ch.elexis.core.interfaces.INumericEnum;

public enum Priority implements INumericEnum, ILocalizedEnum {
	LOW(0), MEDIUM(1), HIGH(2);

	private final int numeric;

	private Priority(int numeric) {
		this.numeric = numeric;
	}

	public int numericValue() {
		return numeric;
	}

	@Override
	public String getLocaleText() {
		try {
			return ResourceBundle.getBundle(ch.elexis.core.l10n.Messages.BUNDLE_NAME)
					.getString(Priority.class.getSimpleName() + "_" + this.name());
		} catch (Exception e) {
			return this.name();
		}
	}

	public static Priority byNumericSafe(String priority) {
		int numeric = Integer.parseInt(priority);
		for (Priority prio : Priority.values()) {
			if (prio.numericValue() == numeric) {
				return prio;
			}
		}
		return Priority.MEDIUM;
	}

}

@@ -60,24 +60,70 @@
 rceBundle;%0A%0A
+import org.apache.commons.lang3.StringUtils;%0A%0A
 import ch.el
@@ -755,16 +755,69 @@
 rity) %7B%0A
+%09%09if (StringUtils.isNotBlank(priority)) %7B%0A%09%09%09try %7B%0A%09%09
 %09%09int nu
@@ -854,16 +854,18 @@
 ity);%0A%09%09
+%09
+%09
 for (Pri
@@ -901,16 +901,18 @@
 )) %7B%0A%09%09%09
+%09%09
 if (prio
@@ -937,24 +937,26 @@
  numeric) %7B%0A
+%09%09
 %09%09%09%09return p
@@ -960,16 +960,101 @@
 n prio;%0A
+%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D catch (NumberFormatException e) %7B%0A%09%09%09%09// ignore and return default%0A
 %09%09%09%7D%0A%09%09%7D
@@ -1080,14 +1080,13 @@
 MEDIUM;%0A
+
 %09%7D%0A
-%0A
 %7D%0A

add input parameter checks to Priority parse from string