Search in sources :

Example 41 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class AbstractTDQFileDuplicateHandle method duplicateItem.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.core.ui.action.actions.handle.IDuplicateHandle#duplicateItem(org.talend.core.model.properties
     * .Item, java.lang.String)
     */
public Item duplicateItem(Item oldItem, String newName) throws BusinessException {
    String fileExtension = file.getFileExtension();
    IPath newFileNamePath = new Path(newName).addFileExtension(fileExtension);
    // IFile newFile = file.getParent().getFile(newFileNamePath);
    ModelElement oldModelElement = PropertyHelper.getModelElement(oldItem.getProperty());
    IFolder folder = extractFolder(oldItem, oldModelElement);
    IFile newFile = folder.getFile(newFileNamePath);
    // createt the file item by the duplicated file
    Item duplicate = createFileItemByDuplicateFile(newFile, fileExtension, newName);
    if (duplicate == null) {
        BusinessException createBusinessException = ExceptionFactory.getInstance().createBusinessException(DefaultMessagesImpl.getString("AbstractTDQFileDuplicateHandle.duplicateFail", // $NON-NLS-1$
        oldItem.getProperty().getDisplayName()));
        throw createBusinessException;
    }
    return duplicate;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) BusinessException(org.talend.commons.exception.BusinessException) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class TdAddTaskAction method run.

@Override
public void run() {
    try {
        TdTaskPropertiesDialog dialog = new TdTaskPropertiesDialog(shell);
        ModelElement modelElement = null;
        if (navObj instanceof RepositoryNode) {
            RepositoryNode node = (RepositoryNode) navObj;
            modelElement = RepositoryNodeHelper.getModelElementFromRepositoryNode(node);
        } else {
            modelElement = (ModelElement) navObj;
        }
        modelElement = (ModelElement) EObjectHelper.resolveObject(modelElement);
        if (modelElement == null || modelElement.eResource() == null || modelElement.getName() == null) {
            // $NON-NLS-1$
            String fileName = "";
            if (navObj instanceof RepositoryNode) {
                Item item = ((RepositoryNode) navObj).getObject().getProperty().getItem();
                if (item instanceof TDQItem) {
                    fileName = ((TDQItem) item).getFilename();
                }
            }
            throw ExceptionFactory.getInstance().createBusinessException(fileName);
        }
        IFile file = WorkspaceUtils.getModelElementResource(modelElement);
        TdResourceModel tdResModel = new TdResourceModel(file.getFullPath(), (Workspace) file.getWorkspace(), modelElement);
        dialog.setResource(tdResModel);
        Map<String, Object> attMap = new HashMap<String, Object>();
        attMap.put(MarkerViewUtil.NAME_ATTRIBUTE, modelElement.getName());
        attMap.put(IMarker.LOCATION, file.getRawLocation().toString());
        attMap.put(IMarker.LINE_NUMBER, file.getRawLocation().toString());
        dialog.setInitialAttributes(attMap);
        dialog.open();
    } catch (BusinessException e) {
        ExceptionHandler.process(e, Level.FATAL);
    } catch (Exception e1) {
        log.error(e1, e1);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) RepositoryNode(org.talend.repository.model.RepositoryNode) BusinessException(org.talend.commons.exception.BusinessException) TdResourceModel(org.talend.dataprofiler.core.model.TdResourceModel) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) TDQItem(org.talend.core.model.properties.TDQItem) BusinessException(org.talend.commons.exception.BusinessException) TdTaskPropertiesDialog(org.talend.dataprofiler.core.ui.dialog.TdTaskPropertiesDialog) TDQItem(org.talend.core.model.properties.TDQItem)

Example 43 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class ActionHandleFactory method createDuplicateHandle.

public IDuplicateHandle createDuplicateHandle(IRepositoryNode node) throws BusinessException {
    IDuplicateHandle handle = null;
    EResourceConstant typedConstant = EResourceConstant.getTypedConstant(node.getObject().getProperty().getItem());
    if (typedConstant == null) {
        BusinessException createBusinessException = ExceptionFactory.getInstance().createBusinessException(// $NON-NLS-1$
        DefaultMessagesImpl.getString("ActionHandleFactory.duplicateFail", node.getLabel()));
        throw createBusinessException;
    } else {
        switch(typedConstant) {
            case DB_CONNECTIONS:
                handle = new DBConnectionDuplicateHandle();
                break;
            case JRXML_TEMPLATE:
                handle = new JrxmlFileDuplicateHandle(node);
                break;
            case ANALYSIS:
                handle = new AnalysisDuplicateHandle();
                break;
            case REPORTS:
                handle = new ReportDuplicateHandle();
                break;
            case PATTERNS:
            case RULES_PARSER:
            case RULES_SQL:
            case RULES_MATCHER:
                handle = new ModelElementDuplicateHandle();
                break;
            case INDICATORS:
                handle = new IndicatorDuplicateHandle();
                break;
            case SOURCE_FILES:
                handle = new SourceFileDuplicateHandle(node);
                break;
            case CONTEXT:
                handle = new ContextDuplicateHandle(node);
            default:
                break;
        }
    }
    return handle;
}
Also used : EResourceConstant(org.talend.resource.EResourceConstant) BusinessException(org.talend.commons.exception.BusinessException)

