public AssetItem next() { return new AssetItem(rulesRepository, it.nextNode()); }
/** * 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); }
private void setUpMockAssets(String assetFormat, String content) { when( unsavedAssetItem.getFormat() ).thenReturn( assetFormat ); when( unsavedAssetItem.getContent() ).thenReturn( content ); when( savedAssetItem.getFormat() ).thenReturn( assetFormat ); when( savedAssetItem.getContent() ).thenReturn( content ); }
public VersionableItem getPrecedingVersion() throws RulesRepositoryException { try { Node precedingVersionNode = this.getPrecedingVersionNode(); if ( precedingVersionNode != null ) { return new AssetItem( this.rulesRepository, precedingVersionNode ); } else { return null; } } catch ( Exception e ) { log.error( "Caught exception", e ); throw new RulesRepositoryException( e ); } }
@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 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); }
try { StringBuilder returnString = new StringBuilder(); returnString.append( "Content of asset item named '" ).append( this.getName() ).append( "':\n" ); returnString.append( "Content: " ).append( this.getContent() ).append( "\n" ); returnString.append( "------\n" ); returnString.append( "Archived: " ).append( this.isArchived() ).append( "\n" ); returnString.append( "------\n" ); returnString.append( "Version: " ).append( this.getVersionNumber() ).append( "\n" ); returnString.append( "------\n" ); returnString.append( "Date Effective: " ).append( this.getDateEffective() ).append( "\n" ); returnString.append( "Date Expired: " ).append( this.getDateExpired() ).append( "\n" ); returnString.append( "------\n" ); StateItem stateItem = this.getState(); if ( stateItem != null ) { returnString.append( this.getState().getName() ).append( "\n" ); } else { returnString.append( "NO STATE SET FOR THIS NODE\n" ); returnString.append("Valid: ").append(this.getValid()); returnString.append( "------\n" ); returnString.append( "Asset tags:\n" ); for ( Iterator it = this.getCategories().iterator(); it.hasNext(); ) { CategoryItem currentTag = (CategoryItem) it.next(); returnString.append( currentTag.getName() ).append( "\n" );
@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() ); }
@Test public void testUpdateContent() throws Exception { AssetItem ruleItem1 = getDefaultPackage().addAsset("testUpdateContent", "test description"); assertFalse(ruleItem1.getCreator().equals( "" )); ruleItem1.updateContent( "test content" ); ruleItem1.checkin( "yeah" ); assertFalse(ruleItem1.getLastContributor().equals( "" )); ruleItem1.updateContent( "new rule content"); assertEquals("new rule content", ruleItem1.getContent()); assertTrue(ruleItem1.getNode().getSession().hasPendingChanges()); ruleItem1.checkin( "yeah !" ); assertFalse(ruleItem1.getNode().getSession().hasPendingChanges()); assertEquals("yeah !", ruleItem1.getCheckinComment()); AssetItem prev = (AssetItem) ruleItem1.getPrecedingVersion(); assertEquals("test content", prev.getContent()); assertFalse("yeah !".equals(prev.getCheckinComment())); assertEquals(prev, ruleItem1.getPrecedingVersion()); ruleItem1 = getDefaultPackage().loadAsset( "testUpdateContent" ); VersionIterator it = VersionableItem.getVersionManager(ruleItem1.getNode()).getVersionHistory(ruleItem1.getNode().getPath()).getAllVersions(); // and this shows using a version iterator. // perhaps migrate to using this rather then next/prev methods. //this way, we can skip. assertTrue(it.hasNext()); while (it.hasNext()) { Version n = it.nextVersion(); AssetItem item = new AssetItem(ruleItem1.getRulesRepository(), n); assertNotNull(item); } }
asset1.updateContent("this is content"); asset1.updateFormat("drl"); asset1.checkin(""); asset2.updateContent("this is content"); asset2.updateFormat("xml"); asset2.checkin(""); asset3.updateBinaryContentAttachment(in); asset3.updateFormat("xls"); asset3.checkin(""); assertTrue(asset3.isBinary()); assertFalse(asset1.isBinary()); assertNotNull(d); assertEquals(sdf.format(asset1.getLastModified().getTime()), dt[0]); assertEquals(asset1.getVersionNumber(), Long.parseLong(dt[1])); assertEquals(asset1.getContent(), s);
when( assetItem.getUUID() ).thenReturn( "UUID" ); when( assetItem.getFormat() ).thenReturn( "format" ); when( assetItem.getName() ).thenReturn( "name" ); when( assetItem.getDescription() ).thenReturn( "descriptiondescriptiondescriptiondescriptiondescriptiondescriptiondescriptiondescriptiondescription" ); when( assetItem.getStateDescription() ).thenReturn( "statedescription" ); when( assetItem.getCreator() ).thenReturn( "creator" ); when( assetItem.getCreatedDate() ).thenReturn( calendar ); when( assetItem.getLastContributor() ).thenReturn( "lastcontributor" ); when( assetItem.getLastModified() ).thenReturn( lastModifiedCalendar ); when( assetItem.getCategorySummary() ).thenReturn( "categorysummary" ); when( assetItem.getExternalSource() ).thenReturn( "externalsource" ); AssetPageRowPopulator assetPageRowPopulator = new AssetPageRowPopulator(); AssetPageRow makeAssetPageRow = assetPageRowPopulator.populateFrom( assetItem ); assertEquals( makeAssetPageRow.getUuid(), assetItem.getUUID() ); assertEquals( makeAssetPageRow.getFormat(), assetItem.getFormat() ); assertEquals( makeAssetPageRow.getName(), assetItem.getName() ); assertEquals( makeAssetPageRow.getDescription(), assetItem.getDescription() ); assertEquals( makeAssetPageRow.getAbbreviatedDescription().length(), 80 ); assertEquals( makeAssetPageRow.getStateName(), assetItem.getStateDescription() ); assertEquals( makeAssetPageRow.getCreator(), assetItem.getCreator() ); assertEquals( makeAssetPageRow.getCreatedDate(), assetItem.getCreatedDate().getTime() );
@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()); } /*
asset1.updateContent("this is content"); asset1.updateFormat("drl"); asset1.checkin(""); Calendar cd = asset1.getLastModified(); asset2.updateBinaryContentAttachment(in); asset2.updateFormat("xls"); asset2.checkin(""); assertEquals("qaz", asset1_.getContent()); assertEquals("a new comment", asset1_.getCheckinComment()); assertTrue(asset1_.getLastModified().after(cd)); assertEquals("def", new String(asset2_.getBinaryContentAsBytes())); assertEquals("a new comment", asset2_.getCheckinComment()); assertTrue(asset2_.getLastModified().after(cd));
@Test public void testGetSucceedingVersion() { AssetItem ruleItem1 = getRepo().loadDefaultModule().addAsset("testGetSucceedingVersion", "test description"); ruleItem1.checkin( "version0" ); assertEquals(1, ruleItem1.getVersionNumber()); AssetItem succeedingRuleItem = (AssetItem) ruleItem1.getSucceedingVersion(); assertTrue(succeedingRuleItem == null); ruleItem1.updateContent("new content"); ruleItem1.checkin( "la" ); assertEquals(2, ruleItem1.getVersionNumber()); AssetItem predecessorRuleItem = (AssetItem) ruleItem1.getPrecedingVersion(); assertEquals("", predecessorRuleItem.getContent()); succeedingRuleItem = (AssetItem) predecessorRuleItem.getSucceedingVersion(); assertNotNull(succeedingRuleItem); assertEquals(ruleItem1.getContent(), succeedingRuleItem.getContent()); }
@Test public void testGetFormatForShareableAsset() throws Exception { AssetItem asset = getRepo().loadGlobalArea().addAsset("testGetFormatForShareableAsset", "desc"); asset.checkin("version0"); AssetItem linkedAsset = getDefaultPackage().addAssetImportedFromGlobalArea(asset.getName()); linkedAsset.updateContent("la"); assertEquals(AssetItem.DEFAULT_CONTENT_FORMAT, linkedAsset.getFormat()); assertTrue(linkedAsset.getNode().hasProperty(AssetItem.CONTENT_PROPERTY_NAME)); assertFalse(linkedAsset.getNode().hasProperty(AssetItem.CONTENT_PROPERTY_BINARY_NAME)); linkedAsset.updateFormat("blah"); assertEquals("blah", linkedAsset.getFormat()); }
protected AssetItem loadAssetWithVersion(final AssetItem assetItem, String version) { long requiredVersion = Long.parseLong(version); if (assetItem.isHistoricalVersion()) { long currentVersion = assetItem.getVersionNumber(); if(requiredVersion == currentVersion) { return assetItem; } else { Node frozenNode = assetItem.getNode(); try { Node headNode = frozenNode.getSession().getNodeByIdentifier( .getString()); AssetHistoryIterator historyIterator = new AssetHistoryIterator( assetItem.getRulesRepository(), headNode); while (historyIterator.hasNext()) { AssetItem historical = historyIterator.next(); if (requiredVersion == historical.getVersionNumber()) { return historical; throw new RulesRepositoryException("Unable to load AssetItem[" + assetItem.getName() + "] with specificed version[" + version + "]", e); AssetHistoryIterator it = assetItem.getHistory(); while (it.hasNext()) { AssetItem historical = (AssetItem) it.next(); if (requiredVersion == historical.getVersionNumber()) { return historical; throw new RulesRepositoryException("Unable to load AssetItem[" + assetItem.getName() + "] with specificed version[" + version + "]");
@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(); } }
/** * 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); } }
@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")); }