use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.
the class RouteResourcesHelper method getRouteResourcesLocation.
public static String getRouteResourcesLocation(IRepositoryViewObject repositoryObject) {
if (repositoryObject == null) {
return null;
}
Item item = repositoryObject.getProperty().getItem();
if (item.getReferenceResources().isEmpty()) {
return null;
}
ReferenceFileItem refFileItem = (ReferenceFileItem) item.getReferenceResources().get(0);
URI uri = refFileItem.getContent().eResource().getURI();
try {
return FileLocator.toFileURL(new URL(uri.toString())).getFile();
} catch (IOException e) {
ExceptionHandler.process(e);
}
return null;
}
use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.
the class OpenWSDLPage method createReferenceResources.
private void createReferenceResources(String fileExtension) {
for (Object resource : item.getReferenceResources()) {
if (resource instanceof ReferenceFileItem && fileExtension.equals(((ReferenceFileItem) resource).getExtension())) {
return;
}
}
ReferenceFileItem referenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
referenceFileItem.setExtension(fileExtension);
item.getReferenceResources().add(referenceFileItem);
}
use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.
the class DataModelOperatorUpdatorTest method testUpdateConditionOperator.
@Test
public void testUpdateConditionOperator() {
// $NON-NLS-1$
String filename = "Product_0.1.xsd";
// $NON-NLS-1$
File file = new File("temp/" + filename);
try {
byte[] fbyteArray = IOUtils.toByteArray(new FileInputStream(file));
WSDataModelItem wsdataModelItem = MdmpropertiesFactory.eINSTANCE.createWSDataModelItem();
ReferenceFileItem xsdFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
//
byteArray = spy(byteArray);
//
when(byteArray.getInnerContent()).thenReturn(fbyteArray);
xsdFileItem.setContent(byteArray);
xsdFileItem.setExtension("xsd");
wsdataModelItem.getReferenceResources().add(xsdFileItem);
WSDataModelE wsdataModelE = MdmserverobjectFactory.eINSTANCE.createWSDataModelE();
wsdataModelE.setXsdSchema(null);
wsdataModelItem.setWsDataModel(wsdataModelE);
ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
itemState.setPath("system");
wsdataModelItem.setState(itemState);
DataModelOperatorUpdator dataModelOperatorUpdator = Mockito.spy(new DataModelOperatorUpdator());
Mockito.doNothing().when(dataModelOperatorUpdator).saveItem(Mockito.any(Item.class), Mockito.anyBoolean());
boolean updated = dataModelOperatorUpdator.updateConditionOperator(wsdataModelItem);
assertFalse(updated);
itemState.setPath("");
updated = dataModelOperatorUpdator.updateConditionOperator(wsdataModelItem);
assertTrue(updated);
String xsdSchema = wsdataModelItem.getWsDataModel().getXsdSchema();
assertNotNull(xsdSchema);
// $NON-NLS-1$
assertFalse(xsdSchema.contains("Strict Contains"));
// $NON-NLS-1$
assertFalse(xsdSchema.contains("Contains Text Of"));
// $NON-NLS-1$
assertTrue(xsdSchema.contains("Contains"));
Mockito.verify(dataModelOperatorUpdator).saveItem(Mockito.any(Item.class), Mockito.anyBoolean());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.
the class ConsistencyService method getReferenceFile.
private IFile getReferenceFile(Item item, ERepositoryObjectType type) {
item = RepositoryResourceUtil.assertItem(item);
List refResources = item.getReferenceResources();
if (refResources != null && !refResources.isEmpty()) {
ReferenceFileItem fileItem = (ReferenceFileItem) refResources.get(0);
ByteArray content = fileItem.getContent();
if (content.eResource() != null) {
URI uri = content.eResource().getURI();
if (uri.isPlatformResource()) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath path = new Path(uri.toPlatformString(true));
IFile file = root.getFile(path);
return file;
}
} else {
return RepositoryResourceUtil.findReferenceFile(type, item, fileItem.getExtension());
}
}
return null;
}
use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.
the class AbstractDataModelUpdator method updateDatamodel.
public boolean updateDatamodel(Item item) {
boolean modified = false;
if (item != null && item instanceof WSDataModelItem && accept(item)) {
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();
String xsdSchema = doUpdate(content.getInnerContent());
if (xsdSchema != null) {
try {
// $NON-NLS-1$
byte[] byteContent = xsdSchema.getBytes("utf-8");
content.setInnerContent(byteContent);
// $NON-NLS-1$
modelItem.getWsDataModel().setXsdSchema(new String(byteContent, "utf-8"));
} catch (UnsupportedEncodingException e) {
// $NON-NLS-1$
LOG.error("Failed to encode/decode string by 'utf-8' encoding.", e);
}
modified = true;
}
break;
}
}
saveItem(item, modified);
}
return modified;
}
Aggregations