Skip to content

Commit

Permalink
closes #198 (#204)
Browse files Browse the repository at this point in the history
add oslc:name and dcterms:description to the ResourceShape class.
Also adding "description" to the Shape annotations in order to be able
to construct resourceshape instances from information in the
annotations.
  • Loading branch information
jadelkhoury committed Sep 25, 2021
1 parent 8677243 commit d2f6118
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
*/
String title() default "";

/**
* Description of the resource shape.
*/
String description() default "";

/**
* Type or types of resource described by this shape.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.lyo.oslc4j.core.annotation.OslcDescription;
import org.eclipse.lyo.oslc4j.core.annotation.OslcName;
import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
import org.eclipse.lyo.oslc4j.core.annotation.OslcOccurs;
import org.eclipse.lyo.oslc4j.core.annotation.OslcPropertyDefinition;
import org.eclipse.lyo.oslc4j.core.annotation.OslcRange;
import org.eclipse.lyo.oslc4j.core.annotation.OslcReadOnly;
Expand All @@ -37,7 +38,9 @@ public final class ResourceShape extends AbstractResource {
private final SortedSet<URI> describes= new TreeSet<URI>();
private final TreeMap<URI, Property> properties = new TreeMap<URI, Property>();

private String name;
private String title;
private String description;

public ResourceShape() {
super();
Expand Down Expand Up @@ -81,7 +84,14 @@ public Property[] getProperties() {
return properties.values().toArray(new Property[properties.size()]);
}


@OslcDescription("The local name of the defined resource")
@OslcOccurs(Occurs.ExactlyOne)
@OslcPropertyDefinition(OslcConstants.OSLC_CORE_NAMESPACE + "name")
@OslcReadOnly
@OslcTitle("Name")
public String getName() {
return name;
}

@OslcDescription("Title of the resource shape. SHOULD include only content that is valid and suitable inside an XHTML <div> element")
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "title")
Expand All @@ -92,6 +102,15 @@ public String getTitle() {
return title;
}

@OslcDescription("The description of the defined constraint.")
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "description")
@OslcReadOnly
@OslcTitle("Description")
@OslcValueType(ValueType.XMLLiteral)
public String getDescription() {
return description;
}

public void setDescribes(final URI[] describes) {
this.describes.clear();
if (describes != null) {
Expand All @@ -109,7 +128,16 @@ public void setProperties(final Property[] properties) {
}
}

public void setName(final String name) {
this.name = name;
}

public void setTitle(final String title) {
this.title = title;
}

public void setDescription(final String description) {
this.description = description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,23 @@ private static ResourceShape createResourceShape(final String baseURI,
final URI about = UriBuilder.fromUri(baseURI).path(resourceShapesPath).path(resourceShapePath).build();
final ResourceShape resourceShape = new ResourceShape(about);

final OslcName nameAnnotation = resourceClass.getAnnotation(OslcName.class);
if (nameAnnotation != null) {
resourceShape.setName(nameAnnotation.value());
} else {
resourceShape.setName(resourceClass.getSimpleName());
}

final String title = resourceShapeAnnotation.title();
if ((title != null) && (title.length() > 0)) {
resourceShape.setTitle(title);
}

final String description = resourceShapeAnnotation.description();
if ((description != null) && (description.length() > 0)) {
resourceShape.setDescription(description);
}

for (final String describesItem : resourceShapeAnnotation.describes()) {
resourceShape.addDescribeItem(new URI(describesItem));
}
Expand Down

0 comments on commit d2f6118

Please sign in to comment.