/** * Copy a package to the target name. */ public String copyModule(String sourceModuleName, String destModuleName) { ModuleItem source = loadModule(sourceModuleName); try { String destPath = source.getNode().getParent().getPath() + "/" + destModuleName; if (this.getAreaNode(MODULE_AREA).hasNode(destModuleName)) { throw new RulesRepositoryException("Destination already exists."); } this.session.getWorkspace().copy(source.getNode().getPath(), destPath); ModuleItem newModuleItem = loadModule(destModuleName); newModuleItem.updateTitle(destModuleName); for (Iterator iter = newModuleItem.getAssets(); iter.hasNext(); ) { AssetItem as = (AssetItem) iter.next(); as.updateStringProperty(destModuleName, AssetItem.MODULE_NAME_PROPERTY); } save(); return newModuleItem.getUUID(); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * Copy a package to the target name. */ public String copyModule(String sourceModuleName, String destModuleName) { ModuleItem source = loadModule(sourceModuleName); try { String destPath = source.getNode().getParent().getPath() + "/" + destModuleName; if (this.getAreaNode(MODULE_AREA).hasNode(destModuleName)) { throw new RulesRepositoryException("Destination already exists."); } this.session.getWorkspace().copy(source.getNode().getPath(), destPath); ModuleItem newModuleItem = loadModule(destModuleName); newModuleItem.updateTitle(destModuleName); for (Iterator iter = newModuleItem.getAssets(); iter.hasNext(); ) { AssetItem as = (AssetItem) iter.next(); as.updateStringProperty(destModuleName, AssetItem.MODULE_NAME_PROPERTY); } save(); return newModuleItem.getUUID(); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * This is showing how to copy a package with standard JCR */ @Test public void testPackageCopy() throws Exception { RulesRepository repo = getRepo(); ModuleItem pkg = repo.createModule( "testPackageCopy", "this is something" ); AssetItem it1 = pkg.addAsset( "testPackageCopy1", "la" ); AssetItem it2 = pkg.addAsset( "testPackageCopy2", "la" ); it1.updateContent( "new content" ); it2.updateContent( "more content" ); it1.checkin( "c" ); it2.checkin( "c" ); it1 = pkg.loadAsset( "testPackageCopy1" ); List hist1 = iteratorToList( it1.getHistory() ); System.out.println(hist1.size()); repo.getSession().getWorkspace().copy( pkg.getNode().getPath(), pkg.getNode().getPath() + "_"); ModuleItem pkg2 = repo.loadModule( "testPackageCopy_" ); assertNotNull(pkg2); assertEquals(2, iteratorToList( pkg2.getAssets() ).size() ); AssetItem it1_ = pkg2.loadAsset( "testPackageCopy1" ); it1.updateContent( "new content2" ); it1.checkin( "la" ); it1_ = pkg2.loadAsset( "testPackageCopy1" ); assertEquals("new content", it1_.getContent()); }
@Test public void testAssetItemCreation() throws Exception { Calendar now = Calendar.getInstance(); Thread.sleep(500); //MN: need this sleep to get the correct date AssetItem ruleItem1 = getDefaultPackage().addAsset("testRuleItem", "test content"); assertNotNull(ruleItem1); assertNotNull(ruleItem1.getNode()); assertEquals("testRuleItem", ruleItem1.getName()); assertNotNull(ruleItem1.getCreatedDate()); assertTrue(now.before( ruleItem1.getCreatedDate() )); String packName = getDefaultPackage().getName(); assertEquals(packName, ruleItem1.getModuleName()); assertNotNull(ruleItem1.getUUID()); //try constructing with node of wrong type try { ModuleItem pitem = getRepo().loadDefaultModule(); new AssetItem(getRepo(), pitem.getNode()); fail("Exception not thrown for node of wrong type"); } catch(RulesRepositoryException e) { assertNotNull(e.getMessage()); } catch(Exception e) { fail("Caught unexpected exception: " + e); } }
@Test public void testLoadRulePackageItemByUUID() throws Exception { ModuleItem rulePackageItem = getRepo().createModule("testLoadRuleRuleItemByUUID", "desc"); String uuid = null; uuid = rulePackageItem.getNode().getUUID(); rulePackageItem = getRepo().loadModuleByUUID(uuid); assertNotNull(rulePackageItem); assertEquals("testLoadRuleRuleItemByUUID", rulePackageItem.getName()); // try loading rule package that was not created try { rulePackageItem = getRepo().loadModuleByUUID("01010101-0101-0101-0101-010101010101"); fail("Exception not thrown loading rule package that was not created."); } catch (RulesRepositoryException e) { // that is OK! assertNotNull(e.getMessage()); } }