Friday, November 5, 2010

India Sanitary Ware Distribution

Customize the Dashboard to JBoss Portal

In

Jboss-Portal users once logged in have access to the dashboard, a personal section of the user can arrange at will. The dashboard is set up at the first login the user using the portal as a base / template. But if we were to have multiple templates for the creation of the dashboard? To have different templates to create different types of dashboards based on user? For example, if a portal user and administrators may have a template already set up with all the portlets for the administration of the portal, as well as for a configuration that contains an editor or editorial tools for easy user configuration that contains its profile and various utilities portal. In this
Jboss-Portal functionality is not possible and for introducing it must act on the MBean CustomizationManager. This service takes care of creating the dashboard to retrieve the user and creates it if does not exist yet. In addition to the dashboard also manages the recovery of the portlet instances that make the portal pages.
First we create a project calling jar jboss-mbean-extensions can also be done using the maven command



mvn archetype: generate-DarchetypeArtifactId = maven-archetype-quickstart-DarchetypeVersion = 1.1-DgroupId = it.ruletheobject -DartifactId = jboss-extensions-mbean

modify the pom.xml and add the dependencies seguneti Libraries necessary to Jboss.
 \u0026lt;dependency> 
\u0026lt;groupId> jboss \u0026lt;/ groupId>
\u0026lt;artifactId> jboss-system \u0026lt;/ artifactId>
\u0026lt;version> 4.0.2 \u0026lt;/ version>
\u0026lt;/ dependency>
\u0026lt; dependency>
\u0026lt;groupId> jboss.common \u0026lt;/ groupId>
\u0026lt;artifactId> jboss-common \u0026lt;/ artifactId>
\u0026lt;version> 1.2.1.GA-brew \u0026lt;/ version>
\u0026lt;/ dependency>
\u0026lt;dependency>
\u0026lt;groupId> org.jboss.portal.core \u0026lt;/ groupId>
\u0026lt;artifactId> Jems \u0026lt;/ artifactId>
\u0026lt;version> 2.7.1.GA \u0026lt;/ version>
\u0026lt;/ dependency> ;
\u0026lt;dependency>
\u0026lt;groupId> org.jboss.portal.core \u0026lt;/ groupId>
\u0026lt;artifactId> security \u0026lt;/ artifactId>
\u0026lt;version> 2.7.1.GA \u0026lt;/ version>
\u0026lt;/ dependency>
\u0026lt;dependency>
\u0026lt;groupId> org.jboss.portal.identity \u0026lt;/ groupId>
\u0026lt;artifactId> identity-identity \u0026lt;/ artifactId>
\u0026lt;version> 1.0.2 \u0026lt;/ version>
\u0026lt;/ dependency>
\u0026lt;dependency> ;
\u0026lt;groupId> org.jboss.portal.core \u0026lt;/ groupId>
\u0026lt;artifactId> core \u0026lt;/ artifactId>
\u0026lt;version> 2.7.1.GA \u0026lt;/ version>
\u0026lt;/ dependency>

\u0026lt; ; dependency>
\u0026lt;groupId> Jboss \u0026lt;/ groupId>
\u0026lt;artifactId> jboss-jmx \u0026lt;/ artifactId>
\u0026lt;version> 4.2.3.GA \u0026lt;/ version>
\u0026lt;/ dependency>



To create our service MyCustomizationManagerService AbstractJBossService we need to extend and implement the 'CustomizationManager interface that exposes the following methods

CustomizationManager.java

Instance getInstance (Window window) throws IllegalArgumentException;

Instance getInstance (Window window, User user) throws IllegalArgumentException;

Portal getDashboard (User user) throws IllegalArgumentException;

boolean isDashboard (PortalObject object, User user);

destroyDashboard void (String userId);

The method that interests us is getDashboard (User user) can implement methods for the courts of relying CustomizationManagerService jboss.
addition to implementing the methods of the interface we need to add class attributes that will be injected from the jboss-service.xml
private String dashboardContextId;
private InstanceContainer instanceContainer;
private PortalAuthorizationManagerFactory portalAuthorizationManagerFactory;
private PortalObjectContainer portalObjectContainer;
private UserModule userModule;
Private RoleModule roleModule;


