Monday, November 19, 2012

Oracle Portal Dynamic SQL Portlets

I recently had some trouble in getting parameter-based SQL Omni Portlets to do what I wanted in Oracle Portal. I wanted the portlet to show different results for each user, filtered on their username. I got confused by Page Parameters, which will not be needed in order to achive this functionality. After finally figuring out how it should be put together, it became a lot less complicated to set up. In this post I will provide the steps to how I was able to achieve the desired functionality. Hope someone finds it usefull!

1: Defining the portlet

First, add an OMNI portlet to the page that you want to work with. Lets assume you have a table called emp_salary that contains... well... you guessed it. Setup the SQL query like you normally would ("Add portlet" -> "Omni Portlet" -> "SQL") and specify the connection and SQL; e.g.:
Select empName, salary from emp_salary where empName = 'Andras'
Now make sure that the SQL works and save the portlet for later editing.

2: Defining a Portlet Parameter

Next we want a page parameter that will contain the name of the employee that we want to show the salary for. Go to the page properties:

Then select the Parameters tab


On this page, we can see a list of OmniPortlets which we can define parameters for. Let us go ahead and map Param1 to the logged in username:
This just maps a new parameter called "Param1" to the username of the currently logged in portal user (which is the value we want to use in our SQL-where-clause).

3: Using the Parameter in our SQL

We have now populated a portlet parameter that will contain the username of the current Portal User. Let's head back to our OmniPortlet and make use of it. Go back to the OmniPortlet and edit it by pressing the pencil icon (edit defaults). Now in the SQL section change the query to:
Select empName, salary from emp_salary where empName = :SELUSR
Then press the "Show Bind Variables" button, to display the bind variable:
We now want the value that we created earlier to be passed to the bind variable, and we there set the SELUSR field to contain the value: ##Param1##

Now apply the changes and/or press OK. All that is left now is checking if it works!


Tuesday, September 18, 2012

Productivity tips for writing assignments (Part 1)

Introduction

I am currently studying Software Engineering at the University of Liverpool through Laureate Online Higher Education, and after 3 modules, I found some productivity tips that I would like to share. This will be a walkthrough of how I usually start by analysing the question given, and how I do my research, and how I then put it all together.

Some notes:


  • I use Microsoft OneNote for notetaking, but some of my classmates have also recommended evernote as one great application to gather your notes.
  • Access to online resources, such as ACM.org or IEEE is an important factor, in order to get quality some resources to base your statements of your document upon.
  • Note-taking is time consuming, and may interrupt your train of thought. Therefore you should keep the activities in your note taking application while you write, and once you think you've found enough information, then switch to word or open office (or your favorite word processing application) to produce your final document.
  • If you have problems with procrastinating, I would highly recommend the Pomodoro Technique, and use the free Pomodoro Application to help you stay on the task. (You should find the time to read the book about the pomodoro technique, which also is free to download).

Getting Started

Now, with those things stated, let's dive into the actual task: Writing the assignment. Well, not exactly, because you need to understand your question(s) before writing anything. Therefore, let us take a look at one example question:

Directions: Complete one of the exercises.
1. You have been asked to design a secure system that requires strong authentication and authorization. The system must be designed so that communications between parts of the system cannot be intercepted and read by an attacker. Suggest the most appropriate client-server architecture for the system and, giving reasons for your answer, propose how functionality should be distributed between the client and the server system.

2. Your customer wants to develop a system for stock information where brokers can access information about companies and evaluate various investment scenaries using a simulation system. Each broker uses this simulation in a different way, according to his or her experience and type of stocks in question. Suggest a client-server architecture for this system that shows where functionality is located. Justify the client-server system model that you ahve chosen.

3. You are developing a vacation package reservation service for a travel agent. Design a workflow that will book ground transportation for a group of passengers arriving at an airport. They should be given the option of booking either a taxi or renting a car. You may assume that the taxi and car rental companies offer web services to make a reservation. 
First of all, you should try figuring out which question will produce most thoughts, and will have a lot of resources. Remember that the easiest question will probably not be the one that gives you the best grades, if it includes a lot of prior knowledge or current assumptions. You need to go into detail and analyse critically the parts of the assignment. That said, you should not exclude the easiest question from your possible answers - just remember to choose wisely.

Continue to "Analysing the question" >>

Wednesday, January 12, 2011

Windows 7 gadget

A friend of mine asked me today about how to write a Windows 7 sidebar gadget. I remembered having read about it being simple, so i wanted to see how to do it. I had a couple of ideas for what I would use it for at work, and I was surtain that my colleagues would use it, if it would prove useful.

So having basic knowledge of programming, I decided to give it a go.

My first assumption was that you would launch Visual Studio, Visual Basic Express or Visual C# Express to get started, but none of those were mentioned in the information I could find. You basically need to create a folder and minimum 2 files. First you create a folder in this location:
%USERPROFILE%\AppData\Local\Microsoft\Windows Sidebar\Gadgets
(Press [WindowsKey]+[R])
Then windows explorer opens and shows you the content of your custom sidebar gadgets folder.
Here you create a new folder called myGadget.gadget where myGadget is replaced with the name of the gadget you want to create. I called my gadget "klokkuskipan" (meaning something simular to "TimeTracker"):



