use of org.talend.core.model.metadata.builder.connection.EbcdicConnection 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;
}
Aggregations