Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
refactor(service-news): fix PR request
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Stiede committed Mar 12, 2020
1 parent a3d754a commit 8120bc0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.hpi.cloud.news.crawler

import de.hpi.cloud.news.crawler.HpiMediaArchiveCrawler.HpiMediaSource
import de.hpi.cloud.common.entity.Id
import de.hpi.cloud.news.crawler.HpiMediaArchiveCrawler.HpiMediaSource
import de.hpi.cloud.news.entities.Article
import java.net.URL
import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.hpi.cloud.news.crawler

import de.hpi.cloud.news.crawler.HpiMediaArchiveCrawler.HpiMediaSource
import de.hpi.cloud.common.entity.Id
import de.hpi.cloud.common.types.Image
import de.hpi.cloud.common.types.MarkupContent
import de.hpi.cloud.common.types.l10n
import de.hpi.cloud.common.utils.removeFirst
import de.hpi.cloud.news.crawler.HpiMediaArchiveCrawler.HpiMediaSource
import de.hpi.cloud.news.entities.Article
import org.jsoup.nodes.Element

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.hpi.cloud.news.crawler

import de.hpi.cloud.news.crawler.utils.days
import de.hpi.cloud.common.Context
import de.hpi.cloud.common.couchbase.upsert
import de.hpi.cloud.common.couchbase.withBucket
import de.hpi.cloud.news.crawler.utils.days
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
Expand Down
29 changes: 14 additions & 15 deletions service-news/src/main/kotlin/de/hpi/cloud/news/entities/Article.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ data class Article(
companion object : Entity.Companion<Article>("article")

object ProtoSerializer : Entity.ProtoSerializer<Article, ProtoArticle, ProtoArticle.Builder>() {
override fun fromProto(proto: ProtoArticle, context: Context): Article =
Article(
sourceId = Id(proto.id),
link = L10n.single(context, proto.link.parseUrl()),
title = L10n.single(context, proto.title),
publishDate = proto.publishDate.parse(context),
authorIds = proto.authorIdsList.toSet(),
cover = if (proto.hasCover()) proto.cover.parse(context) else null,
teaser = L10n.single(context, proto.teaser),
content = L10n.single(context, proto.content.parse(context)),
categories = proto.categoryIdsList.map { Id<Category>(it) }.toSet(),
tags = proto.tagIdsList.map { Id<Tag>(it) }.toSet(),
viewCount = proto.viewCount.value.takeIf { proto.hasViewCount() }
)
override fun fromProto(proto: ProtoArticle, context: Context) = Article(
sourceId = Id(proto.id),
link = L10n.single(context, proto.link.parseUrl()),
title = L10n.single(context, proto.title),
publishDate = proto.publishDate.parse(context),
authorIds = proto.authorIdsList.toSet(),
cover = if (proto.hasCover()) proto.cover.parse(context) else null,
teaser = L10n.single(context, proto.teaser),
content = L10n.single(context, proto.content.parse(context)),
categories = proto.categoryIdsList.map { Id<Category>(it) }.toSet(),
tags = proto.tagIdsList.map { Id<Tag>(it) }.toSet(),
viewCount = proto.viewCount.value.takeIf { proto.hasViewCount() }
)

override fun toProtoBuilder(entity: Article, context: Context): ProtoArticle.Builder =
override fun toProtoBuilder(entity: Article, context: Context) =
ProtoArticle.newBuilder().builder(entity) {
sourceId = it.sourceId.value
link = it.link[context].toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ data class Category(
companion object : Entity.Companion<Category>("category")

object ProtoSerializer : Entity.ProtoSerializer<Category, ProtoCategory, ProtoCategory.Builder>() {
override fun fromProto(proto: ProtoCategory, context: Context): Category = Category(
override fun fromProto(proto: ProtoCategory, context: Context) = Category(
title = proto.title.l10n(context)
)

override fun toProtoBuilder(entity: Category, context: Context): ProtoCategory.Builder =
override fun toProtoBuilder(entity: Category, context: Context) =
ProtoCategory.newBuilder().builder(entity) {
title = it.title[context]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ data class Source(
companion object : Entity.Companion<Source>("source")

object ProtoSerializer : Entity.ProtoSerializer<Source, ProtoSource, ProtoSource.Builder>() {
override fun fromProto(proto: ProtoSource, context: Context): Source = Source(
override fun fromProto(proto: ProtoSource, context: Context) = Source(
title = proto.title.l10n(context),
link = proto.link.parseUri().l10n(context)
)

override fun toProtoBuilder(entity: Source, context: Context): ProtoSource.Builder =
override fun toProtoBuilder(entity: Source, context: Context) =
ProtoSource.newBuilder().builder(entity) {
title = it.title[context]
link = it.link[context].toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ data class Tag(
companion object : Entity.Companion<Tag>("tag")

object ProtoSerializer : Entity.ProtoSerializer<Tag, ProtoTag, ProtoTag.Builder>() {
override fun fromProto(proto: ProtoTag, context: Context): Tag = Tag(
override fun fromProto(proto: ProtoTag, context: Context) = Tag(
title = proto.title.l10n(context),
articleCount = proto.articleCount
)

override fun toProtoBuilder(entity: Tag, context: Context): ProtoTag.Builder =
override fun toProtoBuilder(entity: Tag, context: Context) =
ProtoTag.newBuilder().builder(entity) {
title = it.title[context]
articleCount = it.articleCount
Expand Down

0 comments on commit 8120bc0

Please sign in to comment.