Search in sources :

Example 1 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class UpdateAfterMergeTosApiTask method updateConnectionFile.

/**
 * DOC bZhou Comment method "addConnectionFileToUpdate".
 */
private void updateConnectionFile() {
    File rawDir = getWorkspacePath().append(EResourceConstant.METADATA.getPath()).toFile();
    ArrayList<File> fileList = new ArrayList<File>();
    if (rawDir.exists()) {
        getAllFilesFromFolder(rawDir, fileList, new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.endsWith(FactoriesUtil.ITEM_EXTENSION);
            }
        });
    }
    for (File file : fileList) {
        IFile iFile = WorkspaceUtils.fileToIFile(file);
        Property property = PropertyHelper.getProperty(iFile);
        if (property != null) {
            Item item = property.getItem();
            EResourceConstant type = EResourceConstant.getTypedConstant(item);
            if (type == EResourceConstant.DB_CONNECTIONS) {
                DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                DatabaseConnection connection = (DatabaseConnection) dbItem.getConnection();
                String otherParameter = ConnectionHelper.getOtherParameter(connection);
                if (!StringUtils.isBlank(otherParameter)) {
                    connection.setUiSchema(otherParameter);
                    EMFSharedResources.getInstance().saveResource(connection.eResource());
                }
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EResourceConstant(org.talend.resource.EResourceConstant) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 2 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class ResourceViewContentProvider method getRepositoryNodeChildren.

/**
 * DOC talend Comment method "getRepositoryNodeChildren".
 *
 * @param element
 * @param instance
 * @return
 * @throws PersistenceException
 * @throws CoreException
 */
private Object[] getRepositoryNodeChildren(Object element) throws PersistenceException, CoreException {
    final DQRepositoryNode node = (DQRepositoryNode) element;
    // MOD gdbu 2011-7-20 bug : 23220
    DQRepositoryNode.setIsReturnAllNodesWhenFiltering(false);
    List<IRepositoryNode> children = node.getChildren();
    DQRepositoryNode.setIsReturnAllNodesWhenFiltering(true);
    if ((node instanceof DBTableFolderRepNode || node instanceof DBViewFolderRepNode || node instanceof DBColumnFolderRepNode) && !DQRepositoryNode.isOnFilterring()) {
        if (0 < children.size()) {
            try {
                StructuredSelection structSel = new StructuredSelection(node);
                if (null != treeViewer) {
                    ISelection tempSelection = treeViewer.getSelection();
                    treeViewer.setSelection(structSel);
                    TreeItem[] selectionItems = treeViewer.getTree().getSelection();
                    if (0 != selectionItems.length) {
                        selectionItems[0].setText(node.getLabel());
                        treeViewer.setSelection(tempSelection);
                    }
                } else {
                    ISelection dqTreeSelection = RepositoryNodeHelper.getDQCommonViewer().getSelection();
                    RepositoryNodeHelper.getDQCommonViewer().setSelection(structSel);
                    TreeItem[] selections = RepositoryNodeHelper.getDQCommonViewer().getTree().getSelection();
                    if (0 != selections.length) {
                        selections[0].setText(node.getLabel());
                    }
                    RepositoryNodeHelper.getDQCommonViewer().setSelection(dqTreeSelection);
                }
            } catch (Exception e) {
                log.error(e.toString());
            }
        }
    }
    if (children.size() <= 0) {
        // ~23220
        List<EResourceConstant> resContants = new ArrayList<EResourceConstant>();
        IRepositoryViewObject viewObject = node.getObject();
        String label = viewObject == null ? null : viewObject.getLabel();
        if (EResourceConstant.DATA_PROFILING.getName().equals(label)) {
            resContants.add(EResourceConstant.ANALYSIS);
            if (PluginChecker.isTDQLoaded()) {
                resContants.add(EResourceConstant.REPORTS);
            }
        } else if (EResourceConstant.LIBRARIES.getName().equals(label)) {
            // MOD TDQ-10933 msjian 20150915: Hide the Exchange node
            if (!TalendPropertiesUtil.isHideExchange()) {
                resContants.add(EResourceConstant.EXCHANGE);
            }
            // TDQ-10933~
            resContants.add(EResourceConstant.INDICATORS);
            if (PluginChecker.isTDQLoaded()) {
                resContants.add(EResourceConstant.JRXML_TEMPLATE);
            }
            resContants.add(EResourceConstant.PATTERNS);
            resContants.add(EResourceConstant.RULES);
            resContants.add(EResourceConstant.SOURCE_FILES);
        } else if (EResourceConstant.METADATA.getName().equals(label)) {
            resContants.add(EResourceConstant.DB_CONNECTIONS);
            resContants.add(EResourceConstant.FILEDELIMITED);
            if (PluginChecker.isTDQLoaded() && HadoopClusterUtils.getDefault().isServiceInstalled()) {
                resContants.add(EResourceConstant.HADOOP_CLUSTER);
            }
        }
        if (resContants.size() > 0) {
            RepositoryNodeBuilder.getInstance().createRepositoryNodeSystemFolders(node, resContants, node.getProject());
        }
    } else {
        // to avoid can not get reference project nodes when open the select udi/pattern/rule dialog
        if (EResourceConstant.REFERENCED_PROJECT.getName().equals(node.getProperties(EProperties.LABEL))) {
            if (!ProxyRepositoryManager.getInstance().isMergeRefProject()) {
                for (IRepositoryNode refProjectNode : node.getChildren()) {
                    for (IRepositoryNode refProjectItemNode : refProjectNode.getChildren()) {
                        getRepositoryNodeChildren(refProjectItemNode);
                    }
                }
            }
        }
    }
    if (node instanceof ContextFolderRepNode) {
        children = ((ContextFolderRepNode) node).getChildren();
    }
    return sortRepositoryNode(children.toArray());
}
Also used : DBTableFolderRepNode(org.talend.dq.nodes.DBTableFolderRepNode) EResourceConstant(org.talend.resource.EResourceConstant) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreeItem(org.eclipse.swt.widgets.TreeItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) DBViewFolderRepNode(org.talend.dq.nodes.DBViewFolderRepNode) DBColumnFolderRepNode(org.talend.dq.nodes.DBColumnFolderRepNode) CoreException(org.eclipse.core.runtime.CoreException) MissingDriverException(org.talend.utils.exceptions.MissingDriverException) PersistenceException(org.talend.commons.exception.PersistenceException) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) ISelection(org.eclipse.jface.viewers.ISelection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ContextFolderRepNode(org.talend.dq.nodes.ContextFolderRepNode)

Example 3 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class ResourceDropAdapterAssistant method allowDND.

/**
 * DOC bZhou Comment method "allowDND".
 *
 * @param sourceFile
 * @param targetFolder
 * @return
 */
private boolean allowDND(IFile sourceFile, IFolder targetFolder) {
    ModelElement modelElement = ModelElementFileFactory.getModelElement(sourceFile);
    EResourceConstant typedConstant = EResourceConstant.getTypedConstant(modelElement);
    if (typedConstant != null) {
        IFolder oneFolder = ResourceManager.getOneFolder(typedConstant);
        return oneFolder == null ? false : ResourceService.isSubFolder(oneFolder, targetFolder);
    }
    return false;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EResourceConstant(org.talend.resource.EResourceConstant) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class ImportRemotePatternAction method doImportAfterDownload.

private void doImportAfterDownload(IJobChangeEvent event) {
    final List<ReturnCode> information = new ArrayList<ReturnCode>();
    setEnabled(true);
    if (fExtensionDownloaded > 0) {
        // $NON-NLS-1$
        String csvFormat = System.getProperty("talend.exchange.csv");
        if ("true".equals(csvFormat)) {
            // $NON-NLS-1$
            for (IEcosComponent componet : fInstalledComponents) {
                List<ImportObject> validImportObject = ImportObject.extractImportObject(componet, information);
                if (!validImportObject.isEmpty()) {
                    String categoryName = componet.getCategry().getName();
                    EEcosCategory ecosCategory = EEcosCategory.getEcosCategory(categoryName);
                    if (ecosCategory != null) {
                        EResourceConstant resourceType = ecosCategory.getResource();
                        for (ImportObject importObject : validImportObject) {
                            information.addAll(ImportFactory.doImport(resourceType, importObject, componet.getName()));
                        }
                    }
                }
            }
            // MOD qiongli 2011-11-28 TDQ-4038,give the message when there is nothing to import.
            if (information.isEmpty()) {
                information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportRemotePatternAction.NothingImport"), // $NON-NLS-1$
                false));
            }
            ImportInfoDialog.openImportInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("ImportRemotePatternAction.ImportFinish"), // $NON-NLS-1$
            information.toArray(new ReturnCode[0]));
            CorePlugin.getDefault().refreshDQView();
        } else {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    for (IEcosComponent componet : fInstalledComponents) {
                        try {
                            ImportFactory.importFromExchange(componet);
                        } catch (Exception e) {
                            ExceptionHandler.process(e);
                        }
                    }
                }
            });
        }
    }
}
Also used : EResourceConstant(org.talend.resource.EResourceConstant) ReturnCode(org.talend.utils.sugars.ReturnCode) EEcosCategory(org.talend.dataprofiler.core.helper.EEcosCategory) ArrayList(java.util.ArrayList) IEcosComponent(org.talend.dataprofiler.ecos.model.IEcosComponent) IOException(java.io.IOException)

