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 64a59ef  refactoring
     new 0852d2c  Merge remote-tracking branch 'origin/DLAB-1571' into DLAB-1571
64a59ef is described below

commit 64a59efec394b0a6861671644af5857c618a8bdb
Author: Oleh Fuks <olegfuk...@gmail.com>
AuthorDate: Tue Apr 14 14:03:38 2020 +0300

    refactoring
---
 .../epam/dlab/billing/azure/dao/BillingDAO.java    |  31 ------
 .../billing/azure/dao/impl/BillingDAOImpl.java     | 121 ---------------------
 2 files changed, 152 deletions(-)

diff --git 
a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/dao/BillingDAO.java
 
b/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/dao/BillingDAO.java
deleted file mode 100644
index 793d7cb..0000000
--- 
a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/dao/BillingDAO.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package com.epam.dlab.billing.azure.dao;
-
-import com.epam.dlab.dto.billing.BillingData;
-
-import java.util.List;
-
-public interface BillingDAO {
-
-    List<BillingData> getBillingReport(String dateStart, String dateEnd, 
String dlabId, List<String> products);
-
-    List<BillingData> getBillingReport(List<String> dlabIds);
-}
diff --git 
a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/dao/impl/BillingDAOImpl.java
 
b/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/dao/impl/BillingDAOImpl.java
deleted file mode 100644
index a4dcec5..0000000
--- 
a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/dao/impl/BillingDAOImpl.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package com.epam.dlab.billing.azure.dao.impl;
-
-import com.epam.dlab.billing.azure.dao.BillingDAO;
-import com.epam.dlab.billing.azure.model.AzureDailyResourceInvoice;
-import com.epam.dlab.dto.billing.BillingData;
-import com.epam.dlab.exceptions.DlabException;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.aggregation.Aggregation;
-import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
-import org.springframework.data.mongodb.core.aggregation.GroupOperation;
-import org.springframework.data.mongodb.core.aggregation.MatchOperation;
-import org.springframework.data.mongodb.core.query.Criteria;
-import org.springframework.stereotype.Component;
-
-import java.math.BigDecimal;
-import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import static 
org.springframework.data.mongodb.core.aggregation.Aggregation.group;
-import static 
org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation;
-
-@Component
-@Slf4j
-public class BillingDAOImpl implements BillingDAO {
-    private final MongoTemplate mongoTemplate;
-
-    public BillingDAOImpl(MongoTemplate mongoTemplate) {
-        this.mongoTemplate = mongoTemplate;
-    }
-
-    @Override
-    public List<BillingData> getBillingReport(String dateStart, String 
dateEnd, String dlabId, List<String> products) {
-        try {
-            List<AggregationOperation> aggregationOperations = new 
ArrayList<>();
-            
aggregationOperations.add(Aggregation.match(Criteria.where("dlabId").regex(dlabId,
 "i")));
-            if (!products.isEmpty()) {
-                
aggregationOperations.add(Aggregation.match(Criteria.where("meterCategory").in(products)));
-            }
-            getMatchCriteria(dateStart, Criteria.where("day").gte(dateStart))
-                    .ifPresent(aggregationOperations::add);
-            getMatchCriteria(dateEnd, Criteria.where("day").lte(dateEnd))
-                    .ifPresent(aggregationOperations::add);
-            aggregationOperations.add(getGroupOperation());
-
-            Aggregation aggregation = newAggregation(aggregationOperations);
-
-            return mongoTemplate.aggregate(aggregation, "billing", 
AzureDailyResourceInvoice.class).getMappedResults()
-                    .stream()
-                    .map(this::toBillingData)
-                    .collect(Collectors.toList());
-        } catch (Exception e) {
-            log.error("Cannot retrieve billing information ", e);
-            throw new DlabException("Cannot retrieve billing information", e);
-        }
-    }
-
-    @Override
-    public List<BillingData> getBillingReport(List<String> dlabIds) {
-        try {
-            GroupOperation groupOperation = getGroupOperation();
-            MatchOperation matchOperation = 
Aggregation.match(Criteria.where("dlab_id").in(dlabIds));
-            Aggregation aggregation = newAggregation(matchOperation, 
groupOperation);
-
-            return mongoTemplate.aggregate(aggregation, "billing", 
AzureDailyResourceInvoice.class).getMappedResults()
-                    .stream()
-                    .map(this::toBillingData)
-                    .collect(Collectors.toList());
-        } catch (Exception e) {
-            log.error("Cannot retrieve billing information ", e);
-            throw new DlabException("Cannot retrieve billing information", e);
-        }
-    }
-
-    private GroupOperation getGroupOperation() {
-        return group("meterCategory", "currencyCode", "dlabId")
-                .min("usageStartDate").as("usageStartDate")
-                .max("usageEndDate").as("usageEndDate")
-                .sum("cost").as("cost");
-    }
-
-    private Optional<MatchOperation> getMatchCriteria(String dateStart, 
Criteria criteria) {
-        return Optional.ofNullable(dateStart)
-                .filter(StringUtils::isNotEmpty)
-                .map(date -> Aggregation.match(criteria));
-    }
-
-    private BillingData toBillingData(AzureDailyResourceInvoice billingData) {
-        return BillingData.builder()
-                .tag(billingData.getDlabId())
-                
.usageDateFrom(Optional.ofNullable(billingData.getUsageStartDate()).map(LocalDate::parse).orElse(null))
-                
.usageDateTo(Optional.ofNullable(billingData.getUsageEndDate()).map(LocalDate::parse).orElse(null))
-                .product(billingData.getMeterCategory())
-                .cost(BigDecimal.valueOf(billingData.getCost()).setScale(2, 
BigDecimal.ROUND_HALF_UP).doubleValue())
-                .currency(billingData.getCurrencyCode())
-                .build();
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org
For additional commands, e-mail: commits-h...@dlab.apache.org

Reply via email to