use of org.knime.core.node.workflow.WorkflowManager.AuthorInformation in project knime-core by knime.
the class ReadContextPropertyConfiguration method extractContextProperty.
private static String extractContextProperty(final String property) {
WorkflowManager manager = NodeContext.getContext().getWorkflowManager();
if (CONTEXT_WORKFLOW_NAME.equals(property)) {
return manager.getName();
}
if (CONTEXT_WORKFLOW_PATH.equals(property)) {
WorkflowContext context = manager.getContext();
File wfLocation = context.getOriginalLocation() == null ? context.getCurrentLocation() : context.getOriginalLocation();
File mpLocation = context.getMountpointRoot();
if (mpLocation == null || wfLocation == null) {
return "";
}
String wfPath = wfLocation.getAbsolutePath();
String mpPath = mpLocation.getAbsolutePath();
assert wfPath.startsWith(mpPath);
String resultPath = wfPath.substring(mpPath.length());
return resultPath.replace("\\", "/");
}
if (CONTEXT_WORKFLOW_ABSOLUTE_PATH.equals(property)) {
WorkflowContext context = manager.getContext();
File wfLocation = context.getCurrentLocation();
if (wfLocation == null) {
return "";
}
return wfLocation.getAbsolutePath().replace("\\", "/");
}
if (CONTEXT_SERVER_USER.equals(property)) {
return manager.getContext().getUserid();
}
if (CONTEXT_TEMP_LOCATION.equals(property)) {
return manager.getContext().getTempLocation().getAbsolutePath();
}
AuthorInformation author = manager.getAuthorInformation();
if (author != null) {
if (CONTEXT_AUTHOR.equals(property)) {
return author.getAuthor();
}
if (CONTEXT_EDITOR.equals(property)) {
return author.getLastEditor();
}
if (CONTEXT_CREATION_DATE.equals(property)) {
Date creationDate = author.getAuthoredDate();
if (creationDate != null) {
return creationDate.toString();
}
}
if (CONTEXT_LAST_MODIFIED.equals(property)) {
Date modDate = author.getLastEditDate();
if (modDate != null) {
return modDate.toString();
}
}
}
return null;
}
use of org.knime.core.node.workflow.WorkflowManager.AuthorInformation in project knime-core by knime.
the class FileWorkflowPersistor method loadAuthorInformation.
AuthorInformation loadAuthorInformation(final NodeSettingsRO settings) throws InvalidSettingsException {
if (getLoadVersion().ordinal() >= LoadVersion.V280.ordinal() && settings.containsKey(CFG_AUTHOR_INFORMATION)) {
final NodeSettingsRO sub = settings.getNodeSettings(CFG_AUTHOR_INFORMATION);
final String author = sub.getString("authored-by");
final String authorDateS = sub.getString("authored-when");
final Date authorDate;
if (authorDateS == null) {
authorDate = null;
} else {
try {
authorDate = parseDate(authorDateS);
} catch (ParseException e) {
throw new InvalidSettingsException("Can't parse authored-when \"" + authorDateS + "\": " + e.getMessage(), e);
}
}
final String editor = sub.getString("lastEdited-by");
final String editDateS = sub.getString("lastEdited-when");
final Date editDate;
if (editDateS == null) {
editDate = null;
} else {
try {
editDate = parseDate(editDateS);
} catch (ParseException e) {
throw new InvalidSettingsException("Can't parse lastEdit-when \"" + editDateS + "\": " + e.getMessage(), e);
}
}
return new AuthorInformation(author, authorDate, editor, editDate);
} else {
return AuthorInformation.UNKNOWN;
}
}
Aggregations