Example 44 with BusinessException

use of org.talend.commons.exception.BusinessException in project tmdm-studio-se by Talend.

the class RepositoryDropAssistant method moveViewObj.

/**
 * DOC hbhong Comment method "moveViewObj".
 *
 * @param dragViewObj
 * @param dropViewObj
 * @return
 */
private boolean moveViewObj(IRepositoryViewObject dragViewObj, IRepositoryViewObject dropViewObj) {
    if (dropViewObj != null && dragViewObj != null) {
        if (RepositoryResourceUtil.isLockedViewObject(dragViewObj)) {
            MessageDialog.openError(getShell(), Messages.AbstractRepositoryAction_lockedObjTitle, Messages.RepositoryDropAssistant_stopMoveMsg);
            return false;
        }
        Property dropProp = dropViewObj.getProperty();
        String pathStr = dropProp.getItem().getState().getPath();
        IPath path = new Path(pathStr);
        IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
        try {
            factory.moveObject(dragViewObj, path);
            return true;
        } catch (PersistenceException e) {
            log.error(e.getMessage(), e);
        } catch (BusinessException e) {
            log.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) BusinessException(org.talend.commons.exception.BusinessException) IPath(org.eclipse.core.runtime.IPath) PersistenceException(org.talend.commons.exception.PersistenceException) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 45 with BusinessException

use of org.talend.commons.exception.BusinessException in project tmdm-studio-se by Talend.

the class RepositoryDropAssistant method copyViewObj.

public boolean copyViewObj(IRepositoryViewObject dragViewObj, IRepositoryViewObject dropViewObj) {
    if (dropViewObj != null && dragViewObj != null) {
        Property dragProp = dragViewObj.getProperty();
        Property dropProp = dropViewObj.getProperty();
        Item item = dragProp.getItem();
        String name;
        if (item instanceof MDMServerObjectItem) {
            MDMServerObject serverObj = ((MDMServerObjectItem) item).getMDMServerObject();
            name = serverObj.getName();
        } else {
            name = dragProp.getLabel();
        }
        // show dialog
        IRepositoryViewObject dragParentViewObj = getParentRepositoryViewObject(dragViewObj);
        ContainerItem dragParentItem = (ContainerItem) dragParentViewObj.getProperty().getItem();
        // $NON-NLS-1$
        String newName = showPasteDlg(dragParentItem.getRepObjType(), dragParentItem, "Copy_" + name);
        if (newName != null) {
            String pathStr = dropProp.getItem().getState().getPath();
            pathStr = rebuildPath(dragViewObj, name, newName, pathStr);
            IPath path = new Path(pathStr);
            ERepositoryObjectType type = dropViewObj.getRepositoryObjectType();
            if (type == IServerObjectRepositoryType.TYPE_WORKFLOW) {
                if (exAdapter != null) {
                    return exAdapter.copyWorkflowViewObj(item, name, newName);
                }
            } else {
                IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
                Item copy = null;
                try {
                    copy = factory.copy(item, path, true);
                    if (factory.isEditableAndLockIfPossible(copy)) {
                        if (copy instanceof MDMServerObjectItem) {
                            ((MDMServerObjectItem) copy).getMDMServerObject().setName(newName);
                            ((MDMServerObjectItem) copy).getMDMServerObject().setLastServerDef(null);
                            CommandManager.getInstance().pushCommand(ICommand.CMD_ADD, copy.getProperty().getId(), newName);
                        }
                        copy.getProperty().setLabel(newName);
                        copy.getProperty().setDisplayName(newName);
                        RepositoryResourceUtil.setLastServerDef(copy, null);
                        factory.save(copy);
                        MDMRepositoryView.show().refreshRootNode(type);
                        return true;
                    }
                } catch (PersistenceException e) {
                    log.error(e.getMessage(), e);
                } catch (BusinessException e) {
                    log.error(e.getMessage(), e);
                } finally {
                    try {
                        factory.unlock(copy);
                    } catch (PersistenceException e) {
                        log.error(e.getMessage(), e);
                    } catch (LoginException e) {
                        log.error(e.getMessage(), e);
                    }
                }
            }
        }
    }
    return false;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IPath(org.eclipse.core.runtime.IPath) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) BusinessException(org.talend.commons.exception.BusinessException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

BusinessException (org.talend.commons.exception.BusinessException)46 PersistenceException (org.talend.commons.exception.PersistenceException)21 IPath (org.eclipse.core.runtime.IPath)9 Path (org.eclipse.core.runtime.Path)9 Project (org.talend.core.model.general.Project)9 Item (org.talend.core.model.properties.Item)9 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 ArrayList (java.util.ArrayList)8 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IFile (org.eclipse.core.resources.IFile)6 IProject (org.eclipse.core.resources.IProject)6 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)5 File (java.io.File)4 HashMap (java.util.HashMap)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4 IOException (java.io.IOException)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3