use of org.apache.hop.metadata.serializer.json.JsonMetadataParser in project hop by apache.
the class SerializableMetadataProvider method toJson.
public String toJson() throws HopException {
JSONObject jStore = new JSONObject();
//
for (Class<IHopMetadata> metadataClass : getMetadataClasses()) {
IHopMetadataSerializer<IHopMetadata> serializer = getSerializer(metadataClass);
HopMetadata hopMetadata = metadataClass.getAnnotation(HopMetadata.class);
if (hopMetadata == null) {
throw new HopException("Error: class " + metadataClass + " is not annotated with " + HopMetadata.class.getName());
}
String classKey = hopMetadata.key();
JSONArray jClass = new JSONArray();
JsonMetadataParser parser = new JsonMetadataParser(metadataClass, this);
//
for (String name : serializer.listObjectNames()) {
Object object = serializer.load(name);
JSONObject jObject = parser.getJsonObject((IHopMetadata) object);
jClass.add(jObject);
}
jStore.put(classKey, jClass);
}
return jStore.toJSONString();
}
use of org.apache.hop.metadata.serializer.json.JsonMetadataParser in project hop by apache.
the class MetadataInput method processRow.
@Override
public boolean processRow() throws HopException {
IRowMeta outputRowMeta = new RowMeta();
meta.getFields(outputRowMeta, getTransformName(), null, null, this, metadataProvider);
// Get the list of type key filters...
//
List<String> typeKeyFilters = new ArrayList<>();
for (String typeKeyFilter : meta.getTypeKeyFilters()) {
typeKeyFilters.add(StringUtils.trim(resolve(typeKeyFilter)));
}
// Loop over the metadata classes (types)
List<Class<IHopMetadata>> metadataClasses = metadataProvider.getMetadataClasses();
for (Class<IHopMetadata> metadataClass : metadataClasses) {
IHopMetadataSerializer<IHopMetadata> serializer = metadataProvider.getSerializer(metadataClass);
HopMetadata annotation = HopMetadataUtil.getHopMetadataAnnotation(metadataClass);
// See if we need to include this class in the output...
//
boolean include = typeKeyFilters.isEmpty();
for (String typeKeyFilter : typeKeyFilters) {
if (typeKeyFilter.equals(annotation.key())) {
include = true;
}
}
if (!include) {
// Skip this one
continue;
}
JsonMetadataParser<IHopMetadata> parser = new JsonMetadataParser<>(metadataClass, metadataProvider);
//
for (String name : serializer.listObjectNames()) {
IHopMetadata metadata = serializer.load(name);
// Output the metadata...
//
Object[] outputRow = RowDataUtil.allocateRowData(outputRowMeta.size());
int index = 0;
//
if (StringUtils.isNotEmpty(meta.getProviderFieldName())) {
outputRow[index++] = metadata.getMetadataProviderName();
}
//
if (StringUtils.isNotEmpty(meta.getTypeKeyFieldName())) {
outputRow[index++] = annotation.key();
}
if (StringUtils.isNotEmpty(meta.getTypeDescriptionFieldName())) {
outputRow[index++] = annotation.name();
}
if (StringUtils.isNotEmpty(meta.getTypeDescriptionFieldName())) {
outputRow[index++] = annotation.description();
}
if (StringUtils.isNotEmpty(meta.getTypeClassFieldName())) {
outputRow[index++] = metadataClass.getName();
}
// Some information about the metadata object...
if (StringUtils.isNotEmpty(meta.getNameFieldName())) {
outputRow[index++] = metadata.getName();
}
//
if (StringUtils.isNotEmpty(meta.getJsonFieldName())) {
JSONObject jsonObject = parser.getJsonObject(metadata);
outputRow[index] = jsonObject.toJSONString();
}
putRow(outputRowMeta, outputRow);
}
}
setOutputDone();
return false;
}
Aggregations