Friday, September 28, 2012

Append two Arrays in Java

Still need to optimize this method but this works with out any issues,

public String[] appendArrays(String[] arrayToAdd, String[] arrayFromAdd) {
        List<String> list = new ArrayList<String>(Arrays.asList(arrayToAdd));
        if (arrayFromAdd != null && arrayFromAdd.length > 0) {
            list.addAll(Arrays.asList(arrayFromAdd));
        } else {
            arrayFromAdd = new String[]{"N/A"};
            list.addAll(Arrays.asList(arrayFromAdd));
        }
        return list.toArray(new String[list.size()]);
    }

   



Convert ResultSet to Array in Java

public String[] convertRStoArray(ResultSet resultSet, boolean closeResultSet) {
        String[] arrayofDataColumns = null;
        Map columnsMap = new HashMap();
        int columns = 0;
        try {
            List<String> record = new ArrayList<String>();
            while (resultSet.next()) {
                arrayofDataColumns = new String[resultSet.getMetaData().getColumnCount()];
                columns = (resultSet.getMetaData()).getColumnCount();
                String value = null;
                for (int i = 1; i <= columns; i++) {
                    value = resultSet.getString(i);
                    record.add(value);
                    if (columnsMap.containsKey(i)) {
                        if (value != null && !value.equals("")) {

                            if (columnsMap.get(i) != null && !columnsMap.get(i).equals("") && !columnsMap.get(i).equals(value)) {
                                value = columnsMap.get(i) + "|" + value;
                                columnsMap.put(i, value);
                            }
                        }
                    } else {
                        columnsMap.put(i, value);
                    }
                }
                Object[] keys = columnsMap.keySet().toArray();
                for (int ii = 0; ii < keys.length; ii++) {
                    arrayofDataColumns[ii] = (String) columnsMap.get(ii + 1);
                }
            }

        } catch (Exception e) {
            logger.log(Level.SEVERE, "Got the exception in convertRStoArray:" + e.getMessage());
        } finally {
            if (closeResultSet)
                closeResultSet(resultSet);
        }
        return arrayofDataColumns;
    }
    



Saturday, September 22, 2012

IBM Sterling B2B Integrator Code List Deployment through Command Prompt

C:\Sirish\SterlingIntegrator\install\tp_import>import.cmd -update -passphrase passphrase -input C:\Sirish\bpml_coding\Sirish.xml

This is the format requires to import from command prompt.

Sirish.xml

<?xml version="1.0" encoding="UTF-8"?>
<SI_RESOURCES xmlns="http://www.stercomm.com/SI/SI_IE_Resources" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" GISVersion="6000" FrameworkVersion="2">
            <CODE_LISTS>
                        <CODE_LIST_XREF>
                                    <LIST_NAME>Sirish</LIST_NAME>
                                    <SENDER_ID/>
                                    <RECEIVER_ID/>
                                    <LIST_VERSION>2</LIST_VERSION>
                                    <SIResourceDefaultVersion>true</SIResourceDefaultVersion>
                                    <STATUS>1</STATUS>
                                    <COMMENTS/>
                                    <USERNAME>Sirish Reddy Gongal Reddy</USERNAME>
                                    <CREATE_DATE>2012-09-21 14:43:16.087</CREATE_DATE>
                                    <CODE_LIST_XREF_ITEMS>
                                                <CODE_LIST_XREF_ITEM>
                                                            <SENDER_ITEM>Sirish Reddy</SENDER_ITEM>
                                                            <RECEIVER_ITEM>Gongal Reddy</RECEIVER_ITEM>
                                                            <TEXT1>Target System - One</TEXT1>
                                                            <TEXT2>Target System - Two</TEXT2>
                                                            <TEXT3>Target System - 3</TEXT3>
                                                            <TEXT4>Target System - 4</TEXT4>
                                                            <TEXT5>Target System - 5</TEXT5>
                                                            <TEXT6>Target System - 6</TEXT6>
                                                            <TEXT7>Target System - 7</TEXT7>
                                                            <TEXT8>Target System - Eight</TEXT8>
                                                            <TEXT9>Target System - Nine</TEXT9>
                                                            <DESCRIPTION>Just Testing the Auto Import</DESCRIPTION>
                                                </CODE_LIST_XREF_ITEM>
                                    </CODE_LIST_XREF_ITEMS>
                        </CODE_LIST_XREF>
            </CODE_LISTS>

</SI_RESOURCES>

Tuesday, September 11, 2012

Offset for given Time Zone

import java.util.TimeZone;

public String getTimeZoneOffSet(String timeZoneID) {
        TimeZone tz = TimeZone.getTimeZone(timeZoneID);
        int rawOffset = tz.getRawOffset();
        int hour = rawOffset / (60 * 60 * 1000);
        int minute = Math.abs(rawOffset / (60 * 1000)) % 60;
        return hour + ":" + minute;
    }

Test:
 tc.getTimeZoneOffSet("America/New_York")); This returns Offset for NY -->-5:0

Using Calendar Class

import java.util.Calendar;

public int getOffsetForTimeZone(String timeZoneId) {
        int a;
        Calendar calendar = new GregorianCalendar();
        TimeZone timeZ = calendar.getTimeZone();
        timeZ = timeZ.getTimeZone(timeZoneId);
        a = (int) ((timeZ.getRawOffset()) * (2.77777778 / 10000000));
        return a;
    }


Thursday, September 6, 2012

Graphical Process Modeler not opening in Sterling Integrator

Most of the times we get the below exception while opening Graphical Process modeler because the IP address in the below URL is not correct. Sterling Integrator host address and GMP host address different then we need to fix the host name and make it common.

com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://192.168.235.76:15000/gbm/pmodeler/ProcessModeler.jnlp
    at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
    at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
    at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
    at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
    at com.sun.javaws.Launcher.launch(Unknown Source)
    at com.sun.javaws.Main.launchApp(Unknown Source)
    at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
    at com.sun.javaws.Main$1.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

How to Fix:

       1. Stop Sterling Integrator.
       2. <SI_Install>/bin folder and execute the below commnad.
       3. <SI_Install>/bin> patchJNLP.cmd <put your hostname here>
       4. Start the Sterling Integrator and go to Business Process Manager and Run Graphical Process Modeler. (Don't use old jnlp file and download fresh copy)