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 {
public static final String REST_NAME = "restName";
public static final String REST_TYPE = "restType";
public static final String JAVA_FILES = "javaFiles";
public static final String GENERIC_API_ENABLED = "genericApiEnabled";
private RestPluginConst() {
}
......
......@@ -110,31 +110,25 @@ public class RestPluginResource extends BaseResource {
@POST
@Path("/")
public RestfulList<MessageRestful> executeInstructionPackage(final PostPayloadRestful payloadRestful, @Context ServletContext servletContext) {
final RestfulList<MessageRestful> messages = new RestfulList<>();
final Map<String, String> values = payloadRestful.getValues();
final String restName = values.get(RestPluginConst.REST_NAME);
final String restType = values.get(RestPluginConst.REST_TYPE);
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)) {
messages.add(new ErrorMessageRestful("REST service name / type or both were empty"));
return messages;
}
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);
instructionPackage.setProperties(new HashMap<String, Object>(values));
// add beans for instruction set loop:
instructionPackage.getProperties().put("beans", validBeans);
instructionPackage.execute(context);
// create endpoint rest
if (restType.equals("plain")) {
final InstructionExecutor executor = new PluginInstructionExecutor();
// for each bean, add a resource to the project (site)
for (ValidBean validBean : validBeans) {
final Map<String, Object> properties = new HashMap<>();
properties.put("beanPackage", validBean.getBeanPackage());
......@@ -142,14 +136,25 @@ public class RestPluginResource extends BaseResource {
properties.put("beans", validBean.getFullQualifiedName());
properties.put("fullQualifiedName", validBean.getFullQualifiedName());
properties.put("fullQualifiedResourceName", validBean.getFullQualifiedResourceName());
final FileInstruction instruction = createFileInstruction();
// execute instruction:
final InstructionSet mySet = new PluginInstructionSet();
mySet.addInstruction(instruction);
context.addPlaceholderData(properties);
final InstructionSet mySet = new PluginInstructionSet();
mySet.addInstruction(createFileInstruction());
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";
eventBus.post(new RebuildEvent("restServices", message));
messages.add(new MessageRestful(message));
......@@ -209,5 +214,11 @@ public class RestPluginResource extends BaseResource {
return validBeans;
}
private ValidBean createValidBeanForGenericRestApi() {
final ValidBean vb = new ValidBean();
vb.setFullQualifiedResourceName("org.hippoecm.hst.jaxrs.contentrestapi.ContentRestApiResource");
return vb;
}
}
......@@ -15,62 +15,62 @@
-->
<div class="panel panel-default" ng-controller="restServicesCtrl">
<div class="panel-heading">REST services setup plugin</div>
<div class="list-group">
<div class="list-group-item">
<form novalidate name="restForm">
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Choose endpoint name for REST service of type
<a href="http://www.onehippo.org/library/concepts/rest/restful-api-support---plain-jax-rs-services.html" target="_blank">
plain <hippo-icon name="external-link" size="m"></hippo-icon>
</a>.
</td>
</tr>
</thead>
<tr>
<td>
<div class="input-group">
<span class="input-group-addon">http://localhost:8080/site/</span>
<input type="text" ng-model="restName" ng-pattern="/^[a-z]{1,}$/" class="form-control" ng-required="true" ng-change="onChangeRestName()" placeholder="<Endpoint name>"/>
</div>
</td>
</tr>
<tr>
<td>
<div ng-show="documentTypes.length">
<p>Select document type(s) to expose through REST</p>
<div class="alert alert-info">
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
<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>.
</div>
<ul class="list-group">
<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">
<input type="checkbox" ng-checked="checked(doc)" name="myDocument" ng-model="doc.checked" ng-required="checkedDocuments == 0"/>
</span>
{{doc.name}}
<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>
</span>
</li>
</ul>
</div>
<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.
</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 class="panel-heading">REST resources</div>
<div class="panel-body">
<form novalidate name="restForm">
<p>The Content REST API enables you and your users to access the content in the repository through generic REST
resources. If you are a new Hippo user and you want to experiment with Hipo's capabilities, this is the
recommended mechanism to use. It can be combined with manual resources, which provide greater control over
the look-and-feel and capabilities of your resources, but requires more Java knowledge and some manual steps.
</p>
<p>Choose the base URL for your REST API</p>
<div class="input-group">
<span class="input-group-addon">http://localhost:8080/site/</span>
<input type="text" ng-model="restName" ng-pattern="/^[a-z]{1,}$/" class="form-control" ng-required="true" ng-change="onChangeRestName()" placeholder="<Endpoint name>"/>
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="isGenericContentRestApiEnabled"> Enable generic resourfes via Content REST API
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="isManualRestResourcesEnabled"> Configure manual REST resources
</label>
</div>
<div ng-show="isManualRestResourcesEnabled">
<div ng-show="documentTypes.length">
<p>Select document type(s) to expose through REST</p>
<div class="alert alert-info">
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
<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>.
</div>
<ul class="list-group">
<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">
<input type="checkbox" ng-checked="checked(doc)" name="myDocument" ng-model="doc.checked"/>
</span>
{{doc.name}}
<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>
</span>
</li>
</ul>
<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.
</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>
......@@ -19,9 +19,11 @@
angular.module('hippo.essentials')
.controller('restServicesCtrl', function ($scope, $sce, $log, $rootScope, $http) {
$scope.endpoint = $rootScope.REST.dynamic + 'restservices/';
$scope.restName = "";
$scope.restName = "api";
$scope.documentTypes = [];
$scope.checkedDocuments = 0;
$scope.isGenericContentRestApiEnabled = true;
$scope.isManualRestResourcesEnabled = false;
$scope.onChangeRestName = function () {
updateEndPoints();
......@@ -42,8 +44,9 @@
var payload = Essentials.addPayloadData("restName", $scope.restName, null);
Essentials.addPayloadData("restType", "plain", payload);
Essentials.addPayloadData("javaFiles", fileString, payload);
$http.post($scope.endpoint, payload).success(function (data) {
// TODO: display reboot message and instruction sets executed
Essentials.addPayloadData("genericApiEnabled", $scope.isGenericContentRestApiEnabled, payload);
$http.post($scope.endpoint, payload).success(function () {
// empty
});
};
......
......@@ -24,6 +24,6 @@
</instructionSet>
<instructionSet group="plain">
<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>
</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