Search in sources :

Example 1 with ImportItem

use of org.talend.repository.items.importexport.handlers.model.ImportItem in project tdi-studio-se by Talend.

the class JobDesignImportHandler method afterApplyMigrationTasks.

@Override
protected void afterApplyMigrationTasks(ImportItem importItem) throws Exception {
    Item tmpItem = importItem.getItem();
    if (tmpItem instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) tmpItem;
        ParametersType paType = processItem.getProcess().getParameters();
        boolean statsPSettingRemoved = false;
        // for commanline import project setting
        if (importItem.isRemoveProjectStatslog()) {
            if (paType != null) {
                //$NON-NLS-1$
                String paramName = "STATANDLOG_USE_PROJECT_SETTINGS";
                EList listParamType = paType.getElementParameter();
                for (int j = 0; j < listParamType.size(); j++) {
                    ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                    if (pType != null && paramName.equals(pType.getName())) {
                        pType.setValue(Boolean.FALSE.toString());
                        statsPSettingRemoved = true;
                        break;
                    }
                }
            }
        }
        // 14446: item apply project setting param if use project setting
        String statslogUsePSetting = null;
        String implicitUsePSetting = null;
        if (paType != null) {
            EList listParamType = paType.getElementParameter();
            for (int j = 0; j < listParamType.size(); j++) {
                ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                if (pType != null) {
                    if (!statsPSettingRemoved && "STATANDLOG_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                        //$NON-NLS-1$
                        statslogUsePSetting = pType.getValue();
                    }
                    if ("IMPLICITCONTEXT_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                        //$NON-NLS-1$
                        implicitUsePSetting = pType.getValue();
                    }
                    if (statsPSettingRemoved && implicitUsePSetting != null || !statsPSettingRemoved && implicitUsePSetting != null && statslogUsePSetting != null) {
                        break;
                    }
                }
            }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
            IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
            if (statslogUsePSetting != null && Boolean.parseBoolean(statslogUsePSetting)) {
                //$NON-NLS-1$
                designerCoreService.reloadParamFromProjectSettings(paType, "STATANDLOG_USE_PROJECT_SETTINGS");
            }
            if (implicitUsePSetting != null && Boolean.parseBoolean(implicitUsePSetting)) {
                //$NON-NLS-1$
                designerCoreService.reloadParamFromProjectSettings(paType, "IMPLICITCONTEXT_USE_PROJECT_SETTINGS");
            }
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) EList(org.eclipse.emf.common.util.EList) ProcessItem(org.talend.core.model.properties.ProcessItem) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService)

Example 2 with ImportItem

use of org.talend.repository.items.importexport.handlers.model.ImportItem in project tdi-studio-se by Talend.

the class SqlTemplateImportHandler method isValidSystemItem.

@Override
public boolean isValidSystemItem(ImportItem importItem) {
    boolean valid = super.valid(importItem);
    if (!valid) {
        return false;
    }
    Item item = importItem.getItem();
    if (item instanceof SQLPatternItem) {
        if (isSystemItem(item)) {
            return true;
        }
    }
    return false;
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) Item(org.talend.core.model.properties.Item) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Example 3 with ImportItem

use of org.talend.repository.items.importexport.handlers.model.ImportItem in project tdi-studio-se by Talend.

the class TalendImportUtil method populateItems.

private static List<ImportItem> populateItems(final ImportExportHandlersManager importManager, final ResourcesManager resourcesManager, IProgressMonitor monitor, final boolean overwrite) {
    List<ImportItem> selectedItemRecords = new ArrayList<ImportItem>();
    nodesBuilder.clear();
    if (resourcesManager != null) {
        // if resource is not init successfully.
        try {
            // List<ImportItem> items = importManager.populateImportingItems(resourcesManager, overwrite,
            // new NullProgressMonitor(), true);
            List<ImportItem> items = importManager.populateImportingItems(resourcesManager, overwrite, monitor, true);
            nodesBuilder.addItems(items);
        } catch (Exception e) {
            CommonExceptionHandler.process(e);
        }
    }
    ImportItem[] allImportItemRecords = nodesBuilder.getAllImportItemRecords();
    selectedItemRecords.addAll(Arrays.asList(allImportItemRecords));
    Iterator<ImportItem> itemIterator = selectedItemRecords.iterator();
    while (itemIterator.hasNext()) {
        ImportItem item = itemIterator.next();
        if (!item.isValid()) {
            itemIterator.remove();
        }
    }
    return selectedItemRecords;
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 4 with ImportItem

use of org.talend.repository.items.importexport.handlers.model.ImportItem in project tdi-studio-se by Talend.

the class ImportDemoProjectItemsPage method clearOverWriteErrorMessages.

private void clearOverWriteErrorMessages(List<ImportItem> projectRecords, boolean overwrite) {
    if (overwrite) {
        String overWriteErrorMessage = Messages.getString("RepositoryUtil.nameUsed").trim();
        List<ImportItem> overWriteRecords = new ArrayList<ImportItem>();
        for (ImportItem itemRecord : projectRecords) {
            for (String errorMessage : itemRecord.getErrors()) {
                if (errorMessage.equals(overWriteErrorMessage)) {
                    overWriteRecords.add(itemRecord);
                }
            }
        }
        for (ImportItem overRecord : overWriteRecords) {
            overRecord.getErrors().clear();
        }
    }
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) ArrayList(java.util.ArrayList)

Example 5 with ImportItem

use of org.talend.repository.items.importexport.handlers.model.ImportItem 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)

Aggregations

ImportItem (org.talend.repository.items.importexport.handlers.model.ImportItem)16 ImportExportHandlersManager (org.talend.repository.items.importexport.handlers.ImportExportHandlersManager)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 Before (org.junit.Before)7 Item (org.talend.core.model.properties.Item)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ResourcesManager (org.talend.repository.items.importexport.manager.ResourcesManager)4 ProcessItem (org.talend.core.model.properties.ProcessItem)3 FileNotFoundException (java.io.FileNotFoundException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ZipException (java.util.zip.ZipException)2 ZipFile (java.util.zip.ZipFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 RoutineItem (org.talend.core.model.properties.RoutineItem)2 File (java.io.File)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1