Search in sources :

Example 11 with MDMServerDefItem

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

the class ServerDefService method getAllServerDefViewObjects.

/**
 * Warning: the return result is a encrypted List
 *
 * @return
 */
public static List<IRepositoryViewObject> getAllServerDefViewObjects(boolean includeDisabledServer) {
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    try {
        List<IRepositoryViewObject> viewObjects = factory.getAll(REPOSITORY_TYPE_SERVER_DEF);
        if (viewObjects != null) {
            List<IRepositoryViewObject> serverDefViewObjs = new ArrayList<IRepositoryViewObject>();
            for (IRepositoryViewObject viewObj : viewObjects) {
                Item item = viewObj.getProperty().getItem();
                MDMServerDef serverDef = ((MDMServerDefItem) item).getServerDef();
                if (serverDef != null) {
                    if (tmpPasswordCache.containsKey(viewObj.getId())) {
                        String tmpPasswd = tmpPasswordCache.get(viewObj.getId());
                        serverDef.setTempPasswd(tmpPasswd);
                    }
                }
                if (serverDef != null) {
                    if (includeDisabledServer || serverDef.isEnabled()) {
                        serverDefViewObjs.add(viewObj);
                    }
                }
            }
            return serverDefViewObjs;
        }
        return null;
    } catch (PersistenceException e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) Item(org.talend.core.model.properties.Item) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 12 with MDMServerDefItem

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

the class ServerDefService method createServerDef.

public static String createServerDef(MDMServerDef serverDef) {
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    RepositoryContext context = factory.getRepositoryContext();
    MDMServerDefItem item = MdmpropertiesFactory.eINSTANCE.createMDMServerDefItem();
    item.setServerDef(serverDef);
    Property prop = PropertiesFactory.eINSTANCE.createProperty();
    item.setProperty(prop);
    try {
        String nextId = factory.getNextId();
        Property property = item.getProperty();
        property.setId(nextId);
        property.setVersion(VersionUtils.DEFAULT_VERSION);
        property.setAuthor(context.getUser());
        property.setLabel(item.getServerDef().getName());
        // $NON-NLS-1$
        factory.create(item, new Path(""));
        return nextId;
    } catch (PersistenceException e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) RepositoryContext(org.talend.core.context.RepositoryContext) MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) PersistenceException(org.talend.commons.exception.PersistenceException) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 13 with MDMServerDefItem

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

the class UnifyPasswordEncryption4MDMServerDefMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item != null && item instanceof MDMServerDefItem) {
        MDMServerDef serverDef = ((MDMServerDefItem) item).getServerDef();
        String algorithm = serverDef.getAlgorithm();
        if (algorithm != null && algorithm.equals(PasswordUtil.ALGORITHM_COMMON)) {
            String decryptedPassword = serverDef.getPasswd();
            try {
                decryptedPassword = PasswordEncryptUtil.decryptPassword(serverDef.getPasswd());
            } catch (Exception e) {
                return ExecutionResult.FAILURE;
            }
            serverDef.setPasswd(CryptoHelper.getDefault().encrypt(decryptedPassword));
            serverDef.setAlgorithm(PasswordUtil.ALGORITHM_COMMON_V2);
            try {
                factory.save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
// if (modified) {
// factory.save(item, true);
// return ExecutionResult.SUCCESS_NO_ALERT;
// }
// } catch (Exception e) {
// ExceptionHandler.process(e);
// return ExecutionResult.FAILURE;
// }
// return ExecutionResult.NOTHING_TO_DO;
}
Also used : MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 14 with MDMServerDefItem

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

the class SelectServerDefDialog method setSelectServer.

public void setSelectServer(MDMServerDef server) {
    if (server == null) {
        if (treeViewer.getTree().getItemCount() > 0) {
            TreeItem item = treeViewer.getTree().getItem(0);
            IRepositoryViewObject viewObject = (IRepositoryViewObject) item.getData();
            MDMServerDefItem defitem = (MDMServerDefItem) viewObject.getProperty().getItem();
            MDMServerDef defServer = defitem.getServerDef();
            serverDef = defServer;
            treeViewer.getTree().setSelection(item);
            okBun.setEnabled(true);
            return;
        }
    }
    TreeItem[] items = treeViewer.getTree().getItems();
    for (IRepositoryViewObject viewObject : (List<IRepositoryViewObject>) treeViewer.getInput()) {
        MDMServerDefItem defitem = (MDMServerDefItem) viewObject.getProperty().getItem();
        MDMServerDef defServer = defitem.getServerDef();
        if (server.getName().equals(defServer.getName()) && server.getHost().equals(defServer.getHost()) && server.getPort().equals(defServer.getPort())) {
            serverDef = defServer;
            treeViewer.setSelection(new StructuredSelection(viewObject));
            okBun.setEnabled(true);
            break;
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) List(java.util.List) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 15 with MDMServerDefItem

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

the class ServerSorter method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    MDMServerDefItem mdmItem1 = getMDMItem((IRepositoryViewObject) e1);
    MDMServerDefItem mdmItem2 = getMDMItem((IRepositoryViewObject) e2);
    if (mdmItem1 != null && mdmItem2 != null) {
        MDMServerDef serverDef1 = mdmItem1.getServerDef();
        MDMServerDef serverDef2 = mdmItem2.getServerDef();
        boolean enabled1 = serverDef1.isEnabled();
        boolean enabled2 = serverDef2.isEnabled();
        if (enabled1 == enabled2) {
            return serverDef1.getName().toLowerCase().compareTo(serverDef2.getName().toLowerCase());
        } else {
            return enabled1 ? -1 : 1;
        }
    }
    return 0;
}
Also used : MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Aggregations

MDMServerDefItem (org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem)15 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)10 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 ArrayList (java.util.ArrayList)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 Item (org.talend.core.model.properties.Item)2 ServerDefDialog (org.talend.mdm.workbench.serverexplorer.ui.dialogs.ServerDefDialog)2 ServerSorter (org.talend.mdm.workbench.serverexplorer.ui.providers.ServerSorter)2 TreeContentProvider (org.talend.mdm.workbench.serverexplorer.ui.providers.TreeContentProvider)2 ViewerLabelProvider (org.talend.mdm.workbench.serverexplorer.ui.providers.ViewerLabelProvider)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 List (java.util.List)1 Path (org.eclipse.core.runtime.Path)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 Separator (org.eclipse.jface.action.Separator)1