GeneXus Work With Pattern under gxPortal

Whit this example we’ll show how to create ANY groups under gxPortal, and apply certain privileges, or GRANT privileges to those groups, to perform the basic MODES under Genexus.

That is:

DSP – Display

DLT – Delete

UPD – Update

INS – Insert (Create)

EXP – Export

So, when you “put” a Work With Pattern under the portal, all those Privileges are Guarantee to work automatically.

First Step.

On the Application we are working under the portal, let’s create the following 5 Activities:


WW_List_ALL

WW_EXP

WW_INS

WW_UPD

WW_DSP

WW_DLT

As you can see on the pictures bellow there is a special Activity, that we call WWUsers_ALL which in terms, includes ALL the rest, what this means, is that the “group” that is assigned this Applications has “Admin” privileges, ALL the privileges

WW_ALL

WW_ALL_Activities

Second Step

There is a Procedure that is called by the WW every time they are executed, and its “isAuthorized”

Here’s where we’re going to put some code:

&Authorized = True

LoadContext.Call(&Context)

&Context.Porta_access_DLT = false

&Context.Portal_access_DSP = false

&Context.Portal_access_EXP = false

&Context.Portal_access_INS = false

&Context.Portal_access_UPD = false

//////////////////////// Check GXportal Security /////////////////////////

&GXPConnInf.DBConnection.Type   = GXPDBConnectionType.LAN

&GXPActivity = New GXPActivitySDT()

&GXPActivity.Name   = lower(&GxObject)

&GXPChkSec.Activities.Add(&GXPActivity)

&GXPActivity = New GXPActivitySDT()

&GXPActivity.Name   = !”WWUsers_” + GAMMode.INS

&GXPChkSec.Activities.Add(&GXPActivity)

&GXPActivity = New GXPActivitySDT()

&GXPActivity.Name   = !”WWUsers_” + GAMMode.DSP

&GXPChkSec.Activities.Add(&GXPActivity)

&GXPActivity = New GXPActivitySDT()

&GXPActivity.Name   = !”WWUsers_” + GAMMode.UPD

&GXPChkSec.Activities.Add(&GXPActivity)

&GXPActivity = New GXPActivitySDT()

&GXPActivity.Name   = !”WWUsers_” + GAMMode.DLT

&GXPChkSec.Activities.Add(&GXPActivity)

&GXPActivity = New GXPActivitySDT()

&GXPActivity.Name   = !”WWUsers_EXP” // export Data

&GXPChkSec.Activities.Add(&GXPActivity)  

Call(PGXPCheckSecurity , &GXPChkSec, &GXPConnInf, &GXPStatus )

//////////////////////////////////////////////////////////////////////////

If not Null(&GXPStatus.Id)

&Authorized = False

endif

// Valid Access  /////////////////////////////////////////////////////////

For &GXPActivity In &GXPChkSec.Activities

//msg(‘Name: ‘ + &GXPActivity.Name + ‘ – ProgramName :’ + &GXPActivity.ProgramName + ‘ – Status :’ + &GXPActivity.Status + ‘ – Access :’ +&GXPActivity.Access)

Do Case

Case &GXPActivity.Name = &GxObject

if &GXPActivity.Access  = GAMBoolean.False

&Authorized = False

endif

Case &GXPActivity.Name = !”WWUsers_” + GAMMode.INS

&Context.Portal_access_INS = &GXPActivity.Access

Case &GXPActivity.Name = !”WWUsers_” + GAMMode.DSP

&Context.Portal_access_DSP = &GXPActivity.Access

Case &GXPActivity.Name = !”WWUsers_” + GAMMode.UPD

&Context.Portal_access_UPD = &GXPActivity.Access

Case &GXPActivity.Name = !”WWUsers_” + GAMMode.DLT

&Context.Porta_access_DLT = &GXPActivity.Access

Case &GXPActivity.Name = !”WWUsers_EXP”

&Context.Portal_access_EXP = &GXPActivity.Access

//ExportExcel.Visible = &GXPActivity.Access

//TImportExcel.Visible = &GXPActivity.Access

EndCase

EndFor

//////////////////////////////////////////////////////////////////////////

SetContext.Call(&Context)

After that we are ready to call the WWs from inside the portal

Let’s just analyze it a little bit:

First we reset the “Modes” we’ll be load in the Context later

&Authorized = True
LoadContext.Call(&Context)
&Context.Porta_access_DLT = false
&Context.Portal_access_DSP = false
&Context.Portal_access_EXP = false
&Context.Portal_access_INS = false
&Context.Portal_access_UPD = false

Then we prepare the “Actions” to be checked on the gxPortal

//////////////////////// Check GXportal Security /////////////////////////
&GXPConnInf.DBConnection.Type   = GXPDBConnectionType.LAN
&GXPActivity = New GXPActivitySDT()
&GXPActivity.Name   = lower(&GxObject)
&GXPChkSec.Activities.Add(&GXPActivity)
&GXPActivity = New GXPActivitySDT()
&GXPActivity.Name   = !”WWUsers_” + GAMMode.INS
&GXPChkSec.Activities.Add(&GXPActivity)
&GXPActivity = New GXPActivitySDT()
&GXPActivity.Name   = !”WWUsers_” + GAMMode.DSP
&GXPChkSec.Activities.Add(&GXPActivity)
&GXPActivity = New GXPActivitySDT()
&GXPActivity.Name   = !”WWUsers_” + GAMMode.UPD
&GXPChkSec.Activities.Add(&GXPActivity)
&GXPActivity = New GXPActivitySDT()
&GXPActivity.Name   = !”WWUsers_” + GAMMode.DLT
&GXPChkSec.Activities.Add(&GXPActivity)
&GXPActivity = New GXPActivitySDT()
&GXPActivity.Name   = !”WWUsers_EXP” // export Data
&GXPChkSec.Activities.Add(&GXPActivity)  
Call(PGXPCheckSecurity , &GXPChkSec&GXPConnInf&GXPStatus )
//////////////////////////////////////////////////////////////////////////

and here we check that the actual “program” (work with) it’s authorized to be access under the “current user”, the user who is logged in the gxPortal

Case &GXPActivity.Name = &GxObject
if &GXPActivity.Access  = GAMBoolean.False
&Authorized = False
endif

And on the rest of the “case” we assigned the MODE to the “Context” to be used latter.

At this point pretty much ends up the “automatic” user control of privileges, now we need to proceed to write / apply the rules based on the “Modes”

Third Step

Now we work on the Transaction’s Work With Pattern

Once we’ve applied the Work With Patter, we select the “Modes” on the Main Selection Level of the Pattern.

Screen shot 2009-10-30 at 10.13.37 AM

And now we defined the “Condition” we want to apply for each MODE, for example, for INSERT we want “&Context.Portal_access_INS” to be “TRUE”, so we defined it as shown on the next pictures:

Screen shot 2009-10-30 at 10.16.30 AM

Screen shot 2009-10-30 at 10.16.41 AM

Here you can see an example of how it works with a user logged in with “DSP” privileges

Screen shot 2009-10-30 at 10.40.37 AM

And here with “UPD” privileges, notice the differences, in the previous one all the options were grayed out, on this one the “Edit” it is NOT, so he/she can edit the record

Screen shot 2009-10-30 at 11.41.21 AM

So far everything it’s working fine, but here is where it gets a little bit tricky, take a look at the next images showing the “TABs” on the Work With:

Screen shot 2009-10-30 at 12.42.03 PM

Screen shot 2009-10-30 at 12.42.12 PM

Screen shot 2009-10-30 at 12.42.25 PM

As you can see on the pictures above NONE of the privileges have been applied (by default) on the tabs, in order to correct that, we  have to repeat the same procedure for the MODES on each “TAB” of the work with.

NOTE:

There should be a way to apply the same concepts to the “TRANSACTIONS” inside the gxPortal, but I haven’t try anything yet. Please, let me know if you can figure it out an easy way to apply the privileges through the WW inside the Transactions.

Thanks.

Preparing Genexus to deploy applications on Unix with Java and Mysql

We’ll assume here that you already installed a Unix operating system, or Linux.

I’m using CentOS 5.0 (linux) on this example.

In addition I’m assuming that Apache , php and mysql is already installed, as well as phpMyAdmin since all of them came standard with most Linux.

Although we are not using any of those directlly on our application, we’ll use phpMyAdmin as a visual tool to connect with MySql, but in order to run phpMyAdmin you have to have Apache with php 🙂

Let’s start by downloading Tomcat and Java for Linux

If you are logged in your Lunux through ssh terminal, simply use the following commands:

this is for tomcat

wget http://apache.g5searchmarketing.com/tomcat/tomcat-5/v5.5.27/bin/apache-tomcat-5.5.27.tar.gz

or click here to download the file i used (Tomcat)

this is for java

wget http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jre-6u14-linux-i586-rpm.bin?BundledLineItemUUID=63tIBe.l9l4AAAEhrxM_7Kzm&OrderID=f.5IBe.lA4MAAAEhlhM_7Kzm&ProductID=hhNIBe.pzioAAAEhP1UP5zfr&FileName=/jre-6u14-linux-i586-rpm.bin

or click here to download the file I used (Java)

Or just go to their sites and download them from there.

For Java, we are using the pre-zipped auto-executable rpm file.

This means, that first we’ll give the file the mode to be executed

chmod +x jre-6u14-linux-i586-rpm.bin

./jre-6u14-linux-i586-rpm.bin

and them we execute it to install (you don’t need to rung the rpm command, it’s done automatically). This script install Java in the following directory /usr/java/default/.

Now let’s untar Tomcat. For compatibility reasons, let’s put it under the following directory: /usr/tomcat/default/ , but actually we untar it under /user/tomcat/apache-tomcat-5.5.27/ and later we create the symbolic link “default” to that particular directory.

tar xzf apache-tomcat-5.5.27.tar.gz

ln -s apache-tomcat-5.5.27/ default

Now, let’s configure the operating system with the appropriate global variables

At the end of the /etc/profile (file) we add the following commands:

export JAVA_HOME=/usr/java/default

export CATALINA_HOME=/usr/tomcat/default

Save and restart.
Now, you are ready to go.
Enjoy 🙂

Your First GeneXus Java + MySQL application

If you haven’t prepare your enviroment to develop under Java and Mysql, follow the steps on this post

  • Create a New Model
  • Select the compiler (Java)
  • Create Transactions (First)
  • If your default Data Storage isn’t MySql, Change it under “Preferences”
  • Hit “Execute” (it’ll create database and then run)
  • Enter some Data
  • See the data entered through MySQL Query Tools

That’s it, enjoy 🙂

See pictures bellow

 

Preparing Genexus to deploy applications on Windows with Java and Mysql

Download MySql for windows

Mysql Link  or the version I’m using for this blog here.

 

Let’s install some Graphic tools to work with the database

Original Link is here or this version here

 

 

Now let’s install Java Development Kit

From ( official site ) this version (here)

 

Now we need to install Tomcat from Apache (java server and webserver),

the official site is here (we are using version 5.5 ) and here our file

 

Here you have the gallery 

 

 

 

 

Now it’s time to create a GeneXus application (we are using version X )

Try this example

 

Enjoy 🙂

Read and Generate Excel and Word files

Now you can generate Excel and Word File with NO extra charge, using Jakarta POI

Requirements:

  • .NET Framework 2.0
  •  JSharp framework 2.0
  • Configure your model to compile and execute with Framework 2.0
  • DLL from Jakarta poi

Install JSharp (vjredist)

Install the DLL from Jakarta in your model (jakartapoi-winfx-dll-251-3), if you are compiling for WEB, put them on “DATAxxx/web/bin/”

Now you are ready to Read or Create Excel or Word files, here an example:

 

&excel is ExcelDocument Type

Place the “UseAutomation” = 0 before the “Open” command line.

 

 

Event "Excel"    &excel.UseAutomation = 0     &excel.Open(&File)      If &excel.ErrCode <> 0         msg(&excel.ErrDescription)     else         &excel.Clear()               &excel.Cells(1,1).Text = 'Customers list'          &excel.Cells(1,1).Bold = 1         &excel.Cells(1,1).Color = 54         &excel.Cells(1,1).Size = 10                  &excel.Cells(3,1).Text = 'Customer Id'         &excel.Cells(3,1).Italic = 1         &excel.Cells(3,1).Bold = 1              &row = 4         &col = 1         For each line in Grid                      &excel.Cells(&row,&col).Number = CustomerId                 &excel.Cells(&row,&col).Color = 3                 &row  = 1                           endfor          &excel.Save()      endif EndEvent