Search in sources :

Example 1 with EbcdicConnection

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;
}
Also used : EbcdicConnection(org.talend.core.model.metadata.builder.connection.EbcdicConnection) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) EbcdicConnection(org.talend.core.model.metadata.builder.connection.EbcdicConnection) ByteArray(org.talend.core.model.properties.ByteArray) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 EbcdicConnection (org.talend.core.model.metadata.builder.connection.EbcdicConnection)1 ByteArray (org.talend.core.model.properties.ByteArray)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)1 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)1