Search in sources :

Example 11 with IRepositoryViewObject

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

the class UpdateMainParameterCommand method execute.

@Override
public void execute() {
    if (result == null) {
        return;
    }
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof IProcess2) {
        Process process = (Process) job;
        EComponentCategory category = null;
        IUpdateItemType updateType = result.getUpdateType();
        if (updateType instanceof EUpdateItemType) {
            switch((EUpdateItemType) updateType) {
                case JOB_PROPERTY_EXTRA:
                    category = EComponentCategory.EXTRA;
                    break;
                case JOB_PROPERTY_STATS_LOGS:
                    category = EComponentCategory.STATSANDLOGS;
                    break;
                case JOB_PROPERTY_HEADERFOOTER:
                    category = EComponentCategory.HEADERFOOTER;
                    break;
                case JOB_PROPERTY_STORM:
                    if (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.SPARK_JOB_CONFIG;
                    }
                    break;
                case JOB_PROPERTY_MAPREDUCE:
                    if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP;
                    } else if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.SPARK_JOB_CONFIG;
                    }
                    break;
                default:
            }
            if (category == EComponentCategory.HEADERFOOTER) {
                if (result.getResultType() == EUpdateResult.UPDATE) {
                    if (result.isChecked()) {
                        for (IElementParameter param : process.getElementParameters()) {
                            if (param.getCategory() == EComponentCategory.HEADERFOOTER) {
                                IElementParameter headerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_HEADERID.getName());
                                if (headerIDParameter != null) {
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) headerIDParameter.getValue());
                                    HeaderFooterConnection repositoryConnection = null;
                                    if (lastVersion != null) {
                                        final Item item = lastVersion.getProperty().getItem();
                                        if (item != null && item instanceof ConnectionItem) {
                                            repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
                                            if (repositoryConnection != null) {
                                                Boolean isHeader = repositoryConnection.isIsHeader();
                                                String libraries = repositoryConnection.getLibraries();
                                                String mainCode = repositoryConnection.getMainCode();
                                                String imports = repositoryConnection.getImports();
                                                process.getElementParameter(EParameterName.HEADER_ENABLED.getName()).setValue(isHeader);
                                                process.getElementParameter(EParameterName.HEADER_LIBRARY.getName()).setValue(libraries);
                                                process.getElementParameter(EParameterName.HEADER_CODE.getName()).setValue(mainCode);
                                                process.getElementParameter(EParameterName.HEADER_IMPORT.getName()).setValue(imports);
                                            }
                                        }
                                    }
                                }
                                IElementParameter footerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_FOOTERID.getName());
                                if (footerIDParameter != null) {
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) footerIDParameter.getValue());
                                    HeaderFooterConnection repositoryConnection = null;
                                    if (lastVersion != null) {
                                        final Item item = lastVersion.getProperty().getItem();
                                        if (item != null && item instanceof ConnectionItem) {
                                            repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
                                            if (repositoryConnection != null) {
                                                Boolean isHeader = repositoryConnection.isIsHeader();
                                                String libraries = repositoryConnection.getLibraries();
                                                String mainCode = repositoryConnection.getMainCode();
                                                String imports = repositoryConnection.getImports();
                                                process.getElementParameter(EParameterName.FOOTER_ENABLED.getName()).setValue(!isHeader);
                                                process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName()).setValue(libraries);
                                                process.getElementParameter(EParameterName.FOOTER_CODE.getName()).setValue(mainCode);
                                                process.getElementParameter(EParameterName.FOOTER_IMPORT.getName()).setValue(imports);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (category != null) {
                boolean repository = false;
                if (result.getResultType() == EUpdateResult.UPDATE) {
                    // upgrade from repository
                    if (result.isChecked()) {
                        IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
                        if (property != null) {
                            Map<String, IElementParameter> childParameters = property.getChildParameters();
                            if (childParameters != null) {
                                IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
                                // is repository
                                if (elementParameter != null && EmfComponent.REPOSITORY.equals(elementParameter.getValue())) {
                                    for (IElementParameter param : process.getElementParameters()) {
                                        if (param.getCategory() != category) {
                                            continue;
                                        }
                                        String repositoryValue = param.getRepositoryValue();
                                        if (param.isShow(process.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName()))) {
                                            Object objectValue = RepositoryToComponentProperty.getValue((org.talend.core.model.metadata.builder.connection.Connection) result.getParameter(), repositoryValue, null);
                                            if (objectValue != null) {
                                                if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
                                                    boolean found = false;
                                                    String[] items = param.getListRepositoryItems();
                                                    for (int i = 0; (i < items.length) && (!found); i++) {
                                                        if (objectValue.equals(items[i])) {
                                                            found = true;
                                                            process.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                                                        }
                                                    }
                                                } else if (EParameterName.HADOOP_ADVANCED_PROPERTIES.getName().equals(param.getName()) || EParameterName.SPARK_ADVANCED_PROPERTIES.getName().equals(param.getName())) {
                                                    List<Map> list = (ArrayList) param.getValue();
                                                    for (Map map : list) {
                                                        if (map.get("BUILDIN") != null && map.get("BUILDIN").equals("TRUE")) {
                                                            if (objectValue instanceof List) {
                                                                ((List) objectValue).add(map);
                                                            }
                                                        }
                                                    }
                                                    process.setPropertyValue(param.getName(), objectValue);
                                                } else {
                                                    process.setPropertyValue(param.getName(), objectValue);
                                                }
                                                param.setRepositoryValueUsed(true);
                                                param.setReadOnly(true);
                                                repository = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
                Map<String, IElementParameter> childParameters = null;
                if (property != null) {
                    childParameters = property.getChildParameters();
                }
                if (!repository) {
                    if (childParameters != null) {
                        IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
                        elementParameter.setValue(EmfComponent.BUILTIN);
                    }
                    // built-in
                    IElementParameter dbTypeParam = null;
                    IElementParameter impliciteDbType = null;
                    for (IElementParameter param : process.getElementParameters()) {
                        if (param.getCategory() != category) {
                            continue;
                        }
                        String repositoryValue = param.getRepositoryValue();
                        if (param.isShow(process.getElementParameters()) && (repositoryValue != null)) {
                            // for mysql db verion
                            if (EParameterName.DB_TYPE.getName().equals(param.getName()) && "TYPE".equals(repositoryValue)) {
                                dbTypeParam = param;
                            }
                            if ("DB_TYPE_IMPLICIT_CONTEXT".equals(param.getName()) && "TYPE".equals(repositoryValue)) {
                                impliciteDbType = param;
                            }
                            if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && dbTypeParam != null && dbTypeParam.getValue() != null) {
                                final int indexOfItem = dbTypeParam.getIndexOfItemFromList(dbTypeParam.getValue().toString());
                                String dbType = dbTypeParam.getListItemsDisplayCodeName()[indexOfItem];
                                setDBVersionForMysql(param, dbType);
                            } else if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && impliciteDbType != null && impliciteDbType.getValue() != null) {
                                final int indexOfItem = impliciteDbType.getIndexOfItemFromList(impliciteDbType.getValue().toString());
                                String dbType = impliciteDbType.getListItemsDisplayCodeName()[indexOfItem];
                                setDBVersionForMysql(param, dbType);
                            }
                            param.setRepositoryValueUsed(false);
                            param.setReadOnly(false);
                        }
                    }
                } else {
                    if (childParameters != null) {
                        IElementParameter elementParameter = childParameters.get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) elementParameter.getValue());
                        ConnectionContextHelper.addContextForProcessParameter(process, connItem, category, false);
                    }
                }
            }
        }
    // else { // for extension
    }
}
Also used : HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) ArrayList(java.util.ArrayList) Process(org.talend.designer.core.ui.editor.process.Process) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) EComponentCategory(org.talend.core.model.process.EComponentCategory)

