-
1. Re: How to define custom artifact model in S-RAMP
eric.wittmann Sep 24, 2014 8:36 AM (in response to giorgimode)1 of 1 people found this helpfulThe answer depends on exactly how you want to interact with the S-RAMP repository. But first let me start with just a little bit of background. The S-RAMP spec does not include a way to define your custom types - so they are all ad-hoc and they all live within the /s-ramp/ext model. So unfortunately it is not possible to define some sort of schema that defines your types and bind that schema to a custom model, such as "/s-ramp/foo".
What this means is that defining your own types is simply a matter of adding artifacts to the repository with a custom type name. So instead of adding (for example) a WsdlDocument, you can add a FooDocument or a FooArtifact. Once such an artifact has been added, you can treat it like any other artifact - adding properties, classifiers, and relationships to it. You can obviously query for it by all of that criteria as well.
Finally, it's important to note that there are two kinds of extended artifacts - ExtendedDocument and ExtendedArtifactType. The former has binary (e.g. file) content and the latter does not. So if you want to create an artifact that consists *only* of meta-data (properties, classifiers, relationships) then you would use ExtendedArtifactType. If you are storing a file as an artifact (for example uploading a JBoss 7 SAR file as a SecurityArchive artifact) then you would use ExtendedDocument.
S-RAMP Shell (CLI)
If you're using the shell, you can add an Extended Document like this:
s-ramp> connect http://localhost:8080/s-ramp-server admin admin Successfully connected to S-RAMP endpoint: http://localhost:8080/s-ramp-server s-ramp> upload .project EclipseProjectDocument Successfully uploaded an artifact. -- Core S-RAMP Info -- Type: EclipseProjectDocument Model: ext UUID: 3eddad25-5cdc-4024-bf7d-ef51714f512d Name: .project Derived: false Created By: admin Created On: 2014-09-24T08:11:24.095-04:00 Modified By: admin Modified On: 2014-09-24T08:11:24.095-04:00 -- Document Info -- Content Type: application/xml Content Size: 564 s-ramp> query "/s-ramp/ext/" Querying the S-RAMP repository: /s-ramp/ext Atom Feed (1 entries) Idx Type Name --- ---- ---- 1 EclipseProjectDocument .project
Alternatively you can add an Extended Artifact like this:
s-ramp> help s-ramp:create USAGE s-ramp:create type name [description] The "create" command creates a new artifact in the S-RAMP repository, without file content. The artifact type and name must be provided, along with an optional description. Example usages: > s-ramp:create HumanActor bwayne "An actor who also wears a stylish belt." > s-ramp:create MyCustomArtifactType "Name of my artifact" s-ramp> s-ramp:create FooArtifact "My Foo Artifact" Successfully created the artifact: My Foo Artifact s-ramp> query "/s-ramp/ext/" Querying the S-RAMP repository: /s-ramp/ext Atom Feed (2 entries) Idx Type Name --- ---- ---- 1 EclipseProjectDocument .project 2 FooArtifact My Foo Artifact s-ramp> getMetaData feed: uuid: s-ramp> getMetaData feed:2 Meta Data for: 63be87ec-fbfc-4f45-9d1d-cf267f712074 -------------- -- Core S-RAMP Info -- Type: FooArtifact Model: ext UUID: 63be87ec-fbfc-4f45-9d1d-cf267f712074 Name: My Foo Artifact Derived: false Created By: admin Created On: 2014-09-24T08:12:32.869-04:00 Modified By: admin Modified On: 2014-09-24T08:12:32.869-04:00
User Interface
If you're using the UI, you can only add an Extended Document by uploading a file and giving it your custom artifact type. This can be done from the Import Artifact(s) dialog. This dialog allows you to specify the file to upload as well as the artifact type.
From Java (using our S-RAMP Atom Client library)
If you are integrating with the S-RAMP repository from Java, you're probably using the S-RAMP atom client provided by our project (the s-ramp-client library). If so, you can create an Extended Artifact very easily like this:
SrampAtomApiClient client = new SrampAtomApiClient("http://localhost:8080/s-ramp-server", "admin", "admin", true); ExtendedArtifactType artifact = (ExtendedArtifactType) ArtifactType.ExtendedArtifactType("ArtifactFromClient", false).newArtifactInstance(); artifact.setName("My Artifact (from client)"); client.createArtifact(artifact);
If you are trying to add an Extended Document, you can do this:
SrampAtomApiClient client = new SrampAtomApiClient("http://localhost:8080/s-ramp-server", "admin", "admin", true); ExtendedDocument artifact = (ExtendedDocument) ArtifactType.ExtendedDocument("FooDocument").newArtifactInstance(); artifact.setName("My Foo Document (from client)"); InputStream content = new FileInputStream("/path/to/file.content"); try { client.uploadArtifact(artifact, content); } finally { content.close(); }
-
2. Re: How to define custom artifact model in S-RAMP
giorgimode Sep 24, 2014 10:06 AM (in response to eric.wittmann)Thanks for the thorough explanation.
Is there a way to upload an artifact and automatically specify custom artifact type through its file extension? For instance, is there a central registry to add a mapping from file extension to the artifact type? Or is modifying the source code only way to achieve it?
-
3. Re: How to define custom artifact model in S-RAMP
eric.wittmann Sep 24, 2014 10:57 AM (in response to giorgimode)1 of 1 people found this helpfulUnfortunately there is no central server-side file extension registry that maps file extensions to S-RAMP artifact types. The reason is that the S-RAMP repository's API (defined by the S-RAMP specification) requires that artifacts be added to an Atom collection that includes the artifact model and type. So for example artifacts must be POST'd to a URL like the following:
http://localhost:8080/s-ramp-server/s-ramp/wsdl/WsdlDocument
There is no generic collection that provides a way to upload a file and have the server detect its type.
We do use the file extension when a file is uploaded, but only to determine the mime-type of the content, not to determine the artifact type.