Example 5 with EResourceConstant

use of org.talend.resource.EResourceConstant in project tdq-studio-se by Talend.

the class PropertyHelper method computePath.

/**
 * DOC bZhou Comment method "computePath".
 *
 * @param property
 * @param file
 * @return
 */
public static String computePath(Property property, File file) {
    IPath filePath = new Path(file.getAbsolutePath()).setDevice(null);
    boolean isConnFromOld = file.getAbsolutePath().contains(EResourceConstant.OLD_METADATA.getName());
    int flag = 0;
    EResourceConstant typedConstant = EResourceConstant.getTypedConstant(property.getItem());
    if (typedConstant != null && !isConnFromOld) {
        String typedName = typedConstant.getName();
        for (int i = 0; i < filePath.segmentCount(); i++) {
            String seg = filePath.segment(i);
            if (seg.equals(typedName)) {
                flag = i + 1;
                break;
            }
        }
    } else {
        List<EResourceConstant> typedConstantList = EResourceConstant.getTypedConstantList();
        typedConstantList.add(EResourceConstant.OLD_DB_CONNECTIONS);
        typedConstantList.add(EResourceConstant.OLD_MDM_CONNECTIONS);
        for (int i = 0; i < filePath.segmentCount() && flag == 0; i++) {
            String seg = filePath.segment(i);
            for (EResourceConstant constant : typedConstantList) {
                if (seg.equals(constant.getName())) {
                    flag = i + 1;
                    break;
                }
            }
        }
    }
    IPath statPath = filePath.removeFirstSegments(flag).removeLastSegments(1);
    return statPath.toString();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) EResourceConstant(org.talend.resource.EResourceConstant) IPath(org.eclipse.core.runtime.IPath)

Aggregations

EResourceConstant (org.talend.resource.EResourceConstant)11 ArrayList (java.util.ArrayList)5 File (java.io.File)4 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 Item (org.talend.core.model.properties.Item)3 Property (org.talend.core.model.properties.Property)3 FilenameFilter (java.io.FilenameFilter)2 IFolder (org.eclipse.core.resources.IFolder)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)2 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)2 IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1