Search in sources :

Example 46 with MDMServerObjectItem

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

the class RenameObjectAction method doRun.

@Override
protected void doRun() {
    Object obj = getSelectedObject().get(0);
    if (obj instanceof IRepositoryViewObject) {
        IRepositoryViewObject viewObj = (IRepositoryViewObject) obj;
        MDMServerObjectItem item = (MDMServerObjectItem) viewObj.getProperty().getItem();
        MDMServerObject serverObject = item.getMDMServerObject();
        IRepositoryNodeConfiguration configuration = RepositoryNodeConfigurationManager.getConfiguration(item);
        if (configuration != null) {
            ERepositoryObjectType type = configuration.getResourceProvider().getRepositoryObjectType(item);
            IRepositoryViewObject parentViewObj = ContainerCacheService.get(type, item.getState().getPath());
            try {
                if (serverObject != null) {
                    String oldName = serverObject.getName();
                    String newName = showRenameDlg(type, (ContainerItem) parentViewObj.getProperty().getItem(), oldName);
                    if (newName != null && factory.isEditableAndLockIfPossible(item)) {
                        serverObject.setName(newName);
                        viewObj.getProperty().setLabel(newName);
                        viewObj.getProperty().setDisplayName(newName);
                        factory.save(viewObj.getProperty().getItem(), false);
                        MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(viewObj);
                        if (lastServerDef != null) {
                            CommandManager.getInstance().pushCommand(ICommand.CMD_RENAME, viewObj.getId(), new String[] { oldName, newName });
                        }
                    }
                }
                commonViewer.refresh(obj);
            } catch (PersistenceException e) {
                log.error(e.getMessage(), e);
            } finally {
                try {
                    factory.unlock(item);
                } catch (PersistenceException e) {
                    log.error(e.getMessage(), e);
                } catch (LoginException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    }
}
Also used : MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) LoginException(org.talend.commons.exception.LoginException) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 47 with MDMServerObjectItem

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

the class MarkNodeAsNewAction method run.

public void run(Project project) {
    if (project == null) {
        return;
    }
    List<ERepositoryObjectType> types = new ArrayList<ERepositoryObjectType>();
    types.add(IServerObjectRepositoryType.TYPE_DATAMODEL);
    types.add(IServerObjectRepositoryType.TYPE_CUSTOM_FORM);
    types.add(IServerObjectRepositoryType.TYPE_DATACLUSTER);
    types.add(IServerObjectRepositoryType.TYPE_MENU);
    types.add(IServerObjectRepositoryType.TYPE_RESOURCE);
    types.add(IServerObjectRepositoryType.TYPE_ROLE);
    types.add(IServerObjectRepositoryType.TYPE_ROUTINGRULE);
    types.add(IServerObjectRepositoryType.TYPE_STOREPROCEDURE);
    types.add(IServerObjectRepositoryType.TYPE_TRANSFORMERV2);
    types.add(IServerObjectRepositoryType.TYPE_VIEW);
    types.add(IServerObjectRepositoryType.TYPE_WORKFLOW);
    types.add(ERepositoryObjectType.PROCESS);
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    for (ERepositoryObjectType type : types) {
        List<IRepositoryViewObject> objects;
        try {
            objects = factory.getAll(project, type);
        } catch (PersistenceException e1) {
            log.error(e1.getLocalizedMessage(), e1);
            return;
        }
        if (objects != null && objects.size() > 0) {
            for (IRepositoryViewObject object : objects) {
                Property property = object.getProperty();
                Item item = property.getItem();
                boolean needRemoved = false;
                MDMServerObject serverObj = null;
                if (item instanceof MDMServerObjectItem) {
                    serverObj = ((MDMServerObjectItem) item).getMDMServerObject();
                    if (serverObj.getLastServerName() != null || serverObj.getLastServerDef() != null) {
                        needRemoved = true;
                    }
                } else {
                    Object value = property.getAdditionalProperties().get(RepositoryResourceUtil.PROP_LAST_SERVER_DEF);
                    if (value != null) {
                        needRemoved = true;
                    }
                }
                if (needRemoved) {
                    RepositoryResourceUtil.setLastServerDef(item, null);
                    try {
                        factory.save(project, item);
                    } catch (PersistenceException e) {
                        log.error(e.getMessage(), e);
                    }
                }
                String name = (serverObj == null || serverObj.getName() == null) ? item.getProperty().getLabel() : serverObj.getName();
                // flagged as new
                CommandManager.getInstance().pushCommand(ICommand.CMD_ADD, item.getProperty().getId(), name);
            }
        }
    }
}
Also used : MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ArrayList(java.util.ArrayList) Item(org.talend.core.model.properties.Item) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)

Example 48 with MDMServerObjectItem

use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem 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 49 with MDMServerObjectItem

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

the class AbstractCommand method init.

@Override
public void init(IRepositoryViewObject viewObj) {
    this.viewObject = viewObj;
    this.commandId = viewObject.getId();
    // 
    Item item = viewObj.getProperty().getItem();
    if (item != null) {
        if (item instanceof MDMServerObjectItem) {
            objName = ((MDMServerObjectItem) item).getMDMServerObject().getName();
            lastName = objName;
        } else if (item instanceof ProcessItem) {
            objName = viewObj.getLabel();
            lastName = objName;
        } else if (item instanceof MDMItem) {
            objName = viewObj.getLabel();
            lastName = objName;
        }
    }
}
Also used : MDMItem(org.talend.mdm.repository.model.mdmproperties.MDMItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) MDMItem(org.talend.mdm.repository.model.mdmproperties.MDMItem) ProcessItem(org.talend.core.model.properties.ProcessItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)

Example 50 with MDMServerObjectItem

use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem 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

MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)50 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)33 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)28 Item (org.talend.core.model.properties.Item)22 Property (org.talend.core.model.properties.Property)15 PersistenceException (org.talend.commons.exception.PersistenceException)13 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)12 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)10 LoginException (org.talend.commons.exception.LoginException)9 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)9 TreeObject (com.amalto.workbench.models.TreeObject)7 Test (org.junit.Test)7 TMDMService (com.amalto.workbench.webservices.TMDMService)6 LinkedList (java.util.LinkedList)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 BusinessException (org.talend.commons.exception.BusinessException)5 FolderItem (org.talend.core.model.properties.FolderItem)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 ArrayList (java.util.ArrayList)4