Bug 532633 - Generate a separate page for Resource largePreview

Separate html page is now produced for largePreview.

Change-Id: I1aa73afd4edcc7142849277e2a96c6458975bf16
Signed-off-by: Jad El-khoury <jad@kth.se>
diff --git a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/files/generateResourceService.mtl b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/files/generateResourceService.mtl
index 0fa5988..31d2cde 100644
--- a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/files/generateResourceService.mtl
+++ b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/files/generateResourceService.mtl
@@ -506,12 +506,12 @@
             smallPreview.setDocument(UriBuilder.fromUri(a[javaName(aResource, true)/].getAbout()).path("smallPreview").build());
             compact.setSmallPreview(smallPreview);
 
-            //Use the HTML representation of a change request as the large preview as well
             final Preview largePreview = new Preview();
             largePreview.setHintHeight(largePreviewHintHeight);
             largePreview.setHintWidth(largePreviewHintWidth);
-            largePreview.setDocument(a[javaName(aResource, true)/].getAbout());
+            largePreview.setDocument(UriBuilder.fromUri(a[javaName(aResource, true)/].getAbout()).path("largePreview").build());
             compact.setLargePreview(largePreview);
+
             httpServletResponse.addHeader([javaInterfaceNameForAdaptorConstants(anAdaptorInterface)/].HDR_OSLC_VERSION, [javaInterfaceNameForAdaptorConstants(anAdaptorInterface)/].OSLC_VERSION_V2);
             return compact;
         }
@@ -542,6 +542,31 @@
 
         throw new WebApplicationException(Status.NOT_FOUND);
     }
+
+    @GET
+    [JAXRSPathAnnotation(JAXRSConcatURISegments(aResource.instanceURISegment(aBasicCapability), 'largePreview'))/]
+    @Produces({ MediaType.TEXT_HTML })
+    public void [getResourceLargePreviewMethodName(aBasicCapability, aResource)/](
+        [commaSeparate(instanceMethodSignature(aResource, aBasicCapability, true), false, false)/]
+        ) throws ServletException, IOException, URISyntaxException
+    {
+        // [protected (getResourceLargePreviewMethodName(aBasicCapability, aResource).concat('_init'))]
+        // [/protected]
+
+        final [getResourceMethodResourceType(aBasicCapability, aResource)/] a[javaName(aResource, true)/] = [javaClassNameForAdaptorManager(anAdaptorInterface) /].[getResourceMethodName(aBasicCapability, aResource, true)/](httpServletRequest[commaSeparate(instanceMethodParameterList(aResource, aBasicCapability), true, false)/]);
+
+        if (a[javaName(aResource, true)/] != null) {
+            httpServletRequest.setAttribute("a[javaName(aResource, true)/]", a[javaName(aResource, true)/]);
+            // [protected (getResourceLargePreviewMethodName(aBasicCapability, aResource).concat('_setAttributes'))]
+            // [/protected]
+
+            RequestDispatcher rd = httpServletRequest.getRequestDispatcher("[getResourceLargePreviewJspRelativeFileName(aResource, anAdaptorInterface) /]");
+            httpServletResponse.addHeader([javaInterfaceNameForAdaptorConstants(anAdaptorInterface)/].HDR_OSLC_VERSION, [javaInterfaceNameForAdaptorConstants(anAdaptorInterface)/].OSLC_VERSION_V2);
+            rd.forward(httpServletRequest, httpServletResponse);
+        }
+
+        throw new WebApplicationException(Status.NOT_FOUND);
+    }
     [/for]
     [/if]
     [if (aBasicCapability.delete)]
