Что-то много всего

This commit is contained in:
upagge 2020-03-31 21:44:57 +03:00
parent da8c0bb706
commit 2ae8aa816c
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
9 changed files with 69 additions and 48 deletions

View File

@ -21,7 +21,7 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -81,9 +81,9 @@ public class PullRequest {
private PullRequestStatus status; private PullRequestStatus status;
@Column(name = "create_date") @Column(name = "create_date")
private LocalDate createDate; private LocalDateTime createDate;
@Column(name = "update_date") @Column(name = "update_date")
private LocalDate updateDate; private LocalDateTime updateDate;
} }

View File

@ -1,10 +1,10 @@
package com.tsc.bitbucketbot.dto.bitbucket; package com.tsc.bitbucketbot.dto.bitbucket;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.tsc.bitbucketbot.utils.LocalDateFromEpochDeserializer; import com.tsc.bitbucketbot.utils.LocalDateTimeFromEpochDeserializer;
import lombok.Data; import lombok.Data;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Data @Data
@ -15,10 +15,10 @@ public class CommentJson {
private UserJson author; private UserJson author;
private List<CommentJson> comments; private List<CommentJson> comments;
@JsonDeserialize(using = LocalDateFromEpochDeserializer.class) @JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
private LocalDate createdDate; private LocalDateTime createdDate;
@JsonDeserialize(using = LocalDateFromEpochDeserializer.class) @JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
private LocalDate updatedDate; private LocalDateTime updatedDate;
} }

View File

@ -1,10 +1,10 @@
package com.tsc.bitbucketbot.dto.bitbucket; package com.tsc.bitbucketbot.dto.bitbucket;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.tsc.bitbucketbot.utils.LocalDateFromEpochDeserializer; import com.tsc.bitbucketbot.utils.LocalDateTimeFromEpochDeserializer;
import lombok.Data; import lombok.Data;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -19,11 +19,11 @@ public class PullRequestJson {
private Integer version; private Integer version;
private PullRequestState state; private PullRequestState state;
@JsonDeserialize(using = LocalDateFromEpochDeserializer.class) @JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
private LocalDate createdDate; private LocalDateTime createdDate;
@JsonDeserialize(using = LocalDateFromEpochDeserializer.class) @JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
private LocalDate updatedDate; private LocalDateTime updatedDate;
private String title; private String title;
private String description; private String description;

View File

@ -24,7 +24,7 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -191,8 +191,8 @@ public class SchedulerPullRequest {
@NonNull @NonNull
private Optional<String> changeVersionPr(PullRequest pullRequest, PullRequest newPullRequest) { private Optional<String> changeVersionPr(PullRequest pullRequest, PullRequest newPullRequest) {
LocalDate oldDate = pullRequest.getUpdateDate(); LocalDateTime oldDate = pullRequest.getUpdateDate();
LocalDate newDate = newPullRequest.getUpdateDate(); LocalDateTime newDate = newPullRequest.getUpdateDate();
if (!oldDate.isEqual(newDate)) { if (!oldDate.isEqual(newDate)) {
return Optional.of( return Optional.of(
Message.updatePullRequest( Message.updatePullRequest(

View File

@ -42,20 +42,14 @@ public class Utils {
if (token != null) { if (token != null) {
urlCon.setRequestProperty("Authorization", "Bearer " + token); urlCon.setRequestProperty("Authorization", "Bearer " + token);
} }
BufferedReader in; try (BufferedReader in = (isGzip(urlCon)) ?
if (urlCon.getHeaderField("Content-Encoding") != null new BufferedReader(new InputStreamReader(new GZIPInputStream(urlCon.getInputStream())))
&& urlCon.getHeaderField("Content-Encoding").equals("gzip")) { : new BufferedReader(new InputStreamReader(urlCon.getInputStream()));) {
in = new BufferedReader(new InputStreamReader(new GZIPInputStream(urlCon.getInputStream())));
} else {
in = new BufferedReader(new InputStreamReader(urlCon.getInputStream()));
}
String inputLine; String inputLine;
sb = new StringBuilder(); sb = new StringBuilder();
while ((inputLine = in.readLine()) != null) { while ((inputLine = in.readLine()) != null) {
sb.append(inputLine); sb.append(inputLine);
} }
in.close();
} catch (IOException e) { } catch (IOException e) {
log.trace(e.getMessage()); log.trace(e.getMessage());
} }
@ -66,7 +60,15 @@ public class Utils {
log.error(e.getMessage()); log.error(e.getMessage());
} }
} }
} catch (IOException e) {
log.error(e.getMessage());
}
return Optional.empty(); return Optional.empty();
} }
private static boolean isGzip(URLConnection urlCon) {
return urlCon.getHeaderField("Content-Encoding") != null
&& urlCon.getHeaderField("Content-Encoding").equals("gzip");
}
} }

View File

@ -7,23 +7,22 @@ import lombok.extern.slf4j.Slf4j;
import java.io.IOException; import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
@Slf4j @Slf4j
public class LocalDateFromEpochDeserializer extends JsonDeserializer<LocalDate> { public class LocalDateTimeFromEpochDeserializer extends JsonDeserializer<LocalDateTime> {
@Override @Override
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) { public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt) {
try { try {
Long time = jp.readValueAs(Long.class); Long time = jp.readValueAs(Long.class);
Instant instant = Instant.ofEpochMilli(time); Instant instant = Instant.ofEpochMilli(time);
LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); return instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
return localDate;
} catch (IOException e) { } catch (IOException e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }
return LocalDate.now(); return null;
} }
} }

