Search in sources :

Example 36 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject 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)

Example 37 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.

the class RepositoryResourceUtil method findAllServerObjects.

public static List<MDMServerObject> findAllServerObjects(ERepositoryObjectType type) {
    List<IRepositoryViewObject> viewObjects = RepositoryResourceUtil.findAllViewObjects(type);
    List<MDMServerObject> serverObjects = new LinkedList<MDMServerObject>();
    if (viewObjects != null) {
        for (IRepositoryViewObject viewObj : viewObjects) {
            Item item = viewObj.getProperty().getItem();
            if (item instanceof MDMServerObjectItem) {
                serverObjects.add(((MDMServerObjectItem) item).getMDMServerObject());
            }
        }
    }
    return serverObjects;
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) TDQMatchRuleItem(org.talend.dataquality.properties.TDQMatchRuleItem) WorkspaceRootItem(org.talend.mdm.repository.model.mdmproperties.WorkspaceRootItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) LinkedList(java.util.LinkedList)

Aggregations

MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)37 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)33 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 Item (org.talend.core.model.properties.Item)13 TreeObject (com.amalto.workbench.models.TreeObject)11 Property (org.talend.core.model.properties.Property)11 PersistenceException (org.talend.commons.exception.PersistenceException)9 Test (org.junit.Test)7 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)7 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)7 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)7 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 LoginException (org.talend.commons.exception.LoginException)6 EObject (org.eclipse.emf.ecore.EObject)5 ArrayList (java.util.ArrayList)4 FolderItem (org.talend.core.model.properties.FolderItem)4 TMDMService (com.amalto.workbench.webservices.TMDMService)3 LinkedList (java.util.LinkedList)3 ItemState (org.talend.core.model.properties.ItemState)3