Search in sources :

Example 1 with ExcelFileConnectionItem

use of org.talend.core.model.properties.ExcelFileConnectionItem in project tdi-studio-se by Talend.

the class ExcleGenerationModeMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    FileExcelConnection fileExcelConn = null;
    if (item instanceof ExcelFileConnectionItem) {
        ExcelFileConnectionItem exelConnItem = (ExcelFileConnectionItem) item;
        if (exelConnItem.getConnection() instanceof FileExcelConnection) {
            fileExcelConn = (FileExcelConnection) exelConnItem.getConnection();
        }
    }
    if (fileExcelConn == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        boolean isXsls = false;
        String filePath = fileExcelConn.getFilePath();
        if (filePath.endsWith(".xlsx")) {
            isXsls = true;
        }
        String genMode = fileExcelConn.getGenerationMode();
        if (isXsls && genMode == null) {
            fileExcelConn.setGenerationMode("USER_MODE");
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.NOTHING_TO_DO;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ExcelFileConnectionItem(org.talend.core.model.properties.ExcelFileConnectionItem) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection)

Aggregations

FileExcelConnection (org.talend.core.model.metadata.builder.connection.FileExcelConnection)1 ExcelFileConnectionItem (org.talend.core.model.properties.ExcelFileConnectionItem)1 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)1