Skip to content

Commit

Permalink
Merge branch 'release/7.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmknopf committed Apr 27, 2016
2 parents 92680e2 + c0624f4 commit 8b5bcc3
Show file tree
Hide file tree
Showing 89 changed files with 4,240 additions and 1,952 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
compile 'com.rapidminer:rapidminer-api:0.2.0'

// VLDocking as docking framework (https://code.google.com/p/vldocking/)
compile 'com.rapidminer.external:vldocking:1.1.0'
compile 'com.rapidminer.external:vldocking:1.1.1'

// Freehep for vector graphic export (http://java.freehep.org/)
compile('org.freehep:freehep-graphicsio-ps:2.3') {
Expand Down Expand Up @@ -131,4 +131,4 @@ dependencies {
task wrapper(type: Wrapper) { gradleVersion = '2.8' }

apply from: 'gradle/wsimport.gradle'
apply from: 'gradle/props.gradle'
apply from: 'gradle/props.gradle'
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=7.0.1
group=com.rapidminer.studio
version=7.1.0
group=com.rapidminer.studio
232 changes: 162 additions & 70 deletions src/main/java/com/rapidminer/MacroHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,27 @@ public class MacroHandler extends Observable {
private static final String PROCESS_FILE = "process_file";
private static final String PROCESS_PATH = "process_path";

private static final Set<String> PREDEFINED_MACROS = new HashSet<>(
Arrays.asList(new String[] { PROCESS_NAME, PROCESS_FILE, PROCESS_PATH }));

/**
* Remaining problem is that predefined macros that are overridden by custom macros are
* evaluated first. The result is the predefined value.
*/
private static final String[] ALL_PREDEFINED_MACROS = { "process_name", "process_file", "process_path", "a",
"execution_count", "b", "c", "n", "operator_name", "t", "p[]", "v[]" };
"execution_count", "b", "c", "n", "operator_name", "t", "p[]", "v[]" };

/** all predefined macros that do not depend on an operator except for v[] */
private static final Set<String> PREDEFINED_OPERATOR_INDEPENDENT_MACROS = new HashSet<>(
Arrays.asList(new String[] { PROCESS_NAME, PROCESS_FILE, PROCESS_PATH, Operator.STRING_EXPANSION_MACRO_TIME }));

/** all predefined macros that depend on an operator except for p[] */
private static final Set<String> PREDEFINED_OPERATOR_DEPENDENT_MACROS = new HashSet<>(
Arrays.asList(new String[] { Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_USER_FRIENDLY,
Operator.STRING_EXPANSION_MACRO_OPERATORNAME_USER_FRIENDLY, Operator.STRING_EXPANSION_MACRO_OPERATORNAME,
Operator.STRING_EXPANSION_MACRO_OPERATORCLASS, Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES,
Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_PLUS_ONE }));

private static final String[] ALL_USER_FRIENDLY_PREDEFINED_MACROS = { "process_name", "process_file", "process_path",
Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_USER_FRIENDLY,
Operator.STRING_EXPANSION_MACRO_OPERATORNAME_USER_FRIENDLY };
Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_USER_FRIENDLY,
Operator.STRING_EXPANSION_MACRO_OPERATORNAME_USER_FRIENDLY };

private static final OperatorVersion THROW_ERROR_ON_UNDEFINED_MACRO = new OperatorVersion(6, 0, 3);

Expand All @@ -80,9 +88,9 @@ public class MacroHandler extends Observable {
LEGACY_STRING_EXPANSION_MACRO_KEYS.add(Operator.STRING_EXPANSION_MACRO_PERCENT_SIGN);

LEGACY_STRING_EXPANSION_MACRO_KEYS.add(Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_SHIFTED
+ Operator.STRING_EXPANSION_MACRO_PARAMETER_START);
+ Operator.STRING_EXPANSION_MACRO_PARAMETER_START);
LEGACY_STRING_EXPANSION_MACRO_KEYS
.add(Operator.STRING_EXPANSION_MACRO_OPERATORVALUE + Operator.STRING_EXPANSION_MACRO_PARAMETER_START);
.add(Operator.STRING_EXPANSION_MACRO_OPERATORVALUE + Operator.STRING_EXPANSION_MACRO_PARAMETER_START);
}