diff --git a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/jsp/generateGetResourceLargePreviewJsp.mtl b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/jsp/generateGetResourceLargePreviewJsp.mtl
new file mode 100644
index 0000000..a59419d
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/jsp/generateGetResourceLargePreviewJsp.mtl
@@ -0,0 +1,113 @@
+[comment encoding = UTF-8 /]
+[comment
+<%--
+ Copyright (c) 2011, 2012, 2017 IBM Corporation and others.
+
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+
+ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ and the Eclipse Distribution License is available at
+ http://www.eclipse.org/org/documents/edl-v10.php.
+
+ Contributors:
+
+  Sam Padgett     - initial API and implementation
+  Michael Fiedler - adapted for OSLC4J
+  Jad El-khoury   - initial implementation of code generator (422448)
+  Frédéric Loiret - Switch the template to Bootstrap (519699)
+--%>
+/]
+
+[module generateGetResourceLargePreviewJsp('http://org.eclipse.lyo/oslc4j/adaptorInterface')]
+
+[import org::eclipse::lyo::oslc4j::codegenerator::services::services/]
+[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/]
+[import org::eclipse::lyo::oslc4j::codegenerator::services::resourceServices/]
+[import org::eclipse::lyo::oslc4j::codegenerator::services::resourcePropertyServices/]
+[import org::eclipse::lyo::oslc4j::codegenerator::services::jspServices/]
+
+[template public generateGetResourceLargePreviewJsp(aResource : Resource, contextAdaptorInterface : AdaptorInterface, managingAdaptorInterface: AdaptorInterface)]
+[file (getResourceLargePreviewJspFullFileName(aResource, contextAdaptorInterface), false, 'UTF-8')]
+<!DOCTYPE html>
+<%--[protected ('"Copyright"')]
+--%>
+<%--
+ Copyright (c) 2011, 2012, 2017 IBM Corporation and others.
+
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+
+ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ and the Eclipse Distribution License is available at
+ http://www.eclipse.org/org/documents/edl-v10.php.
+
+ Contributors:
+
+  Sam Padgett     - initial API and implementation
+  Michael Fiedler - adapted for OSLC4J
+  Jad El-khoury   - initial implementation of code generator (422448)
+  Frédéric Loiret - Switch the template to Bootstrap (519699)
+
+ This file is generated by org.eclipse.lyo.oslc4j.codegenerator
+--%>
+<%--[/protected]--%>
+
+<%--[protected ('"body"')]
+--%>
+<%--TODO: Replace/adjust this default content as necessary.
+All manual changes in this "protected" user code area will NOT be overwritten upon subsequent code generations.
+To revert to the default generated content, delete all content in this file, and then re-generate.
+--%>
+
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
+
+<%@page import="org.eclipse.lyo.oslc4j.core.model.ServiceProvider"%>
+<%@page import="java.util.List" %>
+<%@page import="[javaClassFullName(aResource, contextAdaptorInterface, null) /]"%>
+
+<%@ page contentType="text/html" language="java" pageEncoding="UTF-8" %>
+
+<%
+  [javaClassName(aResource)/] a[javaName(aResource, true)/] = ([javaClassName(aResource)/]) request.getAttribute("a[javaName(aResource, true)/]");
+%>
+
+<html lang="en">
+<head>
+  <meta charset="utf-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+
+  <title><%= a[javaName(aResource, true)/].toString(false) %></title>
+
+  <link href="<c:url value="/static/css/bootstrap-4.0.0-beta.min.css"/>" rel="stylesheet">
+  <link href="<c:url value="/static/css/adaptor.css"/>" rel="stylesheet">
+
+  <script src="<c:url value="/static/js/jquery-3.2.1.min.js"/>"></script>
+  <script src="<c:url value="/static/js/popper-1.11.0.min.js"/>"></script>
+  <script src="<c:url value="/static/js/bootstrap-4.0.0-beta.min.js"/>"></script>
+</head>
+
+<body>
+
+<!-- Begin page content -->
+<div>
+        <div>
+          [for (propertiesCollection: Collection(ResourceProperty) | Sequence{aResource.resourceProperties, inheritedProperties(aResource), interfaceProperties(aResource)})]
+          [for (aProperty: ResourceProperty | propertiesCollection)]
+          <dl class="dl-horizontal">
+            <dt>[aProperty.name /]</dt>
+            <dd><%= a[javaName(aResource, true)/].[javaAttributeName(aProperty, aResource) /]ToHtml()%></dd>
+          </dl>
+          [/for]
+          [/for]
+        </div>
+      </div>
+</body>
+</html>
+<%--[/protected]--%>
+[/file]
+[/template]
diff --git a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/main/generate.mtl b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/main/generate.mtl
index 9dfefc1..419a3a3 100644
--- a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/main/generate.mtl
+++ b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/main/generate.mtl
@@ -52,6 +52,7 @@
 [import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateFilteredResourceCollectionJsp/]
 [import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateGetResourceJsp/]
 [import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateGetResourceSmallPreviewJsp/]
+[import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateGetResourceLargePreviewJsp/]
 [import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateResourceCreatorJsp/]
 [import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateResourceSelectorJsp/]
 [import org::eclipse::lyo::oslc4j::codegenerator::jsp::generateResourceSelectorClientJsp/]
@@ -160,6 +161,7 @@
     [if (not basicCapabilities(anAdaptorInterface, aResource)->isEmpty())]
         [aResource.generateGetResourceJsp(anAdaptorInterface, anAdaptorInterface) /]
         [aResource.generateGetResourceSmallPreviewJsp(anAdaptorInterface, anAdaptorInterface) /]
+        [aResource.generateGetResourceLargePreviewJsp(anAdaptorInterface, anAdaptorInterface) /]
     [/if]
 [/for]
 [/template]
diff --git a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/jspServices.mtl b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/jspServices.mtl
index 90be908..6de7f4a 100644
--- a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/jspServices.mtl
+++ b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/jspServices.mtl
@@ -54,6 +54,13 @@
 jspFilesBasePath(anAdaptorInterface).concatenatePaths(getResourceSmallPreviewJspRelativeFileName(aResource, anAdaptorInterface))
 /]
 
+[query public getResourceLargePreviewJspRelativeFileName(aResource: Resource, anAdaptorInterface : AdaptorInterface) : String =
+jspFilesWebappPath(anAdaptorInterface).concatenatePaths(aResource.javaName(true)).concat('largepreview.jsp').toLower()
+/]
+[query public getResourceLargePreviewJspFullFileName(aResource: Resource, anAdaptorInterface : AdaptorInterface) : String =
+jspFilesBasePath(anAdaptorInterface).concatenatePaths(getResourceLargePreviewJspRelativeFileName(aResource, anAdaptorInterface))
+/]
+
 [query private resourceCreatorJspSimpleFileName(aCreationDialog: Dialog) : String =
 (if (aCreationDialog.usages->size() = 0) then
     concatenate(aCreationDialog.resourceTypes.javaName(true)->sep('', 'And', '').oclAsType(String)).toLower()
diff --git a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/serviceServices.mtl b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/serviceServices.mtl
index ca82053..80430af 100644
--- a/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/serviceServices.mtl
+++ b/org.eclipse.lyo.oslc4j.codegenerator/src/org/eclipse/lyo/oslc4j/codegenerator/services/serviceServices.mtl
@@ -299,6 +299,10 @@
 getResourceMethodName(aBasicCapability, aResource, false).concat('SmallPreview')
 /]
 
+[query public getResourceLargePreviewMethodName(aBasicCapability: BasicCapability, aResource: Resource) : String = 
+getResourceMethodName(aBasicCapability, aResource, false).concat('LargePreview')
+/]
+
 [query public deleteResourceMethodName(aBasicCapability: BasicCapability, aResource: Resource) : String = 
 'delete'.concat(javaName(aResource, true))
 /]