Search in sources :

Example 1 with RepositoryViewObject

use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.

the class OpenDiagramAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    ISelection selection = getSelectedObject();
    if (selection == null) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (obj instanceof RepositoryNode) {
        RepositoryNode repositoryNode = (RepositoryNode) obj;
        IRepositoryViewObject repositoryObject = repositoryNode.getObject();
        Property updatedProperty = null;
        if (repositoryObject instanceof RepositoryObject) {
            RepositoryViewObject abstractRepositoryObject = new RepositoryViewObject(repositoryObject.getProperty());
            updatedProperty = abstractRepositoryObject.getProperty();
        } else if (repositoryObject instanceof RepositoryViewObject) {
            updatedProperty = repositoryObject.getProperty();
        }
        if (updatedProperty != null) {
            BusinessProcessItem businessProcessItem = (BusinessProcessItem) updatedProperty.getItem();
            DiagramResourceManager diagramResourceManager = new DiagramResourceManager(getActivePage(), new NullProgressMonitor());
            IFile file = diagramResourceManager.createDiagramFile();
            diagramResourceManager.updateResource(businessProcessItem, file);
            IEditorPart part = diagramResourceManager.openEditor(businessProcessItem, file, false);
            if (part instanceof BusinessDiagramEditor) {
                ((BusinessDiagramEditor) part).setLastVersion(true);
            }
        // TDI-21143 : Studio repository view : remove all refresh call to repo view
        // IRepositoryView view = getViewPart();
        // if (view != null) {
        // view.refresh(repositoryNode);
        // }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RepositoryObject(org.talend.core.model.repository.RepositoryObject) BusinessDiagramEditor(org.talend.designer.business.model.business.diagram.part.BusinessDiagramEditor) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) RepositoryNode(org.talend.repository.model.RepositoryNode) ISelection(org.eclipse.jface.viewers.ISelection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) Property(org.talend.core.model.properties.Property) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 2 with RepositoryViewObject

use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.

the class ImportDemoProjectItemsPage method populateExistItemRecords.

private String populateExistItemRecords(final List<ResourcesManager> manager) {
    //$NON-NLS-1$
    String messageInfo = "";
    final Collection<ImportItem> items = new ArrayList<ImportItem>();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                for (ResourcesManager rm : manager) {
                    items.addAll(importManager.populateImportingItems(rm, true, monitor));
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    };
    try {
        new ProgressMonitorDialog(getShell()).run(true, true, op);
    } catch (Exception e) {
    // ignore me
    }
    for (ImportItem itemRecord : items) {
        if (itemRecord.getExistingItemWithSameId() != null && itemRecord.getExistingItemWithSameId() instanceof RepositoryViewObject) {
            RepositoryViewObject reObject = (RepositoryViewObject) itemRecord.getExistingItemWithSameId();
            if (itemRecord.getProperty() != null && reObject != null) {
                if (!itemRecord.getProperty().getId().equals(reObject.getId()) && itemRecord.getProperty().getLabel().equalsIgnoreCase(reObject.getLabel())) {
                    messageInfo = Messages.getString("ImportDemoProjectPage.loseItems", reObject.getLabel());
                }
                if (itemRecord.getProperty().getId().equals(reObject.getId()) && itemRecord.getProperty().getLabel().equals(reObject.getLabel())) {
                    messageInfo = Messages.getString("ImportDemoProjectPage.overwriteItems");
                }
            }
        }
    }
    return messageInfo;
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 3 with RepositoryViewObject

use of org.talend.core.model.repository.RepositoryViewObject in project tesb-studio-se by Talend.

the class OpenWSDLPage method finish.

public boolean finish() {
    // changed by hqzhang for TDI-19527, label=displayName
    final String label = item.getProperty().getDisplayName();
    item.getProperty().setLabel(label);
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(final IProgressMonitor monitor) throws CoreException {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
                if (creation) {
                    item.getProperty().setId(factory.getNextId());
                    factory.create(item, getDestinationPath());
                    repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
                }
                ((ServiceConnection) item.getConnection()).setWSDLPath(path);
                ((ServiceConnection) item.getConnection()).getServicePort().clear();
                final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
                final InputStream is;
                if (null == path) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    // create new WSDL file from template
                    TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
                    is = new ByteArrayInputStream(baos.toByteArray());
                } else {
                    //$NON-NLS-1$
                    String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
                    Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
                    is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
                    for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
                        String filename = wsdl.getKey();
                        IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
                        if (!importedWsdl.exists()) {
                            importedWsdl.create(wsdl.getValue(), true, monitor);
                        } else {
                            importedWsdl.setContents(wsdl.getValue(), 0, monitor);
                        }
                        createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
                    }
                }
                // store WSDL in service
                if (!fileWsdl.exists()) {
                    fileWsdl.create(is, true, monitor);
                } else {
                    fileWsdl.setContents(is, 0, monitor);
                }
                // create reference to wsdl
                //$NON-NLS-1$
                createReferenceResources("wsdl");
                // path
                definition = WSDLUtils.getDefinition(fileWsdl);
                populateModelFromWsdl(factory, definition, item, repositoryNode);
                factory.save(item);
                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
            } catch (Exception e) {
                //delete the node if any exception during the creation
                if (creation) {
                    try {
                        factory.save(item);
                        factory.deleteObjectPhysical(repositoryNode.getObject());
                    } catch (PersistenceException e1) {
                        throw getCoreException("WDSL creation failed", e1);
                    }
                }
                //throw the exception
                if (e instanceof CoreException) {
                    throw (CoreException) e;
                }
                if (e instanceof InvocationTargetException) {
                    throw getCoreException("WDSL creation failed", e.getCause());
                }
                throw getCoreException("WDSL creation failed", e);
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        // we use the workspace scheduling rule to lock all
        ISchedulingRule schedulingRule = workspace.getRoot();
        // workspace modifications during the run.
        // the update of the project files need to be done in the workspace runnable to avoid all notification
        // of changes before the end of the modifications.
        workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    // open wsdl editor
    OpenWSDLEditorAction action = new OpenWSDLEditorAction();
    action.setServiceItem(item);
    action.run();
    // import schemas if required
    if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
        PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
        try {
            getContainer().run(true, true, publishMetadataRunnable);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
            setErrorMessage("Populate schema to repository: " + message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    return true;
}
Also used : ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) OpenWSDLEditorAction(org.talend.repository.services.action.OpenWSDLEditorAction) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) PublishMetadataRunnable(org.talend.repository.services.action.PublishMetadataRunnable) Map(java.util.Map)

Example 4 with RepositoryViewObject

use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.

the class DBTreeProvider method convert.

private void convert(Container fromModel, RepositoryNode parent, ERepositoryObjectType type) {
    if (fromModel.isEmpty()) {
        return;
    }
    for (Object obj : fromModel.getSubContainer()) {
        Container container = (Container) obj;
        Folder folderRepositoryObject = new Folder(container.getId(), container.getLabel());
        FolderRepositoryObject oFolder = new FolderRepositoryObject(folderRepositoryObject);
        oFolder.setImage(IMAGES_CLOSED_FOLDER);
        oFolder.setSourceName(oFolder.getLabel());
        oFolder.setRepositoryName(null);
        RepositoryNode folder = new RepositoryNodeExt(oFolder, parent, ENodeType.SIMPLE_FOLDER);
        folder.setProperties(EProperties.LABEL, container.getLabel());
        // ERepositoryObjectType.FOLDER);
        folder.setProperties(EProperties.CONTENT_TYPE, RepositoryNodeType.FOLDER);
        parent.getChildren().add(folder);
        convert(container, folder, type);
    }
    if (!isCleared) {
        maps.clear();
        isCleared = true;
    }
    for (Object obj : fromModel.getMembers()) {
        RepositoryObject obj2 = (RepositoryObject) obj;
        if (!connectionParameters.getRepositoryId().equals(obj2.getProperty().getId())) {
            continue;
        }
        RepositoryViewObject viewObject = new RepositoryViewObject(obj2.getProperty());
        maps.put((obj2).getId(), viewObject);
        addNode(parent, viewObject, false, null);
    }
}
Also used : Container(org.talend.commons.utils.data.container.Container) RootContainer(org.talend.commons.utils.data.container.RootContainer) RepositoryObject(org.talend.core.model.repository.RepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) Folder(org.talend.core.model.repository.Folder) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryNodeExt(org.talend.sqlbuilder.RepositoryNodeExt) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 5 with RepositoryViewObject

use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.

the class GenericDragAndDropHandler method isValid.

private boolean isValid(RepositoryNode seletetedNode, IComponent component) {
    // TUP-4151
    IRepositoryViewObject object = seletetedNode.getObject();
    if (component == null || object == null) {
        return false;
    }
    ComponentProperties currentComponentProperties = null;
    if (object instanceof RepositoryViewObject) {
        RepositoryViewObject repositoryViewObj = (RepositoryViewObject) object;
        Connection connection = ((ConnectionItem) repositoryViewObj.getProperty().getItem()).getConnection();
        if (canHandle(connection)) {
            GenericConnection genericConnection = (GenericConnection) connection;
            currentComponentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(genericConnection.getCompProperties(), connection);
        }
    } else if (object instanceof MetadataTableRepositoryObject) {
        MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) object;
        currentComponentProperties = SchemaUtils.getCurrentComponentProperties(metaTableRepObj);
    } else if (object instanceof MetadataColumnRepositoryObject) {
        MetadataColumnRepositoryObject metaColumnRepObj = (MetadataColumnRepositoryObject) object;
        ModelElement element = metaColumnRepObj.getTdColumn();
        if (element != null && element.eContainer() instanceof MetadataTable) {
            MetadataTable metadataTable = (MetadataTable) element.eContainer();
            IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
            currentComponentProperties = SchemaUtils.getCurrentComponentProperties(newTable);
        }
    }
    if (currentComponentProperties != null) {
        try {
            List<ComponentDefinition> possibleComponents = ComponentsUtils.getComponentService().getPossibleComponents(currentComponentProperties);
            if (component instanceof Component) {
                ComponentDefinition componentDefinition = ((Component) component).getComponentDefinition();
                return possibleComponents.contains(componentDefinition);
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return false;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) IComponent(org.talend.core.model.components.IComponent) Component(org.talend.designer.core.generic.model.Component) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Aggregations

RepositoryViewObject (org.talend.core.model.repository.RepositoryViewObject)7 RepositoryNode (org.talend.repository.model.RepositoryNode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ZipException (java.util.zip.ZipException)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 RepositoryObject (org.talend.core.model.repository.RepositoryObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1