Now that I have the folder created, I need to create the two files:
Klokkuskipan.html
gadget.xml

Note that it's important for the manifest file to be called "gadget.xml" or else it won't get displayed in the "Add Gadget Dialog" which we will see later.

First I created the manifest file: gadget.xml
The contens of this file is:

<?xml version="1.0" encoding="utf-8" ?>
<gadget>
  <name>Klokkuskipan</name>
  <version>1.0.0.0</version>
  <author name="Føroya Gjaldstova">
    <info url="blog.isolveit.net" />
  </author>
  <copyright>&#169; 2011</copyright>
  <description>Klokkuskipan Sidebar Gadget</description>
  <hosts>
    <host name="sidebar">
      <base type="HTML" apiVersion="1.0.0" src="Klokkuskipan.html" />
      <permissions>Full</permissions>
      <platform minPlatformVersion="1.0" />
    </host>
  </hosts>
</gadget>


Next up is the html file. This file is the actual content displayed to the user. This filename must match the filename in the highlighted <base "src"> attribute shown above.

The content of the html file in my case was:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
        <title>Klokkuskipan</title>
        <style type="text/css">
        body
        {
            margin: 0;
            width: 130px;
            height: 75px;
            font-family: verdana;
            font-weight: bold;
            font-size: 20px;
        }
        #gadgetContent
        {
            margin-top: 20px;
            width: 130px;
            vertical-align: middle;
            text-align: center;
            overflow: hidden;
        }
        </style>


        <script type="text/jscript" language="jscript">
            // Initialize the gadget.
            function init()
            {
                var oBackground = document.getElementById("imgBackground");
                oBackground.src = "url(images/background.png)";
            }
           
        </script>

    </head>
    <body onload="init()">
        <g:background id="imgBackground">
            <span id="gadgetContent">Klokkuskipanin</span>
        </g:background>
    </body>
</html>


All that is happening in the html file is, that I made a simple style to the gadget, and added a javascript to create a background image to it "on_load". This image resides in an images sub folder that I created. The reason I did this was that I have a black desktop background, which makes my gadget unreadable and ugly. So I made an image for that purpose.

Now after this you should already be able to see your gadget if you add it via the sidebar.

If you do not see the sidebar already check that you indeed run the required operating system, and that the sidebar is running. If it isn't running you can start it by pressing [WindowsKey]+[R], type "sidebar" into the "Open" box and then press [Enter].

Now that sidebar is running, right click on a gadget and select "Add gadget" from the menu:


Then, when the gadget selector shows, you should see your gadget there:


Now try to add this gadget to view your creation:


I'm going to call this the "End of part 1" stay tuned for "part 2".

Monday, January 10, 2011

LDAP lookup in vb.net

I was developing a synchronization feature that should synchronize users from AD to my web application. The scenario was, that when a new user was added to Active Directory, the user would be registered in my app also. In addition to that, names, addresses, phone numbers etc. should also be changed automaticcally to reflect the changes in AD. Deletion should also inactivate the user in my app.

However I ran into problems when I tried to get the directory-entries from AD.
My approach was something like:

My AD path that I would read from was at:

ldap://my_server:389/OU=MyOU Users,OU=MyOU,DC=Mynet,DC=net

so my VB.Net code was:


Imports System.DirectoryServices

    Public Shared Function GetDirectoryEntry(ByVal path As String) As DirectoryEntry
        Dim de As DirectoryEntry = New DirectoryEntry()
        de.Path = path
        de.Username = "domain\user"
        de.Password = "password"
        Return de
    End Function

    Dim de As DirectoryEntry = GetDirectoryEntry("ldap://my_server:389/OU=MyOU Users,OU=MyOU,DC=Mynet,DC=net")
    Dim ds As DirectorySearcher = New DirectorySearcher(de)
    Dim filter As StringBuilder = New StringBuilder()
    filter.Append("(objectClass=user)")
    ds.Filter = filter.ToString()
    ds.SearchScope = SearchScope.Subtree
    Dim results As SearchResultCollection = ds.FindAll()
    For Each result As SearchResult In results
        Dim dey As DirectoryEntry = GetDirectoryEntry(result.Path)
        LocateAndSaveUser(dey.Properties("sAMAccountName").Value, _
               dey.Properties("displayName").Value, _
               dey.Properties("mail").Value, _
               dey.Properties("telephoneNumber").Value)
    Next result
    de.Close()

This returned:
Unknown error (0x80005000)

Quite an informative error message :)

It was a mixture of luck and googling that I found out what was wrong. It seems that you get this error if you don't write the "ldap://" in caps : "LDAP://"

After that it had no problems :)

Changed this:

ldap://my_server:389/OU=MyOU Users,OU=MyOU,DC=Mynet,DC=net

To this:

LDAP://my_server:389/OU=MyOU Users,OU=MyOU,DC=Mynet,DC=net


There weren't so many hits on google that had a solution on this, so I thought this would probably help someone else if I blogged it.