Debug Java From Lotus Notes Designer

We do not prefer to write agents in Java just because we are not able to debug the Java agent in Lotus Notes Designer. As we think Designer do not have any debugger for Java, but let me clarify that Lotus Notes Designer 8.5.x (also known as Domino Designer in Eclipse) has in-built Java debugger.

It is very clear that to write a Java agent we must extend AgentBase class and implement notesmain() function. So if our Java agent requires Domino Infrastructure to execute then how can we debug it? We have to make it a Java application to debug it. So we must define main function in our Java agent.

I am assuming the name of the agent class is MyAgent.

 

Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
protected Session _goSession;
protected AgentContext _goCtx;
        
public MyAgent(){}
public MyAgent(Session s, AgentContext c) {
    _goSession = s;
    _goCtx = c;
}
public static void main(String[] args) {
    Session s = null;    
    NotesThread.sinitThread();
    try {
        s = NotesFactory.createSession();
        // NotesMain(), the way Domino does
        MyAgent a = new MyAgent(s, s.getAgentContext());
        a.NotesMain();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (s != null) s.recycle();
        } catch (Exception x) {}
        NotesThread.stermThread();
    }            
} // end main

After adding above code to your Java agent switch to Java Debugger Perspective and goto Debug Configuration and double click on Java Application in left side. Check stop in main option and click on debug button to start debugging.

I hope this helps you in debugging your Java agent. If any query feel free to write me back…:)

Disable X in Dojo Dialog

I found a trick to disable [x] on the top right corner of dojo dialog and force user to click on the close button to close the dialog box. Create a div element in your html web page and pass its id to following function to achieve this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function createDialog(id, heading) {
    var dialogWidget = dijit.byId(id);
    if( dialogWidget ) {
        dialogWidget.destroyRecursive(true);
    }
    dialogWidget = new dijit.Dialog(
                    { title: heading,
                   isContainer: true,
                   duration:600,
                   isContainer: true,
                   style:"width:600;height:300;overflow:auto;position:absolute;z-index:1000"},
                   dojo.byId(id));
    
    var dialog = dojo.byId(id);
    var dijitDialog = dijit.byId(id);
    dijitDialog.closeButtonNode.style.display = "none";
    dijitDialog._onKey = function(evt){
        key = evt.keyCode;
        if (key == dojo.keys.ESCAPE) {
            dojo.stopEvent(evt);
        }
    };
    if(dialog.parentNode) {
        dialog.parentNode.removeChild(dialog);
    }
    var form = document.forms[0];
    form.appendChild(dialog);
    dialogWidget.startup();
}

File Upload in CakePHP

In this post I will describe how to upload images in CakePHP. It will automatically upload and move the uploaded file to the wanted location. It will automatically rename the file if there is another file with same name exist. A lot of other features are also available.

  • Download Upload Component file and copy it to the location app/Controller/Component/UploadComponent.php
  • Initialize
    1
    var $components = array('Upload');
  • Your add action would looks like:
    PHP
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    public function add() {
        if ($this->request->is('post')) {
            if (!empty($this->request->data) && is_uploaded_file($this->request->data['Gallery']['image']['tmp_name'])) {
                
                $this->Upload->upload($this->data['Gallery']['image']);
                if ($this->Upload->uploaded) {
                    $this->Upload->file_new_name_body = 'image_resized';
                    $this->Upload->image_resize = true;
                    $this->Upload->image_x = 400;
                    $this->Upload->image_ratio_y = true;
                    $this->Upload->process(Configure::read('UploadPath'));
                    if ($this->Upload->processed) {
                        $this->Upload->clean();
                        $this->request->data['Gallery']['image'] = basename($this->Upload->file_dst_name);
                    } else {
                        $errors = $this->Upload->error;
                        $this->Session->setFlash(__($errors));
                        exit();
                    }
                }
            }
            $this->Gallery->create();
            if ($this->Gallery->save($this->request->data)) {
                $this->Session->setFlash(__('The gallery has been saved'));
                $this->redirect(array('controller' => 'galleries' ,'action' => 'index'));
            } else {
                $this->Session->setFlash(__('The gallery could not be saved. Please, try again.'));
            }
        }
    }

  • We have setup our controller. Now its time to setup view file add.ctp. The file file should look like following:

    PHP
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <div class="galleries form">
    < ?php echo $this->Form->create('Gallery', array('enctype' => 'multipart/form-data'));?>
        <fieldset>
            <legend>< ?php echo __('Add Gallery'); ?></legend>
        < ?php
            echo $this->Form->input('caption');
            echo $this->Form->input('desc');
            echo $this->Form->file('image');
        ?>
        </fieldset>
    < ?php echo $this->Form->end(__('Submit'));?>
    </div>
    <div class="actions">
        <h3>< ?php echo __('Actions'); ?></h3>
        <ul>
            <li>< ?php echo $this->Html->link(__('List Galleries'), array('action' => 'index'));?></li>
        </ul>
    </div>

  • All done.

UploadComponent class file is well document so you can always find all configuration setting for the uploaded images.

Setting Auth & ACL in CakePHP

In last few days I learned CakePHP and now I am finding it very interesting. I learned the basics about creation of models and their relationships. Now its time to move ahead. I am exploring more features and I started with inbuilt Auth component of CakePHP which I found very interesting. Let me tell you one thing that if you are following the conventions you can save a lot of time.

To set up Auth and ACL for my application I followed Mark Story’s post which is very helpful. I followed the tutorial and I was easily able to setup Auth & ACL for my application.

But in my application every user belongs to some group and it must inherit permission from that group only. There should not be any user wise permission. This case is not handled in the above tutorial. So, whenever I add new user a new ARO record is being created in aros table, which is not required. I dont want any ARO record for my users as they are inheriting permission from their group. To achieve this functionality I modified $actAs variable as follows:

1
2
3
4
5
6
public $actsAs = array(
            'Acl' => array(
                    'type' => 'requester',
                    'enabled' => false
                )
            );

Look at the declaration carefully as I am passing two parameters type and enabled. Second parameter enabled tells the behaviour class not to look for ARO record for User model if there is already a ARO record of parent Group model. Now we have to define a function bindNode to tell that this user is bind to which ARO node. This function must return a reference to group model. So our bindNode function would look like:

1
2
3
public function bindNode($object) {
    return array('Group' => array('id' => $user['User']['group_id']));
}

Lets Bake in PHP using CakePHP

From last week I decided to learn CakePHP, which is a open source web application framework for producing web applications. It is written in PHP, modeled after the concepts of Ruby on Rails, and distributed under the MIT License.

I started with the official documentation. But I am not finding it very useful when you really get stuck somewhere. But CakePHP has active developer team and very active community.

Here’s a quick list of features you’ll enjoy when using CakePHP:

  • Integrated CRUD for database interaction
  • Application scaffolding
  • Code generation
  • MVC architecture
  • Request dispatcher with clean, custom URLs and routes
  • Built-in validation
  • Fast and flexible templating (PHP syntax, with helpers)
  • View Helpers for AJAX, JavaScript, HTML Forms and more
  • Email, Cookie, Security, Session, and Request Handling Components
  • Flexible ACL
  • Data Sanitization
  • Flexible Caching
  • Works from any web site directory, with little to no Apache configuration involved

Thats all what I get from the initial chapters of CakePHP.