use of org.apache.hop.metadata.api.IHopMetadata 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.api.IHopMetadata in project hop by apache.
the class MemoryMetadataProvider method getSerializer.
@Override
public <T extends IHopMetadata> IHopMetadataSerializer<T> getSerializer(Class<T> managedClass) throws HopException {
IHopMetadataSerializer<IHopMetadata> serializer = serializerMap.get(managedClass.getName());
if (serializer == null) {
HopMetadata hopMetadata = managedClass.getAnnotation(HopMetadata.class);
String description = managedClass.getSimpleName();
if (hopMetadata != null) {
description = hopMetadata.name();
}
serializer = (IHopMetadataSerializer<IHopMetadata>) new MemoryMetadataSerializer<>(this, managedClass, variables, description);
serializerMap.put(managedClass.getName(), serializer);
}
return (IHopMetadataSerializer<T>) serializer;
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class MetadataExplorerDialog method duplicateMetadata.
@GuiToolbarElement(root = GUI_PLUGIN_TOOLBAR_PARENT_ID, id = TOOLBAR_ITEM_DUPLICATE, toolTip = "Create a copy", image = "ui/images/copy.svg")
public void duplicateMetadata() {
MetadataManager<IHopMetadata> manager = getActiveMetadataManger();
if (manager != null && activeObjectName != null) {
try {
IHopMetadata metadata = manager.loadElement(activeObjectName);
int copyNr = 2;
while (true) {
String newName = activeObjectName + " " + copyNr;
if (!manager.getSerializer().exists(newName)) {
metadata.setName(newName);
manager.getSerializer().save(metadata);
refreshTree();
manager.editMetadata(newName);
break;
} else {
copyNr++;
}
}
refreshTree();
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error duplicating metadata", e);
}
}
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class MetadataExplorerDialog method getActiveMetadataManger.
private MetadataManager<IHopMetadata> getActiveMetadataManger() {
try {
IHopMetadataProvider metadataProvider = HopGui.getInstance().getMetadataProvider();
Class<IHopMetadata> metadataClass = metadataProvider.getMetadataClassForKey(activeObjectKey);
MetadataManager<IHopMetadata> manager = new MetadataManager<>(HopGui.getInstance().getVariables(), metadataProvider, metadataClass);
return manager;
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Unexpected error getting the metadata class for key '" + activeObjectKey + "'", e);
return null;
}
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class MetadataExplorerDialog method refreshTree.
@GuiToolbarElement(root = GUI_PLUGIN_TOOLBAR_PARENT_ID, id = TOOLBAR_ITEM_REFRESH, toolTip = "Refresh", image = "ui/images/refresh.svg")
public void refreshTree() {
try {
tree.removeAll();
IHopMetadataProvider metadataProvider = HopGui.getInstance().getMetadataProvider();
// top level: object key
//
List<Class<IHopMetadata>> metadataClasses = metadataProvider.getMetadataClasses();
for (Class<IHopMetadata> metadataClass : metadataClasses) {
HopMetadata hopMetadata = HopMetadataUtil.getHopMetadataAnnotation(metadataClass);
Image image = SwtSvgImageUtil.getImage(shell.getDisplay(), metadataClass.getClassLoader(), hopMetadata.image(), ConstUi.ICON_SIZE, ConstUi.ICON_SIZE);
TreeItem elementTypeItem = new TreeItem(tree, SWT.NONE);
elementTypeItem.setImage(image);
elementTypeItem.setText(0, Const.NVL(hopMetadata.key(), ""));
elementTypeItem.setText(1, Const.NVL(hopMetadata.name(), ""));
// level 1: object names
//
IHopMetadataSerializer<IHopMetadata> serializer = metadataProvider.getSerializer(metadataClass);
List<String> names = serializer.listObjectNames();
Collections.sort(names);
for (final String name : names) {
TreeItem elementItem = new TreeItem(elementTypeItem, SWT.NONE);
elementItem.setText(1, Const.NVL(name, ""));
elementItem.addListener(SWT.Selection, event -> log.logBasic("Selected : " + name));
elementItem.setFont(GuiResource.getInstance().getFontBold());
}
}
TreeUtil.setOptimalWidthOnColumns(tree);
TreeMemory.setExpandedFromMemory(tree, METADATA_EXPLORER_DIALOG_TREE);
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error refreshing metadata tree", e);
}
}
Aggregations