001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.beans.admin.content;
034:
035: import com.flexive.faces.messages.FxFacesMsgErr;
036: import com.flexive.faces.messages.FxFacesMsgInfo;
037: import com.flexive.faces.FxJsfUtils;
038: import com.flexive.shared.EJBLookup;
039: import com.flexive.shared.content.FxContent;
040: import com.flexive.shared.content.FxPK;
041: import com.flexive.shared.interfaces.ContentEngine;
042: import com.flexive.shared.interfaces.TreeEngine;
043: import com.flexive.shared.tree.FxTreeMode;
044: import com.flexive.shared.tree.FxTreeNode;
045: import com.flexive.shared.tree.FxTreeNodeEdit;
046: import org.apache.commons.lang.StringUtils;
047:
048: import java.util.Formatter;
049:
050: /**
051: * Test beans to generate randomized contents for testing.
052: *
053: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
054: * @version $Rev: 150 $
055: */
056: public class ContentGeneratorBean {
057: private long type = -1;
058: private int count = 100;
059: private int maxMultiplicity = 2;
060: private String treeFolder = "/Test Data";
061:
062: public String getParseRequestParameters() {
063: String action = FxJsfUtils.getParameter("action");
064: if (StringUtils.isBlank(action)) {
065: return null;
066: } else if ("setTypeId".equals(action)) {
067: type = FxJsfUtils.getLongParameter("typeId", -1);
068: }
069: return null;
070: }
071:
072: public String create() {
073: try {
074: final ContentEngine contentEngine = EJBLookup
075: .getContentEngine();
076: final TreeEngine treeEngine = EJBLookup.getTreeEngine();
077: final FxTreeNode folder;
078: if (StringUtils.isNotBlank(treeFolder)) {
079: treeFolder = (treeFolder.startsWith("/") ? treeFolder
080: : "/" + treeFolder).trim();
081: final long[] nodes = treeEngine.createNodes(
082: FxTreeMode.Edit, FxTreeNode.ROOT_NODE, 0,
083: treeFolder);
084: folder = treeEngine.getNode(FxTreeMode.Edit,
085: nodes[nodes.length - 1]);
086: } else {
087: folder = null;
088: }
089: final long startTime = System.currentTimeMillis();
090: long initializeTime = 0;
091: long randomizeTime = 0;
092: long saveTime = 0;
093: long treeTime = 0;
094: for (int i = 0; i < count; i++) {
095: long start = System.currentTimeMillis();
096: final FxContent co = contentEngine.initialize(type);
097: initializeTime += System.currentTimeMillis() - start;
098: start = System.currentTimeMillis();
099: co.randomize(maxMultiplicity);
100: randomizeTime += System.currentTimeMillis() - start;
101: start = System.currentTimeMillis();
102: final FxPK pk = contentEngine.save(co);
103: saveTime += System.currentTimeMillis() - start;
104: if (folder != null) {
105: start = System.currentTimeMillis();
106: treeEngine.save(FxTreeNodeEdit.createNewChildNode(
107: folder).setReference(pk));
108: treeTime += System.currentTimeMillis() - start;
109: }
110: }
111: final long totalTime = System.currentTimeMillis()
112: - startTime;
113: new FxFacesMsgInfo("Content.nfo.testData.created", count,
114: totalTime, initializeTime, 100 * initializeTime
115: / totalTime, randomizeTime, 100
116: * randomizeTime / totalTime, saveTime, 100
117: * saveTime / totalTime, new Formatter()
118: .format("%.2f", count / (double) totalTime
119: * 1000), treeTime, 100 * treeTime
120: / totalTime).addToContext();
121: } catch (Exception e) {
122: new FxFacesMsgErr(e).addToContext();
123: }
124: return "contentTestData";
125: }
126:
127: public int getCount() {
128: return count;
129: }
130:
131: public void setCount(int count) {
132: this .count = count;
133: }
134:
135: public long getType() {
136: return type;
137: }
138:
139: public void setType(long type) {
140: this .type = type;
141: }
142:
143: public int getMaxMultiplicity() {
144: return maxMultiplicity;
145: }
146:
147: public void setMaxMultiplicity(int maxMultiplicity) {
148: this .maxMultiplicity = maxMultiplicity;
149: }
150:
151: public String getTreeFolder() {
152: return treeFolder;
153: }
154:
155: public void setTreeFolder(String treeFolder) {
156: this.treeFolder = treeFolder;
157: }
158: }
|