Skip to content

Commit f4975ef

Browse files
authored
Merge pull request #5149 from hansva/5148
do not fail on missing metadata objects, some cleanup, fixes #5148
2 parents 6e08e48 + 527f723 commit f4975ef

File tree

12 files changed

+86
-85
lines changed

12 files changed

+86
-85
lines changed

core/src/main/java/org/apache/hop/core/plugins/BasePluginTypeExposer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
* way.
2929
*
3030
* <p>Unless you're running within OSGI, you should never use this class.
31-
*
32-
* <p>Created by nbaker on 2/11/15.
3331
*/
3432
public class BasePluginTypeExposer {
3533
private BasePluginType pluginType;

core/src/main/java/org/apache/hop/core/plugins/SupplementalPlugin.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
import java.util.concurrent.Callable;
2424
import org.apache.hop.core.exception.HopPluginException;
2525

26-
/**
27-
* This is a holder of Plugin Class mappings which supplement those of the stock Plugin.
28-
*
29-
* <p>Created by nbaker on 3/17/17.
30-
*/
26+
/** This is a holder of Plugin Class mappings which supplement those of the stock Plugin. */
3127
public class SupplementalPlugin extends Plugin implements IClassLoadingPlugin {
3228
Map<Class, Callable> factoryMap = new HashMap<>();
3329
private Class<? extends IPluginType> pluginClass;

core/src/main/java/org/apache/hop/core/row/value/ValueMetaConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
* This class is intended to facilitate any needed conversions of a IValueMeta field from one type
3333
* to another. It was initially implemented for Orc storage in the hadoop shims project. This class
3434
* is added here because the converstions are not dependendant on orc in any way.
35-
*
36-
* <p>Created by tkafalas on 12/8/2017.
3735
*/
3836
public class ValueMetaConverter implements Serializable, IValueMetaConverter {
3937
private static final String DEFAULT_DATE_FORMAT = ValueMetaBase.DEFAULT_DATE_FORMAT_MASK;

core/src/main/java/org/apache/hop/metadata/serializer/json/JsonMetadataParser.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.util.HashMap;
2828
import java.util.List;
2929
import java.util.Map;
30+
import lombok.Getter;
31+
import lombok.Setter;
3032
import org.apache.commons.lang.StringUtils;
3133
import org.apache.hop.core.encryption.ITwoWayPasswordEncoder;
3234
import org.apache.hop.core.exception.HopException;
@@ -42,8 +44,9 @@
4244

4345
public class JsonMetadataParser<T extends IHopMetadata> {
4446

45-
private Class<T> managedClass;
46-
private IHopMetadataProvider metadataProvider;
47+
private final Class<T> managedClass;
48+
49+
@Setter @Getter private IHopMetadataProvider metadataProvider;
4750

4851
public JsonMetadataParser(Class<T> managedClass, IHopMetadataProvider metadataProvider) {
4952
this.managedClass = managedClass;
@@ -401,20 +404,4 @@ private JSONObject savePojoProperty(String key, Object fieldValue, Class<?> fiel
401404
e);
402405
}
403406
}
404-
405-
/**
406-
* Gets provider
407-
*
408-
* @return value of provider
409-
*/
410-
public IHopMetadataProvider getMetadataProvider() {
411-
return metadataProvider;
412-
}
413-
414-
/**
415-
* @param metadataProvider The provider to set
416-
*/
417-
public void setMetadataProvider(IHopMetadataProvider metadataProvider) {
418-
this.metadataProvider = metadataProvider;
419-
}
420407
}

core/src/main/java/org/apache/hop/metadata/serializer/json/JsonMetadataSerializer.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ public T load(String name) throws HopException {
101101
try {
102102
// Load the JSON in a streaming fashion so we can parse the properties one by one...
103103
//
104-
InputStream fileInputStream = null;
105-
try {
106-
fileInputStream = HopVfs.getInputStream(filename);
104+
try (InputStream fileInputStream = HopVfs.getInputStream(filename)) {
107105
JsonFactory jsonFactory = new JsonFactory();
108106
try (com.fasterxml.jackson.core.JsonParser jsonParser =
109107
jsonFactory.createParser(fileInputStream)) {
@@ -116,10 +114,6 @@ public T load(String name) throws HopException {
116114
t.setMetadataProviderName(metadataProvider.getDescription());
117115
return t;
118116
}
119-
} finally {
120-
if (fileInputStream != null) {
121-
fileInputStream.close();
122-
}
123117
}
124118
} catch (Exception e) {
125119
throw new HopException(
@@ -250,7 +244,7 @@ public T delete(String name) throws HopException {
250244
public List<String> listObjectNames() throws HopException {
251245
List<String> names = new ArrayList<>();
252246

253-
// Read only access doesn't require a folder;
247+
// Read-only access doesn't require a folder
254248
validateBaseFolder(false);
255249
if (!baseFolderExists) {
256250
// This is not an error. We simply don't have objects of the given type.
@@ -274,7 +268,7 @@ public List<String> listObjectNames() throws HopException {
274268

275269
@Override
276270
public boolean exists(String name) throws HopException {
277-
// Read only access doesn't require a folder;
271+
// Read-only access doesn't require a folder
278272
validateBaseFolder(false);
279273
if (!baseFolderExists) {
280274
return false;

engine/src/main/java/org/apache/hop/core/metadata/SerializableMetadataProvider.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import com.fasterxml.jackson.core.JsonFactory;
2121
import com.fasterxml.jackson.core.JsonToken;
2222
import java.io.ByteArrayInputStream;
23-
import org.apache.hop.core.Const;
23+
import java.nio.charset.StandardCharsets;
2424
import org.apache.hop.core.exception.HopException;
25+
import org.apache.hop.core.logging.LogChannel;
2526
import org.apache.hop.metadata.api.HopMetadata;
2627
import org.apache.hop.metadata.api.IHopMetadata;
2728
import org.apache.hop.metadata.api.IHopMetadataProvider;
@@ -106,20 +107,28 @@ public SerializableMetadataProvider(String storeJson) throws HopException {
106107
this.description = "Serializable metadata provider (source is JSON)";
107108
try {
108109

109-
ByteArrayInputStream inputStream = null;
110-
try {
111-
inputStream = new ByteArrayInputStream(storeJson.getBytes(Const.XML_ENCODING));
110+
try (ByteArrayInputStream inputStream =
111+
new ByteArrayInputStream(storeJson.getBytes(StandardCharsets.UTF_8))) {
112112

113113
JsonFactory jsonFactory = new JsonFactory();
114114
com.fasterxml.jackson.core.JsonParser jsonParser = jsonFactory.createParser(inputStream);
115115

116116
// Loop over the classes until there's no more left
117117
//
118-
jsonParser.nextToken(); // skip {
118+
jsonParser.nextToken(); // skip "{"
119119
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
120120

121121
String classKey = jsonParser.getText();
122-
Class<IHopMetadata> managedClass = getMetadataClassForKey(classKey);
122+
Class<IHopMetadata> managedClass = getManagedClass(classKey);
123+
124+
if (managedClass == null) {
125+
// Skip this JSON Array
126+
jsonParser.nextToken(); // skip "{"
127+
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
128+
// Go to END_ARRAY
129+
}
130+
continue;
131+
}
123132

124133
JsonMetadataParser<IHopMetadata> metadataParser =
125134
new JsonMetadataParser<>(managedClass, this);
@@ -128,19 +137,32 @@ public SerializableMetadataProvider(String storeJson) throws HopException {
128137

129138
// Loop over the metadata objects in the JSON for the given class...
130139
//
131-
jsonParser.nextToken(); // skip {
140+
jsonParser.nextToken(); // skip "{"
132141
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
133142
IHopMetadata object = metadataParser.loadJsonObject(managedClass, jsonParser);
134-
serializer.save(object);
143+
if (object != null) {
144+
serializer.save(object);
145+
}
135146
}
136147
}
137-
} finally {
138-
if (inputStream != null) {
139-
inputStream.close();
140-
}
141148
}
142149
} catch (Exception e) {
143150
throw new HopException("Error reading metadata from JSON", e);
144151
}
145152
}
153+
154+
/**
155+
* @param classKey
156+
* @return
157+
*/
158+
private Class<IHopMetadata> getManagedClass(String classKey) {
159+
Class<IHopMetadata> managedClass;
160+
try {
161+
managedClass = getMetadataClassForKey(classKey);
162+
} catch (HopException e) {
163+
LogChannel.GENERAL.logError("Error loading class " + classKey, e);
164+
managedClass = null;
165+
}
166+
return managedClass;
167+
}
146168
}

plugins/tech/aws/src/test/java/org/apache/hop/vfs/s3/vfs/S3FileNameParserIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.hop.vfs.s3.s3.vfs.S3FileNameParser;
2525
import org.junit.Test;
2626

27-
/** created by: rfellows date: 5/25/12 */
2827
public class S3FileNameParserIT {
2928

3029
@Test

plugins/tech/aws/src/test/java/org/apache/hop/vfs/s3/vfs/S3FileNameTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.Before;
2525
import org.junit.Test;
2626

27-
/** created by: rfellows date: 05/17/2012 */
2827
public class S3FileNameTest {
2928

3029
private S3FileName fileName = null;

plugins/tech/aws/src/test/java/org/apache/hop/vfs/s3/vfs/S3FileObjectTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import org.junit.Test;
7171
import org.mockito.ArgumentCaptor;
7272

73-
/** created by: dzmitry_bahdanovich date: 10/18/13 */
7473
public class S3FileObjectTest {
7574

7675
public static final String HOST = "S3";

plugins/tech/aws/src/test/java/org/apache/hop/vfs/s3/vfs/S3NFileNameTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.Before;
2525
import org.junit.Test;
2626

27-
/** created by: rfellows date: 05/17/2012 */
2827
public class S3NFileNameTest {
2928

3029
private S3NFileName fileName = null;

0 commit comments

Comments
 (0)