/**
Expand Down Expand Up @@ -169,17 +177,26 @@ public void removeMacro(String macro) {
*
* @param macro
* the macro key
* @param operator
* the operator that can be used to resolve the macro
* @return <code>true</code> in case it was set, <code>false</code> otherwise
*/
public boolean isMacroSet(String macro) {
public boolean isMacroSet(String macro, Operator operator) {
synchronized (LOCK) {
return macroMap.containsKey(macro) || PREDEFINED_MACROS.contains(macro);
if (macroMap.containsKey(macro) || PREDEFINED_OPERATOR_INDEPENDENT_MACROS.contains(macro)) {
return true;
}
}
return operator != null && PREDEFINED_OPERATOR_DEPENDENT_MACROS.contains(macro);

}

/**
* Resolves the macros "process_name", "process_file", "process_path", "t" and user defined
* macros.
*/
public String getMacro(String macro) {
if (PREDEFINED_MACROS.contains(macro)) {
if (PREDEFINED_OPERATOR_INDEPENDENT_MACROS.contains(macro)) {
switch (macro) {
case PROCESS_NAME:
ProcessLocation processLocation = process.getProcessLocation();
Expand All @@ -194,13 +211,58 @@ public String getMacro(String macro) {
return process.getProcessLocation() != null ? process.getProcessLocation().getShortName() : null;
case PROCESS_PATH:
return process.getProcessLocation() != null ? process.getProcessLocation().toString() : null;
case Operator.STRING_EXPANSION_MACRO_TIME:
StringBuffer buffer = new StringBuffer();
resolveTimeMacro(buffer);
return buffer.toString();
default:
return null;
}
}
return this.macroMap.get(macro);
}

/**
* Resolves the macro.
*
* <p>
* Resolves following predefined macros:
* </p>
* <ul>
* <li><b>process_name</b> with the name of the process</li>
* <li><b>process_file</b> with the file name of the process</li>
* <li><b>process_path</b> with the path to the process</li>
* <li><b>t</b> with the current system date and time</li>
* </ul>
* <p>
* Resolves following predefined macros if operator is non-null:
* </p>
* <ul>
* <li><b>n</b> or <b>operator_name</b> with the name of this operator</li>
* <li><b>c</b> with the class of this operator</li>
* <li><b>a</b> or <b>execution_count</b> with the number of times the operator was applied</li>
* <li><b>b</b> with the number of times the operator was applied plus one</li>
* </ul>
* <p>
* Resolves user defined macros.
* </p>
*
* @param macro
* the macro to resolve
* @param operator
* the operator to use for resolving, may be {@code null}
* @return the macro value
*/
public String getMacro(String macro, Operator operator) {
if (operator != null) {
String value = resolveUnshiftedOperatorMacros(macro, operator);
if (value != null) {
return value;
}
}
return getMacro(macro);
}

@Override
public String toString() {
return this.macroMap.toString();
Expand Down Expand Up @@ -234,7 +296,7 @@ public String resolveMacros(String parameterKey, String parameterValue) throws U
// check whether macroString is a predefined macro which will be resolved at String
// expansion
if (STRING_EXPANSION_MACRO_KEYS.contains(macroString) || LEGACY_STRING_EXPANSION_MACRO_KEYS
.contains(macroString.length() > 1 ? macroString.substring(0, 2) : macroString)) {
.contains(macroString.length() > 1 ? macroString.substring(0, 2) : macroString)) {
// skip macro because it will be replaced during the string expansion
result.append(Operator.MACRO_STRING_START + macroString + Operator.MACRO_STRING_END);
} else {
Expand Down Expand Up @@ -262,10 +324,11 @@ public String resolveMacros(String parameterKey, String parameterValue) throws U
* Replaces following predefined macros:
* </p>
* <ul>
* <li><b>%{n}</b> with the name of this operator</li>
* <li><b>%{n}</b> or <b>%{operator_name}</b> with the name of this operator</li>
* <li><b>%{c}</b> with the class of this operator</li>
* <li><b>%{t}</b> with the current system date and time
* <li><b>%{a}</b> with the number of times the operator was applied</li>
* <li><b>%{a}</b> or <b>%{execution_count}</b> with the number of times the operator was
* applied</li>
* <li><b>%{b}</b> with the number of times the operator was applied plus one (a shortcut for
* %{p[1]})</li>
* <li><b>%{p[number]}</b> with the number of times the operator was applied plus number</li>
Expand All @@ -292,18 +355,11 @@ public String resolvePredefinedMacros(String str, Operator operator) throws Unde
}
if (end >= start) {
String command = str.substring(start + 2, end);
if (Operator.STRING_EXPANSION_MACRO_OPERATORNAME.equals(command)
|| Operator.STRING_EXPANSION_MACRO_OPERATORNAME_USER_FRIENDLY.equals(command)) {
result.append(operator.getName());
} else if (Operator.STRING_EXPANSION_MACRO_OPERATORCLASS.equals(command)) {
result.append(operator.getClass().getName());
} else if (Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES.equals(command)
|| Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_USER_FRIENDLY.equals(command)) {
result.append(operator.getApplyCount());
} else if (Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_PLUS_ONE.equals(command)) {
result.append(operator.getApplyCount() + 1);
String unshiftedOperatorMacroResult = resolveUnshiftedOperatorMacros(command, operator);
if (unshiftedOperatorMacroResult != null) {
result.append(unshiftedOperatorMacroResult);
} else if (command.startsWith(Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_SHIFTED
+ Operator.STRING_EXPANSION_MACRO_PARAMETER_START)) {
+ Operator.STRING_EXPANSION_MACRO_PARAMETER_START)) {
int openNumberIndex = command.indexOf(Operator.STRING_EXPANSION_MACRO_PARAMETER_START);
int closeNumberIndex = command.indexOf(Operator.STRING_EXPANSION_MACRO_PARAMETER_END, openNumberIndex);
if (closeNumberIndex < 0 || closeNumberIndex <= openNumberIndex + 1) {
Expand All @@ -318,48 +374,9 @@ public String resolvePredefinedMacros(String str, Operator operator) throws Unde
}
result.append(operator.getApplyCount() + number);
} else if (Operator.STRING_EXPANSION_MACRO_TIME.equals(command)) {
// Please note that Date and DateFormat cannot be used since Windows does not
// support the resulting file names
// TODO: Well, it can and should be used. Just use a custom SimpleDateFormat
Calendar calendar = new GregorianCalendar();
// year
result.append(calendar.get(Calendar.YEAR) + "_");
// month
String month = calendar.get(Calendar.MONTH) + 1 + "";
if (month.length() < 2) {
month = "0" + month;
}
result.append(month + "_");
// day
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
if (day.length() < 2) {
day = "0" + day;
}
result.append(day + "-");
// am - pm
int amPm = calendar.get(Calendar.AM_PM);
String amPmString = amPm == Calendar.AM ? "AM" : "PM";
result.append(amPmString + "_");
// hour
String hour = calendar.get(Calendar.HOUR) + "";
if (hour.length() < 2) {
hour = "0" + hour;
}
result.append(hour + "_");
// minute
String minute = calendar.get(Calendar.MINUTE) + "";
if (minute.length() < 2) {
minute = "0" + minute;
}
result.append(minute + "_");
// second
String second = calendar.get(Calendar.SECOND) + "";
if (second.length() < 2) {
second = "0" + second;
}
result.append(second);
resolveTimeMacro(result);
} else if (command.startsWith(
Operator.STRING_EXPANSION_MACRO_OPERATORVALUE + Operator.STRING_EXPANSION_MACRO_PARAMETER_START)) {
Operator.STRING_EXPANSION_MACRO_OPERATORVALUE + Operator.STRING_EXPANSION_MACRO_PARAMETER_START)) {
int openNumberIndex = command.indexOf(Operator.STRING_EXPANSION_MACRO_PARAMETER_START);
int closeNumberIndex = command.indexOf(Operator.STRING_EXPANSION_MACRO_PARAMETER_END, openNumberIndex);
if (closeNumberIndex < 0 || closeNumberIndex <= openNumberIndex + 1) {
Expand All @@ -373,28 +390,28 @@ public String resolvePredefinedMacros(String str, Operator operator) throws Unde
Operator op = process.getOperator(operatorValuePair[0]);
if (op == null) {
throw new UndefinedMacroError(operator, "predefinedMacro_OperatorValue_wrongOperator",
operatorValuePair[0]);
operatorValuePair[0]);
}
Value value = op.getValue(operatorValuePair[1]);
if (value == null) {
throw new UndefinedMacroError(operator, "predefinedMacro_OperatorValue_noValue",
operatorValuePair[1]);
operatorValuePair[1]);
} else {
if (value.isNominal()) {
Object valueObject = value.getValue();
if (valueObject != null) {
result.append(valueObject.toString());
} else {
throw new UndefinedMacroError(operator, "predefinedMacro_OperatorValue_noValue",
operatorValuePair[1]);
operatorValuePair[1]);
}
} else {
double doubleValue = ((Double) value.getValue()).doubleValue();
if (!Double.isNaN(doubleValue)) {
result.append(Tools.formatIntegerIfPossible(doubleValue));
} else {
operator.logError("Value '" + operatorValuePair[1] + "' of the operator '"
+ operatorValuePair[0] + "' not found!");
+ operatorValuePair[0] + "' not found!");
}
}
}
Expand All @@ -413,4 +430,79 @@ public String resolvePredefinedMacros(String str, Operator operator) throws Unde
return result.toString();
}

/**
* Resolves the macro t by writing the current date and time in the result buffer.
*/
private void resolveTimeMacro(StringBuffer result) {
// Please note that Date and DateFormat cannot be used since Windows does not
// support the resulting file names
// TODO: Well, it can and should be used. Just use a custom SimpleDateFormat
Calendar calendar = new GregorianCalendar();
// year
result.append(calendar.get(Calendar.YEAR) + "_");
// month
String month = calendar.get(Calendar.MONTH) + 1 + "";
if (month.length() < 2) {
month = "0" + month;
}
result.append(month + "_");
// day
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
if (day.length() < 2) {
day = "0" + day;
}
result.append(day + "-");
// am - pm
int amPm = calendar.get(Calendar.AM_PM);
String amPmString = amPm == Calendar.AM ? "AM" : "PM";
result.append(amPmString + "_");
// hour
String hour = calendar.get(Calendar.HOUR) + "";
if (hour.length() < 2) {
hour = "0" + hour;
}
result.append(hour + "_");
// minute
String minute = calendar.get(Calendar.MINUTE) + "";
if (minute.length() < 2) {
minute = "0" + minute;
}
result.append(minute + "_");
// second
String second = calendar.get(Calendar.SECOND) + "";
if (second.length() < 2) {
second = "0" + second;
}
result.append(second);
}

/**
* <p>
* Resolves following predefined macros:
* </p>
* <ul>
* <li><b>n</b> or <b>operator_name</b> with the name of this operator</li>
* <li><b>c</b> with the class of this operator</li>
* <li><b>a</b> or <b>execution_count</b> with the number of times the operator was applied</li>
* <li><b>b</b> with the number of times the operator was applied plus one</li>
* </ul>
*
* Does not resolve p[].
*/
private String resolveUnshiftedOperatorMacros(String command, Operator operator) {
if (Operator.STRING_EXPANSION_MACRO_OPERATORNAME.equals(command)
|| Operator.STRING_EXPANSION_MACRO_OPERATORNAME_USER_FRIENDLY.equals(command)) {
return operator.getName();
} else if (Operator.STRING_EXPANSION_MACRO_OPERATORCLASS.equals(command)) {
return operator.getClass().getName();
} else if (Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES.equals(command)
|| Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_USER_FRIENDLY.equals(command)) {
return operator.getApplyCount() + "";
} else if (Operator.STRING_EXPANSION_MACRO_NUMBER_APPLIED_TIMES_PLUS_ONE.equals(command)) {
return operator.getApplyCount() + 1 + "";
} else {
return null;
}
}

}

0 comments on commit 8b5bcc3

Please sign in to comment.