-
Notifications
You must be signed in to change notification settings - Fork 7
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
34 arc f5 save slack channels #59
Open
NikolayNN
wants to merge
11
commits into
JujaLabs:develop
Choose a base branch
from
NikolayNN:34-ARC-F5-save-slack-channels
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e15c462
#34 get slack channels with slack api
NikolayNN 4dc9d71
#34 added channelDTO
NikolayNN 60d5633
#34 save channels to the database
NikolayNN b61dfbf
#34 implemented feature get and save/update channel in the database b…
NikolayNN 7538449
#34 renamed and move to another package channel entity
NikolayNN cb84d46
#34 some code format, use @Data for model classes, renamed method
NikolayNN 6c1611a
#34 renamed from SlackAPI to SlackAPIClient
NikolayNN 5860ad2
Merge remote-tracking branch 'upstream/develop' into 34-ARC-F5-save-s…
NikolayNN 19cc064
#34: optimized imports
NikolayNN 4261e05
#34: divided SlackArchiveService and SlackArchiveRepository to Channe…
NikolayNN 77b73dd
#34: save rawChannel by schedule
NikolayNN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
slack-archive/src/main/java/juja/microservices/slack/archive/SchedulerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package juja.microservices.slack.archive; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.SchedulingConfigurer; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | ||
import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public class SchedulerConfig implements SchedulingConfigurer { | ||
|
||
private final int POOL_SIZE = 2; | ||
|
||
@Override | ||
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { | ||
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); | ||
threadPoolTaskScheduler.setPoolSize(POOL_SIZE); | ||
threadPoolTaskScheduler.setThreadNamePrefix("sheduled-get-slack-channels-task-pool-"); | ||
threadPoolTaskScheduler.initialize(); | ||
|
||
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
slack-archive/src/main/java/juja/microservices/slack/archive/SlackArchiveApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
package juja.microservices.slack.archive; | ||
|
||
import org.apache.http.impl.client.HttpClients; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.client.ClientHttpRequestFactory; | ||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
import org.springframework.http.converter.FormHttpMessageConverter; | ||
import org.springframework.http.converter.HttpMessageConverter; | ||
import org.springframework.http.converter.StringHttpMessageConverter; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
public class SlackArchiveApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(SlackArchiveApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
RestTemplate restTemplate = new RestTemplate(httpRequestFactory()); | ||
restTemplate.setMessageConverters(getHttpMessageConverters()); | ||
return restTemplate; | ||
} | ||
|
||
private ClientHttpRequestFactory httpRequestFactory() { | ||
return new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault()); | ||
} | ||
|
||
private List<HttpMessageConverter<?>> getHttpMessageConverters() { | ||
List<HttpMessageConverter<?>> converters = new ArrayList<>(); | ||
converters.add(new MappingJackson2HttpMessageConverter()); | ||
converters.add(new StringHttpMessageConverter()); | ||
return converters; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
slack-archive/src/main/java/juja/microservices/slack/archive/api/SlackApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package juja.microservices.slack.archive.api; | ||
|
||
import juja.microservices.slack.archive.model.entity.RawChannel; | ||
|
||
import java.util.List; | ||
|
||
public interface SlackApiClient { | ||
|
||
List<RawChannel> receiveRawChannelsList(); | ||
} |
70 changes: 70 additions & 0 deletions
70
slack-archive/src/main/java/juja/microservices/slack/archive/api/SlackApiClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package juja.microservices.slack.archive.api; | ||
|
||
import juja.microservices.slack.archive.exceptions.ArchiveException; | ||
import juja.microservices.slack.archive.model.dto.ChannelsRawSlackResponse; | ||
import juja.microservices.slack.archive.model.entity.RawChannel; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Repository | ||
@Slf4j | ||
public class SlackApiClientImpl implements SlackApiClient { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Value("${slack.api.token}") | ||
private String slackApiToken; | ||
@Value("${slack.api.channels.urltemplate}") | ||
private String slackApiChannelsUrlTemplate; | ||
|
||
public SlackApiClientImpl(RestTemplate restTemplate) { | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
@Override | ||
public List<RawChannel> receiveRawChannelsList() { | ||
|
||
UriComponentsBuilder builder = UriComponentsBuilder | ||
.fromUriString(slackApiChannelsUrlTemplate) | ||
.queryParam("token", slackApiToken); | ||
|
||
List<RawChannel> result = new LinkedList<>(); | ||
log.debug("Started request to slack api. Get channels list."); | ||
|
||
try { | ||
String cursor = ""; | ||
do { | ||
ResponseEntity<ChannelsRawSlackResponse> response = | ||
this.restTemplate.getForEntity(builder.toUriString(), ChannelsRawSlackResponse.class); | ||
ChannelsRawSlackResponse slackResponse = response.getBody(); | ||
|
||
List<RawChannel> receivedChannels = slackResponse.getChannels() | ||
.stream() | ||
.map(channel -> new RawChannel(channel)) | ||
.collect(Collectors.toList()); | ||
|
||
result.addAll(receivedChannels); | ||
|
||
if (slackResponse.getResponseMetadata() != null && slackResponse.getResponseMetadata().get("cursor") != null) { | ||
cursor = (String) slackResponse.getResponseMetadata().get("cursor"); | ||
} | ||
builder.queryParam("cursor", cursor); | ||
|
||
} while (!cursor.equals("")); | ||
} catch (HttpClientErrorException ex) { | ||
throw new ArchiveException(ex.getMessage()); | ||
} | ||
|
||
log.debug("Received channels : {}", result); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
slack-archive/src/main/java/juja/microservices/slack/archive/model/ChannelDTO.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
slack-archive/src/main/java/juja/microservices/slack/archive/model/dto/ChannelDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package juja.microservices.slack.archive.model.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import lombok.*; | ||
|
||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonPropertyOrder({ | ||
"id", | ||
"name" | ||
}) | ||
@Data | ||
@AllArgsConstructor | ||
public class ChannelDTO { | ||
@JsonProperty("id") | ||
private String channelId; | ||
@JsonProperty("name") | ||
private String name; | ||
} |
22 changes: 22 additions & 0 deletions
22
...rchive/src/main/java/juja/microservices/slack/archive/model/dto/ChannelSlackResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
package juja.microservices.slack.archive.model.dto; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@Getter | ||
@Setter | ||
@ToString | ||
public class ChannelSlackResponse { | ||
|
||
@JsonProperty("ok") | ||
private Boolean ok; | ||
@JsonProperty("channels") | ||
private List<ChannelDTO> channels; | ||
} |
31 changes: 31 additions & 0 deletions
31
...ve/src/main/java/juja/microservices/slack/archive/model/dto/ChannelsRawSlackResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package juja.microservices.slack.archive.model.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ChannelsRawSlackResponse { | ||
|
||
@JsonProperty("ok") | ||
private String ok; | ||
|
||
private List<Map<String, Object>> channels; | ||
|
||
private Map<String, Object> responseMetadata; | ||
|
||
public void addChannels(List<Map<String, Object>> channels) { | ||
|
||
if (this.channels == null) { | ||
channels = new LinkedList<>(); | ||
} | ||
this.channels.addAll(channels); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...services/slack/archive/model/Channel.java → ...s/slack/archive/model/entity/Channel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
slack-archive/src/main/java/juja/microservices/slack/archive/model/entity/RawChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package juja.microservices.slack.archive.model.entity; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class RawChannel { | ||
|
||
@Id | ||
private String id; | ||
private Map<String, Object> channel; | ||
|
||
public RawChannel(Map<String, Object> channel) { | ||
this.channel = channel; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-archive/src/main/java/juja/microservices/slack/archive/repository/ChannelRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package juja.microservices.slack.archive.repository; | ||
|
||
import juja.microservices.slack.archive.model.entity.Channel; | ||
import juja.microservices.slack.archive.model.entity.RawChannel; | ||
|
||
import java.util.List; | ||
|
||
public interface ChannelRepository { | ||
List<Channel> getChannels(); | ||
|
||
void saveRawChannels(List<RawChannel> channels); | ||
} |
8 changes: 3 additions & 5 deletions
8
...archive/repository/ArchiveRepository.java → ...archive/repository/MessageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package juja.microservices.slack.archive.repository; | ||
|
||
import juja.microservices.slack.archive.model.Channel; | ||
import juja.microservices.slack.archive.model.Message; | ||
import juja.microservices.slack.archive.model.entity.Message; | ||
|
||
import java.util.List; | ||
|
||
public interface ArchiveRepository { | ||
void saveMessage(Message message); | ||
public interface MessageRepository { | ||
|
||
List<Channel> getChannels(); | ||
void saveMessage(Message message); | ||
|
||
List<Message> getMessages(String channel, int number); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
need @entity annotation
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 read spring docs. MongoTemplate doesn't require @entity annotation
9.5. Saving, Updating, and Removing Documents
https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo-template
and there are two ways with Id annotation.
I think it is a good case to use @id annotation explicitly
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 agree with Nikolay