Permalink
Browse files

fixes for sramp issues 263, 256

  • Loading branch information...
1 parent 2c22ad0 commit 4707dac30734e64ccca52eca4ac1c0e50dd1b28d @EricWittmann EricWittmann committed Mar 6, 2014
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2013 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.overlord.sramp.common.ontology;
+
+import java.net.URI;
+import java.util.List;
+
+import org.overlord.sramp.common.i18n.Messages;
+import org.overlord.sramp.common.ontology.SrampOntology.SrampOntologyClass;
+
+/**
+ * A simple ontology validator.
+ *
+ * @author eric.wittmann@redhat.com
+ */
+public class OntologyValidator {
+
+ /**
+ * Validates the ontology.
+ * @param ontology
+ */
+ public static void validateOntology(SrampOntology ontology) throws Exception {
+ try {
+ new URI(ontology.getId());
+ } catch (Exception e) {
+ throw new Exception(Messages.i18n.format("INVALID_ONTOLOGY_ID", ontology.getId()));
+ }
+ List<SrampOntologyClass> classes = ontology.getAllClasses();
+ for (SrampOntologyClass oclass : classes) {
+ try {
+ new URI(oclass.getId());
+ } catch (Exception e) {
+ throw new Exception(Messages.i18n.format("INVALID_CLASS_ID", oclass.getId()));
+ }
+ }
+ }
+
+}
@@ -28,4 +28,6 @@ XPATH_UNTERMINATED_PREDICATE=Unterminated predicate in subartifact-set.
XPATH_FUNCTION_EXPECTED=Expected function name.
XPATH_ARGS_EXPECTED=Expected function arguments.
XPATH_UNTERMINATED_ARG_LIST=Unterminated argument list.
-XPATH_TOK_MISSING_QUOTE=No matching closing quote was found.
+XPATH_TOK_MISSING_QUOTE=No matching closing quote was found.
+INVALID_ONTOLOGY_ID=The ontology ID was invalid: {0}
+INVALID_CLASS_ID=An ontology class ID [{0}] was invalid.
@@ -36,6 +36,7 @@
import org.overlord.sramp.atom.err.SrampAtomException;
import org.overlord.sramp.atom.mappers.OntologyToRdfMapper;
import org.overlord.sramp.atom.mappers.RdfToOntologyMapper;
+import org.overlord.sramp.common.ontology.OntologyValidator;
import org.overlord.sramp.common.ontology.SrampOntology;
import org.overlord.sramp.repository.PersistenceFactory;
import org.overlord.sramp.repository.PersistenceManager;
@@ -83,10 +84,16 @@ public OntologyResource() {
@Consumes(MediaType.APPLICATION_RDF_XML)
@Produces(MediaType.APPLICATION_ATOM_XML_ENTRY)
public Entry create(RDF rdf) throws SrampAtomException {
- try {
- SrampOntology ontology = new SrampOntology();
- rdf2o.map(rdf, ontology);
+ SrampOntology ontology;
+ try {
+ ontology = new SrampOntology();
+ rdf2o.map(rdf, ontology);
+ OntologyValidator.validateOntology(ontology);
+ } catch (Exception e) {
+ throw new SrampAtomException(e);
+ }
+ try {
PersistenceManager persistenceManager = PersistenceFactory.newInstance();
ontology = persistenceManager.persistOntology(ontology);
@@ -119,11 +126,17 @@ public Entry create(RDF rdf) throws SrampAtomException {
@Path("ontology/{uuid}")
@Consumes(MediaType.APPLICATION_RDF_XML)
public void update(@PathParam("uuid") String uuid, RDF rdf) throws SrampAtomException {
- try {
- SrampOntology ontology = new SrampOntology();
- rdf2o.map(rdf, ontology);
+ SrampOntology ontology;
+ try {
+ ontology = new SrampOntology();
+ rdf2o.map(rdf, ontology);
ontology.setUuid(uuid);
+ OntologyValidator.validateOntology(ontology);
+ } catch (Exception e) {
+ throw new SrampAtomException(e);
+ }
+ try {
PersistenceManager persistenceManager = PersistenceFactory.newInstance();
persistenceManager.updateOntology(ontology);
} catch (Exception e) {
@@ -23,11 +23,10 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
-import org.junit.Assert;
-
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.resteasy.plugins.providers.atom.Entry;
import org.jboss.resteasy.plugins.providers.atom.Feed;
+import org.junit.Assert;
import org.junit.Test;
import org.overlord.sramp.atom.MediaType;
import org.overlord.sramp.atom.SrampAtomUtils;
@@ -43,21 +42,40 @@
*/
public class OntologyResourceTest extends AbstractNoAuditingResourceTest {
- @Test
- public void testCreate() throws Exception {
- ClientRequest request = new ClientRequest(generateURL("/s-ramp/ontology")); //$NON-NLS-1$
+ @Test
+ public void testCreate() throws Exception {
+ ClientRequest request = new ClientRequest(generateURL("/s-ramp/ontology")); //$NON-NLS-1$
- RDF rdf = loadTestRDF("regional"); //$NON-NLS-1$
+ RDF rdf = loadTestRDF("regional"); //$NON-NLS-1$
- request.body(MediaType.APPLICATION_RDF_XML_TYPE, rdf);
- ClientResponse<Entry> response = request.post(Entry.class);
- Entry entry = response.getEntity();
+ request.body(MediaType.APPLICATION_RDF_XML_TYPE, rdf);
+ ClientResponse<Entry> response = request.post(Entry.class);
+ Entry entry = response.getEntity();
- RDF ontology = SrampAtomUtils.unwrap(entry, RDF.class);
+ RDF ontology = SrampAtomUtils.unwrap(entry, RDF.class);
- Assert.assertNotNull(ontology);
- assertEquals(rdf, ontology);
- }
+ Assert.assertNotNull(ontology);
+ assertEquals(rdf, ontology);
+ }
+
+ /**
+ * Unit test for: https://issues.jboss.org/browse/SRAMP-256
+ * @throws Exception
+ */
+ @Test
+ public void testCreate_SRAMP256() throws Exception {
+ ClientRequest request = new ClientRequest(generateURL("/s-ramp/ontology")); //$NON-NLS-1$
+
+ RDF rdf = loadTestRDF("SRAMP-256"); //$NON-NLS-1$
+
+ request.body(MediaType.APPLICATION_RDF_XML_TYPE, rdf);
+ try {
+ request.post(Entry.class);
+ Assert.fail("Expected an ontology validation error.");
+ } catch (Exception e) {
+ Assert.assertEquals("The ontology ID was invalid: SRAMP 256", e.getMessage());
+ }
+ }
@Test
public void testGet() throws Exception {
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xml:base="http://www.example.org/regional.owl">
+
+ <owl:Ontology rdf:ID="SRAMP 256">
+ <rdfs:label>SRAMP-256 Test</rdfs:label>
+ </owl:Ontology>
+
+ <owl:Class rdf:ID="Root">
+ <rdfs:label>Root</rdfs:label>
+ </owl:Class>
+
+ <owl:Class rdf:ID="Child">
+ <rdfs:subClassOf rdf:resource="http://www.example.org/regional.owl#Root" />
+ <rdfs:label>Child1</rdfs:label>
+ <rdfs:comment>The continent of Asia.</rdfs:comment>
+ </owl:Class>
+
+</rdf:RDF>
@@ -100,6 +100,9 @@
@Inject @DataField("back-to-artifacts")
TransitionAnchor<ArtifactsPage> backToArtifacts;
+ @Inject @DataField("feed-link")
+ Anchor feedLink;
+
// Actions
@Inject @DataField("btn-delete")
Button deleteButton;
@@ -117,6 +120,8 @@
Anchor downloadContentLink;
@Inject @DataField("link-download-metaData")
Anchor downloadMetaDataLink;
+ @Inject @DataField("link-repository-direct")
+ Anchor linkToRepository;
@Inject @DataField("core-property-type-2") @Bound(property="type")
Label type;
@Inject @DataField("core-property-uuid") @Bound(property="uuid")
@@ -381,6 +386,8 @@ protected void update(ArtifactBean artifact) {
this.downloadContentLink.setHref(contentUrl);
this.downloadContentLink.setVisible(!artifact.isDerived());
this.downloadMetaDataLink.setHref(metaDataUrl);
+ this.feedLink.setHref(artifact.getRepositoryLink());
+ this.linkToRepository.setHref(artifact.getRepositoryMediaLink());
this.sourceEditor.setValue(""); //$NON-NLS-1$
if (artifact.isTextDocument()) {
@@ -33,6 +33,7 @@
<li><a data-field="back-to-dashboard" href="dashboard.html" data-i18n-key="breadcrumb.dashboard">S-RAMP Dashboard</a> <span class="divider">/<span data-role="dummy"/></span></li>
<li><a data-field="back-to-artifacts" href="artifacts.html" data-i18n-key="breadcrumb.artifacts">Artifacts</a> <span class="divider">/<span data-role="dummy"/></span></li>
<li class="active" data-i18n-key="breadcrumb.artifact-details">Artifact Details</li>
+ <li class="pull-right"><a data-field="feed-link" href="#"><i class="icon icon-feed"></i></a></li>
</ul>
</div>
@@ -89,6 +90,8 @@
<div class="sramp-meta-data-section-label"><a data-field="link-download-content" data-i18n-key="download-content">Download Content</a></div>
<div class="clearfix"></div>
<div class="sramp-meta-data-section-label"><a data-field="link-download-metaData" data-i18n-key="download-meta-data">Download Meta Data</a></div>
+ <div class="clearfix"></div>
+ <div class="sramp-meta-data-section-label"><a data-field="link-repository-direct" data-i18n-key="link-to-repository">Artifact Content Link (repository)</a></div>
</div>
<!-- Core and Custom Properties -->
<div class="row-fluid">
@@ -40,6 +40,8 @@
private long contentSize = -1;
private String contentType;
private boolean textDocument;
+ private String repositoryLink;
+ private String repositoryMediaLink;
/**
* Constructor.
@@ -174,4 +176,32 @@ public boolean isDocument() {
return this.contentSize != -1;
}
+ /**
+ * @return the repositoryLink
+ */
+ public String getRepositoryLink() {
+ return repositoryLink;
+ }
+
+ /**
+ * @param repositoryLink the repositoryLink to set
+ */
+ public void setRepositoryLink(String repositoryLink) {
+ this.repositoryLink = repositoryLink;
+ }
+
+ /**
+ * @return the repositoryMediaLink
+ */
+ public String getRepositoryMediaLink() {
+ return repositoryMediaLink;
+ }
+
+ /**
+ * @param repositoryMediaLink the repositoryMediaLink to set
+ */
+ public void setRepositoryMediaLink(String repositoryMediaLink) {
+ this.repositoryMediaLink = repositoryMediaLink;
+ }
+
}
@@ -65,7 +65,7 @@ public ArtifactBean get(String uuid) throws SrampUiException {
try {
BaseArtifactType artifact = clientAccessor.getClient().getArtifactMetaData(uuid);
ArtifactType artifactType = ArtifactType.valueOf(artifact);
-
+
ArtifactBean bean = new ArtifactBean();
bean.setModel(artifactType.getArtifactType().getModel());
bean.setType(artifactType.getType());
@@ -79,6 +79,8 @@ public ArtifactBean get(String uuid) throws SrampUiException {
bean.setUpdatedOn(artifact.getLastModifiedTimestamp().toGregorianCalendar().getTime());
bean.setUpdatedBy(artifact.getLastModifiedBy());
bean.setDerived(artifactType.isDerived());
+ bean.setRepositoryLink(getRepositoryLink(artifact, artifactType));
+ bean.setRepositoryMediaLink(getRepositoryMediaLink(artifact, artifactType));
if (SrampModelUtils.isDocumentArtifact(artifact)) {
DocumentArtifactType doc = (DocumentArtifactType) artifact;
bean.setContentSize(doc.getContentSize());
@@ -201,4 +203,33 @@ public void delete(ArtifactBean bean) throws SrampUiException {
}
}
+ /**
+ * Creates a link to the remote repository for the given artifact.
+ * @param artifact
+ * @param artifactType
+ */
+ private String getRepositoryLink(BaseArtifactType artifact, ArtifactType artifactType) {
+ StringBuilder builder = new StringBuilder();
+ String endpoint = clientAccessor.getClient().getEndpoint();
+ builder.append(endpoint);
+ if (!endpoint.endsWith("/")) {
+ builder.append("/");
+ }
+ builder.append(artifactType.getModel());
+ builder.append("/");
+ builder.append(artifactType.getType());
+ builder.append("/");
+ builder.append(artifact.getUuid());
+ return builder.toString();
+ }
+
+ /**
+ * Creates a media link to the remote repository for the given artifact.
+ * @param artifact
+ * @param artifactType
+ */
+ private String getRepositoryMediaLink(BaseArtifactType artifact, ArtifactType artifactType) {
+ return getRepositoryLink(artifact, artifactType) + "/media";
+ }
+
}
@@ -153,6 +153,13 @@ button.tree:hover {
width: 95%;
}
+.icon-feed {
+ background-image: url("../images/feed.gif");
+ background-position: top left;
+ width: 16px;
+ height: 16px;
+}
+
.sortable-column-header {
color: rgb(0, 85, 128);
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4707dac

Please sign in to comment.