Example 12 with IRepositoryViewObject

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

the class ValidationRulesUtil method getComponentsFromItemId.

/**
     * DOC ycbai Comment method "getComponentsFromItemId". modify from method getAppropriateComponent() of
     * TalendEditorDropTargetListener.
     * 
     * @param itemId
     * @param type
     * @param quickCreateInput
     * @param quickCreateOutput
     * @return
     */
public static IComponent getComponentsFromItemId(String itemId, ERepositoryObjectType type, boolean quickCreateInput, boolean quickCreateOutput) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IRepositoryViewObject obj = null;
    try {
        obj = factory.getLastVersion(itemId);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (obj == null) {
        return null;
    }
    Item item = obj.getProperty().getItem();
    if (item == null) {
        return null;
    }
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
    String componentName = null;
    if (item instanceof JobletProcessItem) {
        // joblet
        componentName = item.getProperty().getLabel();
    } else if (name == null) {
        return null;
    } else {
        // tRunjob
        componentName = name.getDefaultComponentName();
    }
    // tRunJob is special from our rules
    if (name == EDatabaseComponentName.RunJob || item instanceof JobletProcessItem) {
        return ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    } else {
        // for database, file, webservices, saleforce ...
        List<IComponent> neededComponents = filterNeededComponents(item, type);
        IComponent component = chooseOneComponent(neededComponents, name, quickCreateInput, quickCreateOutput);
        return component;
    }
}
Also used : HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) WSDLSchemaConnectionItem(org.talend.core.model.properties.WSDLSchemaConnectionItem) Item(org.talend.core.model.properties.Item) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) EDatabaseComponentName(org.talend.designer.core.ui.editor.process.EDatabaseComponentName) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 13 with IRepositoryViewObject

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

