-
Notifications
You must be signed in to change notification settings - Fork 0
Process deleted node correctly #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
56b533b
18dacee
6c8d4dc
c8f6c2b
3c6a1fc
8723990
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package com.epam.eighty.repository; | ||
|
|
||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.data.neo4j.annotation.Query; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.epam.eighty.domain.Topic; | ||
|
|
@@ -10,4 +12,6 @@ | |
| @Repository("topicRepo") | ||
| public interface TopicRepository extends BaseRepository<Topic, Long> { | ||
|
|
||
| @Query(value = "MATCH (root:`Topic`) WHERE ID(root) = {0} return root UNION ALL MATCH (root:`Topic`)-[:`contains`*]->(topic:`Topic`) WHERE ID(topic) = {0} RETURN root", elementClass = Topic.class) | ||
| Slice<Topic> getRootTopicsForTopic(Long id); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.epam.eighty.service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -16,4 +17,6 @@ public interface TopicService { | |
| void updateTopic(Topic topic); | ||
| void deleteTopic(Long id); | ||
| Topic createTopic(Topic topic, Long id); | ||
| Long getIdOfLastNotDeletedTopic(List<Long> topicIds); | ||
| Topic getTopicWithChildsTillTopicWithId(Long id); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too complex name, let's discuss it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe getTopicWithChildrenToCurrentTopic or getRootWithSubtopicsToCurrentTopic but I'm not sure that they are suitable they are too complex and it is not clear what id param means. What are your variants? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.epam.eighty.service.impl; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -70,4 +71,33 @@ public Topic createTopic(final Topic topic, final Long id) { | |
| return topic; | ||
| } | ||
|
|
||
| @Override | ||
| public Long getIdOfLastNotDeletedTopic(List<Long> topicIds) { | ||
| for(Long id: topicIds) { | ||
| Optional<Topic> topic = topicRepo.findOne(id); | ||
| if(topic.isPresent()) { | ||
| return id; | ||
| } | ||
| } | ||
| return null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be more beautiful and efficient to do this with stream. |
||
| } | ||
|
|
||
| @Override | ||
| public Topic getTopicWithChildsTillTopicWithId(Long id) { | ||
| Optional<Topic> root = topicRepo.findBySchemaPropertyValue("title", "root"); | ||
| List<Topic> path = topicRepo.getRootTopicsForTopic(id).getContent(); | ||
| root.ifPresent(r -> { | ||
| topicsFetchIfNeeded(r, path); | ||
| }); | ||
| return root.get(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. U will get exception if |
||
| } | ||
|
|
||
| private void topicsFetchIfNeeded(Topic topic, List<Topic> path) { | ||
| topic.getTopics().forEach(t -> { | ||
| template.fetch(t); | ||
| if(path.contains(t)) { | ||
| topicsFetchIfNeeded(t, path); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's no need to mark interfaces with @repository as u have already has
in your config file which is used to enabled repository support.
I'm not sure and this needs to be clarified but it's possible that repository beans is instantiated twice.Update: this's false as u scanrepositorypackage only once.Plus, it's not a good idea to manually hardcode bean names.