import com.liferay.portal.kernel.service.* import com.liferay.portal.kernel.util.*; import com.liferay.journal.model.*; import com.liferay.journal.service.*; import com.liferay.dynamic.data.mapping.model.*; import com.liferay.dynamic.data.mapping.service.*; import java.util.*; import java.text.*; import org.apache.commons.lang.*; Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmssSS"); String strDate = sdf.format(cal.getTime()); String NAME="WC_Creation_Script"; String webcontentName=NAME+"_"+strDate; String dummyText=RandomStringUtils.randomAlphanumeric(1000); int NUM_ARTICLES=10; int NUM_VERSIONS=5; int GROUPID=3D20181; String LOCALE = "en_US"; /* Set StructureKey and correct XML in order to create a webcontent with a Structure. Template will be retrieved from structure */ String DDMSTRUCTUREKEY=BASIC-WEB-CONTENT; String CONTENT=""; ServiceContext sc = new ServiceContext(); sc.setUserId(Long.parseLong(userInfo.get("liferay.user.id"))); sc.setScopeGroupId(GROUPID); ServiceContextThreadLocal.pushServiceContext(sc); String ddmStructureKey = null; String ddmTemplatesKey = null; DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(GROUPID, PortalUtil.getClassNameId(JournalArticle.class), DDMSTRUCTUREKEY, true); if(ddmStructure == null) { out.println('ERROR Structure ' + DDMSTRUCTUREKEY + ' does not exists'); System.out.println('ERROR Structure ' + DDMSTRUCTUREKEY + ' does not exists'); return; } else { ddmStructureKey = ddmStructure.getStructureKey(); List ddmTemplates = ddmStructure.getTemplates(); if(ddmTemplates == null || ddmTemplates.isEmpty()) { out.println('ERROR Structure ' + ddmStructureKey + ' has no asociated templates'); System.out.println('ERROR Structure ' + ddmStructureKey + ' has no asociated templates'); return; } DDMTemplate ddmTemplate = ddmTemplates.get(0); if(ddmTemplate != null) { ddmTemplatesKey = ddmTemplate.getTemplateKey(); } } for (int j = 0; j < NUM_ARTICLES; j++) { Map titleMap = new HashMap(); titleMap.put(LocaleUtil.getSiteDefault(), webcontentName+"_"+j); titleMap.put(LocaleUtil.ENGLISH, webcontentName+"_"+j); JournalArticle article = JournalArticleLocalServiceUtil.addArticle( sc.getUserId(), sc.getScopeGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, 0, StringPool.BLANK, true, JournalArticleConstants.VERSION_DEFAULT, titleMap, titleMap, CONTENT, ddmStructureKey, ddmTemplatesKey, null, 1, 1, 1965, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, null, null, null, null, sc); out.println('Created article: ' + article.getArticleId()); System.out.println('Created article: ' + article.getArticleId()); long start = System.currentTimeMillis(); long end = start; for (int i = 0; i < NUM_VERSIONS; i++) { long it_start = System.currentTimeMillis(); article = JournalArticleLocalServiceUtil.updateArticle( sc.getUserId(), article.getGroupId(), article.getFolderId(), article.getArticleId(), article.getVersion(), article.getContent(), sc); end = System.currentTimeMillis(); System.out.println('It: '+i+' - Created article version: ' + article.getVersion() + ' Id: '+article.getId()+ ' time: '+(end-it_start)/1000); } out.println(NUM_VERSIONS+' versions created - spend time: '+(end-start)/1000); System.out.println(NUM_VERSIONS+' versions created - spend time: '+(end-start)/1000); }