-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
796 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
authorization-service/src/main/java/com/onemsg/authorization/ObservationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.onemsg.authorization; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationRegistry; | ||
|
||
public class ObservationTest { | ||
|
||
|
||
public static void main(String[] args) { | ||
// ObservationRegistry registry = ObservationRegistry.create(); | ||
|
||
// Observation.createNotStarted("foo", registry) | ||
// .lowCardinalityKeyValue("lowTag", "lowTagValue") | ||
// .highCardinalityKeyValue("highTag", "highTagValue") | ||
// .observe(() -> System.out.println("Hello")); | ||
|
||
MeterRegistry registry = new SimpleMeterRegistry(); | ||
Timer.Sample sample = Timer.start(registry); | ||
try { | ||
// do some work here | ||
} finally { | ||
sample.stop(Timer.builder("my.timer").register(registry)); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
authorization-service/src/main/java/com/onemsg/authorization/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.onemsg.authorization.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/authorization") | ||
public class AuthController { | ||
|
||
@GetMapping("roles") | ||
public ResponseEntity<Object> getRoles() { | ||
return null; | ||
} | ||
|
||
@GetMapping("perms") | ||
public ResponseEntity<Object> getPerms() { | ||
return null; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...g/src/main/java/com/onemsg/protobuf/manager/application/event/RefreshGroupStoreEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.onemsg.protobuf.manager.application.event; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
public class RefreshGroupStoreEvent extends ApplicationEvent{ | ||
|
||
public RefreshGroupStoreEvent(Object source) { | ||
super(source); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ring/src/main/java/com/onemsg/protobuf/manager/application/model/ApplicationCreation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
import java.util.Objects; | ||
|
||
import org.springframework.beans.BeanUtils; | ||
|
||
public class ApplicationCreation { | ||
public String name; | ||
public String zhName; | ||
public String intro; | ||
public int groupId; | ||
public String groupName; | ||
public String creator; | ||
|
||
public String getFullName() { | ||
return groupName + "/" + name; | ||
} | ||
|
||
public static ApplicationCreation create(ApplicationCreationRequest request) { | ||
Objects.requireNonNull(request); | ||
ApplicationCreation creation = new ApplicationCreation(); | ||
BeanUtils.copyProperties(request, creation); | ||
return creation; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...c/main/java/com/onemsg/protobuf/manager/application/model/ApplicationCreationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
public class ApplicationCreationRequest { | ||
|
||
@NotBlank | ||
public String name; | ||
public String zhName; | ||
public String intro; | ||
@Positive | ||
public int groupId; | ||
} |
20 changes: 20 additions & 0 deletions
20
...spring/src/main/java/com/onemsg/protobuf/manager/application/model/ApplicationEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class ApplicationEntity { | ||
|
||
public int id; | ||
public String name; | ||
public String zhName; | ||
public String intro; | ||
public int groupId; | ||
public String groupName; | ||
public String creator; | ||
public LocalDateTime createdTime; | ||
public LocalDateTime updatedTime; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...spring/src/main/java/com/onemsg/protobuf/manager/application/model/ApplicationNameVo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
public record ApplicationNameVo( | ||
int id, | ||
String name | ||
) { | ||
|
||
public static ApplicationNameVo create(ApplicationEntity entity) { | ||
return new ApplicationNameVo(entity.id, entity.name); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/java/com/onemsg/protobuf/manager/application/model/ApplicationUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
public class ApplicationUpdateRequest { | ||
@Positive | ||
public int applicationId; | ||
@NotBlank | ||
public String zhName; | ||
public String intro; | ||
} |
8 changes: 8 additions & 0 deletions
8
...ing/src/main/java/com/onemsg/protobuf/manager/application/model/GroupCreationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public class GroupCreationRequest { | ||
@NotBlank | ||
public String name; | ||
} |
14 changes: 14 additions & 0 deletions
14
...nager-spring/src/main/java/com/onemsg/protobuf/manager/application/model/GroupEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* ApplicationEntity | ||
*/ | ||
public record GroupEntity( | ||
int id, | ||
String name, | ||
String creator, | ||
LocalDateTime create | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
...er-spring/src/main/java/com/onemsg/protobuf/manager/application/model/GroupInsertion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
public class GroupInsertion { | ||
public String name; | ||
public String creator; | ||
} |
8 changes: 8 additions & 0 deletions
8
...nager-spring/src/main/java/com/onemsg/protobuf/manager/application/model/GroupNameVo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.onemsg.protobuf.manager.application.model; | ||
|
||
public record GroupNameVo(int id, String name) { | ||
|
||
public static GroupNameVo create(GroupEntity entity) { | ||
return new GroupNameVo(entity.id(), entity.name()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
protobuf-manager-spring/src/main/java/com/onemsg/protobuf/manager/model/RemoveIdRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.onemsg.protobuf.manager.model; | ||
|
||
import jakarta.validation.constraints.Positive; | ||
|
||
public class RemoveIdRequest { | ||
@Positive | ||
public int id; | ||
} |
198 changes: 198 additions & 0 deletions
198
...ger-spring/src/main/java/com/onemsg/protobuf/manager/protobuf/ProtobufInfoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
package com.onemsg.protobuf.manager.protobuf; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.dao.DataAccessException; | ||
import org.springframework.jdbc.core.simple.JdbcClient; | ||
import org.springframework.jdbc.support.GeneratedKeyHolder; | ||
import org.springframework.jdbc.support.KeyHolder; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.onemsg.protobuf.manager.protobuf.model.ProtobufCodeCreation; | ||
import com.onemsg.protobuf.manager.protobuf.model.ProtobufCodeEntity; | ||
import com.onemsg.protobuf.manager.protobuf.model.ProtobufCodeVersion; | ||
import com.onemsg.protobuf.manager.protobuf.model.ProtobufInfoCreation; | ||
import com.onemsg.protobuf.manager.protobuf.model.ProtobufInfoEntity; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Repository | ||
public class ProtobufInfoRepository { | ||
|
||
private final JdbcClient jdbcClient; | ||
|
||
public ProtobufInfoRepository(JdbcClient jdbcClient) { | ||
this.jdbcClient = jdbcClient; | ||
} | ||
|
||
public List<ProtobufInfoEntity> search(String search, int skip, int limit) { | ||
String sql = """ | ||
SELECT id, name, intro, application_name group_name, protocol, current_version, creator, created_time, updated_time | ||
FROM `protobuf_info` | ||
WHERE group_name like ? OR application_name like ? OR name like ? OR creator like ? | ||
ORDER BY id DESC | ||
LIMIT ?,? | ||
"""; | ||
String word = "%" + search + "%"; | ||
return jdbcClient.sql(sql).params(word, word, word, word, skip, limit) | ||
.query(ProtobufInfoEntity.class) | ||
.list(); | ||
} | ||
|
||
|
||
public int count(String search) { | ||
String sql = """ | ||
SELECT count(id) FROM `protobuf_info` | ||
WHERE group_name like ? OR application_name like ? OR name like ? | ||
"""; | ||
String word = "%" + search + "%"; | ||
return jdbcClient.sql(sql) | ||
.params(word, word, word) | ||
.query(int.class) | ||
.single(); | ||
} | ||
|
||
public List<ProtobufInfoEntity> search(int skip, int limit) { | ||
String sql = """ | ||
SELECT id, name, intro, application_name group_name, protocol, current_version, creator, created_time, updated_time | ||
FROM `protobuf_info` | ||
ORDER BY id DESC | ||
LIMIT ?,? | ||
"""; | ||
|
||
return jdbcClient.sql(sql).params(skip, limit).query(ProtobufInfoEntity.class).list(); | ||
} | ||
|
||
public int count() { | ||
String sql = "SELECT count(id) FROM `protobuf_info`"; | ||
return jdbcClient.sql(sql).query(int.class).single(); | ||
} | ||
|
||
public Optional<ProtobufInfoEntity> findById(int id) { | ||
String sql = """ | ||
SELECT id, name, intro, application_name group_name, protocol, current_version, creator, created_time, updated_time | ||
FROM `protobuf_info` WHERE id = ? | ||
"""; | ||
return jdbcClient.sql(sql).param(id).query(ProtobufInfoEntity.class).optional(); | ||
} | ||
|
||
public boolean existsById(int id) { | ||
String sql = "SELECT count(id) FROM `protobuf_info` WHERE id = ?"; | ||
return jdbcClient.sql(sql).param(id).query(int.class).single() > 0; | ||
} | ||
|
||
public int updateIntroById(int id, String intro) { | ||
String sql = "UPDATE `protobuf_info` SET `intro` = ? WHERE `id` = ?"; | ||
return jdbcClient.sql(sql).param(intro, id).update(); | ||
} | ||
|
||
public int insert(ProtobufInfoCreation creation) { | ||
String sql = """ | ||
INSERT INTO `protobuf_info`(name, intro, application_name, group_name, protocol, creator) | ||
VALUES(:name, :intro, :applicationName, :groupName, :protocol, :creator); | ||
"""; | ||
|
||
log.info("Insert {}", creation); | ||
|
||
KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
jdbcClient.sql(sql) | ||
.paramSource(creation) | ||
.update(keyHolder, "id"); | ||
|
||
return getKeyAsInt(keyHolder, "protobuf_info"); | ||
} | ||
|
||
|
||
private static int getKeyAsInt(KeyHolder keyHolder, String tableName) { | ||
var key = keyHolder.getKey(); | ||
if (key == null) { | ||
String msg = String.format("获取 Table[%s] 自增ID失败", tableName); | ||
throw new DataAccessException(msg) {}; | ||
} | ||
return key.intValue(); | ||
} | ||
|
||
public int delete(int id) { | ||
String sql = "DELETE FROM `protobuf_info` WHERE id = ?"; | ||
return jdbcClient.sql(sql).param(id).update(); | ||
} | ||
|
||
public int insertCode(ProtobufCodeCreation creation) { | ||
|
||
int nextVersion = jdbcClient.sql("SELECT _next_version FROM `protobuf_info` WHERE id = ? FOR UPDATE") | ||
.param(creation.protobufId) | ||
.query(int.class) | ||
.single(); | ||
|
||
creation.version = nextVersion; | ||
|
||
String insertSql = """ | ||
INSERT INTO `protobuf_code`(protobuf_id, protobuf_name, code, version, creator) | ||
VALUES(:protobufId, :protobufName, :code, :version, :creator ); | ||
"""; | ||
KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
jdbcClient.sql(insertSql).paramSource(creation).update(keyHolder, "id"); | ||
|
||
String updateSql = "UPDATE `protobuf_info` SET current_version = ?, _next_version = _next_version + 1 WHERE id = ?"; | ||
jdbcClient.sql(updateSql) | ||
.param(nextVersion) | ||
.param(creation.protobufId) | ||
.update(); | ||
|
||
return getKeyAsInt(keyHolder, "protobuf_code"); | ||
} | ||
|
||
public int updateCurrentVersion(int id, int version) { | ||
String updateSql = "UPDATE `protobuf_info` SET current_version = ? WHERE id = ?"; | ||
return jdbcClient.sql(updateSql).param(version, id).update(); | ||
} | ||
|
||
public Optional<ProtobufCodeEntity> findCodeById(int codeId) { | ||
String sql = """ | ||
SELECT id, protobuf_id, protobuf_name, code, version, creator, created_time | ||
FROM `protobuf_code` WHERE id = ? | ||
"""; | ||
return jdbcClient.sql(sql).param(codeId).query(ProtobufCodeEntity.class).optional(); | ||
} | ||
|
||
public Optional<ProtobufCodeEntity> findCodeByProtobufIdAndVersion(int protobufId, int version) { | ||
String sql = """ | ||
SELECT id, protobuf_id, protobuf_name, code, version, creator, created_time | ||
FROM `protobuf_code` | ||
WHERE protobuf_id = ? AND version = ? | ||
"""; | ||
return jdbcClient.sql(sql).param(protobufId, version).query(ProtobufCodeEntity.class).optional(); | ||
} | ||
|
||
public Optional<ProtobufCodeEntity> findCurrentCodeByProtobufId(int protobufId) { | ||
String sql = """ | ||
SELECT id, protobuf_id, protobuf_name, code, version, creator, created_time | ||
FROM `protobuf_code` | ||
WHERE protobuf_id = ? | ||
AND version in (SELECT current_version FROM `current_version` WHERE id = ?) | ||
"""; | ||
return jdbcClient.sql(sql).param(protobufId, protobufId).query(ProtobufCodeEntity.class).optional(); | ||
} | ||
|
||
public boolean existsCodeByProtobufIdAndVersion(int protobufId, int version) { | ||
String sql = """ | ||
SELECT count(id) | ||
FROM `protobuf_code` | ||
WHERE protobuf_id = ? AND version = ? | ||
"""; | ||
return jdbcClient.sql(sql).param(protobufId, version).query(int.class).single() > 0; | ||
} | ||
|
||
public List<ProtobufCodeVersion> findCodeVersionListByProtobufId(int protobufId) { | ||
String sql = """ | ||
SELECT code.id, code.version, code.version = info.current_version as is_current, code.creator, code.created_time | ||
FROM `protobuf_code` as code | ||
LEFT JOIN `protobuf_info` as info ON code.protobuf_id = info.id | ||
WHERE code.protobuf_id = ? | ||
"""; | ||
return jdbcClient.sql(sql).param(protobufId).query(ProtobufCodeVersion.class).list(); | ||
} | ||
|
||
} |
Oops, something went wrong.