From 248c05840275516cbc5c99c8e5d87d007ca37284 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Thu, 21 Jun 2018 20:24:45 +0300
Subject: www project disabled, all new web development moved to separate repo
---
juick-api/build.gradle | 7 -
.../src/main/java/com/juick/server/api/Post.java | 205 ---
.../server/configuration/ApiSecurityConfig.java | 125 --
.../com/juick/server/configuration/PostConfig.java | 9 -
juick-server-jdbc/build.gradle | 6 -
.../juick/configuration/UpdaterConfiguration.java | 47 -
.../main/java/com/juick/database/MySqlUpdater.java | 153 --
.../java/com/juick/service/BaseJdbcService.java | 41 -
.../com/juick/service/CrosspostServiceImpl.java | 273 ----
.../java/com/juick/service/EmailServiceImpl.java | 92 --
.../com/juick/service/MessagesServiceImpl.java | 1006 -------------
.../com/juick/service/MessengerServiceImpl.java | 71 -
.../com/juick/service/PMQueriesServiceImpl.java | 174 ---
.../juick/service/PrivacyQueriesServiceImpl.java | 63 -
.../com/juick/service/PushQueriesServiceImpl.java | 143 --
.../com/juick/service/ShowQueriesServiceImpl.java | 62 -
.../com/juick/service/SphinxSearchService.java | 85 --
.../com/juick/service/SubscriptionServiceImpl.java | 249 ----
.../java/com/juick/service/TagServiceImpl.java | 273 ----
.../com/juick/service/TelegramServiceImpl.java | 94 --
.../java/com/juick/service/UserServiceImpl.java | 689 ---------
juick-server-jdbc/src/main/resources/juick.sql | 947 ------------
juick-server-jdbc/src/main/resources/pg_schema_wip | 1539 --------------------
juick-server-jdbc/src/main/resources/schema.sql | 379 -----
juick-server-jdbc/src/main/resources/update.sql | 12 -
juick-server/build.gradle | 7 +-
.../src/main/java/com/juick/server/api/Post.java | 205 +++
.../server/configuration/ApiSecurityConfig.java | 125 ++
.../com/juick/server/configuration/PostConfig.java | 9 +
.../java/com/juick/service/BaseJdbcService.java | 41 +
.../com/juick/service/CrosspostServiceImpl.java | 273 ++++
.../java/com/juick/service/EmailServiceImpl.java | 92 ++
.../com/juick/service/MessagesServiceImpl.java | 1006 +++++++++++++
.../com/juick/service/MessengerServiceImpl.java | 71 +
.../com/juick/service/PMQueriesServiceImpl.java | 174 +++
.../juick/service/PrivacyQueriesServiceImpl.java | 63 +
.../com/juick/service/PushQueriesServiceImpl.java | 143 ++
.../com/juick/service/ShowQueriesServiceImpl.java | 62 +
.../com/juick/service/SphinxSearchService.java | 85 ++
.../com/juick/service/SubscriptionServiceImpl.java | 249 ++++
.../java/com/juick/service/TagServiceImpl.java | 273 ++++
.../com/juick/service/TelegramServiceImpl.java | 94 ++
.../java/com/juick/service/UserServiceImpl.java | 689 +++++++++
juick-server/src/main/java/ru/sape/Sape.java | 23 +
.../src/main/java/ru/sape/SapeConnection.java | 108 ++
.../src/main/java/ru/sape/SapePageLinks.java | 76 +
juick-server/src/main/resources/juick.sql | 947 ++++++++++++
juick-server/src/main/resources/pg_schema_wip | 1539 ++++++++++++++++++++
juick-server/src/main/resources/schema.sql | 379 +++++
juick-server/src/main/resources/update.sql | 12 +
.../pebble/extension/FormatterExtension.java | 38 -
.../extension/filters/FormatMessageFilter.java | 52 -
.../pebble/extension/filters/PrettyTimeFilter.java | 51 -
.../pebble/extension/filters/TagsListFilter.java | 41 -
.../pebble/extension/filters/TimestampFilter.java | 23 -
juick-www/src/main/java/ru/sape/Sape.java | 23 -
.../src/main/java/ru/sape/SapeConnection.java | 108 --
juick-www/src/main/java/ru/sape/SapePageLinks.java | 76 -
settings.gradle | 2 +-
59 files changed, 6744 insertions(+), 7159 deletions(-)
delete mode 100644 juick-api/build.gradle
delete mode 100644 juick-api/src/main/java/com/juick/server/api/Post.java
delete mode 100644 juick-api/src/main/java/com/juick/server/configuration/ApiSecurityConfig.java
delete mode 100644 juick-api/src/main/java/com/juick/server/configuration/PostConfig.java
delete mode 100644 juick-server-jdbc/build.gradle
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/configuration/UpdaterConfiguration.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/database/MySqlUpdater.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/ShowQueriesServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java
delete mode 100644 juick-server-jdbc/src/main/resources/juick.sql
delete mode 100644 juick-server-jdbc/src/main/resources/pg_schema_wip
delete mode 100644 juick-server-jdbc/src/main/resources/schema.sql
delete mode 100644 juick-server-jdbc/src/main/resources/update.sql
create mode 100644 juick-server/src/main/java/com/juick/server/api/Post.java
create mode 100644 juick-server/src/main/java/com/juick/server/configuration/ApiSecurityConfig.java
create mode 100644 juick-server/src/main/java/com/juick/server/configuration/PostConfig.java
create mode 100644 juick-server/src/main/java/com/juick/service/BaseJdbcService.java
create mode 100644 juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/EmailServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/PMQueriesServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/PushQueriesServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/ShowQueriesServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/SphinxSearchService.java
create mode 100644 juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/TagServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/TelegramServiceImpl.java
create mode 100644 juick-server/src/main/java/com/juick/service/UserServiceImpl.java
create mode 100644 juick-server/src/main/java/ru/sape/Sape.java
create mode 100644 juick-server/src/main/java/ru/sape/SapeConnection.java
create mode 100644 juick-server/src/main/java/ru/sape/SapePageLinks.java
create mode 100644 juick-server/src/main/resources/juick.sql
create mode 100644 juick-server/src/main/resources/pg_schema_wip
create mode 100644 juick-server/src/main/resources/schema.sql
create mode 100644 juick-server/src/main/resources/update.sql
delete mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java
delete mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
delete mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java
delete mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TagsListFilter.java
delete mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java
delete mode 100644 juick-www/src/main/java/ru/sape/Sape.java
delete mode 100644 juick-www/src/main/java/ru/sape/SapeConnection.java
delete mode 100644 juick-www/src/main/java/ru/sape/SapePageLinks.java
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
deleted file mode 100644
index 2899529a..00000000
--- a/juick-api/build.gradle
+++ /dev/null
@@ -1,7 +0,0 @@
-apply plugin: 'java'
-
-dependencies {
- compile project(':juick-common')
- compile project(':juick-server-jdbc')
- compile 'org.apache.commons:commons-email:1.5'
-}
\ No newline at end of file
diff --git a/juick-api/src/main/java/com/juick/server/api/Post.java b/juick-api/src/main/java/com/juick/server/api/Post.java
deleted file mode 100644
index afe9d2d5..00000000
--- a/juick-api/src/main/java/com/juick/server/api/Post.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.server.api;
-
-import com.juick.Reaction;
-import com.juick.Status;
-import com.juick.User;
-import com.juick.server.CommandsManager;
-import com.juick.server.helpers.CommandResult;
-import com.juick.server.util.*;
-import com.juick.service.MessagesService;
-import com.juick.service.SubscriptionService;
-import com.juick.service.UserService;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.inject.Inject;
-import javax.validation.constraints.NotNull;
-import java.net.URI;
-import java.net.URL;
-import java.util.List;
-
-/**
- * Created by vt on 24/11/2016.
- */
-@RestController
-public class Post {
- private static Logger logger = LoggerFactory.getLogger(Post.class);
-
- @Inject
- private UserService userService;
- @Inject
- private MessagesService messagesService;
- @Inject
- private SubscriptionService subscriptionService;
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
- @Value("${img_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String imgDir;
- @Inject
- CommandsManager commandsManager;
-
- @RequestMapping(value = "/post", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- @ResponseStatus(value = HttpStatus.OK)
- public CommandResult doPostMessage(
- @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body,
- @RequestParam(required = false) String img,
- @RequestParam(required = false) MultipartFile attach) throws Exception {
- User visitor = UserUtils.getCurrentUser();
-
- if (visitor.isAnonymous())
- throw new HttpForbiddenException();
-
- if (body.length() > 4096) {
- throw new HttpBadRequestException();
- }
- body = body.replace("\r", StringUtils.EMPTY);
-
- URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
-
- if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
- URI juickUri = URI.create(img);
- if (juickUri.getScheme().equals("juick")) {
- attachmentFName = juickUri;
- } else {
- try {
- URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
- } catch (Exception e) {
- logger.error("DOWNLOAD ERROR", e);
- throw new HttpBadRequestException();
- }
- }
- }
- if (StringUtils.isBlank(body) && StringUtils.isBlank(attachmentFName.toString())) {
- // Should be there for compatibility
- throw new HttpBadRequestException();
- }
- return commandsManager.processCommand(visitor, body, attachmentFName);
- }
-
- @RequestMapping(value = "/comment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public com.juick.Message doPostComment(
- @RequestParam(defaultValue = "0") int mid,
- @RequestParam(defaultValue = "0") int rid,
- @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body,
- @RequestParam(required = false) String img,
- @RequestParam(required = false) MultipartFile attach)
- throws Exception {
- User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
- throw new HttpForbiddenException();
- }
- if (mid == 0) {
- throw new HttpBadRequestException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
-
- com.juick.Message reply = null;
- if (rid > 0) {
- reply = messagesService.getReply(mid, rid);
- if (reply == null) {
- throw new HttpNotFoundException();
- }
- }
-
- if (body.length() > 4096) {
- throw new HttpBadRequestException();
- }
- body = body.replace("\r", StringUtils.EMPTY);
-
- if ((msg.ReadOnly && msg.getUser().getUid() != vuid) || userService.isInBLAny(msg.getUser().getUid(), vuid)
- || (reply != null && userService.isInBLAny(reply.getUser().getUid(), vuid))) {
- throw new HttpForbiddenException();
- }
-
- URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
-
- if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
- try {
- attachmentFName = HttpUtils.downloadImage(new URL(img), tmpDir);
- } catch (Exception e) {
- logger.error("DOWNLOAD ERROR", e);
- throw new HttpBadRequestException();
- }
- }
-
- return commandsManager.processCommand(visitor, String.format("#%d/%d %s", mid, rid, body), attachmentFName).getNewMessage().get();
- }
-
- @PostMapping("/like")
- @ResponseStatus(value = HttpStatus.OK)
- public Status doPostRecomm(@RequestParam Integer mid) throws Exception {
- com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
- if (msg.getUser().getUid() == visitor.getUid()) {
- throw new HttpForbiddenException();
- }
- CommandResult status = commandsManager.processCommand(visitor, String.format("! #%d", mid),
- URI.create(StringUtils.EMPTY));
- return Status.getStatus(status.getText());
- }
-
- @GetMapping("/reactions")
- @ResponseStatus(value = HttpStatus.OK)
- public List reactionsList() {
- return messagesService.listReactions();
- }
-
- @PostMapping("/react")
- @ResponseStatus(value = HttpStatus.OK)
- public Status doPostReact(@RequestParam Integer mid,@RequestParam @NotNull int reactionId,
- @RequestParam (required = false, defaultValue = "1") int count) {
-
- logger.info("got reaction with type: {}", reactionId);
- com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.isAnonymous()) {
- throw new HttpForbiddenException();
- }
- com.juick.Message msg = messagesService.getMessage(mid);
- if (msg == null) {
- throw new HttpNotFoundException();
- }
- if (msg.getUser().getUid() == visitor.getUid()) {
- throw new HttpForbiddenException();
- }
- MessagesService.RecommendStatus recommendStatus = MessagesService.RecommendStatus.Error;
- for (int i = 0; i < count; i++)
- recommendStatus = messagesService.likeMessage(mid, visitor.getUid(),
- reactionId);
-
- return recommendStatus == MessagesService.RecommendStatus.Error ? Status.ERROR :Status.OK;
- }
-}
diff --git a/juick-api/src/main/java/com/juick/server/configuration/ApiSecurityConfig.java b/juick-api/src/main/java/com/juick/server/configuration/ApiSecurityConfig.java
deleted file mode 100644
index 94c1f1a8..00000000
--- a/juick-api/src/main/java/com/juick/server/configuration/ApiSecurityConfig.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.server.configuration;
-
-import com.juick.service.UserService;
-import com.juick.service.security.JuickUserDetailsService;
-import com.juick.service.security.deprecated.RequestParamHashRememberMeServices;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.config.http.SessionCreationPolicy;
-import org.springframework.security.web.AuthenticationEntryPoint;
-import org.springframework.security.web.authentication.HttpStatusEntryPoint;
-import org.springframework.security.web.authentication.RememberMeServices;
-import org.springframework.web.cors.CorsConfiguration;
-import org.springframework.web.cors.CorsConfigurationSource;
-import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
-
-import javax.inject.Inject;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Created by aalexeev on 11/21/16.
- */
-@Configuration
-@EnableWebSecurity
-public class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
- @Value("${auth_remember_me_key:secret}")
- private String rememberMeKey;
- @Inject
- private UserService userService;
-
- ApiSecurityConfig() {
- super(true);
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests()
- .antMatchers(HttpMethod.OPTIONS).permitAll()
- .antMatchers("/", "/messages", "/users", "/thread", "/tags", "/tlgmbtwbhk", "/fbwbhk",
- "/skypebotendpoint").permitAll()
- .anyRequest().hasRole("USER")
- .and().httpBasic().authenticationEntryPoint(juickAuthenticationEntryPoint())
- .and().anonymous()
- .and().cors().configurationSource(corsConfigurationSource())
- .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
- .and().exceptionHandling().authenticationEntryPoint(juickAuthenticationEntryPoint())
- .and()
- .rememberMe()
- .alwaysRemember(true)
- .tokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(6 * 30))
- .rememberMeServices(rememberMeServices())
- .key(rememberMeKey)
- .and().authenticationProvider(authenticationProvider())
- .headers().defaultsDisabled().cacheControl();
- }
-
- @Bean
- public DaoAuthenticationProvider authenticationProvider() {
- DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
-
- authenticationProvider.setUserDetailsService(userDetailsService());
-
- return authenticationProvider;
- }
-
- @Bean
- public JuickUserDetailsService userDetailsService() {
- return new JuickUserDetailsService(userService);
- }
-
- @Bean
- public RememberMeServices rememberMeServices() {
- return new RequestParamHashRememberMeServices(rememberMeKey, userService);
- }
-
- @Bean
- public AuthenticationEntryPoint juickAuthenticationEntryPoint() {
- return new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED);
- }
-
- @Bean
- public CorsConfigurationSource corsConfigurationSource() {
- CorsConfiguration configuration = new CorsConfiguration();
-
- configuration.setAllowedOrigins(Collections.singletonList("*"));
- configuration.setAllowedMethods(Arrays.asList("POST", "GET", "PUT", "OPTIONS", "DELETE"));
- configuration.setAllowedHeaders(Collections.singletonList("*"));
-
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
- source.registerCorsConfiguration("/**", configuration);
-
- return source;
- }
- @Override
- public void configure(WebSecurity web) throws Exception {
- web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources/**",
- "/configuration/**", "/swagger-ui.html", "/webjars/**", "/ws/**", "/rss/**");
- }
-}
diff --git a/juick-api/src/main/java/com/juick/server/configuration/PostConfig.java b/juick-api/src/main/java/com/juick/server/configuration/PostConfig.java
deleted file mode 100644
index 598a7435..00000000
--- a/juick-api/src/main/java/com/juick/server/configuration/PostConfig.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.juick.server.configuration;
-
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.context.annotation.ComponentScan;
-
-@EnableAutoConfiguration
-@ComponentScan({"com.juick.server", "com.juick.service"})
-public class PostConfig {
-}
diff --git a/juick-server-jdbc/build.gradle b/juick-server-jdbc/build.gradle
deleted file mode 100644
index 7052b04d..00000000
--- a/juick-server-jdbc/build.gradle
+++ /dev/null
@@ -1,6 +0,0 @@
-apply plugin: 'java'
-
-dependencies {
- compile("org.springframework.boot:spring-boot-starter-jdbc")
- compile project(':juick-common')
-}
diff --git a/juick-server-jdbc/src/main/java/com/juick/configuration/UpdaterConfiguration.java b/juick-server-jdbc/src/main/java/com/juick/configuration/UpdaterConfiguration.java
deleted file mode 100644
index 979b38f9..00000000
--- a/juick-server-jdbc/src/main/java/com/juick/configuration/UpdaterConfiguration.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.configuration;
-
-import com.juick.database.MySqlUpdater;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.DependsOn;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.transaction.PlatformTransactionManager;
-
-import javax.inject.Inject;
-
-/**
- * Created by aalexeev on 12/13/16.
- */
-@Configuration
-public class UpdaterConfiguration {
- @Inject
- JdbcTemplate jdbcTemplate;
- @Inject
- PlatformTransactionManager transactionManager;
-
- @Bean
- @DependsOn({"jdbcTemplate", "transactionManager"})
- public MySqlUpdater updater() {
- return new MySqlUpdater(
- jdbcTemplate,
- transactionManager,
- "update.sql");
- }
-}
diff --git a/juick-server-jdbc/src/main/java/com/juick/database/MySqlUpdater.java b/juick-server-jdbc/src/main/java/com/juick/database/MySqlUpdater.java
deleted file mode 100644
index 69cde40b..00000000
--- a/juick-server-jdbc/src/main/java/com/juick/database/MySqlUpdater.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.database;
-
-import org.apache.commons.codec.CharEncoding;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.support.TransactionTemplate;
-import org.springframework.util.Assert;
-
-import javax.annotation.PostConstruct;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Supplier;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static org.springframework.transaction.TransactionDefinition.PROPAGATION_REQUIRED;
-
-/**
- * Created by aalexeev on 12/13/16.
- */
-public class MySqlUpdater {
- private static final Pattern UPDATE_PATTERN = Pattern.compile(
- "update\\s+(version|`version`)\\s+set\\s+(version|`version`)\\s+=\\s*(\\d+)",
- Pattern.CASE_INSENSITIVE);
-
- private final Logger logger = LoggerFactory.getLogger(getClass());
-
- private final JdbcTemplate jdbcTemplate;
- private final TransactionTemplate transactionTemplate;
- private final String updateSqlResource;
-
-
- public MySqlUpdater(JdbcTemplate jdbcTemplate, PlatformTransactionManager transactionManager, String updateSqlResource) {
- Assert.notNull(jdbcTemplate, "JdbcTemplate must be initialized");
- Assert.notNull(transactionManager, "PlatformTransactionManager must be initialized");
- Assert.notNull(updateSqlResource, "sqlResource must be initialized");
-
- this.jdbcTemplate = jdbcTemplate;
- this.transactionTemplate = new TransactionTemplate(transactionManager);
- this.updateSqlResource = updateSqlResource;
- }
-
- @PostConstruct
- public void init() {
- try (
- InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(updateSqlResource);
- ) {
- if (is != null) {
- String content = IOUtils.toString(is, CharEncoding.UTF_8);
- if (StringUtils.isNotEmpty(content)) {
- String[] sqlArray = content.split(";");
- if (sqlArray.length > 0) {
- List sqlList = new ArrayList<>(sqlArray.length);
- for (String sql : sqlArray)
- if (!sql.isEmpty()) {
- String sqlTrimmed = sql.trim();
- if (!sqlTrimmed.isEmpty())
- sqlList.add(sqlTrimmed);
- }
- if (!sqlList.isEmpty())
- processingSql(sqlList);
- }
- }
- }
- } catch (Exception e) {
- logger.error("MySqlUpdater initialization exception", e);
- }
- }
-
- private void processingSql(final List sqls) {
- long currentDbVersion = getSingleResult(this::getVersionRaw);
- long actualVersion;
-
- List changesSql = new ArrayList<>();
-
- for (String sql : sqls) {
- changesSql.add(sql);
-
- Matcher m = UPDATE_PATTERN.matcher(sql);
- if (m.matches()) {
- actualVersion = Long.valueOf(m.group(3));
-
- if (actualVersion > currentDbVersion) {
- updateInTransaction(changesSql);
- currentDbVersion = actualVersion;
- }
- changesSql.clear();
- }
- }
- }
-
- private void updateInTransaction(final List sqls) {
- transactionTemplate.setReadOnly(false);
- transactionTemplate.setPropagationBehavior(PROPAGATION_REQUIRED);
- transactionTemplate.execute(status -> {
- for (String sql : sqls)
- jdbcTemplate.execute(sql);
- return 0;
- });
- }
-
- private T getSingleResult(Supplier supplier) {
- transactionTemplate.setReadOnly(true);
- transactionTemplate.setPropagationBehavior(PROPAGATION_REQUIRED);
-
- return transactionTemplate.execute(status -> supplier.get());
- }
-
- private long getVersionRaw() {
- int cnt = jdbcTemplate.query(
- "SELECT count(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
- rs -> {
- int result = 0;
- if (rs.next())
- result = rs.getInt(1);
- return result;
- },
- "juick", "version");
-
- long version = 0l;
-
- if (cnt == 1) {
- List list = jdbcTemplate.queryForList("select version from version", Long.class);
- if (!list.isEmpty())
- version = list.get(0);
- }
-
- return version;
- }
-}
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java b/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java
deleted file mode 100644
index 496a04ba..00000000
--- a/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.service;
-
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-
-import javax.inject.Inject;
-
-/**
- * Created by aalexeev on 11/13/16.
- */
-public class BaseJdbcService {
- @Inject
- JdbcTemplate jdbcTemplate;
- @Inject
- NamedParameterJdbcTemplate namedParameterJdbcTemplate;
-
- public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
- return namedParameterJdbcTemplate;
- }
-
- public JdbcTemplate getJdbcTemplate() {
- return jdbcTemplate;
- }
-}
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java
deleted file mode 100644
index 0bd5fe66..00000000
--- a/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.service;
-
-import com.juick.ExternalToken;
-import com.juick.server.helpers.ApplicationStatus;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Created by aalexeev on 11/13/16.
- */
-@Repository
-public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostService {
-
- @Transactional(readOnly = true)
- @Override
- public Optional getTwitterToken(final int uid) {
- List list = getJdbcTemplate().query(
- "SELECT uname, access_token, access_token_secret FROM twitter WHERE user_id = ? AND crosspost = 1",
- (rs, num) -> new ExternalToken(rs.getString(1), "twitter",
- rs.getString(2), rs.getString(3)),
- uid);
-
- return list.isEmpty() ?
- Optional.empty() : Optional.of(list.get(0));
- }
-
- @Transactional
- @Override
- public boolean deleteTwitterToken(Integer uid) {
- return getJdbcTemplate().update("DELETE FROM twitter WHERE user_id=?", uid) > 0
- && getJdbcTemplate().update("DELETE FROM subscr_users WHERE user_id=? AND suser_id=1741", uid) > 0;
- }
-
- @Override
- public void addFacebookState(String state) {
- jdbcTemplate.update("INSERT INTO facebook(loginhash) VALUES(?)", state);
- }
-
- @Override
- public boolean verifyFacebookState(String state) {
- try {
- return jdbcTemplate.queryForObject("SELECT COUNT(loginhash) FROM facebook WHERE loginhash=?",
- Integer.class, state) == 1;
- } catch (EmptyResultDataAccessException e) {
- return false;
- }
- }
-
- @Transactional(readOnly = true)
- @Override
- public Optional> getFacebookTokens(final int uid) {
- List>> list = getJdbcTemplate().query(
- "SELECT fb_id, access_token FROM facebook WHERE user_id = ? AND access_token IS NOT NULL AND crosspost = 1",
- (rs, num) -> Optional.of(Pair.of(rs.getString(1), rs.getString(2))),
- uid);
- return list.isEmpty() ?
- Optional.empty() : list.get(0);
- }
-
- @Transactional(readOnly = true)
- @Override
- public ApplicationStatus getFbCrossPostStatus(final int uid) {
- List list = getJdbcTemplate().query(
- "SELECT 1, crosspost FROM facebook WHERE user_id = ? LIMIT 1",
- (rs, num) -> {
- ApplicationStatus status = new ApplicationStatus();
-
- status.setConnected(rs.getInt(1) > 0);
- status.setCrosspostEnabled(rs.getBoolean(2));
-
- return status;
- },
- uid);
-
- return list.isEmpty() ?
- new ApplicationStatus() : list.get(0);
- }
-
- @Transactional
- @Override
- public boolean enableFBCrosspost(Integer uid) {
- return getJdbcTemplate().update("UPDATE facebook SET crosspost=1 WHERE user_id=?", uid) > 0
- && getJdbcTemplate().update(
- "INSERT INTO subscr_users(user_id,suser_id,jid,active) VALUES (?,5863,'juick@facebook.juick.com',1)",
- uid) > 0;
- }
-
- @Transactional
- @Override
- public void disableFBCrosspost(Integer uid) {
- getJdbcTemplate().update("UPDATE facebook SET crosspost=0 WHERE user_id=?", uid);
- // TODO: stop using magic numbers for system users
- getJdbcTemplate().update("DELETE FROM subscr_users WHERE user_id=? AND suser_id=5863", uid);
- }
-
- @Transactional(readOnly = true)
- @Override
- public String getTwitterName(final int uid) {
- List list = getJdbcTemplate().queryForList(
- "SELECT uname FROM twitter WHERE user_id = ?",
- String.class,
- uid);
-
- return list.isEmpty() ?
- StringUtils.EMPTY : list.get(0);
- }
-
- @Transactional(readOnly = true)
- @Override
- public String getTelegramName(final int uid) {
- List list = getJdbcTemplate().queryForList(
- "SELECT tg_name FROM telegram WHERE user_id = ?",
- String.class,
- uid);
-
- return list.isEmpty() ?
- StringUtils.EMPTY : list.get(0);
- }
-
- @Transactional(readOnly = true)
- @Override
- public Optional> getVkTokens(final int uid) {
- List>> list = getJdbcTemplate().query(
- "SELECT vk_id, access_token FROM vk WHERE user_id = ? AND crosspost = 1",
- (rs, num) -> Optional.of(Pair.of(rs.getString(1), rs.getString(2))),
- uid);
-
- return list.isEmpty() ?
- Optional.empty() : list.get(0);
- }
-
- @Transactional
- @Override
- public void deleteVKUser(Integer uid) {
- getJdbcTemplate().update("DELETE FROM vk WHERE user_id=?", uid);
- }
-
- @Transactional(readOnly = true)
- @Override
- public int getUIDbyFBID(long fbID) {
- try {
- return getJdbcTemplate().queryForObject("SELECT user_id FROM facebook WHERE fb_id=? AND user_id IS NOT NULL",
- Integer.class, fbID);
- } catch (EmptyResultDataAccessException e) {
- return 0;
- }
- }
-
- @Transactional
- @Override
- public boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink) {
- return getJdbcTemplate().update("UPDATE facebook SET fb_id=?, access_token=?, fb_name=?, fb_link=? WHERE loginhash=?",
- fbID, token, fbName, fbLink, loginhash) > 0;
- }
-
- @Transactional
- @Override
- public boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink) {
- return getJdbcTemplate().update("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?",
- token, fbName, fbLink, fbID) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public int getUIDbyVKID(long vkID) {
- try {
- return getJdbcTemplate().queryForObject("SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL", Integer.class, vkID);
- } catch (EmptyResultDataAccessException e) {
- return 0;
- }
- }
-
- @Transactional
- @Override
- public boolean createVKUser(long vkID, String loginhash, String token, String vkName, String vkLink) {
- return getJdbcTemplate().update("INSERT INTO vk(vk_id,loginhash,access_token,vk_name,vk_link) VALUES (?,?,?,?,?)",
- vkID, loginhash, token, vkName, vkLink) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public String getFacebookNameByHash(String hash) {
- try {
- List> fb = getJdbcTemplate().query("SELECT fb_name,fb_link FROM facebook WHERE loginhash=?",
- (rs, num) -> Pair.of(rs.getString(1), rs.getString(2)), hash);
- if (fb.size() > 0) {
- return "" + fb.get(0).getLeft() + "";
- }
- return null;
- } catch (EmptyResultDataAccessException e) {
- return null;
- }
- }
-
- @Transactional
- @Override
- public String getTelegramNameByHash(String hash) {
- try {
- String name = getJdbcTemplate().queryForObject("SELECT tg_name FROM telegram WHERE loginhash=?", String.class, hash);
- return "" + name + "";
- } catch (EmptyResultDataAccessException e) {
- return null;
- }
- }
-
- @Transactional
- @Override
- public boolean setFacebookUser(String hash, int uid) {
- return getJdbcTemplate().update("UPDATE facebook SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
- }
-
- @Transactional
- @Override
- public String getVKNameByHash(String hash) {
- List> logins = getJdbcTemplate().query("SELECT vk_name,vk_link FROM vk WHERE loginhash=?",
- (rs, num) -> Pair.of(rs.getString(1), rs.getString(2)), hash);
- if (logins.size() > 0) {
- return "" + logins.get(0).getLeft() + "";
- }
- return null;
- }
-
- @Transactional
- @Override
- public boolean setVKUser(String hash, int uid) {
- return getJdbcTemplate().update("UPDATE vk SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
- }
-
- @Transactional
- @Override
- public boolean setTelegramUser(String hash, int uid) {
- return getJdbcTemplate().update("UPDATE telegram SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public String getJIDByHash(String hash) {
- try {
- return getJdbcTemplate().queryForObject("SELECT jid FROM jids WHERE loginhash=?", String.class, hash);
- } catch (EmptyResultDataAccessException e) {
- return null;
- }
- }
-
- @Transactional
- @Override
- public boolean setJIDUser(String hash, int uid) {
- return getJdbcTemplate().update("UPDATE jids SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
- }
-}
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
deleted file mode 100644
index 0cccc915..00000000
--- a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.service;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.inject.Inject;
-import java.util.List;
-
-/**
- * Created by vitalyster on 09.12.2016.
- */
-@Repository
-@Transactional
-public class EmailServiceImpl extends BaseJdbcService implements EmailService {
-
- @Override
- public boolean verifyAddressByCode(Integer userId, String code) {
- try {
- String address = getJdbcTemplate().queryForObject("SELECT account FROM auth WHERE user_id=? AND protocol='email' AND authcode=?",
- String.class, userId, code);
- addEmail(userId, address);
- getJdbcTemplate().update("DELETE FROM auth WHERE user_id=? AND authcode=?", userId, code);
- } catch (EmptyResultDataAccessException e) {
- return false;
- }
- return true;
- }
-
- @Override
- public boolean addVerificationCode(Integer userId, String account, String code) {
- return getJdbcTemplate().update("INSERT INTO auth(user_id,protocol,account,authcode) VALUES (?,'email',?,?)",
- userId, account, code) > 0;
- }
-
- @Override
- public boolean addEmail(Integer userId, String email) {
- return getJdbcTemplate().update("INSERT INTO emails(user_id,email) VALUES (?,?)", userId, email) > 0;
- }
-
- @Override
- public boolean deleteEmail(Integer userId, String account) {
- return getNamedParameterJdbcTemplate().update("DELETE FROM emails " +
- "WHERE (SELECT COUNT(*) cnt FROM (select user_id, email FROM emails e) c WHERE user_id=:uid) > 1 " +
- "AND user_id=:uid AND email=:email",
- new MapSqlParameterSource()
- .addValue("uid", userId)
- .addValue("email", account)) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public String getNotificationsEmail(Integer userId) {
- List list = getJdbcTemplate().queryForList(
- "SELECT email FROM emails WHERE user_id=? AND subscr_hour IS NOT NULL", String.class, userId);
- return list.isEmpty() ? StringUtils.EMPTY : list.get(0);
- }
-
- @Override
- public boolean setNotificationsEmail(Integer userId, String account) {
- getJdbcTemplate().update("UPDATE emails SET subscr_hour=NULL WHERE user_id=?", userId);
- return StringUtils.isNotEmpty(account) && getJdbcTemplate().update(
- "UPDATE emails SET subscr_hour=1 WHERE user_id=? AND email=?", userId, account) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public List getEmails(Integer userId, boolean active) {
- return getJdbcTemplate().queryForList("SELECT email FROM emails WHERE user_id=? " +
- (active ? "AND subscr_hour IS NOT NULL" : ""), String.class, userId);
- }
-}
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
deleted file mode 100644
index 35e48383..00000000
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ /dev/null
@@ -1,1006 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.service;
-
-import com.juick.*;
-import com.juick.server.helpers.PrivacyOpts;
-import com.juick.server.helpers.ResponseReply;
-import com.juick.util.MessageUtils;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.dao.IncorrectResultSizeDataAccessException;
-import org.springframework.jdbc.core.ConnectionCallback;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.namedparam.SqlParameterSource;
-import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.inject.Inject;
-import java.sql.*;
-import java.time.Instant;
-import java.util.*;
-import java.util.Date;
-import java.util.stream.Collectors;
-
-/**
- * Created by aalexeev on 11/13/16.
- */
-@Repository
-public class MessagesServiceImpl extends BaseJdbcService implements MessagesService {
- private static final Logger logger = LoggerFactory.getLogger(MessagesServiceImpl.class);
- @Inject
- private UserService userService;
- @Inject
- private TagService tagService;
- @Inject
- private SearchService searchService;
- @Inject
- private ImagesService imagesService;
- @Value("${img_url:https://i.juick.com/}")
- private String baseImagesUrl;
-
- private class MessageMapper implements RowMapper {
- @Override
- public Message mapRow(ResultSet rs, int rowNum) throws SQLException {
- Message msg = new Message();
- msg.setMid(rs.getInt(1));
- msg.setRid(rs.getInt(2));
- msg.setReplyto(rs.getInt(3));
- User user = new User();
- user.setUid(rs.getInt(4));
- user.setName(rs.getString(5));
- user.setBanned(rs.getBoolean(6));
- msg.setUser(user);
- msg.setTimestamp(rs.getTimestamp(7).toInstant());
- msg.ReadOnly = rs.getBoolean(8);
- msg.setPrivacy(rs.getInt(9));
- msg.FriendsOnly = msg.getPrivacy() < 0;
- msg.setReplies(rs.getInt(10));
- msg.setAttachmentType(rs.getString(11));
- msg.setLikes(rs.getInt(12));
- msg.Hidden = rs.getBoolean(13);
- String tagsStr = rs.getString(14);
- msg.setTags(MessageUtils.parseTags(tagsStr));
- msg.setRepliesBy(rs.getString(15));
- msg.setText(rs.getString(16));
- msg.setReplyQuote(MessageUtils.formatQuote(rs.getString(17)));
- msg.setUpdated(rs.getTimestamp(18).toInstant());
- int quoteUid = rs.getInt(19);
- if (quoteUid > 0) {
- User quoteUser = new User();
- quoteUser.setUid(quoteUid);
- quoteUser.setName(rs.getString(20));
- msg.setTo(quoteUser);
- }
- if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
- try {
- imagesService.setAttachmentMetadata(baseImagesUrl, msg);
- } catch (Exception e) {
- logger.warn("exception reading images for mid {} rid {}", msg.getMid(), msg.getRid(), e);
- }
- }
- return msg;
- }
- }
-
-
-
- /**
- * @see Java, JDBC and MySQL Types
- */
- @Transactional
- @Override
- public int createMessage(final int uid, final String txt, final String attachment, final Collection tags) {
- SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(getJdbcTemplate()).withTableName("messages")
- .usingColumns("user_id", "attach", "ts")
- .usingGeneratedKeyColumns("message_id");
- Map insertMap = new HashMap<>();
- insertMap.put("user_id", uid);
- Instant now = Instant.now();
- insertMap.put("ts", Timestamp.from(now));
- if (attachment != null) {
- insertMap.put("attach", attachment);
- }
- int mid = simpleJdbcInsert.executeAndReturnKey(insertMap).intValue();
- if (mid > 0) {
- String tagsNames = StringUtils.EMPTY;
-
- if (CollectionUtils.isNotEmpty(tags)) {
- StringBuilder tasNamesBuilder = new StringBuilder();
- List