Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Api Properties Builder addition (#154)
Browse files Browse the repository at this point in the history
* api changes for properties builder api

* change to imports and movement to collectorcontroller

* import changes

* import fixes

* findById fix to Collector

* pom file version change

* changes to Collector for findOne

* fixed syntax in collector controller
  • Loading branch information
Courtneyp123 authored Jul 29, 2020
1 parent 0ae00e6 commit 380db7a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<version>1.3.0.RELEASE</version>
</parent>

<properties>
<com.capitalone.dashboard.core.version>3.7.11</com.capitalone.dashboard.core.version>
<properties>
<com.capitalone.dashboard.core.version>3.7.19</com.capitalone.dashboard.core.version>
<apache.rat.plugin.version>0.13</apache.rat.plugin.version>
<coveralls.maven.plugin.version>4.3.0</coveralls.maven.plugin.version>
<guava.version>19.0</guava.version>
Expand Down Expand Up @@ -97,7 +97,7 @@
<sonar.projectKey>Hygieia_api</sonar.projectKey>
<sonar.organization>hygieia-oss</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.login>f5c0da06f2aa2de97db7a17008c7100a3d6553d3</sonar.login>
<sonar.login>f5c0da06f2aa2de97db7a17008c7100a3d6553d3</sonar.login>
</properties>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.capitalone.dashboard.auth.access.Admin;
import com.capitalone.dashboard.misc.HygieiaException;
import com.capitalone.dashboard.model.ApiToken;
import com.capitalone.dashboard.model.FeatureFlag;
import com.capitalone.dashboard.model.ServiceAccount;
import com.capitalone.dashboard.model.FeatureFlag;
import com.capitalone.dashboard.model.UserInfo;
import com.capitalone.dashboard.request.ApiTokenRequest;
import com.capitalone.dashboard.request.FeatureFlagRequest;
Expand All @@ -23,8 +23,8 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;

import javax.validation.Valid;

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

Expand All @@ -44,7 +44,8 @@ public class AdminController {
private final FeatureFlagService featureFlagService;

@Autowired
public AdminController(UserInfoService userInfoService, ApiTokenService apiTokenService,ServiceAccountService serviceAccountService,FeatureFlagService featureFlagService) {
public AdminController(UserInfoService userInfoService, ApiTokenService apiTokenService,
ServiceAccountService serviceAccountService, FeatureFlagService featureFlagService) {
this.userInfoService = userInfoService;
this.apiTokenService = apiTokenService;
this.serviceAccountService = serviceAccountService;
Expand Down Expand Up @@ -171,6 +172,4 @@ public ResponseEntity<Void> deleteFeatureFlags(@PathVariable ObjectId id) {
featureFlagService.deleteFlags(id);
return ResponseEntity.<Void>noContent().build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
Expand Down Expand Up @@ -135,5 +137,19 @@ public ResponseEntity<List<CollectorItem>> collectorItemsByTypeAndSearchField(@P
.body(pageOfCollectorItems.getContent());
}

@RequestMapping(value = "/collector/addOrUpdateCollector/{name}/{collectorType}", method = RequestMethod.POST)
public ResponseEntity<Collector> addOrUpdateCollector(@PathVariable String name, @PathVariable String collectorType, @Valid @RequestBody Map propertiesObj) {
CollectorType collectorTypeUse = CollectorType.fromString(collectorType);
Collector collector = new Collector();
collector.setName(name);
collector.setCollectorType(collectorTypeUse);
collector.setProperties(propertiesObj);
return ResponseEntity.status(HttpStatus.OK).body(collectorService.createCollector(collector));
}

@RequestMapping(path = "/collector/deletePropertiesCase/{id}", method = RequestMethod.DELETE)
public ResponseEntity<Void> deletePropertiesCase(@PathVariable String id) {
collectorService.deletePropertiesInCollectorById(id);
return ResponseEntity.<Void>noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bson.types.ObjectId;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Map;

Expand All @@ -23,12 +22,12 @@ public interface CollectorService {


/**
* Finds all Collectors of a given id.
* Finds all Collectors of given id
*
* @param id
* @return Collectors matching the specified type
*/
List<Collector> collectorsById(ObjectId id);
List<Collector> collectorsById(ObjectId id);

/**
* Finds paged results of CollectorItems of a given type.
Expand Down Expand Up @@ -68,9 +67,6 @@ public interface CollectorService {
*/
CollectorItem createCollectorItem(CollectorItem item);




/**
* Creates a new CollectorItem. If a CollectorItem already exists with the
* same collector id and niceName, that CollectorItem will be returned instead
Expand Down Expand Up @@ -105,7 +101,6 @@ public interface CollectorService {
*/
Collector createCollector(Collector collector);


/**
* Gets a list of collectorItems for a given component id
* @param id id
Expand All @@ -119,4 +114,10 @@ public interface CollectorService {
* @param deleteFromComponent
*/
void deleteCollectorItem(String id, boolean deleteFromComponent) throws HygieiaException;

/**
* Delete properties section of Collector
* @param id
*/
void deletePropertiesInCollectorById(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import com.capitalone.dashboard.model.Collector;
import com.capitalone.dashboard.model.CollectorItem;
import com.capitalone.dashboard.model.CollectorType;
import com.capitalone.dashboard.model.Component;
import com.capitalone.dashboard.model.Dashboard;
import com.capitalone.dashboard.model.MultiSearchFilter;
import com.capitalone.dashboard.model.Dashboard;
import com.capitalone.dashboard.model.Component;
import com.capitalone.dashboard.repository.CollectorItemRepository;
import com.capitalone.dashboard.repository.CollectorRepository;
import com.capitalone.dashboard.repository.ComponentRepository;
import com.capitalone.dashboard.repository.CustomRepositoryQuery;
import com.capitalone.dashboard.repository.DashboardRepository;
import com.capitalone.dashboard.repository.CustomRepositoryQuery;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand All @@ -26,13 +27,14 @@
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -259,6 +261,8 @@ public Collector createCollector(Collector collector) {
existing.setEnabled(true);
existing.setOnline(true);
existing.setLastExecuted(System.currentTimeMillis());
existing.setProperties(collector.getProperties());

return collectorRepository.save(existing);
}
/*
Expand All @@ -284,6 +288,18 @@ public List<CollectorItem> getCollectorItemForComponent(String id, String type)
return (List<CollectorItem>) collectorItemRepository.findAll(ids);
}

@Override
public void deletePropertiesInCollectorById(String id) {
ObjectId objectId = new ObjectId(id);
Collector collectorById = collectorRepository.findOne(objectId);
Map<String, Object> blankMap = new HashMap<>();

if(collectorById.getProperties().size() > 0) {
collectorById.setProperties(blankMap);
collectorRepository.save(collectorById);
}
}

@Override
public void deleteCollectorItem(String id, boolean deleteFromComponent) throws HygieiaException {
ObjectId objectId = new ObjectId(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -253,4 +252,4 @@ private String str(JSONObject json, String key) throws HygieiaException {
}


}
}

0 comments on commit 380db7a

Please sign in to comment.