When you have completed this training module, you will be able to develop a secure OperationHook
to respond to the creation of documents and rename them automatically.
Project creation
Using your favorite IDE, start by creating a new Maven project with the following POM:
<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>
<groupId>com.flower.docs.samples</groupId>
<artifactId>modify-operation-hook</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.flower.docs</groupId>
<artifactId>flower-docs-starter-client</artifactId>
<version>2.8.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.14</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
Spring Boot application
This Spring Boot application is based on the Spring Boot starter provided by FlowerDocs.
- To start with, we need a main class Spring Boot annotated with the
@SpringBootApplication
annotation:
|
|
Then add the
application.properties
file to your project’ssrc/main/resources
directory to configure the application:1 2 3 4 5 6 7 8
spring.application.name=modify-hook server.port=7777 server.servlet.context-path=/modify ws.url=http://localhost:8081/core/services internal.realm.users[0].id=<user> internal.realm.users[0].password=<password>
1 Spring Boot application name
2 Port used to expose WEB application
3 Application path. The application can be accessed via the basic URL http://localhost:7777/modify
5 URL for accessing the web services exposed by FlowerDocs Core.
7 User identifier for accessing the
OperationHook
.8 User password for accessing the
OperationHook
Hook development
Now we move on to Operation Hook
! To implement your first hook, create a ModifyOperationHook
class such as:
|
|
13 The @RestController
annotation defines the hook as a REST web service exposed on /
14 The ModifyOperationHook
class extends the OperationHook
class, making it easier to implement a hook using the Spring Boot framework
17 The process
method must be implemented to define the behavior following the execution of an operation within FlowerDocs Core
17 TheOperationHook
reacts only to DefaultComponentOperationContext
class contexts
24 Each component of the operating context is renamed using the current date