I'm looking to write a java program that looks at the asset with the given UID, takes the lastest version, clones it then removes all "Depend on" relationships and all the content and replaces both the given set of "Depend on" and the new content.
4 answers
public static void main(String[] args) {
RAMSession session = new RAMSession("http://localhost:8080/ram.ws", "admin", "admin");
session.setWebServiceTimeout(10000);
// Get an asset with GUID/ latest version
// Assumption here that version is in the form of digit.digit.digit .... else, use search on the GUID
RAMAsset asset = session.getAsset(new AssetIdentification("{0C972087-F35B-2907-8505-8A8EA00EF600}", "*"));
// Create a new version (this asset is duplicated, with a new version)
RAMAsset newVer = session.createAssetNewVersion(asset, "5.0", new RAMStatusMonitor());
// over here you play with the new versioned asset
Relationship[] curRel = newVer.getRelationships();
for (int i = 0; i < curRel.length; i++) {
// remove dependent on relationships
if ("dependency".compareToIgnoreCase(curRel[i].getRelationshipTypeName()) == 0)
newVer.removeRelationship(curRel[i]);
}
// upload/create the new version to the repository
// Make sure to create the asset with its artifacts, before removing things off
session.put(newVer, new NullProgressMonitor());
// Remove artifacts
RAMFolderArtifact top = (RAMFolderArtifact)newVer.getArtifactsRoot();
Artifact[] artifacts = top.getChildren();
// Remove all artifacts from prev. version
for (int i = 0; i < artifacts.length; i++)
top.removeArtifact(artifacts[i]);
// Put new content, relationships, categories ....
// upload/create the new version to the repository
session.put(newVer, new NullProgressMonitor());
session.release();
}
Comments
Thank you, Gili. So what was missing is that the new version must be committed before its content can be modified. This overall works now. The only issue I'm having is that the content for the new version comes from a zip file.
// Remove artifacts
RAMFolderArtifact top = (RAMFolderArtifact)newVer.getArtifactsRoot();
Artifact[] artifacts = top.getChildren();
// Remove all artifacts from prev. version
for (int i = 0; i < artifacts.length; i++) {
println artifacts[i]
top.removeArtifact(artifacts[i]);
}
// upload new content
File file = new File(assetContent);
LocalArchiveFolderArtifact artZip = new LocalArchiveFolderArtifact(file);
top.addArtifact(artZip)
This does uploads the content of the zip into the new version of the assets. However, it also creates an empty folder with the same name as the name of the zip file.
// Remove artifacts
RAMFolderArtifact top = (RAMFolderArtifact)newVer.getArtifactsRoot();
Artifact[] artifacts = top.getChildren();
// Remove all artifacts from prev. version
for (int i = 0; i < artifacts.length; i++) {
println artifacts[i]
top.removeArtifact(artifacts[i]);
}
// upload new content
File file = new File(assetContent);
LocalArchiveFolderArtifact artZip = new LocalArchiveFolderArtifact(file);
top.addArtifact(artZip)
This does uploads the content of the zip into the new version of the assets. However, it also creates an empty folder with the same name as the name of the zip file.
Comments
[10/10/12 10:08:10 EDT] CRRAM0001E 4831136829 ERROR ws com.ibm.ram.repository.web.RAMAssetAccess - User=ser_bfbuild:Unknown exception while submitting asset
com.ibm.ram.common.data.exception.RAMRuntimeException: Failed to submit asset - Atom Framework - ID#475A1D35-8724-8C11-AA1F-E669DAFFBCDB Version#1.1.0.211 - Prefix string too short
at com.ibm.ram.common.data.exception.RAMRuntimeException.<init>(RAMRuntimeException.java:82)
at com.ibm.ram.common.data.exception.RAMRuntimeException.<init>(RAMRuntimeException.java:78)
at com.ibm.ram.repository.ws.core.BaseAssetAccess.submitAsset(BaseAssetAccess.java:167)
at com.ibm.ram.repository.web.RAMAssetAccess.submitAsset(RAMAssetAccess.java:489)
at com.ibm.ram.repository.web.RAMAssetAccess.upload(RAMAssetAccess.java:262)
at com.ibm._jsp._RAMAssetAccess._jspService(_RAMAssetAccess.java:87)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:104)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:259)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:354)
at com.ibm.ram.repository.web.ws.RAMSecure.doRequest(RAMSecure.java:40)
at com.ibm.ram.repository.web.ws.RAMSecure.doPost(RAMSecure.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
at com.ibm.ram.repository.web.RAMWSServletFilter.doFilter(RAMWSServletFilter.java:511)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1784)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Caused by:
java.lang.IllegalArgumentException: Prefix string too short
at java.io.File.createTempFile(File.java:1793)
at com.ibm.ram.repository.storage.BaseFileSystemPersistenceAdapter.updateRAS(BaseFileSystemPersistenceAdapter.java:1657)
at com.ibm.ram.repository.storage.BaseFileSystemPersistenceAdapter.persistAsset(BaseFileSystemPersistenceAdapter.java:1054)
at com.ibm.ram.repository.core.sdo.RepositoryStorageAccess.persistAsset(RepositoryStorageAccess.java:52)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.saveAsset(BaseRAMSchemaAccess.java:5637)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.updateAsset(BaseRAMSchemaAccess.java:4669)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.updateAsset(BaseRAMSchemaAccess.java:4207)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.updateAsset(BaseRAMSchemaAccess.java:4178)
at com.ibm.ram.repository.assets.AssetManager.primUpdateAsset(AssetManager.java:3510)
at com.ibm.ram.repository.assets.AssetManager.primUpdateAssetWithState(AssetManager.java:3410)
at com.ibm.ram.repository.assets.AssetManager.updateAssetWithState(AssetManager.java:3277)
at com.ibm.ram.repository.assets.AssetManager.updateAsset(AssetManager.java:3242)
at com.ibm.ram.repository.ws.core.BaseAssetAccess.submitAsset(BaseAssetAccess.java:267)
... 48 more
com.ibm.ram.common.data.exception.RAMRuntimeException: Failed to submit asset - Atom Framework - ID#475A1D35-8724-8C11-AA1F-E669DAFFBCDB Version#1.1.0.211 - Prefix string too short
at com.ibm.ram.common.data.exception.RAMRuntimeException.<init>(RAMRuntimeException.java:82)
at com.ibm.ram.common.data.exception.RAMRuntimeException.<init>(RAMRuntimeException.java:78)
at com.ibm.ram.repository.ws.core.BaseAssetAccess.submitAsset(BaseAssetAccess.java:167)
at com.ibm.ram.repository.web.RAMAssetAccess.submitAsset(RAMAssetAccess.java:489)
at com.ibm.ram.repository.web.RAMAssetAccess.upload(RAMAssetAccess.java:262)
at com.ibm._jsp._RAMAssetAccess._jspService(_RAMAssetAccess.java:87)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:104)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:259)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:354)
at com.ibm.ram.repository.web.ws.RAMSecure.doRequest(RAMSecure.java:40)
at com.ibm.ram.repository.web.ws.RAMSecure.doPost(RAMSecure.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
at com.ibm.ram.repository.web.RAMWSServletFilter.doFilter(RAMWSServletFilter.java:511)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1784)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Caused by:
java.lang.IllegalArgumentException: Prefix string too short
at java.io.File.createTempFile(File.java:1793)
at com.ibm.ram.repository.storage.BaseFileSystemPersistenceAdapter.updateRAS(BaseFileSystemPersistenceAdapter.java:1657)
at com.ibm.ram.repository.storage.BaseFileSystemPersistenceAdapter.persistAsset(BaseFileSystemPersistenceAdapter.java:1054)
at com.ibm.ram.repository.core.sdo.RepositoryStorageAccess.persistAsset(RepositoryStorageAccess.java:52)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.saveAsset(BaseRAMSchemaAccess.java:5637)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.updateAsset(BaseRAMSchemaAccess.java:4669)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.updateAsset(BaseRAMSchemaAccess.java:4207)
at com.ibm.ram.repository.core.sdo.BaseRAMSchemaAccess.updateAsset(BaseRAMSchemaAccess.java:4178)
at com.ibm.ram.repository.assets.AssetManager.primUpdateAsset(AssetManager.java:3510)
at com.ibm.ram.repository.assets.AssetManager.primUpdateAssetWithState(AssetManager.java:3410)
at com.ibm.ram.repository.assets.AssetManager.updateAssetWithState(AssetManager.java:3277)
at com.ibm.ram.repository.assets.AssetManager.updateAsset(AssetManager.java:3242)
at com.ibm.ram.repository.ws.core.BaseAssetAccess.submitAsset(BaseAssetAccess.java:267)
... 48 more