use of org.talend.core.model.properties.ReferenceFileItem in project tdi-studio-se by Talend.
the class ImportItemUtil method copyReferenceFiles.
private boolean copyReferenceFiles(ResourcesManager manager, Item tmpItem, IPath pathToRead) throws IOException {
OutputStream os = null;
InputStream is = null;
boolean haveRef = false;
List<ReferenceFileItem> refItems = tmpItem.getReferenceResources();
URI propertyResourceURI = EcoreUtil.getURI(tmpItem.getProperty());
for (ReferenceFileItem refItem : refItems) {
haveRef = true;
URI relativePlateformDestUri = propertyResourceURI.trimFileExtension().appendFileExtension(refItem.getExtension());
try {
URL fileURL = FileLocator.toFileURL(new java.net.URL(//$NON-NLS-1$
"platform:/resource" + relativePlateformDestUri.toPlatformString(true)));
os = new FileOutputStream(fileURL.getFile());
is = manager.getStream(pathToRead.removeFileExtension().addFileExtension(refItem.getExtension()));
FileCopyUtils.copyStreams(is, os);
} finally {
if (os != null) {
os.close();
}
if (is != null) {
is.close();
}
}
}
return haveRef;
}
use of org.talend.core.model.properties.ReferenceFileItem in project tdi-studio-se by Talend.
the class AddCopyBookXc2jFileMigrationTask method updateXc2jFilePath.
private boolean updateXc2jFilePath(Item item) throws PersistenceException, IOException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean update = false;
if (item instanceof ConnectionItem) {
ConnectionItem connectionItem = (ConnectionItem) item;
Connection con = connectionItem.getConnection();
if (con instanceof EbcdicConnection) {
ReferenceFileItem createReferenceFileItem = null;
// the old copybook version depands MidFile
String midFile = ((EbcdicConnection) con).getMidFile();
if (midFile != null) {
File xc2jMidFile = new File(midFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (xc2jMidFile.exists()) {
readXc2jFile(xc2jMidFile, baos);
}
// create a referenceItem first,maybe it has content,maybe is empty,decide by the midFile
if (connectionItem.getReferenceResources().isEmpty()) {
createReferenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
createReferenceFileItem.setContent(byteArray);
createReferenceFileItem.setExtension("xc2j");
connectionItem.getReferenceResources().add(createReferenceFileItem);
} else {
createReferenceFileItem = (ReferenceFileItem) connectionItem.getReferenceResources().get(0);
}
createReferenceFileItem.getContent().setInnerContent(baos.toByteArray());
// create the phyhical x2cj file and set referenceFileItem content for it
String xc2jFilePath = getReferenceXc2jFile(connectionItem).getLocation().makeAbsolute().toFile().getAbsolutePath();
getXc2jFileFromBytes(createReferenceFileItem.getContent().getInnerContent(), xc2jFilePath);
update = true;
}
}
if (update) {
factory.save(connectionItem, true);
}
}
return update;
}
use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.
the class RemoveRefNameMT method execute.
@Override
public ExecutionResult execute(Item item) {
Property property = item.getProperty();
if (property != null) {
boolean needSave = false;
for (Object itemRefObj : property.getItem().getReferenceResources()) {
ReferenceFileItem refItem = (ReferenceFileItem) itemRefObj;
if (refItem.getName() != null) {
needSave = true;
refItem.setName(null);
}
}
if (needSave) {
try {
saveItem(item);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.ReferenceFileItem 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.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);
PowerMockito.mockStatic(RepositoryResourceUtil.class);
boolean updated = new DatamodelOperatorUpdator().updateConditionOperator(wsdataModelItem);
String xsdSchema = wsdataModelItem.getWsDataModel().getXsdSchema();
assertTrue(updated);
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"));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations