Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #205 Json record. #206

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file was last modified at 2024-05-24 10:14 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* DayBook3.java
* $Id$
*/

package su.svn.daybook3.api.gateway;

import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeIn;
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
import org.eclipse.microprofile.openapi.annotations.info.Contact;
import org.eclipse.microprofile.openapi.annotations.info.Info;
import org.eclipse.microprofile.openapi.annotations.info.License;
import org.eclipse.microprofile.openapi.annotations.security.SecurityScheme;

import jakarta.ws.rs.core.Application;

@OpenAPIDefinition(
info = @Info(
title = "DayBook 3 API",
version = "3.10.0",
contact = @Contact(
name = "To use API Support",
url = "https://svn.su",
email = "[email protected]"),
license = @License(
name = "This is free and unencumbered software released into the public domain",
url = "http://unlicense.org"
))
)
@SecurityScheme(
securitySchemeName = "day-book",
scheme = "Bearer",
type = SecuritySchemeType.HTTP,
in = SecuritySchemeIn.HEADER
)
public class DayBook3 extends Application {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file was last modified at 2024-05-22 12:44 by Victor N. Skurikhin.
* This file was last modified at 2024-05-24 09:04 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* BaseRecord.java
Expand All @@ -15,9 +15,12 @@
import jakarta.annotation.Nonnull;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table;
Expand Down Expand Up @@ -45,10 +48,10 @@
@Getter
@Setter
@Builder
@ToString
@ToString(exclude = "parent")
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false, exclude = {"id"})
@EqualsAndHashCode(callSuper = false, exclude = {"id", "parent"})
@Accessors(fluent = true, chain = false)
@Table(schema = "db", name = "base_records")
@NamedQueries({
Expand All @@ -72,6 +75,18 @@ public class BaseRecord
@Column(name = "id", updatable = false, nullable = false)
private UUID id;

@Column(name = "parent_id", nullable = false)
private UUID parentId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "parent_id",
referencedColumnName = "id",
insertable = false,
nullable = false,
updatable = false)
private BaseRecord parent;

@Builder.Default
@Column(name = "type")
private RecordType type = RecordType.Base;
Expand Down Expand Up @@ -102,6 +117,10 @@ public Uni<BaseRecord> update() {
}

public static Uni<BaseRecord> addBaseRecord(@Nonnull BaseRecord baseRecord) {
if (baseRecord.parentId == null) {
baseRecord.parentId(baseRecord.id());
baseRecord.parent(baseRecord);
}
return Panache
.withTransaction(baseRecord::persistAndFlush)
.replaceWith(baseRecord)
Expand All @@ -126,6 +145,8 @@ public static Uni<BaseRecord> updateBaseRecord(@Nonnull BaseRecord baseRecord) {
.onItem()
.ifNotNull()
.transform(entity -> {
entity.parentId = baseRecord.parentId;
entity.type = baseRecord.type;
entity.userName = baseRecord.userName;
entity.enabled = baseRecord.enabled;
entity.visible = baseRecord.visible;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* This file was last modified at 2024-05-24 12:12 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* JsonRecord.java
* $Id$
*/

package su.svn.daybook3.api.gateway.domain.entities;

import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase;
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
import io.quarkus.panache.common.Parameters;
import io.smallrye.mutiny.Uni;
import jakarta.annotation.Nonnull;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.type.SqlTypes;
import su.svn.daybook3.api.gateway.models.Marked;
import su.svn.daybook3.api.gateway.models.Owned;
import su.svn.daybook3.api.gateway.models.TimeUpdated;
import su.svn.daybook3.api.gateway.models.UUIDIdentification;

import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.UUID;

@Entity
@Getter
@Setter
@Builder
@ToString(exclude = "baseRecord")
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false, exclude = {"id", "baseRecord"})
@Accessors(fluent = true, chain = false)
@Table(schema = "db", name = "json_records")
@NamedQueries({
@NamedQuery(
name = JsonRecord.LIST_ENABLED_WITH_TYPE,
query = "From JsonRecord WHERE enabled = :enabled"
)
})
public class JsonRecord
extends PanacheEntityBase
implements UUIDIdentification, Marked, Owned, TimeUpdated, Serializable {

public static final Duration TIMEOUT_DURATION = Duration.ofMillis(10100);
public static final String LIST_ENABLED_WITH_TYPE = "JsonRecord.ListEnabled";
public static final Parameters ENABLED_JSON_TYPE = Parameters
.with("enabled", Boolean.TRUE);

@Id
@Column(name = "id", updatable = false, nullable = false)
private UUID id;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(
name = "id",
referencedColumnName = "id",
insertable = false,
nullable = false,
updatable = false)
private BaseRecord baseRecord;

@Column(name = "values")
@JdbcTypeCode(SqlTypes.JSON)
private Map<String, String> values;

@Column(name = "user_name")
private String userName;

@CreationTimestamp
@Column(name = "create_time", updatable = false, nullable = false)
private LocalDateTime createTime;

@UpdateTimestamp
@Column(name = "update_time", updatable = false)
private LocalDateTime updateTime;

@Builder.Default
@Column(name = "enabled")
private boolean enabled = true;

@Column(name = "visible")
private boolean visible;

@Column(name = "flags")
private int flags;

public Uni<JsonRecord> update() {
return updateJsonRecord(this);
}

public static Uni<JsonRecord> addJsonRecord(@Nonnull BaseRecord baseRecord, @Nonnull JsonRecord jsonRecord) {
return Panache
.withTransaction(() -> baseRecord.<BaseRecord>persistAndFlush()
.flatMap(base -> {
jsonRecord.id(base.id());
jsonRecord.baseRecord(base);
return jsonRecord.persistAndFlush();
}))
.replaceWith(jsonRecord)
.ifNoItem()
.after(TIMEOUT_DURATION)
.fail()
.onFailure()
.transform(IllegalStateException::new);
}

public static Uni<Boolean> deleteJsonRecordById(@Nonnull UUID id) {
return Panache.withTransaction(() -> deleteById(id));
}

public static Uni<JsonRecord> findByJsonRecordById(@Nonnull UUID id) {
return findById(id);
}

public static PanacheQuery<JsonRecord> getAllEnabledPanacheQuery() {
return find("#" + JsonRecord.LIST_ENABLED_WITH_TYPE, JsonRecord.ENABLED_JSON_TYPE);
}

public static Uni<JsonRecord> updateJsonRecord(@Nonnull JsonRecord jsonRecord) {
return Panache
.withTransaction(() -> findByJsonRecordById(jsonRecord.id)
.onItem()
.ifNotNull()
.transform(entity -> {
entity.values = jsonRecord.values;
entity.userName = jsonRecord.userName;
entity.enabled = jsonRecord.enabled;
entity.visible = jsonRecord.visible;
entity.flags = jsonRecord.flags;
return entity;
})
.onFailure()
.recoverWithNull()
).replaceWith(jsonRecord)
.ifNoItem()
.after(TIMEOUT_DURATION)
.fail()
.onFailure()
.transform(IllegalStateException::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file was last modified at 2024-05-15 20:12 by Victor N. Skurikhin.
* This file was last modified at 2024-05-24 11:27 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* EventAddress.java
Expand All @@ -10,15 +10,25 @@

public enum EventAddress {
Null(null),
Base_Record_Add(EventAddress.BASE_RECORD_ADD),
Base_Record_Del(EventAddress.BASE_RECORD_DEL),
Base_Record_Get(EventAddress.BASE_RECORD_GET),
Base_Record_Page(EventAddress.BASE_RECORD_PAGE),
Base_Record_Put(EventAddress.BASE_RECORD_PUT),
CodifierAdd(EventAddress.CODIFIER_ADD),
CodifierDel(EventAddress.CODIFIER_DEL),
CodifierGet(EventAddress.CODIFIER_GET),
CodifierPut(EventAddress.CODIFIER_PUT),
CodifierDel(EventAddress.CODIFIER_DEL),
I18nAdd(EventAddress.I18N_ADD),
I18nGet(EventAddress.I18N_DEL),
I18nDel(EventAddress.I18N_GET),
I18nGet(EventAddress.I18N_DEL),
I18nPage(EventAddress.I18N_PAGE),
I18nPut(EventAddress.I18N_PUT),
JsonRecordAdd(EventAddress.JSON_RECORD_ADD),
JsonRecordDel(EventAddress.JSON_RECORD_DEL),
JsonRecordGet(EventAddress.JSON_RECORD_GET),
JsonRecordPage(EventAddress.JSON_RECORD_PAGE),
JsonRecordPut(EventAddress.JSON_RECORD_PUT),
KeyValueAdd(EventAddress.KEY_VALUE_ADD),
KeyValueDel(EventAddress.KEY_VALUE_DEL),
KeyValueGet(EventAddress.KEY_VALUE_GET),
Expand Down Expand Up @@ -50,26 +60,26 @@ public enum EventAddress {
TagLabelPage(EventAddress.TAG_LABEL_PAGE),
TagLabelPut(EventAddress.TAG_LABEL_PUT),
UserAdd(EventAddress.USER_ADD),
UserDel(EventAddress.USER_DEL),
UserGet(EventAddress.USER_GET),
UserPut(EventAddress.USER_PUT),
UserDel(EventAddress.USER_DEL),
ValueTypeAdd(EventAddress.VALUE_TYPE_ADD),
ValueTypeDel(EventAddress.VALUE_TYPE_DEL),
ValueTypeGet(EventAddress.VALUE_TYPE_GET),
ValueTypePut(EventAddress.VALUE_TYPE_PUT),
ValueTypeDel(EventAddress.VALUE_TYPE_DEL),
VocabularyAdd(EventAddress.VOCABULARY_ADD),
VocabularyDel(EventAddress.VOCABULARY_DEL),
VocabularyGet(EventAddress.VOCABULARY_GET),
VocabularyPut(EventAddress.VOCABULARY_PUT),
VocabularyDel(EventAddress.VOCABULARY_DEL),
WordAdd(EventAddress.WORD_ADD),
WordDel(EventAddress.WORD_DEL),
WordGet(EventAddress.WORD_GET),
WordPut(EventAddress.WORD_PUT),
WordDel(EventAddress.WORD_DEL);
WordPut(EventAddress.WORD_PUT);

public static final String BASE_RECORD_ADD = "base_record_add";
public static final String BASE_RECORD_GET = "base_record_get";
public static final String BASE_RECORD_PUT = "base_record_put";
public static final String BASE_RECORD_PAGE ="base_record_page_page";
public static final String BASE_RECORD_PAGE = "base_record_page_page";
public static final String BASE_RECORD_DEL = "base_record_del";
public static final String CODIFIER_ADD = "code_add";
public static final String CODIFIER_GET = "code_get";
Expand All @@ -81,6 +91,11 @@ public enum EventAddress {
public static final String I18N_GET = "i18n_get";
public static final String I18N_PAGE = "i18n_page";
public static final String I18N_PUT = "i18n_put";
public static final String JSON_RECORD_ADD = "json_record_add";
public static final String JSON_RECORD_GET = "json_record_get";
public static final String JSON_RECORD_PUT = "json_record_put";
public static final String JSON_RECORD_PAGE = "json_record_page_page";
public static final String JSON_RECORD_DEL = "json_record_del";
public static final String KEY_VALUE_ADD = "key_value_add";
public static final String KEY_VALUE_DEL = "key_value_del";
public static final String KEY_VALUE_GET = "key_value_get";
Expand All @@ -94,17 +109,15 @@ public enum EventAddress {
public static final String ROLE_ADD = "role_add";
public static final String ROLE_DEL = "role_del";
public static final String ROLE_GET = "role_get";
public static final String ROLE_PAGE= "role_page";
public static final String ROLE_PAGE = "role_page";
public static final String ROLE_PUT = "role_put";
public static final String LANGUAGE_PUT = "language_put";

public static final String SESSION_ADD = "session_add";
public static final String SESSION_DEL = "session_del";
public static final String SESSION_GET = "session_get";
public static final String SESSION_PAGE= "session_page";
public static final String SESSION_PAGE = "session_page";
public static final String SESSION_PUT = "session_put";
public static final String SESSION_NAME = "session_get";

public static final String SETTING_ADD = "setting_add";
public static final String SETTING_DEL = "setting_del";
public static final String SETTING_GET = "setting_get";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file was last modified at 2024-05-22 12:46 by Victor N. Skurikhin.
* This file was last modified at 2024-05-24 12:02 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* ResourcePath.java
Expand Down Expand Up @@ -45,6 +45,7 @@ public enum ResourcePath {
public static final String I18N = API_PATH + "/i18n";
public static final String I18NS = API_PATH + "/i18ns";
public static final String ID = "/{id}";
public static final String JSON_RECORD = API_PATH + "/json-record";
public static final String KEY_VALUE = API_PATH + "/key-value";
public static final String KEY_VALUES = API_PATH + "/key-values";
public static final String LANGUAGE = API_PATH + "/lang";
Expand Down
Loading
Loading