ofuks commented on a change in pull request #770:
URL: https://github.com/apache/incubator-dlab/pull/770#discussion_r438266839
##########
File path:
services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
##########
@@ -116,20 +116,20 @@ public BillingReport getBillingReport(UserInfo user,
BillingFilter filter) {
.usageDateTo(max)
.totalCost(new BigDecimal(sum).setScale(2,
BigDecimal.ROUND_HALF_UP).doubleValue())
.currency(currency)
- .isFull(isFullReport(user))
+ .isReportHeaderCompletable(hasUserBillingRole(user))
.build();
}
@Override
public String downloadReport(UserInfo user, BillingFilter filter) {
- boolean isFull = isFullReport(user);
BillingReport report = getBillingReport(user, filter);
- StringBuilder builder = new
StringBuilder(BillingUtils.getFirstLine(report.getSbn(),
report.getUsageDateFrom(), report.getUsageDateTo()));
- builder.append(BillingUtils.getHeader(isFull));
+ StringBuilder reportHead = new
StringBuilder(BillingUtils.getFirstLine(report.getSbn(),
report.getUsageDateFrom(), report.getUsageDateTo()));
+ String stringOfAdjustedHeader =
BillingUtils.getHeader(report.isReportHeaderCompletable());
+ reportHead.append(stringOfAdjustedHeader);
try {
- report.getReportLines().forEach(r ->
builder.append(BillingUtils.printLine(r, isFull)));
- builder.append(BillingUtils.getTotal(report.getTotalCost(),
report.getCurrency()));
- return builder.toString();
+ report.getReportLines().forEach(r ->
reportHead.append(BillingUtils.printLine(r,
report.isReportHeaderCompletable())));
Review comment:
You use report.isReportHeaderCompletable() method more than 1 time.
Suggested to create create variable.
##########
File path:
services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
##########
@@ -212,12 +227,20 @@ public static String printLine(BillingReportLine line,
boolean isFull) {
return CSVFormatter.formatLine(lines, CSVFormatter.SEPARATOR);
}
- public static String getTotal(Double total, String currency) {
+ /**
+ *
+ * @param total monetary amount
+ * @param currency user's currency
+ * @param stringOfAdjustedHeader filtered fields of report header
+ * @return line with cost of resources
+ */
+ public static String getTotal(Double total, String currency, String
stringOfAdjustedHeader) {
Review comment:
You can use the length of the header instead of
**stringOfAdjustedHeader** because the only thing you need in the method is the
length of the header.
##########
File path:
services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
##########
@@ -182,25 +183,39 @@ public static String
getComputationalShape(UserComputationalResource resource) {
return list.stream();
}
+ /**
+ *
+ * @param sbn Service Base Name
+ * @param from formatted date, like 2020-04-07
+ * @param to formatted date, like 2020-05-07
+ * @return line, like:
+ * "Service base name: SERVICE_BASE_NAME. Available reporting period from:
2020-04-07 to: 2020-04-07"
+ */
public static String getFirstLine(String sbn, LocalDate from, LocalDate
to) {
return
CSVFormatter.formatLine(Lists.newArrayList(String.format(REPORT_FIRST_LINE, sbn,
Optional.ofNullable(from).map(date ->
date.format(DateTimeFormatter.ISO_DATE)).orElse(StringUtils.EMPTY),
Optional.ofNullable(to).map(date ->
date.format(DateTimeFormatter.ISO_DATE)).orElse(StringUtils.EMPTY))),
CSVFormatter.SEPARATOR, '\"');
}
- public static String getHeader(boolean isFull) {
- List<String> headers = new
ArrayList<>(Arrays.asList(BillingUtils.REPORT_HEADERS));
- if (!isFull) {
- headers.remove(1);
+ /**
+ * headerType there are two types of header according user role
+ * @return line, like DLab ID,User,Project,DLab Resource
Type,Status,Shape,Product,Cost
+ * in case of additional header type, the ENUM object will be propagated
from the Service Impl Class
+ */
+ public static String getHeader(boolean isReportHeaderCompletable) {
+ if (!isReportHeaderCompletable){
+ return CSVFormatter.formatLine(
+
Arrays.asList(BillingUtils.BILLING_FILTERED_REPORT_HEADERS),
CSVFormatter.SEPARATOR);
Review comment:
Inline this
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]