Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a project is copied to another project, all referenced project variables and their dependent variables are copied to the target project as well (CMEM-6088) #841

Open
wants to merge 7 commits into
base: release/24.3.0
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import org.silkframework.runtime.validation.ValidationException
/**
* Thrown if a plugin cannot be created because of invalid plugin parameter values.
*/
class InvalidPluginParameterValueException(msg: String, cause: Throwable) extends ValidationException(msg, cause) {
case class InvalidPluginParameterValueException(msg: String, cause: Throwable) extends ValidationException(msg, cause) {
def this(msg: String) = this (msg, null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ object GlobalTemplateVariablesConfig {

private final val configNamespace: String = "config.variables"

/**
* Global template variables are nested under this name.
*/
final val globalScope = "global"

/**
* The configured template engine.
*/
Expand Down Expand Up @@ -52,9 +47,9 @@ object GlobalTemplateVariablesConfig {
.getOrElse(throw new InvalidConfigException(configNamespace + ".global." + key, objValue.origin(), "Parameter 'value' is missing."))
val description = if(objValue.containsKey("description")) Some(objValue.toConfig.getString("description")) else None
val isSensitive = if(objValue.containsKey("isSensitive")) objValue.toConfig.getBoolean("isSensitive") else false
TemplateVariable(key, value.unwrapped().toString, None, description, isSensitive = isSensitive, globalScope)
TemplateVariable(key, value.unwrapped().toString, None, description, isSensitive = isSensitive, TemplateVariableScopes.global)
case _ =>
TemplateVariable(key, value.unwrapped().toString, None, None, isSensitive = false, globalScope)
TemplateVariable(key, value.unwrapped().toString, None, None, isSensitive = false, TemplateVariableScopes.global)
}
}

Expand All @@ -80,7 +75,7 @@ object GlobalTemplateVariables extends TemplateVariablesReader with Serializable
/**
* The available variable scopes.
*/
override def scopes: Set[String] = Set(GlobalTemplateVariablesConfig.globalScope)
override def scopes: Set[String] = Set(TemplateVariableScopes.global)

/**
* Retrieves all template variables.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import scala.xml.{Node, PCData}
*/
case class TemplateVariable(override val name: String,
value: String,
template: Option[String],
description: Option[String],
isSensitive: Boolean,
template: Option[String] = None,
description: Option[String] = None,
isSensitive: Boolean = false,
override val scope: String) extends TemplateVariableValue(name, scope, values = Seq(value)) {

validate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.silkframework.runtime.templating

object TemplateVariableScopes {

/**
* Global variables.
*/
final val global = "global"

/**
* Project variables.
*/
final val project = "project"

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ case class TemplateVariables(variables: Seq[TemplateVariable]) {
TemplateVariables(variables ++ other.variables)
}

/**
* Returns a copy with an added variable at the beginning.
*/
def withFirst(variable: TemplateVariable): TemplateVariables = {
TemplateVariables(variable +: variables)
}

/**
* Returns only non-sensitive variables
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GlobalTemplateVariablesTest extends AnyFlatSpec with Matchers {
template = None,
description = None,
isSensitive = false,
scope = GlobalTemplateVariablesConfig.globalScope
scope = TemplateVariableScopes.global
))

variables.map.get("complexVar") shouldBe
Expand All @@ -37,7 +37,7 @@ class GlobalTemplateVariablesTest extends AnyFlatSpec with Matchers {
template = None,
description = Some("my description"),
isSensitive = false,
scope = GlobalTemplateVariablesConfig.globalScope
scope = TemplateVariableScopes.global
))

variables.map.get("sensitiveVar") shouldBe
Expand All @@ -47,7 +47,7 @@ class GlobalTemplateVariablesTest extends AnyFlatSpec with Matchers {
template = None,
description = None,
isSensitive = true,
scope = GlobalTemplateVariablesConfig.globalScope
scope = TemplateVariableScopes.global
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ class ProjectApi @Inject()(accessMonitor: WorkbenchAccessMonitor) extends Inject
val requestMetaData = request.metaData.asMetaData
val clonedProjectConfig = project.config.copy(id = projectId, metaData = requestMetaData.copy(tags = requestMetaData.tags ++ project.metaData.tags))
val clonedProject = workspace.createProject(clonedProjectConfig.copy(projectResourceUriOpt = Some(clonedProjectConfig.generateDefaultUri)))
// Clone resources
WorkspaceIO.copyResources(project.resources, clonedProject.resources)
// Clone tags
for (tag <- project.tagManager.allTags()) {
clonedProject.tagManager.putTag(tag)
}
// Clone variables
clonedProject.templateVariables.put(project.templateVariables.all)
// Clone tasks, since task specs may contain state, e.g. RDF file dataset
for (task <- project.allTasks) {
val taskParameters = task.data.parameters(PluginContext.fromProject(project))
Expand Down
Loading