Skip to content

Commit

Permalink
Merge pull request #8 from EdwinBetanc0urt/feature/get-version
Browse files Browse the repository at this point in the history
feat Add get version with system info.
  • Loading branch information
yamelsenih authored Sep 20, 2024
2 parents 9d3f1d4 + 0660d7d commit 39bbd95
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ jobs:
GITHUB_DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
GITHUB_DEPLOY_REPOSITORY: ${{ secrets.DEPLOY_REPOSITORY }}

- name: Set Main Version
run: echo "MAIN_VERSION=${{ github.event.release.name }}" >> src/main/java/org/spin/base/version.properties

- name: Set Release Date
run: echo "DATE_VERSION=$(date +'%Y-%m-%d')" >> src/main/java/org/spin/base/version.properties

- name: Set Implementation Version
run: echo "IMPLEMENTATION_VERSION=${{ github.event.release.tag_name }}" >> src/main/java/org/spin/base/version.properties

- name: Upload descriptor file artifact
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ sourceSets {
srcDirs 'build/generated/source/proto/main/java'
srcDirs 'src/main/proto'
}
resources {
include 'org/spin/base/version.properties'
}
}
}

Expand Down
Binary file not shown.
89 changes: 89 additions & 0 deletions src/main/java/org/spin/base/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/************************************************************************************
* Copyright (C) 2018-present E.R.P. Consultores y Asociados, C.A. *
* Contributor(s): Edwin Betancourt, [email protected] *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
************************************************************************************/

package org.spin.base;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Properties;

/**
* @author Edwin Betancourt, [email protected], https://github.com/EdwinBetanc0urt
* Service for backend of Version
*/
public final class Version
{

/** Main Version String */
// Conventions for naming second number is even for stable, and odd for unstable
// the releases will have a suffix (a) for alpha - (b) for beta - (t) for trunk - (s) for stable - and (LTS) for long term support
public static String MAIN_VERSION = "1.0.0-dev";

/** Detail Version as date Used for Client/Server */
public static String DATE_VERSION = (new SimpleDateFormat("yyyy-MM-dd")).format(
new Date(
System.currentTimeMillis()
)
);

public static String IMPLEMENTATION_VERSION = "1.0.0-dev";

static {
ClassLoader loader = Version.class.getClassLoader();
InputStream inputStream = loader.getResourceAsStream("org/spin/base/version.properties");
if (inputStream != null) {
Properties properties = new Properties();
try {
properties.load(inputStream);

if (properties.containsKey("MAIN_VERSION")) {
MAIN_VERSION = properties.getProperty("MAIN_VERSION");
}
if (properties.containsKey("DATE_VERSION")) {
DATE_VERSION = properties.getProperty("DATE_VERSION");
}
if (properties.containsKey("IMPLEMENTATION_VERSION")) {
IMPLEMENTATION_VERSION = properties.getProperty("IMPLEMENTATION_VERSION");
}
} catch (IOException e) {
// file does not exist
}
}
}

/**
* Get Product Version
* @return Application Version
*/
public static String getVersion()
{
return MAIN_VERSION + " @ " + DATE_VERSION;
} // getVersion

public static String getMainVersion() {
return MAIN_VERSION;
}

public static String getDateVersion() {
return DATE_VERSION;
}

public static String getImplementationVersion() {
return IMPLEMENTATION_VERSION;
}

} // Adempiere
29 changes: 25 additions & 4 deletions src/main/java/org/spin/report_engine/controller/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,38 @@
import org.spin.backend.grpc.report_engine.ReportEngineGrpc.ReportEngineImplBase;
import org.spin.report_engine.service.Service;
import org.spin.backend.grpc.report_engine.GetReportRequest;
import org.spin.backend.grpc.report_engine.GetSystemInfoRequest;
import org.spin.backend.grpc.report_engine.Report;
import org.spin.backend.grpc.report_engine.RunExportRequest;
import org.spin.backend.grpc.report_engine.RunExportResponse;
import org.spin.backend.grpc.report_engine.SystemInfo;

