Hi,
I was suggested to run this kind of groovy code as a Nexus task in order to create a new asset in a raw hosted repo. It is just a snippet from a bigger script. The content of the file asset is more complex than in this example. So far, I cannot do this using REST API because the content is built inside the server.
I got this error: “java.lang.IllegalStateException: Unit of work has not been set”.
It is from org.sonatype.nexus.orient.raw.internal.RawContentFacetImpl:
@TransactionalStoreBlob
protected Content doPutContent(final String path, final TempBlob tempBlob, final Payload payload)
throws IOException
What should I have to do to make this code working?!
Regards.
import org.sonatype.nexus.content.raw.RawContentFacet
import org.sonatype.nexus.repository.Repository
import org.sonatype.nexus.repository.view.payloads.StringPayload
class AClass {
private final log
private final repo
AClass(log, repo) {
this.log = log
this.repo = repo
}
void doStuff() {
String name = "myFile"
String repoName = "myRepo" // of type raw hosted
Repository myRepo = this.repo.repositoryManager.get(repoName)
StringPayload content = new StringPayload("dummy text for now", null)
RawContentFacet facet = myRepo.facet(RawContentFacet.class)
facet.put(name, content)
}
}
new AClass(log, repository).doStuff()