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;
}
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;
}
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);
}
}
}
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);
}
}
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());
}
Aggregations