Skip to content

Commit

Permalink
feat: Add on recent items when generated/export report.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Jul 27, 2024
1 parent ce4b2a9 commit f65c143
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public void getReport(GetReportRequest request, StreamObserver<Report> responseO
responseObserver.onCompleted();
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException());
.asRuntimeException()
);
}
}

Expand All @@ -53,10 +55,12 @@ public void getView(GetReportRequest request, StreamObserver<Report> responseObs
responseObserver.onCompleted();
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException());
.asRuntimeException()
);
}
}

Expand All @@ -68,10 +72,12 @@ public void runExport(RunExportRequest request, StreamObserver<RunExportResponse
responseObserver.onCompleted();
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
e.printStackTrace();
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException());
.asRuntimeException()
);
}
}
}
48 changes: 47 additions & 1 deletion src/main/java/org/spin/report_engine/service/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.adempiere.core.domains.models.I_AD_Menu;
import org.adempiere.core.domains.models.I_AD_Process;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MRecentItem;
import org.compiere.model.MTable;
import org.compiere.model.Query;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.spin.backend.grpc.report_engine.ReportColumn;
Expand Down Expand Up @@ -54,7 +58,34 @@ public class Service {
private static final String MAXIMUM_KEY = "maximum_value";
private static final String VARIANCE_KEY = "variance_value";
private static final String DEVIATION_KEY = "deviation_value";



/**
* Add element to recent item
* @param reportId
*/
public static void addToRecentItem(int reportId) {
if (reportId <= 0) {
return;
}
final String whereClause = I_AD_Process.COLUMNNAME_AD_Process_ID + " = ?";
// Get menu
int menuId = new Query(
Env.getCtx(),
I_AD_Menu.Table_Name,
whereClause,
null
)
.setParameters(reportId)
.firstId()
;
if (menuId <= 0) {
return;
}
MRecentItem.addMenuOption(Env.getCtx(), menuId, 0);
}


/**
* Get a View after run report
* @param context
Expand All @@ -65,6 +96,11 @@ public static Report.Builder getView(GetReportRequest request) {
if(request.getPrintFormatId() <= 0) {
throw new AdempiereException("@FillMandatory@ @AD_PrintFormat_ID@");
}
// Add to recent Item
addToRecentItem(
request.getReportId()
);

int pageNumber = LimitUtil.getPageNumber(SessionManager.getSessionUuid(), request.getPageToken());
int limit = LimitUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * limit;
Expand Down Expand Up @@ -96,6 +132,11 @@ public static Report.Builder getReport(GetReportRequest request) {
if(request.getReportId() <= 0) {
throw new AdempiereException("@FillMandatory@ @AD_Process_ID@");
}
// Add to recent Item
addToRecentItem(
request.getReportId()
);

int pageNumber = LimitUtil.getPageNumber(SessionManager.getSessionUuid(), request.getPageToken());
int limit = LimitUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * limit;
Expand Down Expand Up @@ -126,6 +167,11 @@ public static RunExportResponse.Builder getExportReport(RunExportRequest request
if(request.getReportId() <= 0) {
throw new AdempiereException("@FillMandatory@ @AD_Process_ID@");
}
// Add to recent Item
addToRecentItem(
request.getReportId()
);

int pageNumber = LimitUtil.getPageNumber(SessionManager.getSessionUuid(), request.getPageToken());
int limit = QueryDefinition.NO_LIMIT;
int offset = 0;
Expand Down

0 comments on commit f65c143

Please sign in to comment.