Search in sources :

Example 1 with WSDataModelItem

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

the class NewDataModelAction method createServerObject.

@Override
protected Item createServerObject(String key) {
    WSDataModelItem item = MdmpropertiesFactory.eINSTANCE.createWSDataModelItem();
    ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
    item.setState(itemState);
    // 
    WSDataModelE dataModel = newBlankDataModel(key);
    item.setWsDataModel(dataModel);
    if (parentItem != null) {
        item.getState().setPath(parentItem.getState().getPath());
        RepositoryResourceUtil.createItem(item, key);
        createERDocument(item);
        createMatchRuleMapInfo(item);
    }
    if (needCreateDataContainer) {
        createDataContainerObject(key);
    }
    return item;
}
Also used : WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) ItemState(org.talend.core.model.properties.ItemState) WSDataModelE(org.talend.mdm.repository.model.mdmserverobject.WSDataModelE)

Example 2 with WSDataModelItem

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

the class DatamodelOperatorUpdator method updateConditionOperator.

public boolean updateConditionOperator(Item item) {
    boolean modified = false;
    if (item != null && item instanceof WSDataModelItem) {
        WSDataModelItem modelItem = (WSDataModelItem) item;
        EList<ReferenceFileItem> resources = modelItem.getReferenceResources();
        for (ReferenceFileItem fileItem : resources) {
            if (fileItem.getExtension().equals("xsd")) {
                // $NON-NLS-1$
                ByteArray content = fileItem.getContent();
                byte[] byteContent = content.getInnerContent();
                String xsdSchema = updateOperator(byteContent);
                if (xsdSchema != null) {
                    try {
                        // $NON-NLS-1$
                        byteContent = xsdSchema.getBytes("utf-8");
                        content.setInnerContent(byteContent);
                        // $NON-NLS-1$
                        modelItem.getWsDataModel().setXsdSchema(new String(byteContent, "utf-8"));
                    } catch (UnsupportedEncodingException e) {
                        log.error(e.getMessage(), e);
                    }
                    modified = true;
                }
                break;
            }
        }
        if (modified) {
            RepositoryResourceUtil.saveItem(item);
        }
    }
    return modified;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) ByteArray(org.talend.core.model.properties.ByteArray) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with WSDataModelItem

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

the class MDMImportItemsWizardPage method exchangeImport.

