Skip to content

Commit

Permalink
Merge branch 'develop' into feature/solop-develop/spuy
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Dec 17, 2024
2 parents 430465d + 7aed29a commit ba7837c
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 106 deletions.
110 changes: 73 additions & 37 deletions src/main/java/org/spin/grpc/service/ReportManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class ReportManagement extends ReportManagementImplBase {
private CLogger log = CLogger.getCLogger(ReportManagement.class);



@Override
public void generateReport(GenerateReportRequest request, StreamObserver<ProcessLog> responseObserver) {
try {
Expand All @@ -116,10 +116,11 @@ public void generateReport(GenerateReportRequest request, StreamObserver<Process
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException()
responseObserver.onError(
Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException()
);
}
}
Expand Down Expand Up @@ -301,10 +302,25 @@ public static ProcessLog.Builder generateReport(
I_AD_PInstance.COLUMNNAME_AD_PInstance_ID + " = ?",
null
)
.setParameters(result.getAD_PInstance_ID())
.first();
.setParameters(
result.getAD_PInstance_ID()
)
.first()
;
response.setInstanceId(instance.getAD_PInstance_ID());

if (!Util.isEmpty(instance.getErrorMsg(), true)) {
result.setError(true);
String errorMessage = Msg.parseTranslation(
Env.getCtx(),
instance.getErrorMsg()
);
if (!Util.isEmpty(result.getSummary(), true)) {
errorMessage = result.getSummary() + " " + errorMessage;
}
result.setSummary(errorMessage);
}

response.setLastRun(
ValueManager.getTimestampFromDate(
instance.getUpdated()
Expand Down Expand Up @@ -476,6 +492,7 @@ public static ProcessLog.Builder addReportOutput(
}



@Override
public void getReportOutput(GetReportOutputRequest request, StreamObserver<ReportOutput> responseObserver) {
try {
Expand All @@ -488,11 +505,12 @@ public void getReportOutput(GetReportOutputRequest request, StreamObserver<Repor
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException())
;
responseObserver.onError(
Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException()
);
}
}

Expand Down Expand Up @@ -623,23 +641,26 @@ private ReportOutput.Builder getReportOutput(GetReportOutputRequest request) thr
reportFile.getName()
);
builder.setFileName(
ValueManager.validateNull(validFileName)
StringManager.getValidString(validFileName)
)
.setName(
ValueManager.validateNull(
StringManager.getValidString(
reportEngine.getName()
)
)
.setMimeType(
ValueManager.validateNull(
StringManager.getValidString(
MimeType.getMimeType(validFileName)
)
)
;
// Header
String headerName = Msg.getMsg(Env.getCtx(), "Report") + ": " + reportEngine.getName() + " " + Env.getHeader(Env.getCtx(), 0);
String headerName = Msg.getMsg(
Env.getCtx(),
"Report"
) + ": " + reportEngine.getName() + " " + Env.getHeader(Env.getCtx(), 0);
builder.setHeaderName(
ValueManager.validateNull(headerName)
StringManager.getValidString(headerName)
);
// Footer
StringBuffer footerName = new StringBuffer ();
Expand All @@ -649,7 +670,7 @@ private ReportOutput.Builder getReportOutput(GetReportOutputRequest request) thr
.append(reportEngine.getRowCount())
;
builder.setFooterName(
ValueManager.validateNull(
StringManager.getValidString(
footerName.toString()
)
);
Expand All @@ -666,7 +687,7 @@ private ReportOutput.Builder getReportOutput(GetReportOutputRequest request) thr
printFormat.getAD_PrintFormat_ID()
)
.setTableName(
ValueManager.validateNull(
StringManager.getValidString(
table.getTableName()
)
)
Expand Down Expand Up @@ -699,7 +720,7 @@ public void listPrintFormats(ListPrintFormatsRequest request, StreamObserver<Lis
);
}
}

@Override
public void printEntitiesBatch(PrintEntitiesBatchRequest request, StreamObserver<PrintEntitiesBatchResponse> responseObserver) {
try {
Expand Down Expand Up @@ -739,7 +760,11 @@ public void printEntitiesBatch(PrintEntitiesBatchRequest request, StreamObserver
if(fileType.equals("pdf")) {
File outFile = File.createTempFile("BatchPrint_", ".pdf");
IText7Document.mergePdf(files, outFile);
printResponse.setFileName(ValueManager.validateNull(S3Manager.putTemporaryFile(outFile)));
printResponse.setFileName(
StringManager.getValidString(
S3Manager.putTemporaryFile(outFile)
)
);
} else {
File outFile = File.createTempFile("BatchPrint_", ".zip");
try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outFile))) {
Expand All @@ -748,18 +773,24 @@ public void printEntitiesBatch(PrintEntitiesBatchRequest request, StreamObserver
Files.copy(file.toPath(), zipOut);
}
}
printResponse.setFileName(ValueManager.validateNull(S3Manager.putTemporaryFile(outFile)));
printResponse.setFileName(
StringManager.getValidString(
S3Manager.putTemporaryFile(outFile)
)
);
}
printResponse.setRecordCount(files.size());
}
responseObserver.onNext(printResponse.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
responseObserver.onError(Status.INTERNAL
responseObserver.onError(
Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException());
.asRuntimeException()
);
}
}

Expand Down Expand Up @@ -836,17 +867,17 @@ private ListPrintFormatsResponse.Builder listPrintFormats(Properties context, Li
printFormat.getAD_PrintFormat_ID()
)
.setUuid(
ValueManager.validateNull(
StringManager.getValidString(
printFormat.getUUID()
)
)
.setName(
ValueManager.validateNull(
StringManager.getValidString(
printFormat.getName()
)
)
.setDescription(
ValueManager.validateNull(
StringManager.getValidString(
printFormat.getDescription()
)
)
Expand All @@ -858,7 +889,7 @@ private ListPrintFormatsResponse.Builder listPrintFormats(Properties context, Li
if (printFormat.getAD_Table_ID() > 0) {
MTable table = MTable.get(Env.getCtx(), printFormat.getAD_Table_ID());
printFormatBuilder.setTableName(
ValueManager.validateNull(
StringManager.getValidString(
table.getTableName()
)
);
Expand Down Expand Up @@ -968,7 +999,8 @@ private ListReportViewsResponse.Builder listReportViews(ListReportViewsRequest r
)
.setParameters(reportView.get_ID(), "Y", language)
.setOnlyActiveRecords(true)
.first();
.first()
;

if (translation != null) {
String nameTranslated = translation.get_ValueAsString(I_AD_ReportView.COLUMNNAME_Name);
Expand All @@ -987,22 +1019,22 @@ private ListReportViewsResponse.Builder listReportViews(ListReportViewsRequest r
reportView.getAD_ReportView_ID()
)
.setUuid(
ValueManager.validateNull(
StringManager.getValidString(
reportView.getUUID()
)
)
.setName(
ValueManager.validateNull(name)
StringManager.getValidString(name)
)
.setDescription(
ValueManager.validateNull(description)
StringManager.getValidString(description)
)
;

if (reportView.getAD_ReportView_ID() > 0) {
MTable table = MTable.get(context, reportView.getAD_Table_ID());
reportViewBuilder.setTableName(
ValueManager.validateNull(
StringManager.getValidString(
table.getTableName()
)
);
Expand All @@ -1028,10 +1060,12 @@ public void listDrillTables(ListDrillTablesRequest request, StreamObserver<ListD
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
responseObserver.onError(
Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException());
.asRuntimeException()
);
}
}

Expand Down Expand Up @@ -1069,7 +1103,7 @@ private ListDrillTablesResponse.Builder listDrillTables(ListDrillTablesRequest r
// Add here
DrillTable.Builder drillTable = DrillTable.newBuilder();
drillTable.setTableName(
ValueManager.validateNull(drillTableName)
StringManager.getValidString(drillTableName)
);
String name = element.getPrintName();
String poName = element.getPO_PrintName();
Expand All @@ -1088,7 +1122,7 @@ private ListDrillTablesResponse.Builder listDrillTables(ListDrillTablesRequest r
}
// Print Name
drillTable.setPrintName(
ValueManager.validateNull(name)
StringManager.getValidString(name)
);
recordCount++;
// Add to list
Expand All @@ -1101,6 +1135,8 @@ private ListDrillTablesResponse.Builder listDrillTables(ListDrillTablesRequest r
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(resultSet, pstmt);
resultSet = null;
pstmt = null;
}
// Return
return builder;
Expand Down
Loading

0 comments on commit ba7837c

Please sign in to comment.