Skip to content

Commit

Permalink
This branch only clears ContentPacks by propagating stream deletion t…
Browse files Browse the repository at this point in the history
…o the widgets
  • Loading branch information
janheise committed Jul 5, 2021
1 parent 84c5132 commit b243113
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,46 +122,6 @@ public Optional<ContentPack> insert(final ContentPack pack) {
return Optional.of(writeResult.getSavedObject());
}

public Optional<ContentPack> filterMissingResourcesAndInsert(final ContentPack pack) {
ContentPackV1 cpv1 = (ContentPackV1) pack;

final Set<String> allStreams = streamService.loadAll().stream().map(stream -> stream.getTitle()).collect(Collectors.toSet());
final Map<String, String> streamsInContentPack = new HashMap<>();

cpv1.entities()
.stream()
.filter(entity -> "stream".equals(entity.type().name()) && "1".equals(entity.type().version()))
.map(entity -> new Tuple2<String, JsonNode>(entity.id().id(), ((EntityV1)entity).data().findValue("title")))
.forEach(tuple2 -> {
JsonNode title = tuple2.v2().findValue("@value");
streamsInContentPack.put(tuple2.v1(), title.textValue());
});

cpv1.entities()
.stream()
.filter(entity -> "dashboard".equals(entity.type().name()) && "2".equals(entity.type().version()))
.map(entity -> ((EntityV1) entity).data().findValue("search"))
.map(node -> node.findValue("queries"))
.map(node -> node.findValue("search_types"))
.forEach(node -> {
final ObjectNode parent = (ObjectNode)node.findParent("streams");
final ArrayNode streams = (ArrayNode)node.findValue("streams");
if(streams != null) {
final ArrayNode filtered = streams.deepCopy();
filtered.removeAll();
streams.forEach(stream -> {
final String sid = stream.textValue();
final String stitle = streamsInContentPack.get(sid);
if(allStreams.contains(stitle))
filtered.add(stream);
});
parent.replace("streams", filtered);
}
});

return this.insert(cpv1);
}

public int deleteById(ModelId id) {
final DBQuery.Query query = DBQuery.is(Identified.FIELD_META_ID, id);
final WriteResult<ContentPack, ObjectId> writeResult = dbCollection.remove(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public Response createContentPack(
@ApiParam(name = "Request body", value = "Content pack", required = true)
@NotNull @Valid final ContentPack contentPack) {
checkPermission(RestPermissions.CONTENT_PACK_CREATE);
final ContentPack pack = contentPackPersistenceService.filterMissingResourcesAndInsert(contentPack)
final ContentPack pack = contentPackPersistenceService.insert(contentPack)
.orElseThrow(() -> new BadRequestException("Content pack " + contentPack.id() + " with this revision " + contentPack.revision() + " already found!"));

final URI packUri = getUriBuilderToSelf().path(ContentPackResource.class)
Expand Down

0 comments on commit b243113

Please sign in to comment.