This is an automated email from the ASF dual-hosted git repository.

ofuks pushed a commit to branch DLAB-1571
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/DLAB-1571 by this push:
     new 581c5a2  Code refactoring
581c5a2 is described below

commit 581c5a2bfb179bf8a57055fcf80eca080e1aa474
Author: Oleh Fuks <[email protected]>
AuthorDate: Fri Mar 6 12:59:21 2020 +0200

    Code refactoring
---
 services/self-service/pom.xml                      |  6 ++++
 .../dlab/backendapi/resources/BillingResource.java | 41 +++++++++++-----------
 .../service/impl/BillingServiceImplNew.java        | 20 ++++++-----
 3 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/services/self-service/pom.xml b/services/self-service/pom.xml
index 25dbf42..382dc7c 100644
--- a/services/self-service/pom.xml
+++ b/services/self-service/pom.xml
@@ -184,6 +184,12 @@
             <artifactId>guacamole-common</artifactId>
             <version>1.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.4</version>
+        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/BillingResource.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/BillingResource.java
index 10ed7bf..54e3695 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/BillingResource.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/BillingResource.java
@@ -25,7 +25,6 @@ import com.epam.dlab.backendapi.service.BillingService;
 import com.epam.dlab.backendapi.service.BillingServiceNew;
 import com.google.inject.Inject;
 import io.dropwizard.auth.Auth;
-import org.bson.Document;
 
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
@@ -50,34 +49,34 @@ public class BillingResource {
         this.billingServiceNew = billingServiceNew;
     }
 
-    @POST
-    @Path("/report")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Document getBillingReport(@Auth UserInfo userInfo, @Valid @NotNull 
BillingFilter formDTO) {
-        return billingService.getBillingReport(userInfo, formDTO);
-    }
-
-    @POST
-    @Path("/report/download")
-    @Produces(MediaType.APPLICATION_OCTET_STREAM)
-    public Response downloadBillingReport(@Auth UserInfo userInfo, @Valid 
@NotNull BillingFilter formDTO) {
-        return Response.ok(billingService.downloadReport(userInfo, formDTO))
-                .header(HttpHeaders.CONTENT_DISPOSITION,
-                        "attachment; filename=\"" + 
billingService.getReportFileName(userInfo, formDTO) + "\"")
-                .build();
-    }
+//    @POST
+//    @Path("/report")
+//    @Produces(MediaType.APPLICATION_JSON)
+//    public Document getBillingReport(@Auth UserInfo userInfo, @Valid 
@NotNull BillingFilter formDTO) {
+//        return billingService.getBillingReport(userInfo, formDTO);
+//    }
+//
+//    @POST
+//    @Path("/report/download")
+//    @Produces(MediaType.APPLICATION_OCTET_STREAM)
+//    public Response downloadBillingReport(@Auth UserInfo userInfo, @Valid 
@NotNull BillingFilter formDTO) {
+//        return Response.ok(billingService.downloadReport(userInfo, formDTO))
+//                .header(HttpHeaders.CONTENT_DISPOSITION,
+//                        "attachment; filename=\"" + 
billingService.getReportFileName(userInfo, formDTO) + "\"")
+//                .build();
+//    }
 
     @POST
-    @Path("/report2")
+    @Path("/report")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response getBillingReport2(@Auth UserInfo userInfo, @Valid @NotNull 
BillingFilter filter) {
+    public Response getBillingReport(@Auth UserInfo userInfo, @Valid @NotNull 
BillingFilter filter) {
         return Response.ok(billingServiceNew.getBillingReport(userInfo, 
filter)).build();
     }
 
     @POST
-    @Path("/report2/download")
+    @Path("/report/download")
     @Produces(MediaType.APPLICATION_OCTET_STREAM)
-    public Response downloadBillingReport2(@Auth UserInfo userInfo, @Valid 
@NotNull BillingFilter filter) {
+    public Response downloadBillingReport(@Auth UserInfo userInfo, @Valid 
@NotNull BillingFilter filter) {
         return Response.ok(billingServiceNew.downloadReport(userInfo, filter))
                 .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; 
filename=\"billing-report.csv\"")
                 .build();
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImplNew.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImplNew.java
index ec595e8..5917c26 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImplNew.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImplNew.java
@@ -43,6 +43,8 @@ import com.google.common.collect.Lists;
 import com.google.inject.Inject;
 import com.google.inject.name.Named;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.http.client.utils.URIBuilder;
 
 import javax.ws.rs.core.GenericType;
@@ -241,18 +243,18 @@ public class BillingServiceImplNew implements 
BillingServiceNew {
     }
 
     private Predicate<BillingReportLine> getBillingReportFilter(BillingFilter 
filter) {
-        return br -> (filter.getUsers().isEmpty() || 
filter.getUsers().contains(br.getUser())) &&
-                (filter.getProjects().isEmpty() || 
filter.getProjects().contains(br.getProject())) &&
-                (filter.getResourceTypes().isEmpty() || 
filter.getResourceTypes().contains(br.getResourceType().name())) &&
-                (filter.getStatuses().isEmpty() || 
filter.getStatuses().contains(br.getStatus())) &&
-                (filter.getShapes().isEmpty() || 
filter.getShapes().contains(br.getShape()));
+        return br -> (CollectionUtils.isEmpty(filter.getUsers()) || 
filter.getUsers().contains(br.getUser())) &&
+                (CollectionUtils.isEmpty(filter.getProjects()) || 
filter.getProjects().contains(br.getProject())) &&
+                (CollectionUtils.isEmpty(filter.getResourceTypes()) || 
filter.getResourceTypes().contains(br.getResourceType().name())) &&
+                (CollectionUtils.isEmpty(filter.getStatuses()) || 
filter.getStatuses().contains(br.getStatus())) &&
+                (CollectionUtils.isEmpty(filter.getShapes()) || 
filter.getShapes().contains(br.getShape()));
     }
 
     private Predicate<BillingData> getBillingDataFilter(BillingFilter filter) {
-        return br -> (filter.getDlabId().isEmpty() || 
filter.getDlabId().equalsIgnoreCase(br.getTag())) &&
-                (filter.getDateStart().isEmpty() || 
LocalDate.parse(filter.getDateStart()).isEqual(br.getUsageDateFrom()) || 
LocalDate.parse(filter.getDateStart()).isBefore(br.getUsageDateFrom())) &&
-                (filter.getDateEnd().isEmpty() || 
LocalDate.parse(filter.getDateEnd()).isEqual(br.getUsageDateTo()) || 
LocalDate.parse(filter.getDateEnd()).isAfter(br.getUsageDateTo())) &&
-                (filter.getProducts().isEmpty() || 
filter.getProducts().contains(br.getProduct()));
+        return br -> (StringUtils.isEmpty(filter.getDlabId()) || 
filter.getDlabId().equalsIgnoreCase(br.getTag())) &&
+                (StringUtils.isEmpty(filter.getDateStart()) || 
LocalDate.parse(filter.getDateStart()).isEqual(br.getUsageDateFrom()) || 
LocalDate.parse(filter.getDateStart()).isBefore(br.getUsageDateFrom())) &&
+                (StringUtils.isEmpty(filter.getDateEnd()) || 
LocalDate.parse(filter.getDateEnd()).isEqual(br.getUsageDateTo()) || 
LocalDate.parse(filter.getDateEnd()).isAfter(br.getUsageDateTo())) &&
+                (CollectionUtils.isEmpty(filter.getProducts()) || 
filter.getProducts().contains(br.getProduct()));
     }
 
     private boolean isFullReport(UserInfo userInfo) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to