Search in sources :

Example 26 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class SetupProcessDependenciesRoutinesDialog method init.

@SuppressWarnings("unchecked")
private void init(ProcessType process) {
    allRoutineItems.clear();
    ProjectManager projectManager = ProjectManager.getInstance();
    Project currentProject = projectManager.getCurrentProject();
    initModels(currentProject);
    Set<Project> referenceProjects = new HashSet<Project>();
    this.getAllReferenceProjects(currentProject, referenceProjects);
    initRefProjects(referenceProjects);
    List<RoutinesParameterType> routinesDependencies = process.getParameters().getRoutinesParameter();
    List<String> typeNames = new ArrayList<String>();
    for (RoutinesParameterType type : routinesDependencies) {
        RoutineItemRecord record = new RoutineItemRecord();
        record.setName(type.getName());
        Property property = findObject(type.getId(), type.getName());
        if (property != null) {
            // if system, id is not used
            record.setId(property.getId());
            record.setLabel(property.getLabel());
        } else {
            record.setHasProblem(true);
            // use the record
            record.setLabel(type.getName());
        }
        if (!record.hasProblem()) {
            // if lost, willn't display
            if (((RoutineItem) property.getItem()).isBuiltIn()) {
                systemRoutines.add(record);
            } else {
                if (typeNames.contains(type.getName())) {
                    break;
                } else {
                    typeNames.add(type.getName());
                    userRoutines.add(record);
                }
            }
        }
    }
}
Also used : Project(org.talend.core.model.general.Project) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) Property(org.talend.core.model.properties.Property) ProjectManager(org.talend.repository.ProjectManager) HashSet(java.util.HashSet)

Example 27 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class SetupProcessDependenciesRoutinesDialog method initModels.

private void initModels(Project project) {
    try {
        IProxyRepositoryFactory proxyRepositoryFactory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
        List<IRepositoryViewObject> allRoutineItemObjects = proxyRepositoryFactory.getAll(project, ERepositoryObjectType.ROUTINES, RoutinesUtil.allowDeletedRoutine());
        allRoutineItemObjects.addAll(proxyRepositoryFactory.getAll(project, ERepositoryObjectType.PIG_UDF, RoutinesUtil.allowDeletedRoutine()));
        for (IRepositoryViewObject obj : allRoutineItemObjects) {
            Property property = obj.getProperty();
            if (project.equals(ProjectManager.getInstance().getCurrentProject())) {
                addItems(project, property);
            } else {
                // don't add system routines in ref-project
                if (property.getItem() instanceof RoutineItem && !((RoutineItem) property.getItem()).isBuiltIn()) {
                    addItems(project, property);
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RoutineItem(org.talend.core.model.properties.RoutineItem) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 28 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class SetupProcessDependenciesRoutinesDialog method findObject.

private Property findObject(String idOrName, String name) {
    for (Project p : allRoutineItems.keySet()) {
        List<Property> list = allRoutineItems.get(p);
        if (list != null) {
            for (Property property : list) {
                String objIdOrName = property.getId();
                String objName = property.getLabel();
                // objIdOrName = property.getLabel();
                if (objIdOrName != null && objIdOrName.equals(idOrName) && property.getItem() instanceof RoutineItem) {
                    return property;
                } else if (objName != null && objName.equals(name) && property.getItem() instanceof RoutineItem) {
                    return property;
                }
            }
        }
    }
    return null;
}
Also used : Project(org.talend.core.model.general.Project) RoutineItem(org.talend.core.model.properties.RoutineItem) Property(org.talend.core.model.properties.Property)

Example 29 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class EditPropertiesAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = selection.size() == 1;
    if (canWork) {
        Object o = selection.getFirstElement();
        if (o instanceof IRepositoryNode) {
            IRepositoryNode node = (IRepositoryNode) o;
            switch(node.getType()) {
                case REPOSITORY_ELEMENT:
                    if (node.getObjectType() == ERepositoryObjectType.BUSINESS_PROCESS || node.getObjectType() == ERepositoryObjectType.PROCESS) {
                        canWork = true;
                    } else if (node.getObjectType() == ERepositoryObjectType.ROUTINES) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof RoutineItem) {
                            canWork = !((RoutineItem) item).isBuiltIn();
                        } else {
                            canWork = false;
                        }
                    } else if (node.getObjectType() == ERepositoryObjectType.SQLPATTERNS) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof SQLPatternItem) {
                            canWork = !((SQLPatternItem) item).isSystem();
                        } else {
                            canWork = false;
                        }
                    } else if (node.getObjectType() == ERepositoryObjectType.JOB_SCRIPT) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof JobScriptItem) {
                            canWork = true;
                        } else {
                            canWork = false;
                        }
                    } else {
                        canWork = isInstanceofCamelRoutes(node.getObjectType()) || isInstanceofCamelBeans(node.getObjectType());
                    }
                    break;
                default:
                    canWork = false;
                    break;
            }
            if (canWork) {
                canWork = (node.getObject().getRepositoryStatus() != ERepositoryStatus.DELETED);
            }
            if (canWork) {
                canWork = isLastVersion(node);
            }
        }
    }
    setEnabled(canWork);
}
Also used : Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Example 30 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class ImportItemUtil method importItemRecords.

