/** * This will restore the historical version, save, and check it in as a new * version with the given comment. * * @param versionToRestore * @param headVersion * @param comment */ public void restoreHistoricalAsset(AssetItem versionToRestore, AssetItem headVersion, String comment) { headVersion.checkout(); if (versionToRestore.isBinary()) { headVersion.updateBinaryContentAttachment(versionToRestore.getBinaryContentAttachment()); } else { headVersion.updateContent(versionToRestore.getContent()); } headVersion.checkin(comment); }
@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()); }
/** * This will restore the historical version, save, and check it in as a new * version with the given comment. * * @param versionToRestore * @param headVersion * @param comment */ public void restoreHistoricalAsset(AssetItem versionToRestore, AssetItem headVersion, String comment) { headVersion.checkout(); if (versionToRestore.isBinary()) { headVersion.updateBinaryContentAttachment(versionToRestore.getBinaryContentAttachment()); } else { headVersion.updateContent(versionToRestore.getContent()); } headVersion.checkin(comment); }
@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 testGetContent() { AssetItem ruleItem1 = getRepo().loadDefaultModule().addAsset("testGetContent", "test content"); ruleItem1.updateContent( "test content" ); ruleItem1.updateFormat("drl"); assertNotNull(ruleItem1); assertNotNull(ruleItem1.getNode()); assertEquals("test content", ruleItem1.getContent()); assertFalse(ruleItem1.isBinary()); assertNotNull(ruleItem1.getBinaryContentAsBytes()); assertNotNull(ruleItem1.getBinaryContentAttachment()); String content = new String(ruleItem1.getBinaryContentAsBytes()); assertNotNull(content); }
@Test public void testGetContentForShareableAsset() { AssetItem asset = getRepo().loadGlobalArea().addAsset("testGetContentForShareableAsset", "test content"); AssetItem linkedAsset = getRepo().loadDefaultModule().addAssetImportedFromGlobalArea(asset.getName()); linkedAsset.updateContent("test content"); linkedAsset.updateFormat("drl"); assertNotNull(linkedAsset.getNode()); assertEquals("test content", linkedAsset.getContent()); assertEquals("test content", asset.getContent()); assertFalse(linkedAsset.isBinary()); assertFalse(asset.isBinary()); assertNotNull(linkedAsset.getBinaryContentAsBytes()); assertNotNull(linkedAsset.getBinaryContentAttachment()); String content = new String(linkedAsset.getBinaryContentAsBytes()); assertNotNull(content); content = new String(asset.getBinaryContentAsBytes()); assertNotNull(content); }