the class ValidationRulesUtil method getRelatedValidationRuleObjs.

public static List<IRepositoryViewObject> getRelatedValidationRuleObjs(String schemaId) {
    List<IRepositoryViewObject> rulesObjs = new ArrayList<IRepositoryViewObject>();
    if (schemaId != null) {
        try {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<IRepositoryViewObject> members = factory.getAll(ERepositoryObjectType.METADATA_VALIDATION_RULES);
            if (members != null && members.size() > 0) {
                for (IRepositoryViewObject member : members) {
                    if (member != null && member.getProperty() != null) {
                        Item item = member.getProperty().getItem();
                        if (item != null && item instanceof ValidationRulesConnectionItem) {
                            ValidationRulesConnectionItem validItem = (ValidationRulesConnectionItem) item;
                            ValidationRulesConnection connection = (ValidationRulesConnection) validItem.getConnection();
                            if (connection != null && !rulesObjs.contains(member)) {
                                rulesObjs.add(member);
                            }
                        }
                    }
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
    return rulesObjs;
}
Also used : ValidationRulesConnection(org.talend.core.model.metadata.builder.connection.ValidationRulesConnection) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) WSDLSchemaConnectionItem(org.talend.core.model.properties.WSDLSchemaConnectionItem) Item(org.talend.core.model.properties.Item) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 14 with IRepositoryViewObject

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

the class ValidationRulesUtil method getCurrentValidationRuleObjs.

public static IRepositoryViewObject getCurrentValidationRuleObjs(IElement element) {
    IElementParameter param = element.getElementParameter(EParameterName.VALIDATION_RULES.getName());
    if (param == null || param.getValue() == null || (Boolean) param.getValue() == false) {
        return null;
    }
    param = element.getElementParameter(EParameterFieldType.VALIDATION_RULE_TYPE.getName());
    if (param == null) {
        return null;
    }
    param = param.getChildParameters().get(EParameterName.REPOSITORY_VALIDATION_RULE_TYPE.getName());
    if (param != null && param.getValue() != null) {
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        String linkedRepository = (String) param.getValue();
        try {
            IRepositoryViewObject object = factory.getLastVersion(linkedRepository);
            if (object == null) {
                return null;
            }
            return object;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
    return null;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 15 with IRepositoryViewObject

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

the class JobErrorsChecker method getErrors.

public static List<IContainerEntry> getErrors() {
    List<IContainerEntry> input = new ArrayList<IContainerEntry>();
    try {
        Item item = null;
        IProxyRepositoryFactory proxyRepositoryFactory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        Set<String> jobIds = new HashSet<String>();
        for (JobInfo jobInfo : LastGenerationInfo.getInstance().getLastGeneratedjobs()) {
            // TDI-28198:get right process item no matter the job open or close
            List<IRepositoryViewObject> allVersions = proxyRepositoryFactory.getAllVersion(jobInfo.getJobId());
            for (IRepositoryViewObject repositoryObject2 : allVersions) {
                Property property2 = repositoryObject2.getProperty();
                if (jobInfo.getJobVersion().equals(property2.getVersion())) {
                    item = property2.getItem();
                    break;
                }
            }
            if (item == null) {
                continue;
            }
            // get source file
            IFile sourceFile = synchronizer.getFile(item);
            if (sourceFile == null) {
                continue;
            }
            jobIds.add(item.getProperty().getId());
            // Property property = process.getProperty();
            Problems.addJobRoutineFile(sourceFile, ProblemType.JOB, item, true);
        }
        if (!CommonsPlugin.isHeadless()) {
            List<IRepositoryViewObject> routinesObjects = proxyRepositoryFactory.getAll(ERepositoryObjectType.ROUTINES, false);
            Set<String> dependentRoutines = LastGenerationInfo.getInstance().getRoutinesNeededWithSubjobPerJob(LastGenerationInfo.getInstance().getLastMainJob().getJobId(), LastGenerationInfo.getInstance().getLastMainJob().getJobVersion());
            if (routinesObjects != null) {
                for (IRepositoryViewObject obj : routinesObjects) {
                    Property property = obj.getProperty();
                    if (dependentRoutines.contains(property.getLabel())) {
                        Item routinesitem = property.getItem();
                        IFile routineFile = synchronizer.getFile(routinesitem);
                        Problems.addJobRoutineFile(routineFile, ProblemType.ROUTINE, routinesitem, true);
                    } else {
                        Problems.clearAllComliationError(property.getLabel());
                    }
                }
            }
        }
        Problems.refreshProblemTreeView();
        // collect error
        List<Problem> errors = Problems.getProblemList().getProblemsBySeverity(ProblemStatus.ERROR);
        ErrorDetailTreeBuilder builder = new ErrorDetailTreeBuilder();
        input.addAll(builder.createTreeInput(errors, jobIds));
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return input;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) JobInfo(org.talend.core.model.process.JobInfo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TalendProblem(org.talend.core.model.process.TalendProblem) Problem(org.talend.core.model.process.Problem) IContainerEntry(org.talend.core.model.process.IContainerEntry) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Aggregations

IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)222 PersistenceException (org.talend.commons.exception.PersistenceException)115 Item (org.talend.core.model.properties.Item)86 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)67 ArrayList (java.util.ArrayList)63 ConnectionItem (org.talend.core.model.properties.ConnectionItem)54 ProcessItem (org.talend.core.model.properties.ProcessItem)54 RepositoryNode (org.talend.repository.model.RepositoryNode)50 IElementParameter (org.talend.core.model.process.IElementParameter)43 Property (org.talend.core.model.properties.Property)43 IRepositoryNode (org.talend.repository.model.IRepositoryNode)33 List (java.util.List)32 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)32 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)31 INode (org.talend.core.model.process.INode)30 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)25 Node (org.talend.designer.core.ui.editor.nodes.Node)25 Connection (org.talend.core.model.metadata.builder.connection.Connection)23 CoreException (org.eclipse.core.runtime.CoreException)17 RoutineItem (org.talend.core.model.properties.RoutineItem)17