View File

@ -24,6 +24,7 @@ public class Message {
private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator(); private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator();
private static final Integer PR_COUNT = 4; private static final Integer PR_COUNT = 4;
private static final String DONATION_LINK = "https://www.tinkoff.ru/sl/1T9s4esiMf"; private static final String DONATION_LINK = "https://www.tinkoff.ru/sl/1T9s4esiMf";
public static final String HELP_LINK = "https://nuzhnapomosh.ru/about/";
private Message() { private Message() {
throw new IllegalStateException("Утилитарный класс"); throw new IllegalStateException("Утилитарный класс");
@ -122,8 +123,9 @@ public class Message {
} }
if (dayX()) { if (dayX()) {
message.append(Smile.BR).append(Smile.FUN).append(" Кстати, поздравляю, сегодня день З").append(Smile.BR) message.append(Smile.BR).append(Smile.FUN).append(" Кстати, поздравляю, сегодня день З").append(Smile.BR)
.append(Smile.DANGEROUS).append("И раз такое дело, то напоминаю, что в виду независящих от разработчика условий, бот работает на платном VDS. Поэтому всячески приветствуются ") .append(Smile.DANGEROUS).append("Спасибо всем, кто ").append(link("донатил", DONATION_LINK)).append(", мы оплатили хостинг до октября :)")
.append(link("донаты на оплату сервера", DONATION_LINK)).append(Smile.BR); .append(Smile.BR).append("Теперь стоит ").append(link("помочь", HELP_LINK)).append(" тем, кто действительно в этом нуждается))")
.append(Smile.BR);
} }
message message
.append(Smile.BR) .append(Smile.BR)

View File

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period; import java.time.Period;
@AllArgsConstructor @AllArgsConstructor
@ -33,8 +34,8 @@ public enum Smile {
@Getter @Getter
private String value; private String value;
public static Smile statusPr(LocalDate updateDate) { public static Smile statusPr(LocalDateTime updateDate) {
int periodDay = Period.between(updateDate, LocalDate.now()).getDays(); int periodDay = Period.between(updateDate.toLocalDate(), LocalDate.now()).getDays();
if (periodDay < 5) { if (periodDay < 5) {
return Smile.valueOf("DAY_" + periodDay); return Smile.valueOf("DAY_" + periodDay);
} else { } else {

View File

@ -34,4 +34,21 @@
<dropForeignKeyConstraint baseTableName="comment_tree" constraintName="fk_child_id_from_comment_id"/> <dropForeignKeyConstraint baseTableName="comment_tree" constraintName="fk_child_id_from_comment_id"/>
</changeSet> </changeSet>
<changeSet id="modifyDataType-date-up-pr" author="upagge">
<modifyDataType catalogName="pg_catalog"
columnName="create_date"
newDataType="datetime"
schemaName="public"
tableName="pull_request"/>
</changeSet>
<changeSet id="modifyDataType-date-create-pr" author="upagge">
<modifyDataType catalogName="pg_catalog"
columnName="update_date"
newDataType="datetime"
schemaName="public"
tableName="pull_request"/>
</changeSet>
</databaseChangeLog> </databaseChangeLog>