-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from JakduK/develop
Develop
- Loading branch information
Showing
179 changed files
with
2,254 additions
and
2,901 deletions.
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
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
114 changes: 114 additions & 0 deletions
114
api/src/main/java/com/jakduk/api/common/DocumentRssFeedView.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,114 @@ | ||
package com.jakduk.api.common; | ||
|
||
import com.jakduk.core.common.util.CoreUtils; | ||
import com.jakduk.core.dao.JakdukDAO; | ||
import com.jakduk.core.model.simple.BoardFreeOnRSS; | ||
import com.rometools.rome.feed.rss.Channel; | ||
import com.rometools.rome.feed.rss.Content; | ||
import com.rometools.rome.feed.rss.Description; | ||
import com.rometools.rome.feed.rss.Item; | ||
import org.bson.types.ObjectId; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.view.feed.AbstractRssFeedView; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author Jang, Pyohwan(1100273) | ||
* @since 2016. 12. 2. | ||
*/ | ||
|
||
@Component("documentRssFeedView") | ||
public class DocumentRssFeedView extends AbstractRssFeedView { | ||
|
||
@Autowired | ||
private MessageSource messageSource; | ||
|
||
@Autowired | ||
private JakdukDAO jakdukDAO; | ||
|
||
private final String link = "https://jakduk.com"; | ||
|
||
/** | ||
* Create a new Channel instance to hold the entries. | ||
* <p>By default returns an RSS 2.0 channel, but the subclass can specify any channel. | ||
*/ | ||
@Override protected Channel newFeed() { | ||
Locale locale = LocaleContextHolder.getLocale(); | ||
|
||
Channel channel = new Channel("rss_2.0"); | ||
channel.setLink(link + "/rss"); | ||
channel.setTitle(messageSource.getMessage("common.jakduk", null, locale)); | ||
channel.setDescription(messageSource.getMessage("common.jakduk.rss.description", null, locale)); | ||
return channel; | ||
} | ||
|
||
/** | ||
* Subclasses must implement this method to build feed items, given the model. | ||
* <p>Note that the passed-in HTTP response is just supposed to be used for | ||
* setting cookies or other HTTP headers. The built feed itself will automatically | ||
* get written to the response after this method returns. | ||
* | ||
* @param model the model Map | ||
* @param request in case we need locale etc. Shouldn't look at attributes. | ||
* @param response in case we need to set cookies. Shouldn't write to it. | ||
* @return the feed items to be added to the feed | ||
* @throws Exception any exception that occurred during document building | ||
* @see Item | ||
*/ | ||
@Override protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, | ||
HttpServletResponse response) throws Exception { | ||
|
||
// updateDate 되는 줄 알고 스트림 API 써가며 만들어 놨더니, XML로 안나오네. | ||
/* | ||
List<BoardHistory> history = post.getHistory(); | ||
if (history != null) { | ||
Stream<BoardHistory> sHistory = history.stream(); | ||
List<BoardHistory> uHistory = sHistory | ||
.filter(item -> item.getProviderId().equals(CoreConst.BOARD_HISTORY_TYPE_EDIT) || item.getProviderId().equals(CoreConst.BOARD_HISTORY_TYPE_EDIT)) | ||
.sorted((h1, h2) -> h1.getId().compareTo(h2.getId())) | ||
.limit(1) | ||
.collect(Collectors.toList()); | ||
if (!uHistory.isEmpty()) { | ||
logger.debug("phjang =" + uHistory); | ||
entry.setUpdatedDate(new ObjectId(uHistory.get(0).getId()).getDate()); | ||
} | ||
} | ||
*/ | ||
|
||
List<BoardFreeOnRSS> posts = jakdukDAO.getRSS(); | ||
|
||
List<Item> items = posts.stream() | ||
.map(post -> { | ||
Item item = new Item(); | ||
item.setTitle(post.getSubject()); | ||
item.setLink(link + "/board/free/" + post.getSeq()); | ||
item.setDescription(createDescription(CoreUtils.stripHtmlTag(post.getContent()))); | ||
item.setPubDate(new ObjectId(post.getId()).getDate()); | ||
|
||
return item; | ||
}) | ||
.collect(Collectors.toList()); | ||
|
||
return items; | ||
} | ||
|
||
private Description createDescription(String content) { | ||
Description description = new Description(); | ||
description.setType(Content.HTML); | ||
description.setValue(content); | ||
|
||
return description; | ||
} | ||
} |
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: 10 additions & 7 deletions
17
...onstraints/ExistEmailOnEditValidator.java → ...constraint/ExistEmailOnEditValidator.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,40 +1,43 @@ | ||
package com.jakduk.api.common.constraints; | ||
package com.jakduk.api.common.constraint; | ||
|
||
import com.jakduk.api.common.util.UserUtils; | ||
import com.jakduk.api.configuration.authentication.user.CommonPrincipal; | ||
import com.jakduk.core.model.simple.UserProfile; | ||
import com.jakduk.core.service.UserService; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author pyohwan | ||
* 16. 7. 3 오후 9:30 | ||
*/ | ||
class ExistEmailOnEditValidator implements ConstraintValidator<ExistEmailOnEdit, String> { | ||
public class ExistEmailOnEditValidator implements ConstraintValidator<ExistEmailOnEdit, String> { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Override | ||
public void initialize(ExistEmailOnEdit constraintAnnotation) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
|
||
if (Objects.isNull(value)) | ||
if (StringUtils.isEmpty(value)) | ||
return false; | ||
|
||
CommonPrincipal commonPrincipal = UserUtils.getCommonPrincipal(); | ||
|
||
UserProfile existEmail = userService.findByNEIdAndEmail(commonPrincipal.getId(), value.trim()); | ||
if (ObjectUtils.isEmpty(commonPrincipal)) | ||
return false; | ||
|
||
UserProfile userProfile = userService.findByNEIdAndEmail(commonPrincipal.getId(), value.trim()); | ||
|
||
return ! Objects.nonNull(existEmail); | ||
return ObjectUtils.isEmpty(userProfile); | ||
|
||
} | ||
} |
15 changes: 9 additions & 6 deletions
15
...mmon/constraints/ExistEmailValidator.java → ...ommon/constraint/ExistEmailValidator.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,33 +1,36 @@ | ||
package com.jakduk.api.common.constraints; | ||
package com.jakduk.api.common.constraint; | ||
|
||
import com.jakduk.core.model.simple.UserProfile; | ||
import com.jakduk.core.service.UserService; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author pyohwan | ||
* 16. 7. 3 오후 9:30 | ||
*/ | ||
class ExistEmailValidator implements ConstraintValidator<ExistEmail, String> { | ||
|
||
public class ExistEmailValidator implements ConstraintValidator<ExistEmail, String> { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Override | ||
public void initialize(ExistEmail constraintAnnotation) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
|
||
UserProfile existEmail = userService.findOneByEmail(value); | ||
if (StringUtils.isEmpty(value)) | ||
return false; | ||
|
||
return ! Objects.nonNull(existEmail); | ||
UserProfile existEmail = userService.findOneByEmail(value); | ||
|
||
return ObjectUtils.isEmpty(existEmail); | ||
} | ||
} |
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
19 changes: 12 additions & 7 deletions
19
...traints/ExistUsernameOnEditValidator.java → ...straint/ExistUsernameOnEditValidator.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,40 +1,45 @@ | ||
package com.jakduk.api.common.constraints; | ||
package com.jakduk.api.common.constraint; | ||
|
||
import com.jakduk.api.common.util.UserUtils; | ||
import com.jakduk.api.configuration.authentication.user.CommonPrincipal; | ||
import com.jakduk.core.exception.ServiceExceptionCode; | ||
import com.jakduk.core.exception.ServiceException; | ||
import com.jakduk.core.model.simple.UserProfile; | ||
import com.jakduk.core.service.UserService; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author pyohwan | ||
* 16. 7. 3 오후 9:40 | ||
*/ | ||
class ExistUsernameOnEditValidator implements ConstraintValidator<ExistUsernameOnEdit, String> { | ||
public class ExistUsernameOnEditValidator implements ConstraintValidator<ExistUsernameOnEdit, String> { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Override | ||
public void initialize(ExistUsernameOnEdit constraintAnnotation) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
|
||
if (Objects.isNull(value)) | ||
if (StringUtils.isEmpty(value)) | ||
return false; | ||
|
||
CommonPrincipal commonPrincipal = UserUtils.getCommonPrincipal(); | ||
|
||
UserProfile existUsername = userService.findByNEIdAndUsername(commonPrincipal.getId().trim(), value.trim()); | ||
if (ObjectUtils.isEmpty(commonPrincipal)) | ||
throw new ServiceException(ServiceExceptionCode.NEED_TO_LOGIN); | ||
|
||
UserProfile userProfile = userService.findByNEIdAndUsername(commonPrincipal.getId().trim(), value.trim()); | ||
|
||
return ! Objects.nonNull(existUsername); | ||
return ObjectUtils.isEmpty(userProfile); | ||
|
||
} | ||
} |
Oops, something went wrong.