Skip to content

Commit d7a6a61

Browse files
committed
#initial-commit
1 parent b9b732a commit d7a6a61

File tree

12 files changed

+1170
-0
lines changed

12 files changed

+1170
-0
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea
8+
*.iws
9+
*.iml
10+
*.ipr
11+
12+
### Eclipse ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
17+
.settings
18+
.springBeans
19+
.sts4-cache
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
!**/src/main/**/build/
29+
!**/src/test/**/build/
30+
31+
### VS Code ###
32+
.vscode/
33+
34+
### Mac OS ###
35+
.DS_Store

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Nested Set Tree Utilities for Spring Boot JPA (Kotlin Implementation)
2+
3+
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4+
[![Maven badge](https://maven-badges.herokuapp.com/maven-central/com.mewebstudio/spring-boot-jpa-nested-set-kotlin/badge.svg?style=flat)](https://central.sonatype.com/artifact/com.mewebstudio/spring-boot-jpa-nested-set-kotlin)
5+
[![javadoc](https://javadoc.io/badge2/com.mewebstudio/spring-boot-jpa-nested-set-kotlin/javadoc.svg)](https://javadoc.io/doc/com.mewebstudio/spring-boot-jpa-nested-set-kotlin)
6+
7+
This package provides a generic and reusable implementation of the [Nested Set Model](https://en.wikipedia.org/wiki/Nested_set_model) for managing hierarchical data using Spring Boot and JPA.
8+
9+
It is designed to be extended and adapted for any entity that implements the `INestedSetNode<ID, T : INestedSetNode<ID, T>>` interface.
10+
11+
---
12+
13+
## 📦 Package Overview
14+
15+
**Package:** `com.mewebstudio.springboot.jpa.nestedset.kotlin`
16+
17+
### Core Components
18+
19+
- **`INestedSetNode<ID, T : INestedSetNode<ID, T>>`**
20+
Interface that defines the structure of a nested set node (left, right, parent).
21+
22+
- **`INestedSetNodeResponse<ID>`**
23+
Interface for representing nodes with children, used for building hierarchical responses.
24+
25+
- **`JpaNestedSetRepository<T : INestedSetNode<ID, T>, ID> : JpaRepository<T, ID>`**
26+
Base JPA repository interface with custom queries for nested set operations (e.g. find ancestors, descendants, siblings).
27+
28+
- **`AbstractNestedSetService<T : INestedSetNode<ID, T>, ID>`**
29+
Abstract service class that implements common logic for creating, moving, and restructuring nodes in a nested set tree.
30+
31+
---
32+
33+
## ✅ Features
34+
35+
- Create new nodes in the correct position in the nested set.
36+
- Move nodes up or down among siblings.
37+
- Retrieve ancestors and descendants of a node.
38+
- Rebuild the entire tree from an unordered list of nodes.
39+
- Shift and close gaps in the tree on node deletion.
40+
- Generic and type-safe structure, reusable across multiple domain entities.
41+
42+
---
43+
44+
## 📥 Installation
45+
46+
#### for maven users
47+
Add the following dependency to your `pom.xml` file:
48+
```xml
49+
<dependency>
50+
<groupId>com.mewebstudio</groupId>
51+
<artifactId>spring-boot-jpa-nested-set-kotlin</artifactId>
52+
<version>0.1.0</version>
53+
</dependency>
54+
```
55+
#### for gradle users
56+
Add the following dependency to your `build.gradle` file:
57+
```groovy
58+
implementation 'com.mewebstudio:spring-boot-jpa-nested-set-kotlin:0.1.0'
59+
```
60+
61+
## 🚀 Usage
62+
63+
### 1. Example entity class `INestedSetNode<ID, T : INestedSetNode<ID, T>>`
64+
```kotlin
65+
@Entity
66+
class Category(
67+
// implement getId, getLeft, getRight, getParent, etc.
68+
) : AbstractBaseEntity(), INestedSetNode<String, Category>
69+
```
70+
71+
### 2. Example repository interface `JpaNestedSetRepository<T : INestedSetNode<ID, T>, ID> : JpaRepository<T, ID>`
72+
```kotlin
73+
interface CategoryRepository : JpaNestedSetRepository<Category, String>
74+
```
75+
76+
### 3. Example service class `AbstractNestedSetService<T : INestedSetNode<ID, T>, ID>`
77+
```kotlin
78+
@Service
79+
class CategoryService(
80+
private val categoryRepository: CategoryRepository
81+
) : AbstractNestedSetService<Category, String>(categoryRepository) {
82+
// Implement additional service methods as needed
83+
}
84+
```
85+
86+
## 🔁 Other Implementations
87+
88+
[Spring Boot JPA Nested Set (Java Maven Package)](https://github.com/mewebstudio/spring-boot-jpa-nested-set)
89+
90+
## 💡 Example Implementations
91+
92+
[Spring Boot JPA Nested Set - Kotlin Implementation](https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin-impl)
93+
94+
[Spring Boot JPA Nested Set - Java Implementation](https://github.com/mewebstudio/spring-boot-jpa-nested-set-java-impl)

pom.xml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<name>JPA Nested Set</name>
7+
<description>Spring Boot JPA Nested Set (Kotlin)</description>
8+
<url>https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin</url>
9+
<groupId>com.mewebstudio</groupId>
10+
<artifactId>spring-boot-jpa-nested-set-kotlin</artifactId>
11+
<version>0.1.0</version>
12+
<packaging>jar</packaging>
13+
14+
<developers>
15+
<developer>
16+
<name>Muharrem Erin</name>
17+
<email>erin.muharrem@gmail.com</email>
18+
<url>https://www.mewebstudio.com</url>
19+
<organization>MeWebStudio</organization>
20+
<organizationUrl>https://www.mewebstudio.com</organizationUrl>
21+
<roles>
22+
<role>Developer</role>
23+
</roles>
24+
<timezone>Europe/Istanbul</timezone>
25+
</developer>
26+
</developers>
27+
28+
<licenses>
29+
<license>
30+
<name>MIT</name>
31+
<url>https://opensource.org/licenses/MIT</url>
32+
<distribution>repo</distribution>
33+
</license>
34+
</licenses>
35+
36+
<scm>
37+
<url>https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin</url>
38+
<connection>scm:git:git://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin.git</connection>
39+
<developerConnection>scm:git:git://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin.git
40+
</developerConnection>
41+
</scm>
42+
43+
<profiles>
44+
<profile>
45+
<id>release</id>
46+
</profile>
47+
</profiles>
48+
49+
<properties>
50+
<maven.compiler.source>17</maven.compiler.source>
51+
<maven.compiler.target>17</maven.compiler.target>
52+
<kotlin.version>1.9.23</kotlin.version>
53+
<spring-boot-starter-data-jpa.version>[3.0.11,)</spring-boot-starter-data-jpa.version>
54+
<junit-jupiter.version>5.11.4</junit-jupiter.version>
55+
<mockito.version>5.14.2</mockito.version>
56+
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
57+
<maven-javadoc-plugin.version>3.10.1</maven-javadoc-plugin.version>
58+
<maven-gpg-plugin.version>3.2.7</maven-gpg-plugin.version>
59+
<central-publishing-maven-plugin.version>0.7.0</central-publishing-maven-plugin.version>
60+
<maven-release-plugin.version>3.1.1</maven-release-plugin.version>
61+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
62+
</properties>
63+
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-starter-data-jpa</artifactId>
68+
<version>${spring-boot-starter-data-jpa.version}</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.jetbrains.kotlin</groupId>
72+
<artifactId>kotlin-reflect</artifactId>
73+
<version>${kotlin.version}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.jetbrains.kotlin</groupId>
77+
<artifactId>kotlin-stdlib</artifactId>
78+
<version>${kotlin.version}</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.junit.jupiter</groupId>
82+
<artifactId>junit-jupiter</artifactId>
83+
<version>${junit-jupiter.version}</version>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.mockito</groupId>
88+
<artifactId>mockito-core</artifactId>
89+
<version>${mockito.version}</version>
90+
<scope>test</scope>
91+
</dependency>
92+
</dependencies>
93+
94+
<distributionManagement>
95+
<snapshotRepository>
96+
<id>central-portal-snapshots</id>
97+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
98+
</snapshotRepository>
99+
<repository>
100+
<id>central-portal-releases</id>
101+
<url>https://central.sonatype.com/repository/maven-releases/</url>
102+
</repository>
103+
</distributionManagement>
104+
105+
<build>
106+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
107+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
108+
<plugins>
109+
<plugin>
110+
<groupId>org.jetbrains.kotlin</groupId>
111+
<artifactId>kotlin-maven-plugin</artifactId>
112+
<version>${kotlin.version}</version>
113+
<executions>
114+
<execution>
115+
<id>compile</id>
116+
<phase>compile</phase>
117+
<goals>
118+
<goal>compile</goal>
119+
</goals>
120+
</execution>
121+
<execution>
122+
<id>test-compile</id>
123+
<phase>test-compile</phase>
124+
<goals>
125+
<goal>test-compile</goal>
126+
</goals>
127+
</execution>
128+
</executions>
129+
<configuration>
130+
<jvmTarget>17</jvmTarget>
131+
</configuration>
132+
</plugin>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-source-plugin</artifactId>
136+
<version>${maven-source-plugin.version}</version>
137+
<executions>
138+
<execution>
139+
<id>attach-sources</id>
140+
<goals>
141+
<goal>jar-no-fork</goal>
142+
</goals>
143+
</execution>
144+
</executions>
145+
</plugin>
146+
<plugin>
147+
<groupId>org.apache.maven.plugins</groupId>
148+
<artifactId>maven-javadoc-plugin</artifactId>
149+
<version>${maven-javadoc-plugin.version}</version>
150+
<executions>
151+
<execution>
152+
<id>attach-javadocs</id>
153+
<goals>
154+
<goal>jar</goal>
155+
</goals>
156+
</execution>
157+
</executions>
158+
</plugin>
159+
<plugin>
160+
<groupId>org.apache.maven.plugins</groupId>
161+
<artifactId>maven-gpg-plugin</artifactId>
162+
<version>${maven-gpg-plugin.version}</version>
163+
<executions>
164+
<execution>
165+
<id>sign-artifacts</id>
166+
<phase>verify</phase>
167+
<goals>
168+
<goal>sign</goal>
169+
</goals>
170+
</execution>
171+
</executions>
172+
<configuration>
173+
<gpgArguments>
174+
<arg>--batch</arg>
175+
<arg>--yes</arg>
176+
<arg>--pinentry-mode</arg>
177+
<arg>loopback</arg>
178+
</gpgArguments>
179+
<useAgent>false</useAgent>
180+
<defaultKeyring>false</defaultKeyring>
181+
<keyname>${env.GPG_KEY_ID}</keyname>
182+
<passphrase>${env.GPG_PASSPHRASE}</passphrase>
183+
</configuration>
184+
</plugin>
185+
<plugin>
186+
<groupId>org.sonatype.central</groupId>
187+
<artifactId>central-publishing-maven-plugin</artifactId>
188+
<version>${central-publishing-maven-plugin.version}</version>
189+
<extensions>true</extensions>
190+
<configuration>
191+
<publishingServerId>central</publishingServerId>
192+
<autoPublish>true</autoPublish>
193+
</configuration>
194+
</plugin>
195+
<plugin>
196+
<groupId>org.apache.maven.plugins</groupId>
197+
<artifactId>maven-release-plugin</artifactId>
198+
<version>${maven-release-plugin.version}</version>
199+
<configuration>
200+
<autoVersionSubmodules>true</autoVersionSubmodules>
201+
<useReleaseProfile>false</useReleaseProfile>
202+
<releaseProfiles>release</releaseProfiles>
203+
<goals>deploy</goals>
204+
</configuration>
205+
</plugin>
206+
</plugins>
207+
</build>
208+
209+
</project>

0 commit comments

Comments
 (0)