Search in sources :

Example 1 with IHopMetadata

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();
}
Also used : JSONObject(org.json.simple.JSONObject) JsonMetadataParser(org.apache.hop.metadata.serializer.json.JsonMetadataParser) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) HopException(org.apache.hop.core.exception.HopException) JSONArray(org.json.simple.JSONArray) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) JSONObject(org.json.simple.JSONObject)

Example 2 with IHopMetadata

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;
}
Also used : IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) IHopMetadataSerializer(org.apache.hop.metadata.api.IHopMetadataSerializer)

Example 3 with IHopMetadata

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);
        }
    }
}
Also used : IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 4 with IHopMetadata

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;
    }
}
Also used : MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog)

Example 5 with IHopMetadata

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);
    }
}
Also used : IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Image(org.eclipse.swt.graphics.Image) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Aggregations

IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)20 HopException (org.apache.hop.core.exception.HopException)10 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)9 HopMetadata (org.apache.hop.metadata.api.HopMetadata)8 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)6 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)6 MetadataManager (org.apache.hop.ui.core.metadata.MetadataManager)4 ArrayList (java.util.ArrayList)3 JsonMetadataParser (org.apache.hop.metadata.serializer.json.JsonMetadataParser)2 TabItemHandler (org.apache.hop.ui.hopgui.perspective.TabItemHandler)2 MetadataPerspective (org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective)2 Image (org.eclipse.swt.graphics.Image)2 JSONObject (org.json.simple.JSONObject)2 Field (java.lang.reflect.Field)1 FileObject (org.apache.commons.vfs2.FileObject)1 GuiKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiKeyboardShortcut)1 GuiOsxKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiOsxKeyboardShortcut)1 IRowMeta (org.apache.hop.core.row.IRowMeta)1 RowMeta (org.apache.hop.core.row.RowMeta)1 AuditList (org.apache.hop.history.AuditList)1