import io.grpc.Status;
import io.grpc.stub.StreamObserver;

public class ReportService extends ReportEngineImplBase {

/** Logger */
private CLogger log = CLogger.getCLogger(ReportService.class);



@Override
public void getSystemInfo(GetSystemInfoRequest request, StreamObserver<SystemInfo> responseObserver) {
try {
SystemInfo.Builder builder = Service.getSystemInfo();
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException()
);
}
}

@Override
public void getReport(GetReportRequest request, StreamObserver<Report> responseObserver) {
try {
Expand All @@ -46,7 +66,7 @@ public void getReport(GetReportRequest request, StreamObserver<Report> responseO
);
}
}

@Override
public void getView(GetReportRequest request, StreamObserver<Report> responseObserver) {
try {
Expand All @@ -63,7 +83,7 @@ public void getView(GetReportRequest request, StreamObserver<Report> responseObs
);
}
}

@Override
public void runExport(RunExportRequest request, StreamObserver<RunExportResponse> responseObserver) {
try {
Expand All @@ -80,4 +100,5 @@ public void runExport(RunExportRequest request, StreamObserver<RunExportResponse
);
}
}

}
30 changes: 30 additions & 0 deletions src/main/java/org/spin/report_engine/service/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.spin.backend.grpc.report_engine.ReportRow;
import org.spin.backend.grpc.report_engine.RunExportRequest;
import org.spin.backend.grpc.report_engine.RunExportResponse;
import org.spin.backend.grpc.report_engine.SystemInfo;
import org.spin.base.Version;
import org.spin.backend.grpc.report_engine.GetReportRequest;
import org.spin.backend.grpc.report_engine.Report;
import org.spin.report_engine.data.Cell;
Expand All @@ -43,6 +45,7 @@
import org.spin.service.grpc.util.db.LimitUtil;
import org.spin.service.grpc.util.query.Filter;
import org.spin.service.grpc.util.query.FilterManager;
import org.spin.service.grpc.util.value.TimeManager;
import org.spin.service.grpc.util.value.ValueManager;

import com.google.protobuf.Struct;
Expand Down Expand Up @@ -87,6 +90,33 @@ public static void addToRecentItem(int reportId) {
}


public static SystemInfo.Builder getSystemInfo() {
SystemInfo.Builder builder = SystemInfo.newBuilder();

// backend info
builder.setDateVersion(
ValueManager.getTimestampFromDate(
TimeManager.getTimestampFromString(
Version.DATE_VERSION
)
)
)
.setMainVersion(
ValueManager.validateNull(
Version.MAIN_VERSION
)
)
.setImplementationVersion(
ValueManager.validateNull(
Version.IMPLEMENTATION_VERSION
)
)
;

return builder;
}


/**
* Get a View after run report
* @param context
Expand Down
18 changes: 18 additions & 0 deletions src/main/proto/service/report_engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ option java_outer_classname = "ReportEngineService";

import "google/api/annotations.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

// Base URL
// /report-engine/
Expand All @@ -15,6 +16,13 @@ package report_engine;

// The greeting service definition.
service ReportEngine {
// system information
rpc GetSystemInfo(GetSystemInfoRequest) returns (SystemInfo) {
option (google.api.http) = {
get: "/v1/report-engine/system-info"
};
}

// Get Report Format
rpc GetView(GetReportRequest) returns (Report) {
option (google.api.http) = {
Expand All @@ -35,6 +43,16 @@ service ReportEngine {
}
}

message GetSystemInfoRequest {
// empty request
}
message SystemInfo {
// report service
google.protobuf.Timestamp date_version = 1;
string main_version = 2;
string implementation_version = 3;
}

// Run Export Request
message RunExportRequest {
int32 report_id = 1;
Expand Down

0 comments on commit 39bbd95

Please sign in to comment.