Skip to content

Commit

Permalink
Fix #205 Json record.
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor N. Skurikhin committed May 24, 2024
1 parent f572dde commit e5dba66
Show file tree
Hide file tree
Showing 14 changed files with 427 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file was last modified at 2024-05-24 09:04 by Victor N. Skurikhin.
* 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
Expand Down Expand Up @@ -75,7 +75,7 @@ public class JsonRecord
@Column(name = "id", updatable = false, nullable = false)
private UUID id;

@OneToOne(fetch = FetchType.LAZY)
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(
name = "id",
referencedColumnName = "id",
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file was last modified at 2024-05-17 09:49 by Victor N. Skurikhin.
* This file was last modified at 2024-05-24 11:40 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* NewBaseRecord.java
Expand All @@ -13,10 +13,11 @@
import lombok.Builder;

import java.io.Serializable;
import java.util.UUID;

@JsonPropertyOrder({"visible", "flags"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public record NewBaseRecord(boolean visible, int flags) implements Serializable {
public record NewBaseRecord(UUID parentId, boolean visible, int flags) implements Serializable {
@Builder
public NewBaseRecord {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file was last modified at 2024-05-24 11:40 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* NewJsonRecord.java
* $Id$
*/

package su.svn.daybook3.api.gateway.models.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Builder;

import java.io.Serializable;
import java.util.Map;
import java.util.UUID;

@JsonPropertyOrder({"visible", "flags"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public record NewJsonRecord(
@JsonProperty UUID parentId,
@JsonProperty Map<String, String> values,
@JsonProperty boolean visible,
@JsonProperty int flags) implements Serializable {
@Builder
public NewJsonRecord {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file was last modified at 2024-05-24 09:06 by Victor N. Skurikhin.
* This file was last modified at 2024-05-24 11:40 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* ResourceJsonRecord.java
Expand All @@ -24,6 +24,7 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ResourceJsonRecord(
@JsonProperty UUID id,
@JsonProperty UUID parentId,
@JsonProperty Map<String, String> values,
@JsonIgnore String userName,
@JsonProperty boolean visible,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file was last modified at 2024-05-24 11:59 by Victor N. Skurikhin.
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <http://unlicense.org>
* UpdateJsonRecord.java
* $Id$
*/

package su.svn.daybook3.api.gateway.models.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import su.svn.daybook3.api.gateway.models.UUIDIdentification;

import java.io.Serializable;
import java.util.Map;
import java.util.UUID;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record UpdateJsonRecord(
@JsonProperty UUID id,
@JsonProperty Map<String, String> values,
@JsonProperty boolean visible,
@JsonProperty int flags)
implements UUIDIdentification, Serializable {
@Builder
public UpdateJsonRecord {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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>
* JsonRecordResource.java
* $Id$
*/

package su.svn.daybook3.api.gateway.resources;

import io.smallrye.mutiny.Uni;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import su.svn.daybook3.api.gateway.annotations.PrincipalLogging;
import su.svn.daybook3.api.gateway.domain.enums.ResourcePath;
import su.svn.daybook3.api.gateway.domain.messages.Request;
import su.svn.daybook3.api.gateway.models.dto.NewJsonRecord;
import su.svn.daybook3.api.gateway.models.dto.UpdateJsonRecord;
import su.svn.daybook3.api.gateway.models.pagination.PageRequest;
import su.svn.daybook3.api.gateway.services.mappers.JsonRecordMapper;
import su.svn.daybook3.api.gateway.services.models.JsonRecordService;

import java.util.UUID;

@PrincipalLogging
@Path(ResourcePath.JSON_RECORD)
public class JsonRecordResource
extends AbstractResource {

@Inject
JsonRecordMapper mapper;

@Inject
JsonRecordService service;

@Operation(summary = "Get JSON record")
@GET
@Path(ResourcePath.ID)
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> get(UUID id) {

var request = new Request<>(id, authContext.getPrincipal());

return service.get(request)
.map(this::createResponseBuilder)
.map(Response.ResponseBuilder::build);
}

@Operation(summary = "Get page with list of JSON record")
@GET
@Path(ResourcePath.PAGE)
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> page(@QueryParam("page") int page, @QueryParam("limit") short limit) {

var pageRequest = new PageRequest(page, limit);
var request = new Request<>(pageRequest, authContext.getPrincipal());

return service.getPage(request)
.map(this::createPageResponseBuilder)
.map(Response.ResponseBuilder::build);
}

@Operation(summary = "Create JSON record")
@POST
@Path(ResourcePath.NONE)
@RolesAllowed("ADMIN")
@SecurityRequirement(name = "day-book")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> post(NewJsonRecord entry) {

var record = mapper.toResource(entry)
.toBuilder()
.userName("root")
.build();
var request = new Request<>(record, authContext.getPrincipal());

return service.add(request)
.map(this::createResponseBuilder)
.map(Response.ResponseBuilder::build);
}

@Operation(summary = "Update JSON record")
@PUT
@Path(ResourcePath.NONE)
@RolesAllowed("ADMIN")
@SecurityRequirement(name = "day-book")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> put(UpdateJsonRecord entry) {

var record = mapper.toResource(entry)
.toBuilder()
.userName("root")
.build();
var request = new Request<>(record, authContext.getPrincipal());

return service.put(request)
.map(this::createResponseBuilder)
.map(Response.ResponseBuilder::build);
}

@Operation(summary = "Delete JSON record")
@DELETE
@Path(ResourcePath.ID)
@RolesAllowed("ADMIN")
@SecurityRequirement(name = "day-book")
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> delete(UUID id) {

var request = new Request<>(id, authContext.getPrincipal());

return service.delete(request)
.map(this::createResponseBuilder)
.map(Response.ResponseBuilder::build);
}

@ServerExceptionMapper
public RestResponse<String> exception(Throwable x) {
return exceptionMapper(x);
}
}
Loading

0 comments on commit e5dba66

Please sign in to comment.