Commit c10cac9e authored by Tobias Jeger's avatar Tobias Jeger

ESSENTIALS-817: Extend REST service configuration tool to cover the 10.2 generic REST API feature.

parent 12be0e40
...@@ -25,6 +25,7 @@ public final class RestPluginConst { ...@@ -25,6 +25,7 @@ public final class RestPluginConst {
public static final String REST_NAME = "restName"; public static final String REST_NAME = "restName";
public static final String REST_TYPE = "restType"; public static final String REST_TYPE = "restType";
public static final String JAVA_FILES = "javaFiles"; public static final String JAVA_FILES = "javaFiles";
public static final String GENERIC_API_ENABLED = "genericApiEnabled";
private RestPluginConst() { private RestPluginConst() {
} }
......
...@@ -110,31 +110,25 @@ public class RestPluginResource extends BaseResource { ...@@ -110,31 +110,25 @@ public class RestPluginResource extends BaseResource {
@POST @POST
@Path("/") @Path("/")
public RestfulList<MessageRestful> executeInstructionPackage(final PostPayloadRestful payloadRestful, @Context ServletContext servletContext) { public RestfulList<MessageRestful> executeInstructionPackage(final PostPayloadRestful payloadRestful, @Context ServletContext servletContext) {
final RestfulList<MessageRestful> messages = new RestfulList<>();
final Map<String, String> values = payloadRestful.getValues(); final Map<String, String> values = payloadRestful.getValues();
final String restName = values.get(RestPluginConst.REST_NAME); final String restName = values.get(RestPluginConst.REST_NAME);
final String restType = values.get(RestPluginConst.REST_TYPE); final String restType = values.get(RestPluginConst.REST_TYPE);
final String selectedBeans = values.get(RestPluginConst.JAVA_FILES); final String selectedBeans = values.get(RestPluginConst.JAVA_FILES);
final boolean isGenericApiEnabled = Boolean.valueOf(values.get(RestPluginConst.GENERIC_API_ENABLED));
final RestfulList<MessageRestful> messages = new RestfulList<>();
if (Strings.isNullOrEmpty(restName) || Strings.isNullOrEmpty(restType)) { if (Strings.isNullOrEmpty(restName) || Strings.isNullOrEmpty(restType)) {
messages.add(new ErrorMessageRestful("REST service name / type or both were empty")); messages.add(new ErrorMessageRestful("REST service name / type or both were empty"));
return messages; return messages;
} }
final PluginContext context = PluginContextFactory.getContext(); final PluginContext context = PluginContextFactory.getContext();
final InstructionPackage instructionPackage = new RestServicesInstructionPackage();
// TODO: figure out injection part
getInjector().autowireBean(instructionPackage);
final Set<ValidBean> validBeans = annotateBeans(selectedBeans, context); final Set<ValidBean> validBeans = annotateBeans(selectedBeans, context);
instructionPackage.setProperties(new HashMap<String, Object>(values));
// add beans for instruction set loop:
instructionPackage.getProperties().put("beans", validBeans);
instructionPackage.execute(context);
// create endpoint rest // create endpoint rest
if (restType.equals("plain")) { if (restType.equals("plain")) {
final InstructionExecutor executor = new PluginInstructionExecutor(); final InstructionExecutor executor = new PluginInstructionExecutor();
// for each bean, add a resource to the project (site)
for (ValidBean validBean : validBeans) { for (ValidBean validBean : validBeans) {
final Map<String, Object> properties = new HashMap<>(); final Map<String, Object> properties = new HashMap<>();
properties.put("beanPackage", validBean.getBeanPackage()); properties.put("beanPackage", validBean.getBeanPackage());
...@@ -142,14 +136,25 @@ public class RestPluginResource extends BaseResource { ...@@ -142,14 +136,25 @@ public class RestPluginResource extends BaseResource {
properties.put("beans", validBean.getFullQualifiedName()); properties.put("beans", validBean.getFullQualifiedName());
properties.put("fullQualifiedName", validBean.getFullQualifiedName()); properties.put("fullQualifiedName", validBean.getFullQualifiedName());
properties.put("fullQualifiedResourceName", validBean.getFullQualifiedResourceName()); properties.put("fullQualifiedResourceName", validBean.getFullQualifiedResourceName());
final FileInstruction instruction = createFileInstruction();
// execute instruction:
final InstructionSet mySet = new PluginInstructionSet();
mySet.addInstruction(instruction);
context.addPlaceholderData(properties); context.addPlaceholderData(properties);
final InstructionSet mySet = new PluginInstructionSet();
mySet.addInstruction(createFileInstruction());
executor.execute(mySet, context); executor.execute(mySet, context);
} }
} }
if (isGenericApiEnabled) {
validBeans.add(createValidBeanForGenericRestApi());
}
// Set up REST mount and Spring configuration
final InstructionPackage instructionPackage = new RestServicesInstructionPackage();
getInjector().autowireBean(instructionPackage);
instructionPackage.setProperties(new HashMap<>(values));
instructionPackage.getProperties().put("beans", validBeans);
instructionPackage.execute(context);
final String message = "HST Configuration changed, project rebuild needed"; final String message = "HST Configuration changed, project rebuild needed";
eventBus.post(new RebuildEvent("restServices", message)); eventBus.post(new RebuildEvent("restServices", message));
messages.add(new MessageRestful(message)); messages.add(new MessageRestful(message));
...@@ -209,5 +214,11 @@ public class RestPluginResource extends BaseResource { ...@@ -209,5 +214,11 @@ public class RestPluginResource extends BaseResource {
return validBeans; return validBeans;
} }
private ValidBean createValidBeanForGenericRestApi() {
final ValidBean vb = new ValidBean();
vb.setFullQualifiedResourceName("org.hippoecm.hst.jaxrs.contentrestapi.ContentRestApiResource");
return vb;
}
} }
...@@ -15,62 +15,62 @@ ...@@ -15,62 +15,62 @@
--> -->
<div class="panel panel-default" ng-controller="restServicesCtrl"> <div class="panel panel-default" ng-controller="restServicesCtrl">
<div class="panel-heading">REST services setup plugin</div> <div class="panel-heading">REST resources</div>
<div class="list-group"> <div class="panel-body">
<div class="list-group-item"> <form novalidate name="restForm">
<form novalidate name="restForm"> <p>The Content REST API enables you and your users to access the content in the repository through generic REST
<table class="table table-striped table-bordered"> resources. If you are a new Hippo user and you want to experiment with Hipo's capabilities, this is the
<thead> recommended mechanism to use. It can be combined with manual resources, which provide greater control over
<tr> the look-and-feel and capabilities of your resources, but requires more Java knowledge and some manual steps.
<td>Choose endpoint name for REST service of type </p>
<a href="http://www.onehippo.org/library/concepts/rest/restful-api-support---plain-jax-rs-services.html" target="_blank"> <p>Choose the base URL for your REST API</p>
plain <hippo-icon name="external-link" size="m"></hippo-icon> <div class="input-group">
</a>. <span class="input-group-addon">http://localhost:8080/site/</span>
</td> <input type="text" ng-model="restName" ng-pattern="/^[a-z]{1,}$/" class="form-control" ng-required="true" ng-change="onChangeRestName()" placeholder="<Endpoint name>"/>
</tr> </div>
</thead> <div class="checkbox">
<tr> <label>
<td> <input type="checkbox" ng-model="isGenericContentRestApiEnabled"> Enable generic resourfes via Content REST API
<div class="input-group"> </label>
<span class="input-group-addon">http://localhost:8080/site/</span> </div>
<input type="text" ng-model="restName" ng-pattern="/^[a-z]{1,}$/" class="form-control" ng-required="true" ng-change="onChangeRestName()" placeholder="<Endpoint name>"/> <div class="checkbox">
</div> <label>
</td> <input type="checkbox" ng-model="isManualRestResourcesEnabled"> Configure manual REST resources
</tr> </label>
<tr> </div>
<td> <div ng-show="isManualRestResourcesEnabled">
<div ng-show="documentTypes.length"> <div ng-show="documentTypes.length">
<p>Select document type(s) to expose through REST</p> <p>Select document type(s) to expose through REST</p>
<div class="alert alert-info"> <div class="alert alert-info">
You may want to add more document types first by installing additional features from You may want to add more document types first by installing additional features from
the <a href="#/library">Library</a> or creating custom document types in the the <a href="#/library">Library</a> or creating custom document types in the
<a href="http://www.onehippo.org/library/concepts/document-types/document-type-editor.html" <a href="http://www.onehippo.org/library/concepts/document-types/document-type-editor.html"
target="_blank">CMS Document Type Editor <hippo-icon name="external-link" size="m"></hippo-icon></a>. target="_blank">CMS Document Type Editor <hippo-icon name="external-link" size="m"></hippo-icon></a>.
</div> </div>
<ul class="list-group"> <ul class="list-group">
<li ng-repeat="doc in documentTypes" style="cursor: move; height: 28px; padding-top: 2px" class="list-group-item"> <li ng-repeat="doc in documentTypes" style="cursor: move; height: 28px; padding-top: 2px" class="list-group-item">
<span style="padding-right: 20px; cursor: default"> <span style="padding-right: 20px; cursor: default">
<input type="checkbox" ng-checked="checked(doc)" name="myDocument" ng-model="doc.checked" ng-required="checkedDocuments == 0"/> <input type="checkbox" ng-checked="checked(doc)" name="myDocument" ng-model="doc.checked"/>
</span> </span>
{{doc.name}} {{doc.name}}
<span style="padding-left: 40px; cursor: default" class="pull-right" ng-show="doc.checked && doc.endpoint"> <span style="padding-left: 40px; cursor: default" class="pull-right" ng-show="doc.checked && doc.endpoint">
<a target="_blank" href="{{doc.endpoint}}">{{doc.endpoint}}</a> <a target="_blank" href="{{doc.endpoint}}">{{doc.endpoint}}</a>
</span> </span>
</li> </li>
</ul> </ul>
</div> <div class="alert alert-danger" ng-hide="checkedDocuments > 0">
<div class="alert alert-danger" ng-hide="checkedDocuments > 0"> You need to select at least one document type in order to set up the REST API.
You need to select at least one document type in order to set up the REST API. </div>
</div>
</td>
</tr>
<tr>
<td>
<button ng-disabled="!restForm.$valid" class="btn btn-primary pull-right" ng-click="runRestSetup()">Run setup</button>
</td>
</tr>
</table>
</form>
</div> </div>
</div> <div class="alert alert-danger" ng-hide="documentTypes.length">
No document types are available yet. You need to create or install some to configure manual REST resources.
</div>
</div>
</form>
</div>
<div class="panel-footer">
<button ng-disabled="!restForm.$valid || (!isGenericContentRestApiEnabled && (!isManualRestResourcesEnabled || checkedDocuments == 0))"
class="btn btn-primary pull-right" ng-click="runRestSetup()">Run setup</button>
<div class="clearfix"></div>
</div>
</div> </div>
...@@ -19,9 +19,11 @@ ...@@ -19,9 +19,11 @@
angular.module('hippo.essentials') angular.module('hippo.essentials')
.controller('restServicesCtrl', function ($scope, $sce, $log, $rootScope, $http) { .controller('restServicesCtrl', function ($scope, $sce, $log, $rootScope, $http) {
$scope.endpoint = $rootScope.REST.dynamic + 'restservices/'; $scope.endpoint = $rootScope.REST.dynamic + 'restservices/';
$scope.restName = ""; $scope.restName = "api";
$scope.documentTypes = []; $scope.documentTypes = [];
$scope.checkedDocuments = 0; $scope.checkedDocuments = 0;
$scope.isGenericContentRestApiEnabled = true;
$scope.isManualRestResourcesEnabled = false;
$scope.onChangeRestName = function () { $scope.onChangeRestName = function () {
updateEndPoints(); updateEndPoints();
...@@ -42,8 +44,9 @@ ...@@ -42,8 +44,9 @@
var payload = Essentials.addPayloadData("restName", $scope.restName, null); var payload = Essentials.addPayloadData("restName", $scope.restName, null);
Essentials.addPayloadData("restType", "plain", payload); Essentials.addPayloadData("restType", "plain", payload);
Essentials.addPayloadData("javaFiles", fileString, payload); Essentials.addPayloadData("javaFiles", fileString, payload);
$http.post($scope.endpoint, payload).success(function (data) { Essentials.addPayloadData("genericApiEnabled", $scope.isGenericContentRestApiEnabled, payload);
// TODO: display reboot message and instruction sets executed $http.post($scope.endpoint, payload).success(function () {
// empty
}); });
}; };
......
...@@ -24,6 +24,6 @@ ...@@ -24,6 +24,6 @@
</instructionSet> </instructionSet>
<instructionSet group="plain"> <instructionSet group="plain">
<xml action="copy" overwrite="false" source="plain_mount.xml" target="/hst:hst/hst:hosts/dev-localhost/localhost/hst:root"/> <xml action="copy" overwrite="false" source="plain_mount.xml" target="/hst:hst/hst:hosts/dev-localhost/localhost/hst:root"/>
<file action="copy" overwrite="false" source="spring-plain-rest-api.xml" target="{{siteOverrideFolder}}/spring-plain-rest-api.xml"/> <file action="copy" overwrite="true" source="spring-plain-rest-api.xml" target="{{siteOverrideFolder}}/spring-plain-rest-api.xml"/>
</instructionSet> </instructionSet>
</instructions> </instructions>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment