Skip to content

Commit d502a01

Browse files
authored
Add support for renaming/refactoring metadata and hop files, fixes #6777 (#6778)
1 parent bf37eda commit d502a01

File tree

70 files changed

+3410
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3410
-343
lines changed

core/src/main/java/org/apache/hop/core/database/DatabaseMeta.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
description = "i18n::DatabaseMeta.description",
6464
image = "ui/images/database.svg",
6565
documentationUrl = "/metadata-types/rdbms-connection.html",
66-
hopMetadataPropertyType = HopMetadataPropertyType.RDBMS_CONNECTION)
66+
hopMetadataPropertyType = HopMetadataPropertyType.RDBMS_CONNECTION,
67+
supportsGlobalReplace = true)
6768
public class DatabaseMeta extends HopMetadataBase implements Cloneable, IHopMetadata {
6869
private static final Class<?> PKG = Database.class;
6970

core/src/main/java/org/apache/hop/core/variables/resolver/VariableResolver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
import org.apache.hop.metadata.api.HopMetadata;
2424
import org.apache.hop.metadata.api.HopMetadataBase;
2525
import org.apache.hop.metadata.api.HopMetadataProperty;
26-
import org.apache.hop.metadata.api.HopMetadataPropertyType;
2726
import org.apache.hop.metadata.api.IHopMetadata;
2827

2928
@HopMetadata(
3029
key = "variable-resolver",
3130
name = "i18n::VariableResolver.name",
3231
description = "i18n::VariableResolver.Description",
3332
image = "ui/images/variable.svg",
34-
documentationUrl = "/metadata-types/variable-resolver/",
35-
hopMetadataPropertyType = HopMetadataPropertyType.RDBMS_CONNECTION)
33+
documentationUrl = "/metadata-types/variable-resolver/")
3634
@Getter
3735
@Setter
3836
public class VariableResolver extends HopMetadataBase implements IHopMetadata {

core/src/main/java/org/apache/hop/metadata/api/HopMetadata.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@
5151
* @return the type of metadata this property represents.
5252
*/
5353
HopMetadataPropertyType hopMetadataPropertyType() default HopMetadataPropertyType.NONE;
54+
55+
/**
56+
* Set this to identify if this metadata object supports replacing values in Workflows and
57+
* Pipelines
58+
*
59+
* @return true if global replace is supported
60+
*/
61+
boolean supportsGlobalReplace() default false;
5462
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hop.metadata.api;
19+
20+
import org.apache.hop.core.exception.HopException;
21+
22+
/**
23+
* Utility to link metadata elements to their {@link HopMetadataPropertyType} for refactoring (e.g.
24+
* rename) so references in pipelines and workflows can be found and updated.
25+
*/
26+
public final class MetadataRefactorUtil {
27+
28+
private MetadataRefactorUtil() {}
29+
30+
/**
31+
* Returns the property type for a metadata type key, if the metadata class declares it via {@link
32+
* HopMetadata#hopMetadataPropertyType()}. This links the metadata element to the kind of
33+
* reference used in pipeline/workflow XML (e.g. RDBMS_CONNECTION for "rdbms").
34+
*
35+
* @param provider metadata provider (used to resolve the class for the key)
36+
* @param metadataKey the metadata type key (e.g. "rdbms", "restconnection")
37+
* @return the property type, or {@link HopMetadataPropertyType#NONE} if not declared or unknown
38+
*/
39+
public static HopMetadataPropertyType getPropertyTypeForMetadataKey(
40+
IHopMetadataProvider provider, String metadataKey) {
41+
try {
42+
Class<? extends IHopMetadata> clazz = provider.getMetadataClassForKey(metadataKey);
43+
HopMetadata annotation = clazz.getAnnotation(HopMetadata.class);
44+
if (annotation == null) {
45+
return HopMetadataPropertyType.NONE;
46+
}
47+
HopMetadataPropertyType type = annotation.hopMetadataPropertyType();
48+
return type == null ? HopMetadataPropertyType.NONE : type;
49+
} catch (HopException e) {
50+
return HopMetadataPropertyType.NONE;
51+
}
52+
}
53+
54+
/**
55+
* Returns whether the metadata type supports global replace (finding and updating references in
56+
* pipelines and workflows when renaming). Uses {@link HopMetadata#supportsGlobalReplace()}.
57+
*
58+
* @param provider metadata provider (used to resolve the class for the key)
59+
* @param metadataKey the metadata type key (e.g. "rdbms", "restconnection")
60+
* @return true if global replace is supported, false otherwise
61+
*/
62+
public static boolean supportsGlobalReplace(IHopMetadataProvider provider, String metadataKey) {
63+
try {
64+
Class<? extends IHopMetadata> clazz = provider.getMetadataClassForKey(metadataKey);
65+
HopMetadata annotation = clazz.getAnnotation(HopMetadata.class);
66+
return annotation != null && annotation.supportsGlobalReplace();
67+
} catch (HopException e) {
68+
return false;
69+
}
70+
}
71+
}

engine/src/main/java/org/apache/hop/execution/ExecutionInfoLocation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
description = "i18n::ExecutionInfoLocation.description",
3232
image = "ui/images/location.svg",
3333
documentationUrl = "/metadata-types/execution-information-location.html",
34-
hopMetadataPropertyType = HopMetadataPropertyType.EXEC_INFO_LOCATION)
34+
hopMetadataPropertyType = HopMetadataPropertyType.EXEC_INFO_LOCATION,
35+
supportsGlobalReplace = true)
3536
public class ExecutionInfoLocation extends HopMetadataBase implements IHopMetadata, Cloneable {
3637
public static final String GUI_PLUGIN_ELEMENT_PARENT_ID =
3738
"ExecutionInfoLocation-PluginSpecific-Options";

engine/src/main/java/org/apache/hop/execution/profiling/ExecutionDataProfile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
description = "i18n::ExecutionDataProfile.description",
3838
image = "ui/images/analyzer.svg",
3939
documentationUrl = "/metadata-types/execution-data-profile.html",
40-
hopMetadataPropertyType = HopMetadataPropertyType.EXEC_INFO_DATA_PROFILE)
40+
hopMetadataPropertyType = HopMetadataPropertyType.EXEC_INFO_DATA_PROFILE,
41+
supportsGlobalReplace = true)
4142
public class ExecutionDataProfile extends HopMetadataBase implements IHopMetadata, Cloneable {
4243

4344
public static final String GUI_PLUGIN_ELEMENT_PARENT_ID = "ExecutionDataSamplerParent";

engine/src/main/java/org/apache/hop/execution/remote/RemoteExecutionInfoLocation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.hop.execution.IExecutionSelector;
4545
import org.apache.hop.execution.plugin.ExecutionInfoLocationPlugin;
4646
import org.apache.hop.metadata.api.HopMetadataProperty;
47+
import org.apache.hop.metadata.api.HopMetadataPropertyType;
4748
import org.apache.hop.metadata.api.IHopMetadataProvider;
4849
import org.apache.hop.server.HopServerMeta;
4950
import org.apache.hop.www.GetExecutionInfoServlet;
@@ -71,7 +72,9 @@ public class RemoteExecutionInfoLocation implements IExecutionInfoLocation {
7172
metadata = HopServerMeta.class,
7273
toolTip = "i18n::RemoteExecutionInfoLocation.HopServer.Tooltip",
7374
label = "i18n::RemoteExecutionInfoLocation.HopServer.Label")
74-
@HopMetadataProperty(key = "server")
75+
@HopMetadataProperty(
76+
key = "server",
77+
hopMetadataPropertyType = HopMetadataPropertyType.SERVER_DEFINITION)
7578
protected String serverName;
7679

7780
@GuiWidgetElement(
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hop.metadata.refactor;
19+
20+
import java.util.Objects;
21+
22+
/**
23+
* Describes a reference to a metadata element from another metadata object (e.g. a
24+
* PipelineRunConfiguration referencing an ExecutionInfoLocation by name).
25+
*/
26+
public class MetadataObjectReference {
27+
28+
private final String containerMetadataKey;
29+
private final String containerObjectName;
30+
31+
public MetadataObjectReference(String containerMetadataKey, String containerObjectName) {
32+
this.containerMetadataKey = containerMetadataKey;
33+
this.containerObjectName = containerObjectName;
34+
}
35+
36+
public String getContainerMetadataKey() {
37+
return containerMetadataKey;
38+
}
39+
40+
public String getContainerObjectName() {
41+
return containerObjectName;
42+
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (this == o) return true;
47+
if (o == null || getClass() != o.getClass()) return false;
48+
MetadataObjectReference that = (MetadataObjectReference) o;
49+
return Objects.equals(containerMetadataKey, that.containerMetadataKey)
50+
&& Objects.equals(containerObjectName, that.containerObjectName);
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(containerMetadataKey, containerObjectName);
56+
}
57+
}

0 commit comments

Comments
 (0)