Skip to content

Commit

Permalink
Merge pull request tmobile#394 from tmobile/release/2.0
Browse files Browse the repository at this point in the history
Release/2.0
  • Loading branch information
kaykumar committed Dec 6, 2019
2 parents 9a9617d + 3b96ad5 commit 3a4e582
Show file tree
Hide file tree
Showing 254 changed files with 15,808 additions and 2,673 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![GitHub contributors](https://img.shields.io/github/contributors/tmobile/pacbot.svg)](https://github.com/tmobile/pacbot/graphs/contributors)
[![Gitter](https://github.com/tmobile/pacbot/blob/master/wiki/images/chat.svg)](https://gitter.im/TMO-OSS/PacBot)


<img src="./wiki/images/banner_magenta.png">

# Introduction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ public interface TargetTypesRepository extends JpaRepository<TargetTypes, String

@Query("SELECT target.targetName AS id, target.targetName AS text FROM TargetTypes target GROUP BY target.targetName")
public List<TargetTypesProjection> getAllTargetTypes();

@Query("SELECT dataSourceName FROM TargetTypes WHERE targetName = (:targetType) ")
public String findDataSourceByTargetType(@Param("targetType") String targetType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private UpdateAssetGroupDetails buildAssetGroupDetails(final AssetGroupDetails e
targetTypesIndex.put(targetTypeDetails.getTargetType(), idx[0]);
targetTypes.setAdded(true);
targetTypes.setTargetName(targetTypeDetails.getTargetType());
targetTypes.setAllAttributesName(commonService.getFieldNames(existingAssetGroupDetails.getDataSource() + "_" + targetTypeDetails.getTargetType(), targetTypeDetails.getTargetType()));
targetTypes.setAllAttributesName(commonService.getFieldNames(targetTypesRepository.findDataSourceByTargetType(targetTypeDetails.getTargetType()) + "_" + targetTypeDetails.getTargetType(), targetTypeDetails.getTargetType()));
if(targetTypeDetails.getAttributeName().equalsIgnoreCase("all") && targetTypeDetails.getAttributeValue().equalsIgnoreCase("all")) {
targetTypes.setIncludeAll(true);
targetTypes.setAttributes(Lists.newArrayList());
Expand Down Expand Up @@ -335,7 +335,7 @@ private UpdateAssetGroupDetails buildAssetGroupDetails(final AssetGroupDetails e
TargetTypesDetails targetTypeAttribute = new TargetTypesDetails();
targetTypeAttribute.setAttributes(Lists.newArrayList());
targetTypeAttribute.setTargetName(targetName.trim());
targetTypeAttribute.setAllAttributesName(commonService.getFieldNames(existingAssetGroupDetails.getDataSource() + "_" + targetName, targetName));
targetTypeAttribute.setAllAttributesName(commonService.getFieldNames(targetTypesRepository.findDataSourceByTargetType(targetName) + "_" + targetName, targetName));
targetTypeAttribute.setIncludeAll(false);
attributes.add(targetTypeAttribute);
}
Expand All @@ -353,8 +353,9 @@ private boolean deleteAssetGroupAlias(final AssetGroupDetails assetGroupDetails)

if(!targetTypes.isEmpty()) {
targetTypes.forEach(targetType -> {
String targetName = targetType.getTargetType().toLowerCase().trim().replaceAll(" ", "-");
Map<String, Object> addObj = Maps.newHashMap();
addObj.put("index", assetGroupDetails.getDataSource().toLowerCase().trim().replaceAll(" ", "-")+"_"+targetType.getTargetType().toLowerCase().trim().replaceAll(" ", "-"));
addObj.put("index", targetTypesRepository.findDataSourceByTargetType(targetName).toLowerCase().trim().replaceAll(" ", "-")+"_"+targetName);
addObj.put("alias", aliasName);
Map<String, Object> add = Maps.newHashMap();
add.put("remove", addObj);
Expand Down Expand Up @@ -384,7 +385,8 @@ private Map<String, Object> createAliasForAssetGroup(final CreateUpdateAssetGrou
final String aliasName = assetGroupDetailsJson.getGroupName().toLowerCase().trim().replaceAll(" ", "-");
for (int targetIndex = 0; targetIndex < targetTypes.size(); targetIndex++) {
Map<String, Object> addObj = Maps.newHashMap();
addObj.put("index", assetGroupDetailsJson.getDataSourceName().toLowerCase().trim().replaceAll(" ", "-") + "_" + targetTypes.get(targetIndex).getTargetName().toLowerCase().trim().replaceAll(" ", "-"));
String targetType = targetTypes.get(targetIndex).getTargetName().toLowerCase().trim().replaceAll(" ", "-");
addObj.put("index", targetTypesRepository.findDataSourceByTargetType(targetType).toLowerCase().trim().replaceAll(" ", "-") + "_" + targetType);
addObj.put("alias", aliasName);
List<AttributeDetails> attributes = Lists.newArrayList();
if (!targetTypes.get(targetIndex).isIncludeAll()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
******************************************************************************/
package com.tmobile.pacman.api.admin.repository.service;

import java.util.Collection;
import java.util.List;

import com.tmobile.pacman.api.admin.repository.model.Datasource;

/**
* DataSource Service Functionalities
Expand All @@ -28,5 +30,5 @@ public interface DatasourceService {
* @author Nidhish
* @return All dataSource details list
*/
public Collection<Object[]> getAllDatasourceDetails();
public List<Datasource> getAllDatasourceDetails();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
******************************************************************************/
package com.tmobile.pacman.api.admin.repository.service;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tmobile.pacman.api.admin.repository.DatasourceRepository;
import com.tmobile.pacman.api.admin.repository.model.Datasource;
import com.tmobile.pacman.api.commons.Constants;

/**
Expand All @@ -33,7 +34,7 @@ public class DatasourceServiceImpl implements DatasourceService, Constants {
private DatasourceRepository datasourceRepository;

@Override
public Collection<Object[]> getAllDatasourceDetails() {
return datasourceRepository.getAllDatasourceDetails();
public List<Datasource> getAllDatasourceDetails() {
return datasourceRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -60,13 +59,10 @@ public void init() {

@Test
public void getAllDatasourceDetailsTest() throws Exception {
Collection<Object[]> allDatasources = new ArrayList<Object[]>();
Object[] datasources = { "aws", "azure" };
allDatasources.add(datasources);
when(datasourceService.getAllDatasourceDetails()).thenReturn(allDatasources);
when(datasourceService.getAllDatasourceDetails()).thenReturn(new ArrayList<>());
mockMvc.perform(get("/datasource/list")).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
.andExpect(jsonPath("$.data", hasSize(1)));
.andExpect(jsonPath("$.data", hasSize(0)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -41,10 +40,7 @@ public class DatasourceServiceImplTest {

@Test
public void getAllDatasourceDetailsTest() throws Exception {
Collection<Object[]> allDatasources = new ArrayList<Object[]>();
Object[] datasources = { "aws", "azure" };
allDatasources.add(datasources);
when(datasourceService.getAllDatasourceDetails()).thenReturn(allDatasources);
assertThat(datasourceRepository.getAllDatasourceDetails().size(), is(1));
when(datasourceRepository.findAll()).thenReturn(new ArrayList<>());
assertThat(datasourceService.getAllDatasourceDetails().size(), is(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ private AssetConstants() {
public static final String FILTER_CATEGORY = "category";
public static final String FILTER_GENERAL = "general";
public static final String FILTER_RECOMMENDATION_ID = "recommendationId";
public static final String ASSET_TYPE = "assettype";
public static final String TOTAL_ASSETS = "totalassets";

}

Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public class AssetController {
*/
@GetMapping(value = "/v1/list/targettype")
public ResponseEntity<Object> getListOfTargetTypes(@RequestParam(name = "ag", required = true) String assetGroup,
@RequestParam(name = "domain", required = false) String domain) {
@RequestParam(name = "domain", required = false) String domain,
@RequestParam(name = "provider", required = false) String provider) {
Map<String, Object> targetTypesResponse = new HashMap<>();
List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(assetGroup, domain);
List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(assetGroup, domain, provider);
if (targetTypes.isEmpty()) {
return ResponseUtils.buildFailureResponse(new Exception(
"No target types found for the asset group . Please check the asset group configuration"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand All @@ -30,6 +32,7 @@

import com.tmobile.pacman.api.asset.AssetConstants;
import com.tmobile.pacman.api.asset.service.AssetService;
import com.tmobile.pacman.api.commons.Constants;
import com.tmobile.pacman.api.commons.utils.ResponseUtils;

/**
Expand Down Expand Up @@ -58,20 +61,20 @@ public class AssetCountController {
@GetMapping(value = "/v1/count")
public ResponseEntity<Object> geAssetCount(@RequestParam(name = "ag", required = true) String assetGroup,
@RequestParam(name = "type", required = false) String type,
@RequestParam(name = "domain", required = false) String domain) {
@RequestParam(name = "domain", required = false) String domain,
@RequestParam(name = "application", required = false) String application,
@RequestParam(name = "provider", required = false) String provider) {
if (type == null) {
type = "all";
}
List<Map<String, Object>> countMap = assetService.getAssetCountByAssetGroup(assetGroup, type, domain);

List<Map<String, Object>> countMap = assetService.getAssetCountAndEnvDistributionByAssetGroup(assetGroup, type, domain, application, provider);
LongSummaryStatistics totalCount = countMap.stream().collect(Collectors.summarizingLong(map -> (Long) map.get(Constants.COUNT)));
Map<String, Object> response = new HashMap<>();
response.put("ag", assetGroup);
response.put(AssetConstants.ASSET_COUNT, countMap);
if (!countMap.isEmpty()) {
return ResponseUtils.buildSucessResponse(response);
} else {
return ResponseUtils.buildFailureResponse(new Exception("No data found"));
}
response.put(AssetConstants.ASSET_TYPE, totalCount.getCount());
response.put(AssetConstants.TOTAL_ASSETS, totalCount.getSum());
return ResponseUtils.buildSucessResponse(response);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public ResponseEntity<Object> getEditableFieldsByTargetType(
return ResponseUtils.buildFailureResponse(new Exception("Asset group/TargetType is Mandatory"));
}
boolean isTargetTypePresent = false;
for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null)) {
for (Map<String, Object> targetType : assetService.getTargetTypesForAssetGroup(assetGroup, null, null)) {
if (targetType.get("type").toString().equals(resourceType)) {
isTargetTypePresent = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setassetService(AssetService assetService) {
*/
public static boolean isValidTargetType(String ag, String type) {
try {
List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null);
List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null, null);
return targetTypes.stream().filter(obj -> type.equals(obj.get("type"))).count() > 0 ? true : false;
} catch (Exception e) {
LOGGER.error("Error in isValidTargetType ",e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public interface AssetRepository {
*
* @param aseetGroupName name of the asset group
* @param type target type
* @param domain the domain of asset group
* @param application the application of asset group
*
* @return list of type and its asset count.
*/
public Map<String, Long> getAssetCountByAssetGroup(String aseetGroupName, String type);
public Map<String, Long> getAssetCountByAssetGroup(String aseetGroupName, String type, String application);

/**
* Fetches all the target types for the particular asset group. If asset
Expand All @@ -53,7 +53,7 @@ public interface AssetRepository {
*
* @return list of target types.
*/
public List<Map<String, Object>> getTargetTypesByAssetGroup(String aseetGroupName, String domain);
public List<Map<String, Object>> getTargetTypesByAssetGroup(String aseetGroupName, String domain, String provider);

/**
* Fetches all the applications for the particular asset group.
Expand Down Expand Up @@ -93,7 +93,7 @@ public interface AssetRepository {
*
* @return list of target type details.
*/
public List<Map<String, Object>> getAllTargetTypes();
public List<Map<String, Object>> getAllTargetTypes(String datasource);

/**
* Fetches all the asset groups and its name, display name, description,
Expand Down Expand Up @@ -515,6 +515,40 @@ public List<Map<String, Object>> getAssetLists(String assetGroup, Map<String, St
* @return list of applications.
* @throws DataException when there is an error while fetching data from ES
*/
public Map<String, Long> getApplicationAssetCountByAssetGroup(String assetGroupName, String domain) throws DataException;
public Map<String, Long> getApplicationAssetCountByAssetGroup(String assetGroupName, String domain, String provider) throws DataException;

/**
* Fetches all the datasource and its targetName for the list of targetNames
*
* @return list of target type details.s
*/
public List<Map<String, Object>> getDataSourceForTargetTypes(List<String> targetTypes);

public Map<String, Object> getApplicationAssetCountByAssetGroupWithProvider(String assetGroupName, String domain,
String provider) throws DataException;

/**
* Fetches the total count of assets and distribution based on environment for the particular asset group. If no
* type is passed, all the assets of valid target type for the asset group
* is considered.
*
* @param aseetGroupName name of the asset group
* @param type target type
* @param domain the domain of asset group
* @param application the application of asset group
*
* @return list of type and its asset count.
*/
public Map<String, Object> getAssetCountAndEnvDistributionByAssetGroup(String aseetGroupName, String type,
String application);

/**
* Fetches provider list for an asset group
*
* @param Asset Group
* @return list of providers.
* @throws DataException
*/
public List<String> getProvidersForAssetGroup(String assetGroup) throws DataException;

}
Loading

0 comments on commit 3a4e582

Please sign in to comment.