Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
2cde50ff
Commit
2cde50ff
authored
Jun 25, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
clean code
parent
8579f4ef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
133 deletions
+124
-133
src/main/java/org/b3log/solo/service/ArticleMgmtService.java
src/main/java/org/b3log/solo/service/ArticleMgmtService.java
+124
-133
No files found.
src/main/java/org/b3log/solo/service/ArticleMgmtService.java
View file @
2cde50ff
...
@@ -54,7 +54,7 @@ import static org.b3log.solo.model.Article.*;
...
@@ -54,7 +54,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service.
* Article management service.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @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
* @since 0.3.5
*/
*/
@Service
@Service
...
@@ -63,7 +63,7 @@ public class ArticleMgmtService {
...
@@ -63,7 +63,7 @@ public class ArticleMgmtService {
/**
/**
* Logger.
* Logger.
*/
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ArticleMgmtService
.
class
.
getName
()
);
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ArticleMgmtService
.
class
);
/**
/**
* Article query service.
* Article query service.
...
@@ -155,6 +155,24 @@ public class ArticleMgmtService {
...
@@ -155,6 +155,24 @@ public class ArticleMgmtService {
@Inject
@Inject
private
TagMgmtService
tagMgmtService
;
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.
* Article comment count +1 for an article specified by the given article id.
*
*
...
@@ -245,7 +263,6 @@ public class ArticleMgmtService {
...
@@ -245,7 +263,6 @@ public class ArticleMgmtService {
* Updates an article by the specified request json object.
* Updates an article by the specified request json object.
*
*
* @param requestJSONObject the specified request json object, for example,
* @param requestJSONObject the specified request json object, for example,
* <pre>
* {
* {
* "article": {
* "article": {
* "oId": "",
* "oId": "",
...
@@ -261,7 +278,6 @@ public class ArticleMgmtService {
...
@@ -261,7 +278,6 @@ public class ArticleMgmtService {
* "articleEditorType": "" // optional, preference specified if not exists this key
* "articleEditorType": "" // optional, preference specified if not exists this key
* }
* }
* }
* }
* </pre>
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
public
void
updateArticle
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
public
void
updateArticle
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
...
@@ -361,7 +377,7 @@ public class ArticleMgmtService {
...
@@ -361,7 +377,7 @@ public class ArticleMgmtService {
eventData
.
put
(
ARTICLE
,
article
);
eventData
.
put
(
ARTICLE
,
article
);
eventData
.
put
(
Keys
.
RESULTS
,
ret
);
eventData
.
put
(
Keys
.
RESULTS
,
ret
);
try
{
try
{
eventManager
.
fireEventSynchronously
(
new
Event
<
JSONObject
>(
EventTypes
.
ADD_ARTICLE
,
eventData
));
eventManager
.
fireEventSynchronously
(
new
Event
<>(
EventTypes
.
ADD_ARTICLE
,
eventData
));
}
catch
(
final
EventException
e
)
{
}
catch
(
final
EventException
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
}
}
...
@@ -372,7 +388,7 @@ public class ArticleMgmtService {
...
@@ -372,7 +388,7 @@ public class ArticleMgmtService {
eventData
.
put
(
ARTICLE
,
article
);
eventData
.
put
(
ARTICLE
,
article
);
eventData
.
put
(
Keys
.
RESULTS
,
ret
);
eventData
.
put
(
Keys
.
RESULTS
,
ret
);
try
{
try
{
eventManager
.
fireEventSynchronously
(
new
Event
<
JSONObject
>(
EventTypes
.
UPDATE_ARTICLE
,
eventData
));
eventManager
.
fireEventSynchronously
(
new
Event
<>(
EventTypes
.
UPDATE_ARTICLE
,
eventData
));
}
catch
(
final
EventException
e
)
{
}
catch
(
final
EventException
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
}
}
...
@@ -402,7 +418,6 @@ public class ArticleMgmtService {
...
@@ -402,7 +418,6 @@ public class ArticleMgmtService {
* Adds an article from the specified request json object.
* Adds an article from the specified request json object.
*
*
* @param requestJSONObject the specified request json object, for example,
* @param requestJSONObject the specified request json object, for example,
* <pre>
* {
* {
* "article": {
* "article": {
* "articleAuthorEmail": "",
* "articleAuthorEmail": "",
...
@@ -420,7 +435,6 @@ public class ArticleMgmtService {
...
@@ -420,7 +435,6 @@ public class ArticleMgmtService {
* "oId": "" // optional, generate it if not exists this key
* "oId": "" // optional, generate it if not exists this key
* }
* }
* }
* }
* </pre>
* @return generated article id
* @return generated article id
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
...
@@ -534,7 +548,7 @@ public class ArticleMgmtService {
...
@@ -534,7 +548,7 @@ public class ArticleMgmtService {
final
JSONObject
eventData
=
new
JSONObject
();
final
JSONObject
eventData
=
new
JSONObject
();
eventData
.
put
(
Article
.
ARTICLE
,
article
);
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
);
article
.
remove
(
Common
.
POST_TO_COMMUNITY
);
...
@@ -773,7 +787,7 @@ public class ArticleMgmtService {
...
@@ -773,7 +787,7 @@ public class ArticleMgmtService {
/**
/**
* Processes tags for article update.
* Processes tags for article update.
*
*
<p>
* <ul>
* <ul>
* <li>Un-tags old article, decrements tag reference count</li>
* <li>Un-tags old article, decrements tag reference count</li>
* <li>Removes old article-tag relations</li>
* <li>Removes old article-tag relations</li>
...
@@ -789,7 +803,7 @@ public class ArticleMgmtService {
...
@@ -789,7 +803,7 @@ public class ArticleMgmtService {
final
List
<
JSONObject
>
oldTags
=
tagRepository
.
getByArticleId
(
oldArticleId
);
final
List
<
JSONObject
>
oldTags
=
tagRepository
.
getByArticleId
(
oldArticleId
);
final
String
tagsString
=
newArticle
.
getString
(
Article
.
ARTICLE_TAGS_REF
);
final
String
tagsString
=
newArticle
.
getString
(
Article
.
ARTICLE_TAGS_REF
);
String
[]
tagStrings
=
tagsString
.
split
(
","
);
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
++)
{
for
(
int
i
=
0
;
i
<
tagStrings
.
length
;
i
++)
{
final
String
tagTitle
=
tagStrings
[
i
].
trim
();
final
String
tagTitle
=
tagStrings
[
i
].
trim
();
...
@@ -802,9 +816,9 @@ public class ArticleMgmtService {
...
@@ -802,9 +816,9 @@ public class ArticleMgmtService {
newTags
.
add
(
newTag
);
newTags
.
add
(
newTag
);
}
}
final
List
<
JSONObject
>
tagsDropped
=
new
ArrayList
<
JSONObject
>();
final
List
<
JSONObject
>
tagsDropped
=
new
ArrayList
<>();
final
List
<
JSONObject
>
tagsNeedToAdd
=
new
ArrayList
<
JSONObject
>();
final
List
<
JSONObject
>
tagsNeedToAdd
=
new
ArrayList
<>();
final
List
<
JSONObject
>
tagsUnchanged
=
new
ArrayList
<
JSONObject
>();
final
List
<
JSONObject
>
tagsUnchanged
=
new
ArrayList
<>();
for
(
final
JSONObject
newTag
:
newTags
)
{
for
(
final
JSONObject
newTag
:
newTags
)
{
final
String
newTagTitle
=
newTag
.
getString
(
Tag
.
TAG_TITLE
);
final
String
newTagTitle
=
newTag
.
getString
(
Tag
.
TAG_TITLE
);
...
@@ -872,7 +886,7 @@ public class ArticleMgmtService {
...
@@ -872,7 +886,7 @@ public class ArticleMgmtService {
tagIdsDropped
[
i
]
=
id
;
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
()];
tagStrings
=
new
String
[
tagsNeedToAdd
.
size
()];
for
(
int
i
=
0
;
i
<
tagStrings
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
tagStrings
.
length
;
i
++)
{
...
@@ -888,7 +902,7 @@ public class ArticleMgmtService {
...
@@ -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.
* Removes tag-article relations by the specified article id and tag ids of the relations to be removed.
*
*
<p>
* <p>
* <p>
* Removes all relations if not specified the tag ids.
* Removes all relations if not specified the tag ids.
* </p>
* </p>
...
@@ -996,7 +1010,7 @@ public class ArticleMgmtService {
...
@@ -996,7 +1010,7 @@ public class ArticleMgmtService {
/**
/**
* Removes article comments by the specified article id.
* Removes article comments by the specified article id.
*
*
<p>
* <p> Removes related comments, sets article/blog comment statistic count.
* <p> Removes related comments, sets article/blog comment statistic count.
* </p>
* </p>
*
*
...
@@ -1021,36 +1035,16 @@ public class ArticleMgmtService {
...
@@ -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.
* Archive the create date with the specified article.
*
*
* @param article the specified article, for example,
* @param article the specified article, for example,
* <pre>
* {
* {
* ....,
* ....,
* "oId": "",
* "oId": "",
* "articleCreateDate": java.util.Date,
* "articleCreateDate": java.util.Date,
* ....
* ....
* }
* }
* </pre>
* @throws RepositoryException repository exception
* @throws RepositoryException repository exception
*/
*/
private
void
archiveDate
(
final
JSONObject
article
)
throws
RepositoryException
{
private
void
archiveDate
(
final
JSONObject
article
)
throws
RepositoryException
{
...
@@ -1061,7 +1055,7 @@ public class ArticleMgmtService {
...
@@ -1061,7 +1055,7 @@ public class ArticleMgmtService {
if
(
null
==
archiveDate
)
{
if
(
null
==
archiveDate
)
{
archiveDate
=
new
JSONObject
();
archiveDate
=
new
JSONObject
();
try
{
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_ARTICLE_COUNT
,
0
);
archiveDate
.
put
(
ArchiveDate
.
ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT
,
0
);
archiveDate
.
put
(
ArchiveDate
.
ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT
,
0
);
...
@@ -1091,13 +1085,14 @@ public class ArticleMgmtService {
...
@@ -1091,13 +1085,14 @@ public class ArticleMgmtService {
/**
/**
* Fills 'auto' properties for the specified article and old article.
* Fills 'auto' properties for the specified article and old article.
*
* <p>
* <p> Some properties of an article are not been changed while article
* Some properties of an article are not been changed while article
* updating, these properties are called 'auto' properties. </p>
* updating, these properties are called 'auto' properties.
*
* </p>
* <p> The property(named {@value
* <p>
* org.b3log.solo.model.Article#ARTICLE_RANDOM_DOUBLE}) of the specified
* The property(named {@value org.b3log.solo.model.Article#ARTICLE_RANDOM_DOUBLE}) of the specified
* article will be regenerated. </p>
* article will be regenerated.
* </p>
*
*
* @param oldArticle the specified old article
* @param oldArticle the specified old article
* @param article the specified article
* @param article the specified article
...
@@ -1116,8 +1111,7 @@ public class ArticleMgmtService {
...
@@ -1116,8 +1111,7 @@ public class ArticleMgmtService {
}
}
/**
/**
* Gets article permalink for adding article with the specified
* Gets article permalink for adding article with the specified article.
* article.
*
*
* @param article the specified article
* @param article the specified article
* @return permalink
* @return permalink
...
@@ -1148,8 +1142,7 @@ public class ArticleMgmtService {
...
@@ -1148,8 +1142,7 @@ public class ArticleMgmtService {
}
}
/**
/**
* Gets article permalink for updating article with the specified
* Gets article permalink for updating article with the specified old article, article, create date.
* old article, article, create date.
*
*
* @param oldArticle the specified old article
* @param oldArticle the specified old article
* @param article the specified article
* @param article the specified article
...
@@ -1186,8 +1179,7 @@ public class ArticleMgmtService {
...
@@ -1186,8 +1179,7 @@ public class ArticleMgmtService {
}
}
/**
/**
* Decrements reference count of archive date of an published article
* Decrements reference count of archive date of an published article specified by the given article id.
* specified by the given article id.
*
*
* @param articleId the given article id
* @param articleId the given article id
* @throws JSONException json exception
* @throws JSONException json exception
...
@@ -1205,8 +1197,7 @@ public class ArticleMgmtService {
...
@@ -1205,8 +1197,7 @@ public class ArticleMgmtService {
}
}
/**
/**
* Increments reference count of archive date of an published article
* Increments reference count of archive date of an published article specified by the given article id.
* specified by the given article id.
*
*
* @param articleId the given article id
* @param articleId the given article id
* @throws JSONException json exception
* @throws JSONException json exception
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment