use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.
the class FileFolderPerformanceTester method run.
private static void run(final ApplicationContext ctx, String... args) throws Throwable {
ArgumentHelper argHelper = new ArgumentHelper(getUsage(), args);
final int fileCount = argHelper.getIntegerValue("files", true, 1, 10000);
final String folderRefStr = argHelper.getStringValue("folder", false, true);
final int threadCount = argHelper.getIntegerValue("threads", false, 1, 100);
final NodeRef selectedFolderNodeRef = folderRefStr == null ? null : new NodeRef(folderRefStr);
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
final MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
final PermissionService permissionService = serviceRegistry.getPermissionService();
final NodeService nodeService = serviceRegistry.getNodeService();
final SearchService searchService = serviceRegistry.getSearchService();
final TransactionService transactionService = serviceRegistry.getTransactionService();
final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
RunAsWork<String> createUserRunAs = new RunAsWork<String>() {
public String doWork() throws Exception {
String user = GUID.generate();
authenticationService.createAuthentication(user, user.toCharArray());
return user;
}
};
final String user = AuthenticationUtil.runAs(createUserRunAs, AuthenticationUtil.getSystemUserName());
// Create the files
final RetryingTransactionCallback<NodeRef> createCallback = new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
AuthenticationUtil.pushAuthentication();
DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
M2Model model = M2Model.createModel("tempModel");
model.createNamespace("test", "t");
model.createNamespace("testx", "");
for (int m = 0; m < 30; m++) {
model.createAspect("t:aspect_" + m);
}
dictionaryDao.putModel(model);
NodeRef folderNodeRef = null;
try {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
if (selectedFolderNodeRef == null) {
// find the guest folder
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet rs = searchService.query(storeRef, SearchService.LANGUAGE_XPATH, "/app:company_home");
try {
if (rs.length() == 0) {
throw new AlfrescoRuntimeException("Didn't find Company Home");
}
NodeRef companyHomeNodeRef = rs.getNodeRef(0);
folderNodeRef = fileFolderService.create(companyHomeNodeRef, "TOP_FOLDER_" + System.currentTimeMillis(), ContentModel.TYPE_FOLDER).getNodeRef();
System.out.println("Created folder " + folderNodeRef + " with user " + user);
} finally {
rs.close();
}
// Grant permissions
permissionService.setPermission(folderNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
} else {
folderNodeRef = selectedFolderNodeRef;
// Grant permissions
permissionService.setPermission(folderNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
System.out.println("Reusing folder " + folderNodeRef + " with user " + user);
}
} finally {
AuthenticationUtil.popAuthentication();
}
if (selectedFolderNodeRef == null) {
List<String> largeCollection = new ArrayList<String>(1000);
for (int i = 0; i < 50; i++) {
largeCollection.add(String.format("Large-collection-value-%05d", i));
}
// Create the files
for (int i = 0; i < fileCount; i++) {
FileInfo fileInfo = fileFolderService.create(folderNodeRef, String.format("FILE-%4d", i), ContentModel.TYPE_CONTENT);
NodeRef nodeRef = fileInfo.getNodeRef();
nodeService.setProperty(nodeRef, QName.createQName("{test}mv"), (Serializable) largeCollection);
for (int m = 0; m < 30; m++) {
nodeService.addAspect(nodeRef, QName.createQName("{test}aspect_" + m), null);
}
// write the content
ContentWriter writer = fileFolderService.getWriter(nodeRef);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent("Some small text data");
}
System.out.println("Created " + fileCount + " files in folder " + folderNodeRef);
}
// Done
return folderNodeRef;
}
};
RunAsWork<NodeRef> createRunAs = new RunAsWork<NodeRef>() {
public NodeRef doWork() throws Exception {
return transactionService.getRetryingTransactionHelper().doInTransaction(createCallback);
}
};
final NodeRef folderNodeRef = AuthenticationUtil.runAs(createRunAs, user);
// Now wait for some input before commencing the read run
System.out.print("Hit any key to commence directory listing ...");
System.in.read();
final RunAsWork<List<FileInfo>> readRunAs = new RunAsWork<List<FileInfo>>() {
public List<FileInfo> doWork() throws Exception {
return fileFolderService.list(folderNodeRef);
}
};
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
Thread readThread = new Thread("FolderList-" + i) {
int iteration = 0;
public void run() {
while (++iteration <= 2) {
runImpl();
}
}
private void runImpl() {
String threadName = Thread.currentThread().getName();
long start = System.currentTimeMillis();
List<FileInfo> nodeRefs = AuthenticationUtil.runAs(readRunAs, user);
long time = System.currentTimeMillis() - start;
double average = (double) time / (double) (fileCount);
// Make sure that we have the correct number of entries
if (folderRefStr != null && nodeRefs.size() != fileCount) {
System.err.println("WARNING: Thread " + threadName + " got " + nodeRefs.size() + " but expected " + fileCount);
}
System.out.print("\n" + "Thread " + threadName + ": \n" + " Read " + String.format("%4d", fileCount) + " files \n" + " Average: " + String.format("%10.2f", average) + " ms per file \n" + " Average: " + String.format("%10.2f", 1000.0 / average) + " files per second");
}
};
readThread.start();
threads[i] = readThread;
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
}
use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.
the class ArchiveAndRestoreTest method setUp.
@Override
public void setUp() throws Exception {
ctx = ApplicationContextHelper.getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
nodeService = serviceRegistry.getNodeService();
permissionService = serviceRegistry.getPermissionService();
authenticationService = serviceRegistry.getAuthenticationService();
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
ownableService = (OwnableService) ctx.getBean("ownableService");
transactionService = serviceRegistry.getTransactionService();
DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
ClassLoader cl = ArchiveAndRestoreTest.class.getClassLoader();
// load the test model
InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/archive/archiveTest_model.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
// Start a transaction
txn = transactionService.getUserTransaction();
txn.begin();
// downgrade integrity checks
IntegrityChecker.setWarnInTransaction();
try {
authenticationComponent.setSystemUserAsCurrentUser();
// Create the work store
workStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
workStoreRootNodeRef = nodeService.getRootNode(workStoreRef);
archiveStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "archive" + getName() + System.currentTimeMillis());
archiveStoreRootNodeRef = nodeService.getRootNode(archiveStoreRef);
// Map the work store to the archive store. This will already be wired into the NodeService.
StoreArchiveMap archiveMap = (StoreArchiveMap) ctx.getBean("storeArchiveMap");
archiveMap.put(workStoreRef, archiveStoreRef);
TestWithUserUtils.createUser(USER_A, USER_A, workStoreRootNodeRef, nodeService, authenticationService);
TestWithUserUtils.createUser(USER_B, USER_B, workStoreRootNodeRef, nodeService, authenticationService);
TestWithUserUtils.createUser(USER_C, USER_C, workStoreRootNodeRef, nodeService, authenticationService);
// grant A and B rights to the work store
permissionService.setPermission(workStoreRootNodeRef, USER_A, PermissionService.ALL_PERMISSIONS, true);
permissionService.setPermission(workStoreRootNodeRef, USER_B, PermissionService.ALL_PERMISSIONS, true);
permissionService.setPermission(workStoreRootNodeRef, USER_C, PermissionService.ALL_PERMISSIONS, false);
} finally {
authenticationComponent.clearCurrentSecurityContext();
}
// authenticate as normal user
authenticationService.authenticate(USER_A, USER_A.toCharArray());
createNodeStructure();
}
use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.
the class PerformanceNodeServiceTest method loadModel.
/**
* Loads the test model required for building the node graphs
*/
public static DictionaryService loadModel(ApplicationContext applicationContext) {
DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
// load the system model
ClassLoader cl = PerformanceNodeServiceTest.class.getClassLoader();
InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
// load the test model
modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
assertNotNull(modelStream);
model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
DictionaryComponent dictionary = new DictionaryComponent();
dictionary.setDictionaryDAO(dictionaryDao);
return dictionary;
}
use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.
the class DbNodeServiceImplPropagationTest method loadModel.
/**
* Loads the test model required for building the node graphs
*/
public static DictionaryService loadModel(ApplicationContext applicationContext) {
DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
// load the system model
ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
// load the test model
modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
assertNotNull(modelStream);
model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
DictionaryComponent dictionary = new DictionaryComponent();
dictionary.setDictionaryDAO(dictionaryDao);
// done
return dictionary;
}
use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.
the class DbNodeServiceImplPropagationTest method before.
@Before
public void before() throws Exception {
txnService = (TransactionService) applicationContext.getBean("transactionComponent");
nodeDAO = (NodeDAO) applicationContext.getBean("nodeDAO");
dialect = (Dialect) applicationContext.getBean("dialect");
nodeService = (NodeService) applicationContext.getBean("dbNodeService");
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
// load the system model
ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
// load the test model
modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
assertNotNull(modelStream);
model = M2Model.createModel(modelStream);
dictionaryDao.putModel(model);
DictionaryComponent dictionary = new DictionaryComponent();
dictionary.setDictionaryDAO(dictionaryDao);
dictionaryService = loadModel(applicationContext);
restartAuditableTxn();
}
Aggregations