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

reafctor: move build time and build version into InfoAdaptor interface #96

Merged
merged 1 commit into from
Aug 31, 2023
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
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());
}

}