Search in sources :

Example 11 with SQLPatternItem

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

the class OpenExistVersionProcessWizard method getEditorInput.

protected RepositoryEditorInput getEditorInput(final Item item, final boolean readonly, final IWorkbenchPage page) throws SystemException {
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        return new ProcessEditorInput(processItem, true, false, readonly);
    } else if (item instanceof BusinessProcessItem) {
        BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
        IFile file = CorePlugin.getDefault().getDiagramModelService().getDiagramFileAndUpdateResource(page, businessProcessItem);
        return new RepositoryEditorInput(file, businessProcessItem);
    } else if (item instanceof RoutineItem) {
        final RoutineItem routineItem = (RoutineItem) item;
        final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        ITalendSynchronizer routineSynchronizer = codeGenService.createRoutineSynchronizer();
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        String lastVersion = factory.getLastVersion(routineItem.getProperty().getId()).getVersion();
        String curVersion = routineItem.getProperty().getVersion();
        routineSynchronizer.syncRoutine(routineItem, true, true);
        final IFile file;
        if (curVersion != null && curVersion.equals(lastVersion)) {
            file = routineSynchronizer.getFile(routineItem);
        } else {
            file = routineSynchronizer.getRoutinesFile(routineItem);
        }
        if (file != null) {
            return new RoutineEditorInput(file, routineItem);
        }
    } else if (item instanceof SQLPatternItem) {
        SQLPatternItem patternItem = (SQLPatternItem) item;
        final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        ISQLPatternSynchronizer SQLPatternSynchronizer = codeGenService.getSQLPatternSynchronizer();
        SQLPatternSynchronizer.syncSQLPattern(patternItem, true);
        IFile file = SQLPatternSynchronizer.getSQLPatternFile(patternItem);
        if (file != null) {
            return new RepositoryEditorInput(file, patternItem);
        }
    }
    return null;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) RoutineEditorInput(org.talend.repository.ui.actions.routines.RoutineEditorInput) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem)

Example 12 with SQLPatternItem

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

the class SaveAsSQLPatternWizard method performFinish.

