Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion extras/injection/src/main/java/conf/portal/configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<type>org.exoplatform.forum.extras.injection.forum.CategoryInjector</type>
</component>

<component>
<component>
<type>org.exoplatform.forum.extras.injection.forum.ForumInjector</type>
</component>

Expand All @@ -54,6 +54,27 @@
<!-- Poll Data Injection Configuration -->

<!-- FAQ Data Injection Configuration -->
<component>
<type>org.exoplatform.forum.extras.injection.faq.CategoryInjector</type>
</component>
<component>
<type>org.exoplatform.forum.extras.injection.faq.AnswerInjector</type>
</component>
<component>
<type>org.exoplatform.forum.extras.injection.faq.ProfileInjector</type>
</component>
<component>
<type>org.exoplatform.forum.extras.injection.faq.QuestionInjector</type>
</component>
<component>
<type>org.exoplatform.forum.extras.injection.faq.CommentInjector</type>
</component>
<component>
<type>org.exoplatform.forum.extras.injection.faq.AttachmentInjector</type>
</component>
<component>
<type>org.exoplatform.forum.extras.injection.faq.MembershipInjector</type>
</component>

<component>
<type>org.exoplatform.services.bench.DataInjectorService</type>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.exoplatform.forum.extras.injection.faq;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import javax.jcr.Node;
Expand Down Expand Up @@ -295,7 +293,7 @@ public Question getQuestionByName(String questionName) throws Exception {
question.setQuestion(questionName);
question.setPath(quesNodePath.substring(quesNodePath.indexOf(KSDataLocation.Locations.FAQ_CATEGORIES_HOME)));
question.setTopicIdDiscuss(reader.string(FAQNodeTypes.EXO_TOPIC_ID_DISCUSS));
question.setUsersWatch(reader.strings(FAQNodeTypes.EXO_USER_WATCHING));
question.setUsersVote(reader.strings(FAQNodeTypes.EXO_USERS_VOTE));

return question;
}
Expand All @@ -315,6 +313,8 @@ public Answer getAnswerByName(String answerName) throws Exception {
PropertyReader reader = new PropertyReader(answerNode);
answer.setDateResponse(reader.date(FAQNodeTypes.EXO_DATE_RESPONSE));
answer.setId(reader.string(FAQNodeTypes.EXO_ID));
answer.setLanguage(reader.string(FAQNodeTypes.EXO_LANGUAGE));
answer.setUsersVoteAnswer(reader.strings(FAQNodeTypes.EXO_USERS_VOTE_ANSWER));

return answer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,36 @@ public class AnswerInjector extends AbstractFAQInjector {

@Override
public void inject(HashMap<String, String> params) throws Exception {
//
int number = param(params, NUMBER);
int fromQues = param(params, FROM_QUES);
int toQues = param(params, TO_QUES);
String questionPrefix = params.get(QUESTION_PREFIX);
String answerPrefix = params.get(ANSWER_PREFIX);
init(null, null, questionPrefix, answerPrefix, null, 0);

//
init(null, null, questionPrefix, answerPrefix, null, 0);

int q = fromQues;
for (;q <= toQues; q++) {

String questionName = questionBase + q;
Question question = getQuestionByName(questionName);
String questionName = null;
String answerName = null;
Question question = null;
Answer answer = null;

for (int i = fromQues;i <= toQues; i++) {
//
questionName = questionBase + i;
question = getQuestionByName(questionName);
if (question == null) {
getLog().info("Question name '" + questionName + "' is wrong. Aborting injection ..." );
return;
}

//
String answerName = null;
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++) {
//
answerName = answerName();

Answer answer = new Answer();
//
answer = new Answer();
answer.setFullName(answerName);
answer.setLanguage("English");
answer.setMarksVoteAnswer(0.0);
Expand All @@ -57,12 +62,13 @@ public void inject(HashMap<String, String> params) throws Exception {
answer.setResponseBy(question.getAuthor());
answer.setResponses(lorem.getParagraphs(1));

//
faqService.saveAnswer(question.getPath(), answer, true);
answerNumber++;

//
getLog().info("Answer '" + answerName + "' created by " + question.getAuthor());
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ public class AttachmentInjector extends AbstractFAQInjector {

@Override
public void inject(HashMap<String, String> params) throws Exception {
//
int number = param(params, NUMBER);
int fromQues = param(params, FROM_QUES);
int toQues = param(params, TO_QUES);

String questionPrefix = params.get(QUESTION_PREFIX);

//
init(null, null, questionPrefix, null, null, 0);

//
Expand All @@ -59,25 +57,30 @@ public void inject(HashMap<String, String> params) throws Exception {
return;
}

//
String questionName = null;
Question question = null;

for (int i = fromQues; i <= toQues; ++i) {
//
questionName = questionBase + i;
question = getQuestionByName(questionName);
if (question == null) {
getLog().info("Question name is '" + questionName + "' wrong. Aborting injection ..." );
return;
}

//
generateAttachments(question, QUESTION_PREFIX, number, byteSize);
faqService.saveQuestion(question, false, faqSetting);

//
getLog().info("Uploads " + number + " attachments into '" + questionName + "' with each attachment's " + byteSize + " byte(s)");
}
}

private void generateAttachments(Question question, String prefix, int number, int byteSize) throws Exception {
//
if (question.getAttachMent() == null || question.getAttachMent().size() == 0) {
question.setAttachMent(new ArrayList<FileAttachment>());
}
Expand All @@ -89,6 +92,7 @@ private void generateAttachments(Question question, String prefix, int number, i
FileAttachment att = null;

for (int i = 0; i < number; i++) {
//
attId = generateId(prefix + baseNumber, Utils.ATTACHMENT, byteSize, i);
att = new FileAttachment();
att.setId(attId);
Expand All @@ -99,6 +103,8 @@ private void generateAttachments(Question question, String prefix, int number, i
long fileSize = (long) byteSize * 1024;
att.setSize(fileSize);
question.getAttachMent().add(att);

//
baseNumber++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ public class CategoryInjector extends AbstractFAQInjector {

@Override
public void inject(HashMap<String, String> params) throws Exception {
//
int number = param(params, NUMBER);
String categoryPrefix = params.get(CATEGORY_PREFIX);
init(null, categoryPrefix, null, null, null, 0);


//
Category rootCategory = getCategoryRoot(true);
String categoryName = null;
Category cat = null;

for(int i = 0; i < number; i++) {
//
categoryName = categoryName();


//
cat = new Category();
cat.setIndex(i);
cat.setName(categoryName);
cat.setDescription(lorem.getParagraphs(1));
cat.setModerators(new String[] {""});
cat.setUserPrivate(new String[] {""});

//
faqService.saveCategory(rootCategory.getPath(), cat, true);
categoryNumber++;

//
getLog().info("Category '" + categoryName + "' created with parent is '" + rootCategory.getId() + "'");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,47 @@ public class CommentInjector extends AbstractFAQInjector {
/** . */
private static final String QUESTION_PREFIX = "quesPrefix";

/** . */
private static final String COMMENT_PREFIX = "commentPrefix";

@Override
public void inject(HashMap<String, String> params) throws Exception {
//
int number = param(params, NUMBER);
int to = param(params, TO_QUES);
int toQues = param(params, TO_QUES);
String questionPrefix = params.get(QUESTION_PREFIX);

//
init(null, null, questionPrefix, null, null, 0);
String commentPrefix = params.get(COMMENT_PREFIX);
init(null, null, questionPrefix, null, commentPrefix, 0);

//
String questionName = questionBase + to;
String questionName = questionBase + toQues;
Question question = getQuestionByName(questionName);
if (question == null) {
getLog().info("Question name '" + questionName + "' is wrong. Aborting injection ..." );
return;
}

//
String commentName = null;
Comment comment = null;

for (int i = 0; i <= number; i++) {
for (int i = 0; i < number; i++) {
//
commentName = commentName();

Comment comment = new Comment();

//
comment = new Comment();
comment.setCommentBy(question.getAuthor());
comment.setComments(lorem.getParagraphs(1));
comment.setFullName(commentName);
comment.setNew(true);
comment.setPostId("");

//
faqService.saveComment(question.getPath(), comment, true);
commentNumber++;

//
getLog().info("Comment '" + commentName + "' created by " + question.getAuthor());
}
}
Expand Down
Loading