Commit 2cde50ff authored by Liang Ding's avatar Liang Ding

🎨 clean code

parent 8579f4ef
......@@ -54,7 +54,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.2.7, Nov 20, 2015
* @version 1.2.2.8, Jun 25, 2017
* @since 0.3.5
*/
@Service
......@@ -63,7 +63,7 @@ public class ArticleMgmtService {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(ArticleMgmtService.class.getName());
private static final Logger LOGGER = Logger.getLogger(ArticleMgmtService.class);
/**
* Article query service.
......@@ -155,6 +155,24 @@ public class ArticleMgmtService {
@Inject
private TagMgmtService tagMgmtService;
/**
* Determines whether the specified tag title exists in the specified tags.
*
* @param tagTitle the specified tag title
* @param tags the specified tags
* @return {@code true} if it exists, {@code false} otherwise
* @throws JSONException json exception
*/
private static boolean tagExists(final String tagTitle, final List<JSONObject> tags) throws JSONException {
for (final JSONObject tag : tags) {
if (tag.getString(Tag.TAG_TITLE).equals(tagTitle)) {
return true;
}
}
return false;
}
/**
* Article comment count +1 for an article specified by the given article id.
*
......@@ -245,7 +263,6 @@ public class ArticleMgmtService {
* Updates an article by the specified request json object.
*
* @param requestJSONObject the specified request json object, for example,
* <pre>
* {
* "article": {
* "oId": "",
......@@ -261,7 +278,6 @@ public class ArticleMgmtService {
* "articleEditorType": "" // optional, preference specified if not exists this key
* }
* }
* </pre>
* @throws ServiceException service exception
*/
public void updateArticle(final JSONObject requestJSONObject) throws ServiceException {
......@@ -361,7 +377,7 @@ public class ArticleMgmtService {
eventData.put(ARTICLE, article);
eventData.put(Keys.RESULTS, ret);
try {
eventManager.fireEventSynchronously(new Event<JSONObject>(EventTypes.ADD_ARTICLE, eventData));
eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_ARTICLE, eventData));
} catch (final EventException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
}
......@@ -372,7 +388,7 @@ public class ArticleMgmtService {
eventData.put(ARTICLE, article);
eventData.put(Keys.RESULTS, ret);
try {
eventManager.fireEventSynchronously(new Event<JSONObject>(EventTypes.UPDATE_ARTICLE, eventData));
eventManager.fireEventSynchronously(new Event<>(EventTypes.UPDATE_ARTICLE, eventData));
} catch (final EventException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
}
......@@ -402,7 +418,6 @@ public class ArticleMgmtService {
* Adds an article from the specified request json object.
*
* @param requestJSONObject the specified request json object, for example,
* <pre>
* {
* "article": {
* "articleAuthorEmail": "",
......@@ -420,7 +435,6 @@ public class ArticleMgmtService {
* "oId": "" // optional, generate it if not exists this key
* }
* }
* </pre>
* @return generated article id
* @throws ServiceException service exception
*/
......@@ -534,7 +548,7 @@ public class ArticleMgmtService {
final JSONObject eventData = new JSONObject();
eventData.put(Article.ARTICLE, article);
eventManager.fireEventSynchronously(new Event<JSONObject>(EventTypes.ADD_ARTICLE, eventData));
eventManager.fireEventSynchronously(new Event<>(EventTypes.ADD_ARTICLE, eventData));
}
article.remove(Common.POST_TO_COMMUNITY);
......@@ -773,7 +787,7 @@ public class ArticleMgmtService {
/**
* Processes tags for article update.
*
* <p>
* <ul>
* <li>Un-tags old article, decrements tag reference count</li>
* <li>Removes old article-tag relations</li>
......@@ -789,7 +803,7 @@ public class ArticleMgmtService {
final List<JSONObject> oldTags = tagRepository.getByArticleId(oldArticleId);
final String tagsString = newArticle.getString(Article.ARTICLE_TAGS_REF);
String[] tagStrings = tagsString.split(",");
final List<JSONObject> newTags = new ArrayList<JSONObject>();
final List<JSONObject> newTags = new ArrayList<>();
for (int i = 0; i < tagStrings.length; i++) {
final String tagTitle = tagStrings[i].trim();
......@@ -802,9 +816,9 @@ public class ArticleMgmtService {
newTags.add(newTag);
}
final List<JSONObject> tagsDropped = new ArrayList<JSONObject>();
final List<JSONObject> tagsNeedToAdd = new ArrayList<JSONObject>();
final List<JSONObject> tagsUnchanged = new ArrayList<JSONObject>();
final List<JSONObject> tagsDropped = new ArrayList<>();
final List<JSONObject> tagsNeedToAdd = new ArrayList<>();
final List<JSONObject> tagsUnchanged = new ArrayList<>();
for (final JSONObject newTag : newTags) {
final String newTagTitle = newTag.getString(Tag.TAG_TITLE);
......@@ -872,7 +886,7 @@ public class ArticleMgmtService {
tagIdsDropped[i] = id;
}
removeTagArticleRelations(oldArticleId, 0 == tagIdsDropped.length ? new String[] {"l0y0l"} : tagIdsDropped);
removeTagArticleRelations(oldArticleId, 0 == tagIdsDropped.length ? new String[]{"l0y0l"} : tagIdsDropped);
tagStrings = new String[tagsNeedToAdd.size()];
for (int i = 0; i < tagStrings.length; i++) {
......@@ -888,7 +902,7 @@ public class ArticleMgmtService {
/**
* Removes tag-article relations by the specified article id and tag ids of the relations to be removed.
*
* <p>
* <p>
* Removes all relations if not specified the tag ids.
* </p>
......@@ -996,7 +1010,7 @@ public class ArticleMgmtService {
/**
* Removes article comments by the specified article id.
*
* <p>
* <p> Removes related comments, sets article/blog comment statistic count.
* </p>
*
......@@ -1021,36 +1035,16 @@ public class ArticleMgmtService {
}
}
/**
* Determines whether the specified tag title exists in the specified tags.
*
* @param tagTitle the specified tag title
* @param tags the specified tags
* @return {@code true} if it exists, {@code false} otherwise
* @throws JSONException json exception
*/
private static boolean tagExists(final String tagTitle, final List<JSONObject> tags) throws JSONException {
for (final JSONObject tag : tags) {
if (tag.getString(Tag.TAG_TITLE).equals(tagTitle)) {
return true;
}
}
return false;
}
/**
* Archive the create date with the specified article.
*
* @param article the specified article, for example,
* <pre>
* {
* ....,
* "oId": "",
* "articleCreateDate": java.util.Date,
* ....
* }
* </pre>
* @throws RepositoryException repository exception
*/
private void archiveDate(final JSONObject article) throws RepositoryException {
......@@ -1061,7 +1055,7 @@ public class ArticleMgmtService {
if (null == archiveDate) {
archiveDate = new JSONObject();
try {
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate(createDateString, new String[] {"yyyy/MM"}).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate(createDateString, new String[]{"yyyy/MM"}).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 0);
archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 0);
......@@ -1091,13 +1085,14 @@ public class ArticleMgmtService {
/**
* Fills 'auto' properties for the specified article and old article.
*
* <p> Some properties of an article are not been changed while article
* updating, these properties are called 'auto' properties. </p>
*
* <p> The property(named {@value
* org.b3log.solo.model.Article#ARTICLE_RANDOM_DOUBLE}) of the specified
* article will be regenerated. </p>
* <p>
* Some properties of an article are not been changed while article
* updating, these properties are called 'auto' properties.
* </p>
* <p>
* The property(named {@value org.b3log.solo.model.Article#ARTICLE_RANDOM_DOUBLE}) of the specified
* article will be regenerated.
* </p>
*
* @param oldArticle the specified old article
* @param article the specified article
......@@ -1116,8 +1111,7 @@ public class ArticleMgmtService {
}
/**
* Gets article permalink for adding article with the specified
* article.
* Gets article permalink for adding article with the specified article.
*
* @param article the specified article
* @return permalink
......@@ -1148,8 +1142,7 @@ public class ArticleMgmtService {
}
/**
* Gets article permalink for updating article with the specified
* old article, article, create date.
* Gets article permalink for updating article with the specified old article, article, create date.
*
* @param oldArticle the specified old article
* @param article the specified article
......@@ -1186,8 +1179,7 @@ public class ArticleMgmtService {
}
/**
* Decrements reference count of archive date of an published article
* specified by the given article id.
* Decrements reference count of archive date of an published article specified by the given article id.
*
* @param articleId the given article id
* @throws JSONException json exception
......@@ -1205,8 +1197,7 @@ public class ArticleMgmtService {
}
/**
* Increments reference count of archive date of an published article
* specified by the given article id.
* Increments reference count of archive date of an published article specified by the given article id.
*
* @param articleId the given article id
* @throws JSONException json exception
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment