(→AHPSCRIPTS-134)
|
(→Create a Folder and Append Name if One Already Exists)
|
Line 2315: | |||
BuildService.getInstance().runWorkflow(br);</pre> | BuildService.getInstance().runWorkflow(br);</pre> | ||
- | = Create a Folder and Append Name if One Already Exists = | ||
- | ==== AHPSCRIPTS-134 ==== | ||
- | <pre>import com.urbancode.anthill3.main.client.AnthillClient; | ||
- | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
- | import com.urbancode.anthill3.domain.folder.*; | ||
- | import com.urbancode.anthill3.domain.persistent.PersistenceException; | ||
- | //The following settings are for establishing a connection to the anthill server | ||
- | String serverHost = "localhost"; | ||
- | int serverPort = 4567; | ||
- | String userName = "admin"; | ||
- | String password = "admin"; | ||
- | //obtain connection to the Anthill server | ||
- | AnthillClient anthill = AnthillClient.connect(serverHost, serverPort, | ||
- | userName, password); | ||
- | // create a Unit of Work | ||
- | UnitOfWork uow = anthill.createUnitOfWork(); | ||
- | String fname = "ZNAME"; //Folder name to create | ||
- | String parent = "/"; //Parent folder | ||
- | String copy = " (New)"; | ||
- | boolean notdone = true; | ||
- | print("Now attempting to create a folder with name: " + fname); | ||
- | Thread.sleep(750); | ||
- | print(""); | ||
- | Folder parentFolder = FolderFactory.getInstance().restoreForName(parent); | ||
- | while (notdone == true) { | ||
- | if (FolderFactory.getInstance().restoreForName(fname) !=null) { | ||
- | print(FolderFactory.getInstance().restoreForName(fname) + " already exists!"); | ||
- | fname = fname+copy; | ||
- | } | ||
- | else notdone = false; | ||
- | } | ||
- | print("Folder with name '" + fname + " is being created . . ."); | ||
- | Folder creationFolder = new Folder(true); | ||
- | creationFolder.setName(fname); | ||
- | creationFolder.setParent(parentFolder); | ||
- | creationFolder.setActive(true); | ||
- | creationFolder.store(); | ||
- | Thread.sleep(400); | ||
- | try{ | ||
- | uow.commit(); | ||
- | print(FolderFactory.getInstance().restoreForName(fname) + " has been created."); | ||
- | uow.close(); | ||
- | } | ||
- | catch (Exception e){ | ||
- | print("Does the folder '" + fname + "' already exist under '" + parent + "'?\n\n"); | ||
- | print("---STACKTRACE BEGAN---"); | ||
- | e.printStackTrace(); | ||
- | print("---STACKTRACE ENDED---"); | ||
- | } | ||
- | //BMG</pre> | ||
= Find All Agents Online And Offline = | = Find All Agents Online And Offline = |