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
d1850024
Unverified
Commit
d1850024
authored
Jan 28, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
#12633
parent
c2dc15dd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
85 deletions
+58
-85
src/main/java/org/b3log/solo/repository/TagArticleRepository.java
.../java/org/b3log/solo/repository/TagArticleRepository.java
+34
-0
src/main/java/org/b3log/solo/repository/TagRepository.java
src/main/java/org/b3log/solo/repository/TagRepository.java
+2
-27
src/main/java/org/b3log/solo/service/DataModelService.java
src/main/java/org/b3log/solo/service/DataModelService.java
+3
-3
src/test/java/org/b3log/solo/processor/console/RepairConsoleTestCase.java
...g/b3log/solo/processor/console/RepairConsoleTestCase.java
+0
-19
src/test/java/org/b3log/solo/repository/TagArticleRepositoryImplTestCase.java
...log/solo/repository/TagArticleRepositoryImplTestCase.java
+19
-11
src/test/java/org/b3log/solo/repository/TagRepositoryImplTestCase.java
.../org/b3log/solo/repository/TagRepositoryImplTestCase.java
+0
-25
No files found.
src/main/java/org/b3log/solo/repository/TagArticleRepository.java
View file @
d1850024
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
*/
*/
package
org
.
b3log
.
solo
.
repository
;
package
org
.
b3log
.
solo
.
repository
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.repository.*
;
import
org.b3log.latke.repository.*
;
...
@@ -26,6 +28,7 @@ import org.b3log.solo.model.Article;
...
@@ -26,6 +28,7 @@ import org.b3log.solo.model.Article;
import
org.b3log.solo.model.Tag
;
import
org.b3log.solo.model.Tag
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -50,6 +53,37 @@ public class TagArticleRepository extends AbstractRepository {
...
@@ -50,6 +53,37 @@ public class TagArticleRepository extends AbstractRepository {
super
(
Tag
.
TAG
+
"_"
+
Article
.
ARTICLE
);
super
(
Tag
.
TAG
+
"_"
+
Article
.
ARTICLE
);
}
}
/**
* Gets most used tags with the specified number.
*
* @param num the specified number
* @return a list of most used tags, returns an empty list if not found
* @throws RepositoryException repository exception
*/
public
List
<
JSONObject
>
getMostUsedTags
(
final
int
num
)
throws
RepositoryException
{
final
String
tableNamePrefix
=
StringUtils
.
isNotBlank
(
Latkes
.
getLocalProperty
(
"jdbc.tablePrefix"
))
?
Latkes
.
getLocalProperty
(
"jdbc.tablePrefix"
)
+
"_"
:
""
;
setDebug
(
true
);
final
List
<
JSONObject
>
records
=
select
(
"SELECT\n"
+
"\t`tag_oId`,\n"
+
"\tcount(*) AS cnt\n"
+
"FROM `"
+
tableNamePrefix
+
"tag_article`\n"
+
"GROUP BY\n"
+
"\t`tag_oId`\n"
+
"ORDER BY\n"
+
"\tcnt DESC\n"
+
"LIMIT ?"
,
num
);
final
List
<
JSONObject
>
ret
=
new
ArrayList
<>();
for
(
final
JSONObject
record
:
records
)
{
final
String
tagId
=
record
.
optString
(
Tag
.
TAG
+
"_"
+
Keys
.
OBJECT_ID
);
final
JSONObject
tag
=
get
(
tagId
);
ret
.
add
(
tag
);
}
return
ret
;
}
/**
/**
* Gets article count of a tag specified by the given tag id.
* Gets article count of a tag specified by the given tag id.
*
*
...
...
src/main/java/org/b3log/solo/repository/TagRepository.java
View file @
d1850024
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
*/
*/
package
org
.
b3log
.
solo
.
repository
;
package
org
.
b3log
.
solo
.
repository
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.ioc.Inject
;
import
org.b3log.latke.ioc.Inject
;
import
org.b3log.latke.repository.*
;
import
org.b3log.latke.repository.*
;
import
org.b3log.latke.repository.annotation.Repository
;
import
org.b3log.latke.repository.annotation.Repository
;
...
@@ -91,31 +93,4 @@ public class TagRepository extends AbstractRepository {
...
@@ -91,31 +93,4 @@ public class TagRepository extends AbstractRepository {
return
array
.
optJSONObject
(
0
);
return
array
.
optJSONObject
(
0
);
}
}
/**
* Gets most used tags with the specified number.
*
* @param num the specified number
* @return a list of most used tags, returns an empty list if not found
* @throws RepositoryException repository exception
*/
public
List
<
JSONObject
>
getMostUsedTags
(
final
int
num
)
throws
RepositoryException
{
final
List
<
JSONObject
>
records
=
select
(
"SELECT\n"
+
"\t`tag_oId`,\n"
+
"\tcount(*) AS cnt\n"
+
"FROM `"
+
getName
()
+
"`\n"
+
"GROUP BY\n"
+
"\ttag_oId\n"
+
"ORDER BY\n"
+
"\tcnt DESC\n"
+
"LIMIT ?"
,
num
);
final
List
<
JSONObject
>
ret
=
new
ArrayList
<>();
for
(
final
JSONObject
record
:
records
)
{
final
String
tagId
=
record
.
optString
(
Tag
.
TAG
+
"_"
+
Keys
.
OBJECT_ID
);
final
JSONObject
tag
=
get
(
tagId
);
ret
.
add
(
tag
);
}
return
ret
;
}
}
}
src/main/java/org/b3log/solo/service/DataModelService.java
View file @
d1850024
...
@@ -100,10 +100,10 @@ public class DataModelService {
...
@@ -100,10 +100,10 @@ public class DataModelService {
private
CategoryRepository
categoryRepository
;
private
CategoryRepository
categoryRepository
;
/**
/**
* Tag repository.
* Tag
-Article
repository.
*/
*/
@Inject
@Inject
private
Tag
Repository
tag
Repository
;
private
Tag
ArticleRepository
tagArticle
Repository
;
/**
/**
* Link repository.
* Link repository.
...
@@ -343,7 +343,7 @@ public class DataModelService {
...
@@ -343,7 +343,7 @@ public class DataModelService {
try
{
try
{
LOGGER
.
debug
(
"Filling most used tags...."
);
LOGGER
.
debug
(
"Filling most used tags...."
);
final
int
mostUsedTagDisplayCnt
=
preference
.
getInt
(
Option
.
ID_C_MOST_USED_TAG_DISPLAY_CNT
);
final
int
mostUsedTagDisplayCnt
=
preference
.
getInt
(
Option
.
ID_C_MOST_USED_TAG_DISPLAY_CNT
);
final
List
<
JSONObject
>
tags
=
tagRepository
.
getMostUsedTags
(
mostUsedTagDisplayCnt
);
final
List
<
JSONObject
>
tags
=
tag
Article
Repository
.
getMostUsedTags
(
mostUsedTagDisplayCnt
);
dataModel
.
put
(
Common
.
MOST_USED_TAGS
,
tags
);
dataModel
.
put
(
Common
.
MOST_USED_TAGS
,
tags
);
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Fills most used tags failed"
,
e
);
LOGGER
.
log
(
Level
.
ERROR
,
"Fills most used tags failed"
,
e
);
...
...
src/test/java/org/b3log/solo/processor/console/RepairConsoleTestCase.java
View file @
d1850024
...
@@ -62,23 +62,4 @@ public class RepairConsoleTestCase extends AbstractTestCase {
...
@@ -62,23 +62,4 @@ public class RepairConsoleTestCase extends AbstractTestCase {
final
String
content
=
response
.
body
();
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"Restore signs succeeded."
));
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"Restore signs succeeded."
));
}
}
/**
* repairTagArticleCounter.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"init"
)
public
void
repairTagArticleCounter
()
throws
Exception
{
final
MockHttpServletRequest
request
=
mockRequest
();
request
.
setRequestURI
(
"/fix/tag-article-counter-repair"
);
mockAdminLogin
(
request
);
final
MockHttpServletResponse
response
=
mockResponse
();
mockDispatcherServletService
(
request
,
response
);
final
String
content
=
response
.
body
();
Assert
.
assertTrue
(
StringUtils
.
contains
(
content
,
"Repair successfully!"
));
}
}
}
src/test/java/org/b3log/solo/repository/TagArticleRepositoryImplTestCase.java
View file @
d1850024
...
@@ -33,7 +33,7 @@ import java.util.List;
...
@@ -33,7 +33,7 @@ import java.util.List;
* {@link TagArticleRepository} test case.
* {@link TagArticleRepository} test case.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.
0.0.0, Dec 30, 2011
* @version 1.
1.0.0, Jan 28, 2019
*/
*/
@Test
(
suiteName
=
"repository"
)
@Test
(
suiteName
=
"repository"
)
public
class
TagArticleRepositoryImplTestCase
extends
AbstractTestCase
{
public
class
TagArticleRepositoryImplTestCase
extends
AbstractTestCase
{
...
@@ -48,7 +48,6 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
...
@@ -48,7 +48,6 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
final
TagArticleRepository
tagArticleRepository
=
getTagArticleRepository
();
final
TagArticleRepository
tagArticleRepository
=
getTagArticleRepository
();
final
JSONObject
tagArticle
=
new
JSONObject
();
final
JSONObject
tagArticle
=
new
JSONObject
();
tagArticle
.
put
(
Article
.
ARTICLE
+
"_"
+
Keys
.
OBJECT_ID
,
"article1 id"
);
tagArticle
.
put
(
Article
.
ARTICLE
+
"_"
+
Keys
.
OBJECT_ID
,
"article1 id"
);
tagArticle
.
put
(
Tag
.
TAG
+
"_"
+
Keys
.
OBJECT_ID
,
"tag1 id"
);
tagArticle
.
put
(
Tag
.
TAG
+
"_"
+
Keys
.
OBJECT_ID
,
"tag1 id"
);
...
@@ -64,11 +63,9 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
...
@@ -64,11 +63,9 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/
*/
@Test
(
dependsOnMethods
=
"add"
)
@Test
(
dependsOnMethods
=
"add"
)
public
void
getByArticleId
()
throws
Exception
{
public
void
getByArticleId
()
throws
Exception
{
final
TagArticleRepository
tagArticleRepository
final
TagArticleRepository
tagArticleRepository
=
getTagArticleRepository
();
=
getTagArticleRepository
();
final
List
<
JSONObject
>
tagArticle
final
List
<
JSONObject
>
tagArticle
=
tagArticleRepository
.
getByArticleId
(
"article1 id"
);
=
tagArticleRepository
.
getByArticleId
(
"article1 id"
);
Assert
.
assertNotNull
(
tagArticle
);
Assert
.
assertNotNull
(
tagArticle
);
Assert
.
assertEquals
(
0
,
tagArticleRepository
.
getByArticleId
(
""
).
size
());
Assert
.
assertEquals
(
0
,
tagArticleRepository
.
getByArticleId
(
""
).
size
());
...
@@ -81,12 +78,23 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
...
@@ -81,12 +78,23 @@ public class TagArticleRepositoryImplTestCase extends AbstractTestCase {
*/
*/
@Test
(
dependsOnMethods
=
"add"
)
@Test
(
dependsOnMethods
=
"add"
)
public
void
getByTagId
()
throws
Exception
{
public
void
getByTagId
()
throws
Exception
{
final
TagArticleRepository
tagArticleRepository
final
TagArticleRepository
tagArticleRepository
=
getTagArticleRepository
();
=
getTagArticleRepository
();
final
JSONArray
results
final
JSONArray
results
=
tagArticleRepository
.
getByTagId
(
"tag1 id"
,
1
,
Integer
.
MAX_VALUE
).
getJSONArray
(
Keys
.
RESULTS
);
=
tagArticleRepository
.
getByTagId
(
"tag1 id"
,
1
,
Integer
.
MAX_VALUE
).
getJSONArray
(
Keys
.
RESULTS
);
Assert
.
assertEquals
(
1
,
results
.
length
());
Assert
.
assertEquals
(
1
,
results
.
length
());
}
}
/**
* Get Most Used Tags.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"add"
)
public
void
getMostUsedTags
()
throws
Exception
{
final
TagArticleRepository
tagArticleRepository
=
getTagArticleRepository
();
final
List
<
JSONObject
>
mostUsedTags
=
tagArticleRepository
.
getMostUsedTags
(
3
);
Assert
.
assertNotNull
(
mostUsedTags
);
Assert
.
assertEquals
(
1
,
mostUsedTags
.
size
());
}
}
}
src/test/java/org/b3log/solo/repository/TagRepositoryImplTestCase.java
View file @
d1850024
...
@@ -71,31 +71,6 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
...
@@ -71,31 +71,6 @@ public class TagRepositoryImplTestCase extends AbstractTestCase {
Assert
.
assertNull
(
notFound
);
Assert
.
assertNull
(
notFound
);
}
}
/**
* Get Most Used Tags.
*
* @throws Exception exception
*/
@Test
(
dependsOnMethods
=
"add"
)
public
void
getMostUsedTags
()
throws
Exception
{
final
TagRepository
tagRepository
=
getTagRepository
();
final
JSONObject
tag
=
new
JSONObject
();
tag
.
put
(
Tag
.
TAG_TITLE
,
"tag title2"
);
final
Transaction
transaction
=
tagRepository
.
beginTransaction
();
tagRepository
.
add
(
tag
);
transaction
.
commit
();
List
<
JSONObject
>
mostUsedTags
=
tagRepository
.
getMostUsedTags
(
3
);
Assert
.
assertNotNull
(
mostUsedTags
);
Assert
.
assertEquals
(
2
,
mostUsedTags
.
size
());
mostUsedTags
=
tagRepository
.
getMostUsedTags
(
1
);
Assert
.
assertNotNull
(
mostUsedTags
);
Assert
.
assertEquals
(
1
,
mostUsedTags
.
size
());
}
/**
/**
* Get By ArticleId.
* Get By ArticleId.
*
*
...
...
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