getDashboard method (User user) and the method that retrieves the user's dashbord here we must insert our logic for the selection of templates based on the type of user that is logged.

 public getDashboard Portal (User user) throws IllegalArgumentException {
/ /
Portal dashboardPortal = null;
if (user! = Null) {String userId =
getUserId (user);

try {Context = dashboardContext portalObjectContainer
. getContext (dashboardContextId)
/ /
dashboardPortal dashboardContext.getPortal = (userId);
/ / Create the dashboard if there
if (dashboardPortal == null)
{String userTemplate = getUserTemplate (userid);
Portal templatePortal = null;
PortalObjectId templates;
if (userTemplate! = Null) {template = PortalObjectId.parse
("/" + userTemplate,
PortalObjectPath.CANONICAL_FORMAT);
templatePortal = (Portal) portalObjectContainer.getObject (template);}


if (templatePortal == null) {template = PortalObjectId.parse
("/ template",
PortalObjectPath.CANONICAL_FORMAT);
templatePortal = (Portal) portalObjectContainer.getObject (template);}


/ / Copy the template portal
dashboardPortal = (Portal) templatePortal.copy (dashboardContext, userId, false);
copy (templatePortal, dashboardContext.getChild (userId));}



} catch (DuplicatePortalObjectException e) {log.error
("", e);

}} return
dashboardPortal;

}


The dashboard is created the first user login. In fact, in the method getDashboard first you go to check if the user has a dashboard and otherwise proceed in creazione.Per First we make a connection between you and the template to use. For our example I used a convention based on user roles. If the role of the user admin and use the template "/ template_admin" else "/ template_user. You can decide the relationship between user and needed this to your template, for example, by saving it in the database, a properties file, a property of the user on the ldap etc.


 private String getUserTemplate (User user) {String template = 
"template_user"


try {final set roles = membershipModule.getRoles (user);
for (Role role: roles)
{if (role . getName (). equals ("Admin")) {template =
"template_admin";}


}} catch (IdentityException e) {
e.printStackTrace ();}


return template;}




Once recovered proceed to use the template to retrieve the corresponding portal and proceed to copy and assiociandolo as the user dashboard.

 PortalObjectId PortalObjectId.parse template = ("/" + userTemplate, 
portalObjectPath.CANONICAL_FORMAT)
templatePortal = Portal (Portal) portalObjectContainer.getObject (template);
(Portal) templatePortal.copy (dashboardContext, userId, false )
copy (templatePortal, dashboardContext.getChild (userId));


To see our work CustomizationManager we have to configure the jboss-service.xml in the folder to find the configuration jboss-portal.sar/META-INF Customization of manager and change the configuration org.jboss.portal.core.impl.model.CustomizationManagerService with our
it.ruletheobject.jboss.core.customization.MyCustomizationManagerService.

 \u0026lt;! - Customization manager -> 
\u0026lt;mbean code = "it.ruletheobject.jboss.core.customization.MyCustomizationManagerService"
name = "portal: service = CustomizationManager"
xmbean-dd = "" xmbean-code = "org.jboss.portal.jems.as.system.JBossServiceModelMBean">
\u0026lt;xmbean/>
\u0026lt;depends optional-attribute-name = "PortalAuthorizationManagerFactory"
proxy-type = "attribute">
portal: service = PortalAuthorizationManagerFactory
\u0026lt;/ depends>
\u0026lt;depends optional-attribute-name="InstanceContainer"
proxy-type="attribute"> portal: container = Instance \u0026lt;/ depends>
\u0026lt;depends optional-attribute-name="PortalObjectContainer"
proxy-type="attribute"> portal: container = portal object
\u0026lt;/ depends>
\u0026lt;depends> portal: service = Module, type = identity ServiceController \u0026lt;/ depends>
\u0026lt;attribute name="DashboardContextId"> dashboard \u0026lt;/ attribute>
\u0026lt;/ mbean>


After configuring our MBean we do build our project with mvn clean install and copy the jar created under the jboss-portal.sar/lib below target folder.
After starting the portal you need to create portals that will be used as a template in this case / template_user and / template_admin.
To test the proper operation create two users and an administrator and a user login effettunado check if you have used the correct template to create the dashboard.

The version of jboss portal tested is 2.7.2

0 comments:

Post a Comment