Tuesday, June 7, 2011

BIRT! Column! Width! Must! Be! Set!

Alright, just to show you how ugly it may look in Excel (I have the 2010 version installed) if a BIRT report does not have the width property set for the column:
Ugly ugly ugly ugly (actually, the first two are alright, they DO have the width set to 40 mm).

It's but a simple change, but the difference is subtle:


Oh, by the way, I tried out the Tribix XLS emitter for BIRT. It actually worked, but I decided to remove it because it created bad looking XLS files.

Sunday, June 5, 2011

Two hours @ Klánovice station

ZSSK 350 019-6

CD 471 042-2

CD 971 042-7 ;-)

CD 471 009-1

CD 362 161-2

ZSSK 350 015-4

CD 362 112-5

CD 682 001-3

CD 150 222-8

CD 971 069-0

CD 380 005-9

:-( Two Vectrons behind, my bad, could not get a good shot.

CD Cargo 130 037-5

CD 971 009-6

ÖBB 1216 210

CD 150 224-4

CD Cargo 163 003-7

CD 363 040-7

CD 362 021-8

ÖBB 1216 226

CD 380 012-5

Monday, March 7, 2011

Having fun with Config_Message_Log

Recently I spent at least ten minutes trying to figure out why ICM Configurator just won't let me update any configuration. Of course, the database was in really bad shape, the Config_Message_Log tables were totally out of sync.

What I tried first:
1. Opened icmdba and said truncate Config_Message_Log. It did not let me, obviously, it just kept saying the table is corrupted.
2. manually truncated the table. Now, icmdba was able to truncate it too (how lovely it is, truncate an empty table). But ICM Configurator just kept complaining.
3. Tried CCO and found this: http://www.cisco.com/en/US/products/sw/custcosw/ps1001/products_tech_note09186a0080568f5c.shtml
After I did insert into Config_Message_Log values (0, 'LogBegin', 'Config_Message_Log', getdate(),0x0000) - everything went smoooooooth.

Bottom line: it is good to ask Cisco if you are stuck. Sometimes.

Monday, January 17, 2011

Dynamically changing datetime format in BIRT

It's really easy to change the format of a datetime data value. One may change the onPrepare function of the data item, and then

switch (params["d1"].value) {
 case "YE": this.getStyle().dateTimeFormat = "YYYY"; break;
 case "MO": this.getStyle().dateTimeFormat = "YYYY MMMM"; break;
 //case "WK": row["dtWeek"]; break;
 case "DY": this.getStyle().dateTimeFormat = "YYYY MMMM DD"; break;
 case "HO": this.getStyle().dateTimeFormat = "YYYY MMMM DD hh:00:00"; break;
 case "HH": this.getStyle().dateTimeFormat = "YYYY MMMM DD hh:mm:00"; break;
 //default: row["dtHalfHour"]; break;
}
So based on the value of the parameter named d1, the report will format the datetime value as year, year and month etc etc.

Friday, December 31, 2010

Scripted data set

Easy. Just create a scripted data source, then attach a data set to it. Its fetch script would look like:

if (XRowNum == 3) {
    row["KEY"] = '1';
    row["VALUE"] = 'Agenti';
    XRowNum--;
    return true;
}
if (XRowNum == 2) {
    row["KEY"] = '2';
    row["VALUE"] = 'Týmy';
    XRowNum--;
    return true;
}
if (XRowNum == 1) {
    row["KEY"] = '3';
    row["VALUE"] = 'SkillGrupy';
    XRowNum--;
    return true;
}
return false;

Friday, December 3, 2010

Dynamic queries in BIRT - query text replacement

var selectedParams = params["calltypes"].value;
var selectedString = "";
for (var counter=0; counter < selectedParams.length; counter++) {
 selectedString += selectedParams[counter] + ",";
}
selectedString = selectedString.substring(0,selectedString.length-1);
var before = this.queryText.toString();
var injection = "";
injection =  selectedString;
this.queryText = before.replace('53279',injection);

Tuesday, October 12, 2010

Copy files from/to between local and HTTP(s), (S)FTP, local, mail filesystems

Using Apache VFS. Sweet.

package jobs;

import org.apache.commons.vfs.FileFilter;
import org.apache.commons.vfs.FileFilterSelector;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelectInfo;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.impl.StandardFileSystemManager;
import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileCopyJob implements Job {
    Logger log = LoggerFactory.getLogger(getClass());
    String fileNameStartsWith = null;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        long startPoint = System.nanoTime();
        log.info("Reading config.");
        JobDataMap data = context.getJobDetail().getJobDataMap();
        String fromDirURL = data.getString("fromDirURL");
        String toDirURL = data.getString("toDirURL");
        fileNameStartsWith = data.getString("fileNameStartsWith");
        log.debug("fromDirURL=                 {}",fromDirURL);
        log.debug("toDirURL=                   {}",toDirURL);
        log.debug("fileNameStartsWith=       {}",fileNameStartsWith);
        log.info("Instantiating File System Manager (FSM).");
        StandardFileSystemManager fileSystemManager = null;
        FileObject fromDirFileObject = null;
        FileObject toDirFileObject   = null;
        try {
            fileSystemManager = new StandardFileSystemManager();
            log.info("Creating file objects.");
            FileSystemOptions opts = new FileSystemOptions();
            SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
            fileSystemManager.init();
            fromDirFileObject = fileSystemManager.resolveFile(fromDirURL,opts);
            toDirFileObject = fileSystemManager.resolveFile(toDirURL,opts);
            Boolean fromDirFileObjectExists = fromDirFileObject.exists();
            Boolean toDirFileObjectExists = toDirFileObject.exists();
            log.info("fromDirFileObjectExists? {}", fromDirFileObjectExists);
            log.info("toDirFileObjectExists?   {}", toDirFileObjectExists);
            if (fromDirFileObjectExists==false || toDirFileObjectExists==false) {
                log.error("Please check file paths, either directory does not exist.");
                throw new RuntimeException("Directory does not exists.");
            }
            FileFilter ff = new FileFilter()
            {
                public boolean accept(FileSelectInfo fileInfo)
                {
                    FileObject fo = fileInfo.getFile();
                    return fo.getName().getBaseName().startsWith(fileNameStartsWith);
                }
            };
            FileObject[] foundFiles = null;
            foundFiles = fromDirFileObject.findFiles(new FileFilterSelector(ff));
            if (foundFiles.length < 1 ) {
            log.info("No files found.");   
            } else {
                for (FileObject foundFile:foundFiles) {
                    String baseName = foundFile.getName().getBaseName();
                    String destinationFullName = toDirURL + toDirFileObject.getName().SEPARATOR + baseName;
                    log.debug("Trying to move {} into {}",baseName,destinationFullName);
                    foundFile.moveTo(fileSystemManager.resolveFile(destinationFullName,opts));
                    log.info("Moved {}",foundFile);
                }
            } // no code beyond this point
        } catch (FileSystemException e) {
            log.error("Something bad happened with the file system you are trying to reach. ", e);
        } finally {
            log.info("Closing FSM.");
            fileSystemManager.close();
        }
        long endPoint = System.nanoTime();
        log.info("Operation took {} nanoseconds.", (endPoint-startPoint));
    }
}

Friday, October 1, 2010

Number format and report title in BIRT, programmatically

Like this:
if (params["forexport"].value == 'n') {
this.getStyle().numberFormat = "Percent";
this.helpText = reportContext.getDesignHandle().title;
}