protected void exchangeImport() {
    ImportExchangeOptionsDialog dlg = getExchangeOptionsDialog();
    dlg.setBlockOnOpen(true);
    if (dlg.open() == Window.OK) {
        File directory = new File(zipFileRepository.toString());
        File[] files = directory.listFiles(new FileFilter() {

            public boolean accept(File pathname) {
                // $NON-NLS-1$
                return pathname.getName().endsWith(".xsd");
            }
        });
        if (null != files && files.length > 0) {
            try {
                MDMRepositoryView view = MDMRepositoryView.show();
                for (File file : files) {
                    final String label = file.getName().substring(0, file.getName().lastIndexOf('.'));
                    final WSDataModelItem item = MdmpropertiesFactory.eINSTANCE.createWSDataModelItem();
                    ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
                    item.setState(itemState);
                    WSDataModelE dataModel = MdmserverobjectFactory.eINSTANCE.createWSDataModelE();
                    dataModel.setName(label);
                    InputStream stream = null;
                    try {
                        stream = new FileInputStream(file);
                        dataModel.setXsdSchema(IOUtils.toString(stream));
                        item.setWsDataModel(dataModel);
                    } catch (Exception e) {
                        log.error(e.getMessage());
                    }
                    IOUtils.closeQuietly(stream);
                    // $NON-NLS-1$
                    item.getState().setPath("");
                    RepositoryResourceUtil.createItem(item, label);
                    view.refreshRootNode(IServerObjectRepositoryType.TYPE_DATAMODEL);
                }
            } catch (Exception ex) {
                log.error(ex.getMessage());
            }
            WizardDialog dialog = (WizardDialog) getWizard().getContainer();
            dialog.close();
        } else {
            MessageDialog.openWarning(getShell(), null, Messages.NO_XSD_RESOURCE);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) WSDataModelE(org.talend.mdm.repository.model.mdmserverobject.WSDataModelE) ImportExchangeOptionsDialog(com.amalto.workbench.dialogs.ImportExchangeOptionsDialog) FileInputStream(java.io.FileInputStream) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) ItemState(org.talend.core.model.properties.ItemState) FileFilter(java.io.FileFilter) MDMRepositoryView(org.talend.mdm.repository.ui.navigator.MDMRepositoryView) File(java.io.File) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 4 with WSDataModelItem

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

the class ContainerCacheServiceTest method testPutPropertyIRepositoryViewObject.

@Test
public void testPutPropertyIRepositoryViewObject() {
    // $NON-NLS-1$
    String propId = "propertyId";
    Property mockProp = Mockito.mock(Property.class);
    Mockito.when(mockProp.getId()).thenReturn(propId);
    IRepositoryViewObject mockViewObj = Mockito.mock(IRepositoryViewObject.class);
    RepositoryObject mockRepObj = Mockito.mock(RepositoryObject.class);
    Mockito.when(mockRepObj.getProperty()).thenReturn(mockProp);
    // 
    try {
        ContainerCacheService.put(null, mockViewObj);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        ContainerCacheService.put(mockProp, null);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        ContainerCacheService.put(null, null);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    ContainerCacheService.put(mockProp, mockViewObj);
    assertEquals(mockViewObj, ContainerCacheService.get(propId));
    ContainerCacheService.clearCache();
    try {
        // $NON-NLS-1$
        String path = "path";
        ItemState mockItemState = Mockito.mock(ItemState.class);
        Mockito.when(mockItemState.getPath()).thenReturn(path);
        Mockito.when(mockItemState.isDeleted()).thenReturn(false);
        WSDataModelItem mockModelItem = Mockito.mock(WSDataModelItem.class);
        Mockito.when(mockModelItem.getState()).thenReturn(mockItemState);
        Mockito.when(mockProp.getItem()).thenReturn(mockModelItem);
        IRepositoryViewObject mockRepoViewObj = PowerMockito.mock(IRepositoryViewObject.class);
        PowerMockito.mockStatic(ContainerCacheService.class);
        // $NON-NLS-1$
        PowerMockito.when(ContainerCacheService.class, "put", any(Property.class), any(RepositoryObject.class)).thenCallRealMethod();
        // $NON-NLS-1$
        PowerMockito.when(ContainerCacheService.class, "get", anyString()).thenCallRealMethod();
        // $NON-NLS-1$
        PowerMockito.when(ContainerCacheService.class, "createRepositoryViewObject", any(IRepositoryViewObject.class)).thenReturn(mockRepoViewObj);
        ContainerCacheService.put(mockProp, mockRepObj);
        assertTrue(ContainerCacheService.get(propId) != null);
        assertSame(mockRepoViewObj, ContainerCacheService.get(propId));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : RepositoryObject(org.talend.core.model.repository.RepositoryObject) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) ItemState(org.talend.core.model.properties.ItemState) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with WSDataModelItem

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

the class NewDataModelActionTest method testCreateServerObject.

@Test
public void testCreateServerObject() throws Exception {
    // 
    ContainerItem newItem = MdmpropertiesFactory.eINSTANCE.createContainerItem();
    ContainerItem mockContainerItem = spy(newItem);
    PowerMockito.mockStatic(MDMWorbenchPlugin.class);
    when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
    IMatchRuleMapInfoService mapInfoService = mock(IMatchRuleMapInfoService.class);
    PowerMockito.mockStatic(ServiceUtil.class);
    PowerMockito.when(ServiceUtil.getService(IMatchRuleMapInfoService.class)).thenReturn(mapInfoService);
    // new action
    NewDataModelAction action = new NewDataModelAction();
    NewDataModelAction spyAction = spy(action);
    // 
    // $NON-NLS-1$
    Whitebox.setInternalState(spyAction, "parentItem", mockContainerItem);
    ItemState itemState = mock(ItemState.class);
    when(mockContainerItem.getState()).thenReturn(itemState);
    // $NON-NLS-1$
    when(mockContainerItem.getState().getPath()).thenReturn("");
    WSDataModelItem item = MdmpropertiesFactory.eINSTANCE.createWSDataModelItem();
    WSDataModelItem spyModelItem = spy(item);
    Resource mockResource = mock(Resource.class);
    ResourceSet mockResourceSet = mock(ResourceSet.class);
    when(mockResource.getResourceSet()).thenReturn(mockResourceSet);
    when(spyModelItem.eResource()).thenReturn(mockResource);
    PowerMockito.whenNew(WSDataModelItemImpl.class).withNoArguments().thenReturn((WSDataModelItemImpl) spyModelItem);
    // run
    // $NON-NLS-1$
    Item addedItem = spyAction.createServerObject("abc");
    assertThat(addedItem, notNullValue());
}
Also used : WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ItemState(org.talend.core.model.properties.ItemState) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) Resource(org.eclipse.emf.ecore.resource.Resource) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IMatchRuleMapInfoService(org.talend.mdm.repository.core.service.IMatchRuleMapInfoService) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractSimpleAddActionTest(org.talend.mdm.repository.ui.actions.AbstractSimpleAddActionTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

WSDataModelItem (org.talend.mdm.repository.model.mdmproperties.WSDataModelItem)8 ItemState (org.talend.core.model.properties.ItemState)4 WSDataModelE (org.talend.mdm.repository.model.mdmserverobject.WSDataModelE)4 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ByteArray (org.talend.core.model.properties.ByteArray)2 ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)2 ImportExchangeOptionsDialog (com.amalto.workbench.dialogs.ImportExchangeOptionsDialog)1 WSDataModel (com.amalto.workbench.webservices.WSDataModel)1 FileFilter (java.io.FileFilter)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Item (org.talend.core.model.properties.Item)1 Property (org.talend.core.model.properties.Property)1