@SuppressWarnings("unchecked")
public List<ItemRecord> importItemRecords(final ResourcesManager manager, final List<ItemRecord> itemRecords, final IProgressMonitor monitor, final boolean overwrite, final IPath destinationPath, final String contentType) {
    TimeMeasure.display = CommonsPlugin.isDebugMode();
    TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
    TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    TimeMeasure.begin("importItemRecords");
    hasJoblets = false;
    statAndLogsSettingsReloaded = false;
    implicitSettingsReloaded = false;
    restoreFolder = new RestoreFolderUtil();
    Collections.sort(itemRecords, new Comparator<ItemRecord>() {

        @Override
        public int compare(ItemRecord o1, ItemRecord o2) {
            if (o1.getProperty().getItem() instanceof RoutineItem && o2.getProperty().getItem() instanceof RoutineItem) {
                return 0;
            } else if (!(o1.getProperty().getItem() instanceof RoutineItem) && !(o2.getProperty().getItem() instanceof RoutineItem)) {
                // TUP-2548 sort items by label
                String label = o1.getLabel();
                if (label == null) {
                    return -1;
                }
                final String label2 = o2.getLabel();
                if (label2 == null) {
                    return 1;
                }
                return label.compareTo(label2);
            } else if (o1.getProperty().getItem() instanceof RoutineItem) {
                return -1;
            } else {
                return 1;
            }
        }
    });
    //$NON-NLS-1$
    monitor.beginTask(Messages.getString("ImportItemWizardPage.ImportSelectedItems"), itemRecords.size() * 2 + 1);
    RepositoryWorkUnit repositoryWorkUnit = new //$NON-NLS-1$
    RepositoryWorkUnit(//$NON-NLS-1$
    "Import Items") {

        @Override
        public void run() throws PersistenceException {
            final IWorkspaceRunnable op = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    final IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                    // bug 10520
                    final Set<String> overwriteDeletedItems = new HashSet<String>();
                    final Set<String> idDeletedBeforeImport = new HashSet<String>();
                    Map<String, String> nameToIdMap = new HashMap<String, String>();
                    for (ItemRecord itemRecord : itemRecords) {
                        if (!monitor.isCanceled()) {
                            if (itemRecord.isValid()) {
                                if (itemRecord.getState() == State.ID_EXISTED) {
                                    String id = nameToIdMap.get(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString());
                                    if (id == null) {
                                        /*
                                             * if id exsist then need to genrate new id for this job,in this case the
                                             * job won't override the old one
                                             */
                                        id = EcoreUtil.generateUUID();
                                        nameToIdMap.put(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString(), id);
                                    }
                                    itemRecord.getProperty().setId(id);
                                }
                            }
                        }
                    }
                    for (ItemRecord itemRecord : itemRecords) {
                        if (!monitor.isCanceled()) {
                            if (itemRecord.isValid()) {
                                importItemRecord(manager, itemRecord, overwrite, destinationPath, overwriteDeletedItems, idDeletedBeforeImport, contentType, monitor);
                                IRepositoryViewObject object;
                                try {
                                    Property property = itemRecord.getProperty();
                                    if (property == null) {
                                        object = factory.getSpecificVersion(itemRecord.getItemId(), itemRecord.getItemVersion(), true);
                                        property = object.getProperty();
                                    }
                                    RelationshipItemBuilder.getInstance().addOrUpdateItem(property.getItem(), true);
                                    itemRecord.setProperty(null);
                                    ProxyRepositoryFactory.getInstance().unloadResources(property);
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                                statAndLogsSettingsReloaded = false;
                                implicitSettingsReloaded = false;
                                monitor.worked(1);
                            }
                        }
                    }
                    // deploy routines Jar
                    if (!getRoutineExtModulesMap().isEmpty()) {
                        Set<String> extRoutines = new HashSet<String>();
                        for (String id : getRoutineExtModulesMap().keySet()) {
                            Set<String> set = getRoutineExtModulesMap().get(id);
                            if (set != null) {
                                extRoutines.addAll(set);
                            }
                        }
                        if (manager instanceof ProviderManager || manager instanceof ZipFileManager) {
                            deployJarToDesForArchive(manager, extRoutines);
                        } else {
                            deployJarToDes(manager, extRoutines);
                        }
                    }
                    if (PluginChecker.isJobLetPluginLoaded()) {
                        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                        if (service != null) {
                            service.loadComponentsFromProviders();
                        }
                    }
                    checkDeletedFolders();
                    monitor.done();
                    TimeMeasure.step("importItemRecords", "before save");
                    if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
                        RelationshipItemBuilder.getInstance().saveRelations();
                        TimeMeasure.step("importItemRecords", "save relations");
                    } else {
                        // with relations
                        try {
                            factory.saveProject(ProjectManager.getInstance().getCurrentProject());
                        } catch (PersistenceException e) {
                            throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Import errors", e));
                        }
                        TimeMeasure.step("importItemRecords", "save project");
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update 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(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
            // ?
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    repositoryWorkUnit.setUnloadResourcesAfterRun(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    monitor.done();
    // for (ItemRecord itemRecord : itemRecords) {
    // itemRecord.clear();
    // }
    clearAllData();
    if (hasJoblets) {
        ComponentsFactoryProvider.getInstance().resetSpecificComponents();
    }
    TimeMeasure.end("importItemRecords");
    TimeMeasure.display = false;
    TimeMeasure.displaySteps = false;
    TimeMeasure.measureActive = false;
    return itemRecords;
}
Also used : Status(org.eclipse.core.runtime.Status) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) RoutineItem(org.talend.core.model.properties.RoutineItem) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RestoreFolderUtil(org.talend.core.repository.ui.actions.RestoreFolderUtil) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Aggregations

RoutineItem (org.talend.core.model.properties.RoutineItem)39 PersistenceException (org.talend.commons.exception.PersistenceException)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)13 Item (org.talend.core.model.properties.Item)12 Property (org.talend.core.model.properties.Property)12 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)9 CoreException (org.eclipse.core.runtime.CoreException)8 ProcessItem (org.talend.core.model.properties.ProcessItem)8 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)7 IMPORTType (org.talend.designer.core.model.utils.emf.component.IMPORTType)7 Project (org.talend.core.model.general.Project)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 HashSet (java.util.HashSet)5 PartInitException (org.eclipse.ui.PartInitException)5 SystemException (org.talend.commons.exception.SystemException)5 List (java.util.List)4