Skip to content

Commit

Permalink
Format the code and replace the new logo.
Browse files Browse the repository at this point in the history
  • Loading branch information
ytwp committed Jan 4, 2024
1 parent 16ca2a8 commit 873a071
Show file tree
Hide file tree
Showing 29 changed files with 1,527 additions and 1,332 deletions.
2 changes: 0 additions & 2 deletions gateway-ha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
<artifactId>dropwizard-views</artifactId>
</dependency>


<!-- Required for ClusterStatsJdbcMonitor -->
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void initialize(Bootstrap<HaGatewayConfiguration> bootstrap)
super.initialize(bootstrap);
bootstrap.addBundle(new ViewBundle<>());
bootstrap.addBundle(new AssetsBundle("/static/assets", "/assets", null, "assets"));
bootstrap.addBundle(new AssetsBundle("/static", "/logo.svg","logo.svg", "logo.svg"));
bootstrap.addBundle(new AssetsBundle("/static", "/logo.svg", "logo.svg", "logo.svg"));
}

public static void main(String[] args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public void setPresetUsers(Map<String, UserConfiguration> presetUsers)
this.presetUsers = presetUsers;
}


public Map<String, String> getPagePermissions()
{
return this.pagePermissions;
Expand Down Expand Up @@ -217,7 +216,7 @@ public boolean equals(final Object o)
final Object pagePermissions = this.getPagePermissions();
final Object otherPagePermissions = other.getPagePermissions();
if (!Objects.equals(pagePermissions, otherPagePermissions)) {
return false;
return false;
}
final Object backendState = this.getBackendState();
final Object otherBackendState = other.getBackendState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean equals(final Object o)
final Object userIdField = this.getUserIdField();
final Object otherUserIdField = other.getUserIdField();
if (!Objects.equals(userIdField, otherUserIdField)) {
return false;
return false;
}
final Object redirectWebUrl = this.getRedirectWebUrl();
final Object otherRedirectWebUrl = other.getRedirectWebUrl();
Expand Down
293 changes: 165 additions & 128 deletions gateway-ha/src/main/java/io/trino/gateway/ha/domain/R.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* 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 io.trino.gateway.ha.domain;

import jakarta.ws.rs.core.Response;
Expand All @@ -10,132 +23,156 @@
*
* @author Wei Peng
*/
public class R<T> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

/**
* success
*/
public static final int SUCCESS = 200;

/**
* fail
*/
public static final int FAIL = 500;

/**
* warn
*/
public static final int WARN = 601;

private int code;

private String msg;

private T data;

public static <T> R<T> ok() {
return restResult(null, SUCCESS, "Successful.");
}

public static <T> R<T> ok(T data) {
return restResult(data, SUCCESS, "Successful.");
}

public static <T> R<T> ok(String msg) {
return restResult(null, SUCCESS, msg);
}

public static <T> R<T> ok(String msg, T data) {
return restResult(data, SUCCESS, msg);
}

public static <T> R<T> fail() {
return restResult(null, FAIL, "Failed.");
}

public static <T> R<T> fail(String msg) {
return restResult(null, FAIL, msg);
}

public static <T> R<T> fail(T data) {
return restResult(data, FAIL, "Failed.");
}

public static <T> R<T> fail(String msg, T data) {
return restResult(data, FAIL, msg);
}

public static <T> R<T> fail(int code, String msg) {
return restResult(null, code, msg);
}

public static <T> R<T> fail(Response.Status status) {
return restResult(null, status.getStatusCode(), status.getReasonPhrase());
}

/**
* return warn message
*
* @param msg 返回内容
* @return R
*/
public static <T> R<T> warn(String msg) {
return restResult(null, WARN, msg);
}

/**
* return warn message
*
* @param msg return message
* @param data return data
* @return R
*/
public static <T> R<T> warn(String msg, T data) {
return restResult(data, WARN, msg);
}

private static <T> R<T> restResult(T data, int code, String msg) {
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
return r;
}

public static <T> Boolean isError(R<T> ret) {
return !isSuccess(ret);
}

public static <T> Boolean isSuccess(R<T> ret) {
return R.SUCCESS == ret.getCode();
}

public R() {
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public T getData() {
return data;
}

public void setData(T data) {
this.data = data;
}
public class R<T>
implements Serializable
{
@Serial
private static final long serialVersionUID = 1L;

/**
* success
*/
public static final int SUCCESS = 200;

/**
* fail
*/
public static final int FAIL = 500;

/**
* warn
*/
public static final int WARN = 601;

private int code;

private String msg;

private T data;

public static <T> R<T> ok()
{
return restResult(null, SUCCESS, "Successful.");
}

public static <T> R<T> ok(T data)
{
return restResult(data, SUCCESS, "Successful.");
}

public static <T> R<T> ok(String msg)
{
return restResult(null, SUCCESS, msg);
}

public static <T> R<T> ok(String msg, T data)
{
return restResult(data, SUCCESS, msg);
}

public static <T> R<T> fail()
{
return restResult(null, FAIL, "Failed.");
}

public static <T> R<T> fail(String msg)
{
return restResult(null, FAIL, msg);
}

public static <T> R<T> fail(T data)
{
return restResult(data, FAIL, "Failed.");
}

public static <T> R<T> fail(String msg, T data)
{
return restResult(data, FAIL, msg);
}

public static <T> R<T> fail(int code, String msg)
{
return restResult(null, code, msg);
}

public static <T> R<T> fail(Response.Status status)
{
return restResult(null, status.getStatusCode(), status.getReasonPhrase());
}

/**
* return warn message
*
* @param msg 返回内容
* @return R
*/
public static <T> R<T> warn(String msg)
{
return restResult(null, WARN, msg);
}

/**
* return warn message
*
* @param msg return message
* @param data return data
* @return R
*/
public static <T> R<T> warn(String msg, T data)
{
return restResult(data, WARN, msg);
}

private static <T> R<T> restResult(T data, int code, String msg)
{
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
return r;
}

public static <T> Boolean isError(R<T> ret)
{
return !isSuccess(ret);
}

public static <T> Boolean isSuccess(R<T> ret)
{
return R.SUCCESS == ret.getCode();
}

public R()
{
}

public int getCode()
{
return code;
}

public void setCode(int code)
{
this.code = code;
}

public String getMsg()
{
return msg;
}

public void setMsg(String msg)
{
this.msg = msg;
}

public T getData()
{
return data;
}

public void setData(T data)
{
this.data = data;
}
}
Loading

0 comments on commit 873a071

Please sign in to comment.