From 4bc9426418e0aede4ae16e122018821e673da20f Mon Sep 17 00:00:00 2001 From: siujamo Date: Tue, 17 Jun 2025 10:33:55 +0800 Subject: [PATCH] refactor: remove `simple-serial` --- settings.gradle.kts | 1 - simple-serial-spring-boot-starter/README.md | 14 --- .../java/com/onixbyte/serial/RedisConfig.java | 57 ----------- .../com/onixbyte/serial/SerialService.java | 99 ------------------- .../serial/properties/SerialProperties.java | 59 ----------- ...ot.autoconfigure.AutoConfiguration.imports | 19 ---- .../src/main/resources/logback.xml | 32 ------ 7 files changed, 281 deletions(-) delete mode 100644 simple-serial-spring-boot-starter/README.md delete mode 100644 simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/RedisConfig.java delete mode 100644 simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/SerialService.java delete mode 100644 simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/properties/SerialProperties.java delete mode 100644 simple-serial-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 simple-serial-spring-boot-starter/src/main/resources/logback.xml diff --git a/settings.gradle.kts b/settings.gradle.kts index bbe70f4..f18fb5f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,5 +28,4 @@ include( "simple-jwt-facade", "simple-jwt-authzero", "simple-jwt-spring-boot-starter", - "simple-serial-spring-boot-starter" ) diff --git a/simple-serial-spring-boot-starter/README.md b/simple-serial-spring-boot-starter/README.md deleted file mode 100644 index 8a4d20c..0000000 --- a/simple-serial-spring-boot-starter/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Simple Serial - -> Thanks to [@siujamo](https://github.com/siujamo)'s donation. - -Simple Serial reuses the configuration of Redis connections to provide am easy-to-use serial -service. - -## Configuration - -Simple Serial reused the redis configuration of Spring Boot to provide redis support for the -service. - -Besides, **Simple Serial** provides a configuration property `onixbyte.serial.start-serial` to -specify the start value of a serial, and default to `0`. \ No newline at end of file diff --git a/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/RedisConfig.java b/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/RedisConfig.java deleted file mode 100644 index d0417a4..0000000 --- a/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/RedisConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2024-2025 OnixByte. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.onixbyte.serial; - -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.RedisSerializer; - -/** - * Redis Configuration provides redis templates for operations to serial. - * - * @author siujamo - */ -@AutoConfiguration -public class RedisConfig { - - /** - * Redis auto configuration. - */ - public RedisConfig() { - } - - /** - * RedisTemplate for serial service. - * - * @param redisConnectionFactory redis connection factory - * @return a configured redis template for serial service - */ - @Bean - public RedisTemplate serialRedisTemplate(RedisConnectionFactory redisConnectionFactory) { - var redisTemplate = new RedisTemplate(); - redisTemplate.setConnectionFactory(redisConnectionFactory); - redisTemplate.setKeySerializer(RedisSerializer.string()); - redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Long.class)); - redisTemplate.afterPropertiesSet(); - return redisTemplate; - } - -} diff --git a/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/SerialService.java b/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/SerialService.java deleted file mode 100644 index 55d6fbf..0000000 --- a/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/SerialService.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2024-2025 OnixByte. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.onixbyte.serial; - -import com.onixbyte.serial.properties.SerialProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.util.Optional; - -/** - * {@code SerialService} provides simple serial operations. - * - * @author siujamo - */ -@Service -@EnableConfigurationProperties(SerialProperties.class) -public class SerialService { - - private static final Logger log = LoggerFactory.getLogger(SerialService.class); - - private final String appName; - private final RedisTemplate serialRedisTemplate; - private final SerialProperties serialProperties; - - /** - * Default constructor. - * - * @param appName the name of this application - * @param serialRedisTemplate serial redis template - * @param serialProperties serial properties - */ - public SerialService(@Value("${spring.application.name}") String appName, - RedisTemplate serialRedisTemplate, - SerialProperties serialProperties) { - this.appName = appName; - this.serialRedisTemplate = serialRedisTemplate; - this.serialProperties = serialProperties; - } - - /** - * Build a serial key. - * - * @param tag tag of the serial - * @return key of a serial - */ - public String buildKey(String tag) { - return appName + ":serial:" + tag; - } - - /** - * Get the next available serial for specific tag. - * - * @param tag tag of the serial - * @return next available serial - */ - public Long nextSerial(String tag) { - var key = buildKey(tag); - var next = Optional.ofNullable(serialRedisTemplate.opsForValue().get(key)) - .orElse(serialProperties.getStartSerial()); - serialRedisTemplate.opsForValue().set(key, next + 1); - return next; - } - - /** - * Reset all serial values. - */ - public void reset() { - var keys = serialRedisTemplate.keys(buildKey("*")); - var startSerial = serialProperties.getStartSerial(); - - if (!keys.isEmpty()) { - for (var key : keys) { - serialRedisTemplate.opsForValue().set(key, startSerial); - log.debug("Serial {} has been reset to {}", key, startSerial); - } - } - } - -} diff --git a/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/properties/SerialProperties.java b/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/properties/SerialProperties.java deleted file mode 100644 index cb2552d..0000000 --- a/simple-serial-spring-boot-starter/src/main/java/com/onixbyte/serial/properties/SerialProperties.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2024-2025 OnixByte. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.onixbyte.serial.properties; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * SerialProperties can modify the start value of a serial. - * - * @author siujamo - */ -@ConfigurationProperties(prefix = "onixbyte.serial") -public class SerialProperties { - - /** - * The start of the serial, default to 0. - */ - private Long startSerial = 0L; - - /** - * Get the start of the serial. - * - * @return start of the serial - */ - public Long getStartSerial() { - return startSerial; - } - - /** - * Set the start of the serial. - * - * @param startSerial start of the serial - */ - public void setStartSerial(Long startSerial) { - this.startSerial = startSerial; - } - - /** - * Default constructor. - */ - public SerialProperties() { - } - -} diff --git a/simple-serial-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/simple-serial-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 7fd0a37..0000000 --- a/simple-serial-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,19 +0,0 @@ -# -# Copyright (C) 2024-2025 OnixByte. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# -# See the License for the specific language governing permissions and -# limitations under the License. -# - -com.onixbyte.serial.RedisConfig -com.onixbyte.serial.SerialService \ No newline at end of file diff --git a/simple-serial-spring-boot-starter/src/main/resources/logback.xml b/simple-serial-spring-boot-starter/src/main/resources/logback.xml deleted file mode 100644 index fd31eac..0000000 --- a/simple-serial-spring-boot-starter/src/main/resources/logback.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - ${COLOURFUL_OUTPUT} - - - - - - \ No newline at end of file