Skip to content

Commit

Permalink
Added OSGi based portlet module
Browse files Browse the repository at this point in the history
  • Loading branch information
azzazzel committed Mar 15, 2015
1 parent d027af1 commit 3d280aa
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<module>usecases</module>
<module>catalog-microservice</module>
<module>osgi</module>
<module>portlet</module>
</modules>


Expand Down
1 change: 1 addition & 0 deletions portlet/catalog-portlet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
61 changes: 61 additions & 0 deletions portlet/catalog-portlet/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.glassfish.javaeetutorial</groupId>
<artifactId>portlet</artifactId>
<version>7.0.6-SNAPSHOT</version>
</parent>

<artifactId>catalog-portlet</artifactId>
<name>Catalog portlet </name>
<packaging>bundle</packaging>


<dependencies>
<dependency>
<groupId>org.glassfish.javaeetutorial</groupId>
<artifactId>usecases-catalog</artifactId>
<version>7.0.6-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package></Export-Package>
<Private-Package>com.forest.portlet.catalog</Private-Package>
<Import-Package>
javax.servlet,
javax.portlet;version=0.0.0,
com.forest.model,
*
</Import-Package>
<Include-Resource>
META-INF/resources=src/main/resources
</Include-Resource>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Require-Capability>
osgi.extender;filter:="(&amp;(osgi.extender=jsp.taglib)(uri=http://java.sun.com/portlet_2_0))",
osgi.extender;filter:="(&amp;(osgi.extender=jsp.taglib)(uri=http://liferay.com/tld/aui))",
osgi.extender;filter:="(&amp;(osgi.extender=jsp.taglib)(uri=http://liferay.com/tld/portlet))",
osgi.extender;filter:="(&amp;(osgi.extender=jsp.taglib)(uri=http://liferay.com/tld/theme))",
osgi.extender;filter:="(&amp;(osgi.extender=jsp.taglib)(uri=http://liferay.com/tld/ui))"
</Require-Capability>
<_dsannotations>*</_dsannotations>
</instructions>
</configuration>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.forest.portlet.catalog;

import java.io.IOException;

import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;

import com.forest.usecase.catalog.ProductManager;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;

@Component(immediate = true, property = {
"com.liferay.portlet.css-class-wrapper=portlet-catalog",
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.reasultinstanceable=false",
"com.liferay.portlet.preferences-owned-by-group=true",
"com.liferay.portlet.private-request-attributes=false",
"com.liferay.portlet.private-session-attributes=false",
"com.liferay.portlet.render-weight=50",
"javax.portlet.display-name=Duke's Catalog",
"javax.portlet.expiration-cache=0",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.security-role-ref=power-user,user" }, service = Portlet.class)
public class CatalogPortlet extends MVCPortlet {

ProductManager productManager;

@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL)
void bindProductManager(ProductManager productManager) {
this.productManager = productManager;
}

void unbindProductManager(ProductManager productManager) {
this.productManager = null;
}

@Override
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {

if (productManager == null) {
include("/error.jsp", renderRequest, renderResponse);
} else {
renderRequest.setAttribute("productManager", productManager);
super.doView(renderRequest, renderResponse);
}
}

}
3 changes: 3 additions & 0 deletions portlet/catalog-portlet/src/main/resources/error.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h3> Coffee time !!!</h3>

Why don't you cet a cup of coffee while we try to put our catalog back online!
26 changes: 26 additions & 0 deletions portlet/catalog-portlet/src/main/resources/init.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>

<%@ page import="com.liferay.portal.kernel.util.Constants"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ page import="com.liferay.portal.kernel.util.StringPool"%>
<%@ page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ page import="javax.portlet.PortletURL"%>
<%@ page import="com.forest.model.Product"%>
<%@ page import="com.forest.usecase.catalog.ProductManager"%>
<%@ page import="java.util.List"%>

<portlet:defineObjects />

<liferay-theme:defineObjects />

<%
PortletURL portletURL = renderResponse.createRenderURL();
String currentURL = portletURL.toString();
%>
49 changes: 49 additions & 0 deletions portlet/catalog-portlet/src/main/resources/view.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

<%@ include file="/init.jsp" %>

<%
ProductManager pm = (ProductManager)request.getAttribute("productManager");
List<Product> products = pm.getAll();
%>


<liferay-ui:search-container
total="<%= products.size() %>"
>
<liferay-ui:search-container-results
results="<%= products %>"
/>

<liferay-ui:search-container-row
className="com.forest.model.Product"
escapedModel="true"
modelVar="foo"
>
<liferay-ui:search-container-column-text
name="id"
property="id"
valign="top"
/>

<liferay-ui:search-container-column-text
name="name"
property="name"
valign="top"
/>

<liferay-ui:search-container-column-text
name="description"
property="description"
valign="top"
/>

<liferay-ui:search-container-column-text
name="price"
property="price"
valign="top"
/>
</liferay-ui:search-container-row>

<liferay-ui:search-iterator />
</liferay-ui:search-container>

63 changes: 63 additions & 0 deletions portlet/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.glassfish.javaeetutorial</groupId>
<artifactId>dukes-forest</artifactId>
<version>7.0.6-SNAPSHOT</version>
</parent>

<artifactId>portlet</artifactId>
<packaging>pom</packaging>

<properties>
<liferay.version>7.0.0-m4</liferay.version>
</properties>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

</dependencies>

<repositories>
<repository>
<id>liferay</id>
<url>http://cdn.repository.liferay.com/nexus/content/groups/public</url>
</repository>
</repositories>



<modules>
<module>catalog-portlet</module>
</modules>
</project>

0 comments on commit 3d280aa

Please sign in to comment.