Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

I'm looking for the examples of the code to address all or parts of the above.

0 votes



4 answers

Permanent link
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();
}

1 vote

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.

Also, while putting the new version, I get the following error:
Exception: com.ibm.ram.common.data.exception.RAMRuntimeException: Unknown exception while submitting asset: Failed to submit asset - Publish Asset Test - ID#F77F4063-132F-6C6F-2405-2A1760D0A1F5 Version#1.0.0.29 - Prefix string too short
Any idea what this means?
Thanks

We'll need the stack trace from the host ramdebug.log for the actual failure.

Richard, how can I get the log to you?
Thanks

All we need is the stack trace that includes the error on the host. So just cut/paste from your ramdebug.log to here in the forum. It shouldn't be too big.

Make sure you get the entire stack trace, including the "Caused by:" traces if any.


Permanent link
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.


0 votes

Comments

I don't think you need to commit it first. You should be able to remove the artifacts BEFORE the initial submit, at the same time you removed the dependencies.

This is actually a bug in the definition. All of the zip contents are supposed to be under that folder that had same name as the zip file. It isn't supposed to be the contents of the zip file under Top folder. I know that would you are expecting makes more sense, but that is not how the code is actually structured. The bug is that it should of put the zip contents under the folder instead of leaving the folder empty.

What we should of have instead of LocalArchiveFikderArtifact is a LocalArchiveArtifact which can then be added to a folder artifact and expanded right there instead.

Since you are already writing this as API, you can just extract the Zip yourself and add the directory structure. .... yes, need more disk space :-( / time, but from code point of view, it is quite small/simple.

Thanks, Gili. I'll try that. In the meantime, as a workaround, I upload the zip and them remove the directory with the same name as the zip file, just clean up. It seems to work.


Permanent link
Is this the file name, ramDebugRAM1WebApplication.log?

0 votes


Permanent link
[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

0 votes

Comments

Interesting. That happens because you have a file that has less than three characters before the '.' (period). We're trying to create a temp file based on this name. I didn't know Java had a restriction that for temp file the part before the '.' needs to be at least three characters.

1) Please open a defect
2) For a workaround, recreate the original asset, and the replacement asset so that there are no file names that have less than 3 characters before the '.'.

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,941

Question asked: Sep 26 '12, 3:39 p.m.

Question was seen: 7,465 times

Last updated: Oct 10 '12, 2:03 p.m.

Confirmation Cancel Confirm