Skip to content

Commit

Permalink
add method in InfoAdaptor (oceanbase#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkPotato777 authored and krihy committed Aug 31, 2023
1 parent 5c43837 commit a5f4203
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.oceanbase.odc.service.info;

import java.time.OffsetDateTime;

import javax.servlet.http.HttpServletRequest;

public interface InfoAdapter {
Expand All @@ -25,6 +27,10 @@ public interface InfoAdapter {

String getSupportGroupQRCodeUrl();

String getBuildVersion();

OffsetDateTime getBuildTime();

boolean isPasswordLoginEnabled();

default String ssoLoginName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ public class OdcInfoService {
@PostConstruct
public void init() {
staticOdcInfo = new OdcInfo();
staticOdcInfo.setVersion(buildProperties.getVersion());
staticOdcInfo.setStartTime(
instant2OffsetDateTime(Instant.ofEpochMilli(ManagementFactory.getRuntimeMXBean().getStartTime())));
staticOdcInfo.setBuildTime(instant2OffsetDateTime(buildProperties.getTime()));
staticOdcInfo.setHomePageText(infoProperties.getHomePageText());
staticOdcInfo.setSupportEmail(infoProperties.getSupportEmail());
staticOdcInfo.setSupportUrl(infoProperties.getSupportUrl());
Expand Down Expand Up @@ -139,6 +137,8 @@ public OffsetDateTime time() {
public OdcInfo info() {
OdcInfo odcInfo = ObjectUtil.deepCopy(this.staticOdcInfo, OdcInfo.class);
String[] profiles = SpringContextUtil.getProfiles();
odcInfo.setVersion(infoAdapter.getBuildVersion());
odcInfo.setBuildTime(infoAdapter.getBuildTime());
odcInfo.setProfiles(profiles);
odcInfo.setPasswordLoginEnabled(this.infoAdapter.isPasswordLoginEnabled());
odcInfo.setSsoLoginEnabled(Objects.nonNull(getLoginUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

package com.oceanbase.odc.service.info;

import java.time.OffsetDateTime;
import java.time.ZoneId;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

Expand All @@ -32,6 +37,9 @@ public class DesktopInfoAdapter implements InfoAdapter {
@Value("${odc.help.supportGroupQRCodeUrl:#{null}}")
private String supportGroupQRCodeUrl;

@Autowired
private BuildProperties buildProperties;

@Override
public boolean isPasswordLoginEnabled() {
return false;
Expand All @@ -52,4 +60,13 @@ public String getSupportGroupQRCodeUrl() {
return supportGroupQRCodeUrl;
}

@Override
public String getBuildVersion() {
return buildProperties.getVersion();
}

@Override
public OffsetDateTime getBuildTime() {
return OffsetDateTime.ofInstant(buildProperties.getTime(), ZoneId.systemDefault());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
package com.oceanbase.odc.service.info;

import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

Expand All @@ -46,6 +49,8 @@ public class WebInfoAdapter implements InfoAdapter {
private PlaysiteOpenApiProperties alipayOpenApiProperties;
@Autowired
protected IntegrationService integrationService;
@Autowired
private BuildProperties buildProperties;

@Override
public boolean isPasswordLoginEnabled() {
Expand Down Expand Up @@ -97,4 +102,14 @@ public String getSupportGroupQRCodeUrl() {
return supportGroupQRCodeUrl;
}

@Override
public String getBuildVersion() {
return buildProperties.getVersion();
}

@Override
public OffsetDateTime getBuildTime() {
return OffsetDateTime.ofInstant(buildProperties.getTime(), ZoneId.systemDefault());
}

}

0 comments on commit a5f4203

Please sign in to comment.