public boolean performFinish() {
    boolean ok = false;
    try {
        isUpdate = isUpdate();
        if (isUpdate) {
            assginVlaues(oldProperty, property);
            repositoryFactory.save(oldSqlpatternItem);
            // assign value
            sqlpatternItem = oldSqlpatternItem;
        } else {
            property.setId(repositoryFactory.getNextId());
            // copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
            SQLPatternItem oldItem = (SQLPatternItem) repositoryEditorInput.getItem();
            ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
            byteArray.setInnerContent(oldItem.getContent().getInnerContent());
            sqlpatternItem.setContent(byteArray);
            // don't need to add depended routines.
            repositoryFactory.create(sqlpatternItem, mainPage.getDestinationPath());
        }
        ok = true;
    } catch (Exception e) {
        MessageDialog.openError(getShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
        ExceptionHandler.process(e);
    }
    return ok;
}
Also used : ByteArray(org.talend.core.model.properties.ByteArray) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Example 13 with SQLPatternItem

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

the class TosTokenCollector method collectProjectDetails.

private JSONObject collectProjectDetails() throws PersistenceException, JSONException {
    JSONObject jObject = new JSONObject();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    JSONObject repoStats = new JSONObject();
    // metadata
    for (DynaEnum type : ERepositoryObjectType.values()) {
        if (type instanceof ERepositoryObjectType && ((ERepositoryObjectType) type).isResourceItem()) {
            try {
                List<IRepositoryViewObject> all = factory.getAll(currentProject, (ERepositoryObjectType) type);
                int nb = all.size();
                if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_PATTERN_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_RULES.equals(type) || "TDQ_SOURCE_FILE_ELEMENT".equals(type.getType())) {
                    //$NON-NLS-1$
                    continue;
                }
                if (ERepositoryObjectType.ROUTINES.equals(type)) {
                    nb = 0;
                    List<IRepositoryViewObject> newList = new ArrayList<IRepositoryViewObject>();
                    for (IRepositoryViewObject object : all) {
                        RoutineItem rItem = (RoutineItem) object.getProperty().getItem();
                        if (!rItem.isBuiltIn()) {
                            nb++;
                            newList.add(object);
                        }
                    }
                    all = newList;
                }
                if (ERepositoryObjectType.SQLPATTERNS.equals(type)) {
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        SQLPatternItem spItem = (SQLPatternItem) object.getProperty().getItem();
                        if (!spItem.isSystem()) {
                            nb++;
                        }
                    }
                }
                if ("MDM.DataModel".equals(type.getType())) {
                    //$NON-NLS-1$
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        String path = object.getProperty().getItem().getState().getPath();
                        if (!"System".equals(path)) {
                            //$NON-NLS-1$
                            nb++;
                        }
                    }
                }
                if (nb > 0) {
                    JSONObject typeStats = new JSONObject();
                    //$NON-NLS-1$
                    typeStats.put("nb", nb);
                    if (ERepositoryObjectType.getAllTypesOfProcess().contains(type)) {
                        JSONObject jobDetails = new JSONObject();
                        collectJobDetails(all, jobDetails);
                        //$NON-NLS-1$
                        typeStats.put("details", jobDetails);
                    }
                    if (ERepositoryObjectType.ROUTINES.equals(type) || //$NON-NLS-1$
                    ((ERepositoryObjectType) type).getFolder().startsWith("metadata/") || ERepositoryObjectType.CONTEXT.equals(type) || type.equals(ERepositoryObjectType.JOBLET)) {
                        int nbUsed = 0;
                        for (IRepositoryViewObject object : all) {
                            List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getId());
                            relations.addAll(RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getLabel()));
                            if (relations.size() > 0) {
                                nbUsed++;
                            }
                        }
                        //$NON-NLS-1$
                        typeStats.put("nb.used", nbUsed);
                    }
                    if (ERepositoryObjectType.METADATA_CONNECTIONS.equals(type)) {
                        JSONObject objects = new JSONObject();
                        for (IRepositoryViewObject object : all) {
                            DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
                            String dbType = ((DatabaseConnection) item.getConnection()).getDatabaseType();
                            int nbDbTypes = 1;
                            if (objects.has(dbType)) {
                                nbDbTypes = objects.getInt(dbType);
                                nbDbTypes++;
                            }
                            objects.put(dbType, nbDbTypes);
                        }
                        //$NON-NLS-1$
                        typeStats.put("types", objects);
                    }
                    repoStats.put(type.getType(), typeStats);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    //$NON-NLS-1$
    jObject.put(PROJECTS.getKey(), repoStats);
    jObject.put(TYPE.getKey(), ProjectManager.getInstance().getProjectType(currentProject));
    int nbRef = ProjectManager.getInstance().getAllReferencedProjects().size();
    if (nbRef > 0) {
        jObject.put("nb.refProjects", nbRef);
    }
    return jObject;
}
Also used : DynaEnum(org.talend.core.model.repository.DynaEnum) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) JSONException(us.monoid.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Project(org.talend.core.model.general.Project) Relation(org.talend.core.model.relationship.Relation) JSONObject(us.monoid.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 14 with SQLPatternItem

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

the class ImportItemUtil method checkItem.

private boolean checkItem(ItemRecord itemRecord, boolean overwrite) {
    boolean result = false;
    try {
        Item item = itemRecord.getItem();
        if (item instanceof TDQItem) {
            // hide tdq first
            return false;
        }
        ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
        if (itemType == null) {
            //$NON-NLS-1$
            itemRecord.addError(Messages.getString("ImportItemUtil.unsupportItem"));
            // can't import this item.
            return false;
        }
        cache.initialize(itemType);
        boolean isAllowMultipleName = (itemType == ERepositoryObjectType.SQLPATTERNS || itemType == ERepositoryObjectType.METADATA_FILE_XML);
        String itemPath = null;
        if (item.getState() != null) {
            itemPath = item.getState().getPath();
        } else {
            itemRecord.addError(Messages.getString("ImportItemUtil.unsupportItem"));
            return false;
        }
        boolean nameAvailable = true;
        IRepositoryViewObject itemWithSameId = null;
        IRepositoryViewObject itemWithSameName = null;
        // take care, in cache it's RepositoryViewObject, not RepositoryObject
        for (IRepositoryViewObject current : cache.getItemsFromRepository().get(itemType)) {
            final Property property = itemRecord.getProperty();
            if (property != null) {
                if (property.getLabel() != null && property.getLabel().equalsIgnoreCase(current.getLabel()) && property.getId() != current.getId()) {
                    // repository.
                    if (!isAllowMultipleName || current.getPath().equals(itemPath)) {
                        nameAvailable = false;
                    }
                    // elements
                    if (!nameAvailable) {
                        itemWithSameName = current;
                    }
                }
                if (property.getId() != null && property.getId().equalsIgnoreCase(current.getId())) {
                    itemWithSameId = current;
                }
            }
        }
        itemRecord.setExistingItemWithSameId(itemWithSameId);
        boolean idAvailable = itemWithSameId == null;
        boolean isSystem = false;
        // we do not import built in routines
        if (item.eClass().equals(PropertiesPackage.eINSTANCE.getRoutineItem())) {
            RoutineItem routineItem = (RoutineItem) item;
            if (routineItem.isBuiltIn()) {
                isSystem = true;
            }
        }
        // we do not import system sql patterns
        if (item.eClass().equals(PropertiesPackage.eINSTANCE.getSQLPatternItem())) {
            SQLPatternItem sqlPatternItem = (SQLPatternItem) item;
            if (sqlPatternItem.isSystem()) {
                isSystem = true;
            }
        }
        if (isSystem) {
            itemRecord.addError(Messages.getString("RepositoryUtil.isSystem"));
            return false;
        }
        if (nameAvailable) {
            if (idAvailable) {
                if (!isSystem) {
                    result = true;
                }
            /*
                       * else { itemRecord.addError(Messages.getString("RepositoryUtil.isSystemRoutine")); //$NON-NLS-1$
                       * }
                       */
            } else {
                // same id but different name,no need to care overwrite cause the item will be considered as a
                // different one,see bug 20445
                itemRecord.setState(State.ID_EXISTED);
                // if (overwrite) {
                // result = true;
                // } else {
                // see bug 0005222: [Import items] [Errors and Warnings]
                // id is already in use
                result = true;
            // RepositoryNode nodeWithSameId = RepositoryNodeUtilities.getRepositoryNode(itemWithSameId);
            // IPath path = getPath(nodeWithSameId);
            // itemRecord.addError(Messages.getString(
            //                                "RepositoryUtil.idUsed", itemWithSameId.getLabel(), path.toOSString())); //$NON-NLS-1$
            // }
            }
        } else {
            if (idAvailable) {
                // same name but different id
                itemRecord.setState(State.NAME_EXISTED);
                if (!isSystem && overwrite) {
                    // if anything system, don't replace the source item if same name.
                    // if not from system, can overwrite.
                    itemRecord.setExistingItemWithSameId(itemWithSameName);
                    result = true;
                }
                // if item is locked, cannot overwrite
                if (result && overwrite && itemWithSameName != null) {
                    ERepositoryStatus status = itemWithSameName.getRepositoryStatus();
                    if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
                        //$NON-NLS-1$
                        itemRecord.addError(Messages.getString("RepositoryUtil.itemLocked"));
                        return false;
                    }
                }
            } else {
                // same name and same id
                itemRecord.setState(State.NAME_AND_ID_EXISTED);
                if (overwrite) {
                    result = true;
                }
                if (!isSystem && overwrite && !itemWithSameName.getProperty().getLabel().equals(itemWithSameId.getProperty().getLabel())) {
                    // if anything system, don't replace the source item if same name.
                    // if not from system, can overwrite.
                    itemRecord.setExistingItemWithSameId(itemWithSameName);
                    result = true;
                }
            }
            if (!result && !isSystem) {
                //$NON-NLS-1$
                itemRecord.addError(Messages.getString("RepositoryUtil.nameUsed"));
            }
        }
        if (result && overwrite && itemRecord.getState() == State.NAME_AND_ID_EXISTED) {
            // if item is locked, cannot overwrite
            if (checkIfLocked(itemRecord)) {
                //$NON-NLS-1$
                itemRecord.addError(Messages.getString("RepositoryUtil.itemLocked"));
                result = false;
            }
        }
    } catch (Exception e) {
        log.error("Error when checking item :" + itemRecord.getPath(), e);
    }
    return result;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TDQItem(org.talend.core.model.properties.TDQItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 15 with SQLPatternItem

use of org.talend.core.model.properties.SQLPatternItem 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)

Aggregations

SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)24 PersistenceException (org.talend.commons.exception.PersistenceException)11 Item (org.talend.core.model.properties.Item)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 PartInitException (org.eclipse.ui.PartInitException)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 RoutineItem (org.talend.core.model.properties.RoutineItem)5 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 Project (org.talend.core.model.general.Project)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 FileItem (org.talend.core.model.properties.FileItem)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 Property (org.talend.core.model.properties.Property)4 HashMap (java.util.HashMap)3