/** * This moves an asset from one module to another, preserving history * etc etc. * * @param newModule The destination module. * @param uuid The UUID of the asset * @param explanation The reason (which will be added as the checkin message). */ public void moveRuleItemModule(String newModule, String uuid, String explanation) { try { AssetItem item = loadAssetByUUID(uuid); String sourcePath = item.node.getPath(); String destPath = loadModule(newModule).node.getPath() + "/" + ModuleItem.ASSET_FOLDER_NAME + "/" + item.getName(); this.session.move(sourcePath, destPath); this.session.save(); item.checkout(); item.node.setProperty(AssetItem.MODULE_NAME_PROPERTY, newModule); item.checkin(explanation); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
/** * This moves an asset from one module to another, preserving history * etc etc. * * @param newModule The destination module. * @param uuid The UUID of the asset * @param explanation The reason (which will be added as the checkin message). */ public void moveRuleItemModule(String newModule, String uuid, String explanation) { try { AssetItem item = loadAssetByUUID(uuid); String sourcePath = item.node.getPath(); String destPath = loadModule(newModule).node.getPath() + "/" + ModuleItem.ASSET_FOLDER_NAME + "/" + item.getName(); this.session.move(sourcePath, destPath); this.session.save(); item.checkout(); item.node.setProperty(AssetItem.MODULE_NAME_PROPERTY, newModule); item.checkin(explanation); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
/** * This will rename an asset and apply the change immediately. * * @return the UUID of the new asset */ public String renameAsset(String uuid, String newAssetName) { try { AssetItem itemOriginal = loadAssetByUUID(uuid); log.info("Renaming asset: " + itemOriginal.getNode().getPath() + " to " + newAssetName); Node node = itemOriginal.getNode(); String sourcePath = node.getPath(); String destPath = node.getParent().getPath() + "/" + newAssetName; this.session.move(sourcePath, destPath); this.session.save(); itemOriginal.updateTitle(newAssetName); itemOriginal.checkin("Renamed asset " + itemOriginal.getName()); return itemOriginal.getUUID(); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * This will rename an asset and apply the change immediately. * * @return the UUID of the new asset */ public String renameAsset(String uuid, String newAssetName) { try { AssetItem itemOriginal = loadAssetByUUID(uuid); log.info("Renaming asset: " + itemOriginal.getNode().getPath() + " to " + newAssetName); Node node = itemOriginal.getNode(); String sourcePath = node.getPath(); String destPath = node.getParent().getPath() + "/" + newAssetName; this.session.move(sourcePath, destPath); this.session.save(); itemOriginal.updateTitle(newAssetName); itemOriginal.checkin("Renamed asset " + itemOriginal.getName()); return itemOriginal.getUUID(); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
String destinationName) { try { AssetItem source = loadAssetByUUID(uuidSource); String sourcePath = source.getNode().getPath(); String safeDestinationName = NodeUtils.makeJSR170ComplaintName(destinationName);
String destinationName) { try { AssetItem source = loadAssetByUUID(uuidSource); String sourcePath = source.getNode().getPath(); String safeDestinationName = NodeUtils.makeJSR170ComplaintName(destinationName);
@Test public void testHistoryIterator() throws Exception { AssetItem ruleItem1 = getRepo().loadDefaultModule().addAsset("testHistoryIterator", "test description"); ruleItem1.checkin( "version0" ); ruleItem1 = getRepo().loadAssetByUUID( ruleItem1.getUUID() ); ruleItem1.updateContent( "wo" ); ruleItem1.checkin( "version1" ); ruleItem1 = getRepo().loadAssetByUUID( ruleItem1.getUUID() ); ruleItem1.updateContent( "ya" ); ruleItem1.checkin( "version2" ); Iterator it = ruleItem1.getHistory(); for ( int i = 0; i < 2; i++ ) { assertTrue(it.hasNext()); it.next(); } }
@Test public void testHistoryIteratorForShareableAsset() throws Exception { AssetItem asset = getRepo().loadGlobalArea().addAsset("testHistoryIteratorForShareableAsset", "desc"); asset.checkin("version0"); AssetItem linkedAsset = getDefaultPackage().addAssetImportedFromGlobalArea(asset.getName()); linkedAsset = getRepo().loadAssetByUUID(linkedAsset.getUUID()); linkedAsset.updateContent("wo"); linkedAsset.checkin("version2"); asset = getRepo().loadAssetByUUID(asset.getUUID()); asset.updateContent("ya"); asset.checkin("version3"); Iterator it = asset.getHistory(); for (int i = 0; i < 3; i++) { assertTrue(it.hasNext()); it.next(); } }
@Test public void testUpdateStringProperty() throws Exception { RulesRepository repo = getRepo(); ModuleItem def = repo.loadDefaultModule(); AssetItem asset = repo.loadDefaultModule().addAsset("testUpdateStringProperty", "test content"); asset.updateContent("new content"); asset.checkin(""); Calendar lm = asset.getLastModified(); Thread.sleep(100); asset.updateStringProperty("Anything", "AField"); assertEquals("Anything", asset.getStringProperty("AField")); Calendar lm_ = asset.getLastModified(); assertTrue(lm_.getTimeInMillis() > lm.getTimeInMillis()); Thread.sleep(100); asset.updateStringProperty("More", "AField", false); assertEquals(lm_.getTimeInMillis(), asset.getLastModified().getTimeInMillis()); asset.updateContent("more content"); asset.checkin(""); asset = repo.loadAssetByUUID(asset.getUUID()); assertEquals("More", asset.getStringProperty("AField")); }
AssetItem loaded = repo.loadAssetByUUID( uuid ); assertNotNull( loaded ); assertEquals( "testLoadRuleByUUID", loaded.checkin( "woo" ); AssetItem reload = repo.loadAssetByUUID( uuid ); assertEquals( "testLoadRuleByUUID", reload.getName() ); repo.loadAssetByUUID( "01010101-0101-0101-0101-010101010101" ); fail( "Exception not thrown loading rule package that was not created." ); } catch ( RulesRepositoryException e ) { AssetItem asset2 = repo2.loadAssetByUUID( uuid ); asset2.updateContent( "yeah 42" ); asset2.checkin( "yeah" ); asset1 = repo.loadAssetByUUID( uuid ); assertEquals( "yeah 42", asset1.getContent() ); asset1.checkin( "la" ); asset2 = repo2.loadAssetByUUID( uuid ); assertEquals( "yeah 43", asset2.getContent() );
@Test public void testBinaryAsset() throws Exception { AssetItem item = getRepo().loadDefaultModule().addAsset( "testBinaryAsset", "yeah" ); String data = "abc 123"; ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes()); item.updateBinaryContentAttachment( in ); item.updateBinaryContentAttachmentFileName( "x.x" ); in.close(); assertEquals(data, item.getContent()); assertFalse(item.getNode().hasProperty( AssetItem.CONTENT_PROPERTY_NAME )); assertTrue(item.getNode().hasProperty( AssetItem.CONTENT_PROPERTY_BINARY_NAME )); item.checkin( "lalalala" ); assertTrue(item.isBinary()); item = getRepo().loadDefaultModule().loadAsset( "testBinaryAsset" ); InputStream in2 = item.getBinaryContentAttachment(); assertNotNull(in2); byte[] data2 = item.getBinaryContentAsBytes(); assertEquals(data, new String(data2)); assertEquals("x.x", item.getBinaryContentAttachmentFileName()); assertTrue(item.isBinary()); item.updateContent("qed"); item.checkin(""); item = getRepo().loadAssetByUUID(item.getUUID()); assertEquals("qed", item.getContent()); }
@Test public void testBinaryAssetForShareableAsset() throws Exception { AssetItem asset = getRepo().loadGlobalArea().addAsset("testBinaryAssetForShareableAsset", "desc"); asset.checkin("version0"); AssetItem linkedAsset = getDefaultPackage().addAssetImportedFromGlobalArea(asset.getName()); String data = "abc 123"; ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes()); linkedAsset.updateBinaryContentAttachment(in); linkedAsset.updateBinaryContentAttachmentFileName("x.x"); in.close(); assertEquals(data, linkedAsset.getContent()); assertFalse(linkedAsset.getNode().hasProperty(AssetItem.CONTENT_PROPERTY_NAME)); assertTrue(linkedAsset.getNode().hasProperty(AssetItem.CONTENT_PROPERTY_BINARY_NAME)); linkedAsset.checkin("lalalala"); assertTrue(linkedAsset.isBinary()); asset = getRepo().loadGlobalArea().loadAsset("testBinaryAssetForShareableAsset"); InputStream in2 = asset.getBinaryContentAttachment(); assertNotNull(in2); byte[] data2 = asset.getBinaryContentAsBytes(); assertEquals(data, new String(data2)); assertEquals("x.x", asset.getBinaryContentAttachmentFileName()); assertTrue(asset.isBinary()); linkedAsset.updateContent("qed"); linkedAsset.checkin(""); linkedAsset = getRepo().loadAssetByUUID(linkedAsset.getUUID()); assertEquals("qed", linkedAsset.getContent()); }
@Test public void testRenameAsset() throws Exception { RulesRepository repo = getRepo(); repo.createModule( "testRenameAsset", "asset" ); AssetItem item = repo.loadModule( "testRenameAsset" ).addAsset( "testRenameAssetSource", "desc" ); item.updateContent( "la" ); item.checkin( "" ); String uuid = repo.renameAsset( item.getUUID(), "testRename2" ); item = repo.loadAssetByUUID( uuid ); assertEquals( "testRename2", item.getName() ); assertEquals( "testRename2", item.getTitle() ); List assets = iteratorToList( repo.loadModule( "testRenameAsset" ).getAssets() ); assertEquals( 1, assets.size() ); item = (AssetItem) assets.get( 0 ); assertEquals( "testRename2", item.getName() ); assertEquals( "la", item.getContent() ); }
@Test public void testUpdateStringPropertyForShareableAsset() throws Exception { AssetItem asset = loadGlobalArea().addAsset("testUpdateStringPropertyForShareableAsset", "desc"); asset.checkin("initial"); AssetItem linkedAsset = getDefaultPackage().addAssetImportedFromGlobalArea(asset.getName()); linkedAsset.updateContent("new content"); linkedAsset.checkin(""); linkedAsset.updateStringProperty("Anything", "AField"); assertEquals("Anything", linkedAsset.getStringProperty("AField")); assertEquals("Anything", asset.getStringProperty("AField")); asset.updateStringProperty("More", "AField", false); asset.updateContent("more content"); asset.checkin(""); asset = getRepo().loadAssetByUUID(asset.getUUID()); assertEquals("More", asset.getStringProperty("AField")); assertEquals("more content", asset.getContent()); linkedAsset = getRepo().loadAssetByUUID(linkedAsset.getUUID()); assertEquals("More", linkedAsset.getStringProperty("AField")); assertEquals("more content", asset.getContent()); } /*
@Test public void testGetAssetItemWithSpecifiedVersion() throws Exception { AssetItem ruleItem1 = getRepo().loadDefaultModule().addAsset("testGetAssetItemWithSpecifiedVersion", "test description"); ruleItem1.checkin( "version0" ); ruleItem1 = getRepo().loadAssetByUUID( ruleItem1.getUUID() ); ruleItem1.updateContent( "wo" ); ruleItem1.checkin( "version1" ); ruleItem1 = getRepo().loadAssetByUUID( ruleItem1.getUUID() ); ruleItem1.updateContent( "ya" ); ruleItem1.checkin( "version2" ); AssetItem assetItemVersion1 = getRepo().loadDefaultModule().loadAsset("testGetAssetItemWithSpecifiedVersion", 1); assertEquals("", assetItemVersion1.getContent()); assertEquals(1, assetItemVersion1.getVersionNumber()); AssetItem assetItemVersion2 = getRepo().loadDefaultModule().loadAsset("testGetAssetItemWithSpecifiedVersion", 2); assertEquals("wo", assetItemVersion2.getContent()); assertEquals(2, assetItemVersion2.getVersionNumber()); AssetItem assetItemVersion3 = getRepo().loadDefaultModule().loadAsset("testGetAssetItemWithSpecifiedVersion", 3); assertEquals("ya", assetItemVersion3.getContent()); assertEquals(3, assetItemVersion3.getVersionNumber()); }
@Test public void testPackageCheckinConfig() { ModuleItem item = getRepo().createModule( "testPackageCheckinConfig", "description" ); AssetItem rule = item.addAsset( "testPackageCheckinConfig", "w" ); rule.checkin( "goo" ); assertEquals(1, iteratorToList( item.getAssets() ).size()); updateHeader( "la", item ); item.checkin( "woot" ); updateHeader( "we", item ); item.checkin( "gah" ); // PackageItem pre = (PackageItem) item.getPrecedingVersion(); // assertNotNull(pre); // assertEquals("la", getHeader(pre)); AssetItem rule_ = getRepo().loadAssetByUUID( rule.getUUID() ); assertEquals(rule.getVersionNumber(), rule_.getVersionNumber()); item = getRepo().loadModule( "testPackageCheckinConfig"); long v = item.getVersionNumber(); item.updateCheckinComment( "x" ); getRepo().save(); assertEquals(v, item.getVersionNumber()); }
@Test public void testCopyAsset() throws Exception { RulesRepository repo = getRepo(); repo.createModule( "testCopyAsset", "asset" ); AssetItem item = repo.loadDefaultModule().addAsset( "testCopyAssetSource", "desc" ); item.updateContent( "la" ); item.checkin( "" ); item.updateDescription( "mmm" ); item.checkin( "again" ); assertEquals( 2, item.getVersionNumber() ); String uuid = repo.copyAsset( item.getUUID(), "testCopyAsset", "testCopyAssetDestination" ); AssetItem dest = repo.loadAssetByUUID( uuid ); assertEquals( dest.getName(), dest.getTitle() ); assertEquals( "la", dest.getContent() ); assertEquals( "testCopyAsset", dest.getModuleName() ); assertFalse( uuid.equals( item.getUUID() ) ); assertEquals( 1, dest.getVersionNumber() ); }
AssetItem loadedHistorical = getRepo().loadAssetByUUID( predecessorRuleItem.getVersionSnapshotUUID() ); assertTrue(loadedHistorical.isHistoricalVersion()); assertFalse(ruleItem1.getVersionNumber() == loadedHistorical.getVersionNumber()); AssetItem toRestore = getRepo().loadAssetByUUID( predecessorRuleItem.getVersionSnapshotUUID() );
AssetItem loadedHistorical = getRepo().loadAssetByUUID(predecessorRuleItem.getVersionSnapshotUUID()); assertTrue(loadedHistorical.isHistoricalVersion()); assertFalse(asset.getVersionNumber() == loadedHistorical.getVersionNumber()); AssetItem toRestore = getRepo().loadAssetByUUID(predecessorRuleItem.getVersionSnapshotUUID());