Permalink
Browse files

Working on API View in wrmldoc

  • Loading branch information...
1 parent 17d7762 commit 5ebfb076f24972d1e9f09c79c4119e1eac53ece0 @markmasse markmasse committed Nov 19, 2015
Showing with 1,138 additions and 631 deletions.
  1. +4 −0 contrib/runtime/service/s3/src/main/java/org/wrml/contrib/runtime/service/s3/S3Service.java
  2. +0 −58 core/src/main/java/org/wrml/runtime/DefaultContext.java
  3. +70 −2 core/src/main/java/org/wrml/runtime/DefaultModel.java
  4. +7 −5 core/src/main/java/org/wrml/runtime/format/DefaultFormatLoader.java
  5. +2 −0 core/src/main/java/org/wrml/runtime/format/ParserModelGraph.java
  6. +25 −11 core/src/main/java/org/wrml/runtime/format/application/vnd/wrml/complete/api/CompleteApiBuilder.java
  7. +38 −24 core/src/main/java/org/wrml/runtime/format/application/vnd/wrml/swagger/api/SwaggerApiBuilder.java
  8. +5 −1 core/src/main/java/org/wrml/runtime/format/application/vnd/wrml/wrmldoc/JstreeDataBuilder.java
  9. +6 −0 core/src/main/java/org/wrml/runtime/rest/ApiBuilder.java
  10. +55 −39 core/src/main/java/org/wrml/runtime/rest/DefaultApiLoader.java
  11. +2 −0 core/src/main/java/org/wrml/runtime/schema/DefaultSchemaLoader.java
  12. +13 −3 core/src/main/java/org/wrml/runtime/syntax/DefaultSyntaxLoader.java
  13. +121 −39 server/server-core/src/main/java/org/wrml/server/WrmlServlet.java
  14. +3 −0 wrml-server-docker-build/docker-clean-build.sh
  15. +18 −0 wrmldoc/css/app/components/_base.scss
  16. +11 −0 wrmldoc/css/wrmldoc.css
  17. +1 −1 wrmldoc/css/wrmldoc.min.css
  18. +18 −0 wrmldoc/css/wrmldoc.scss
  19. +11 −0 wrmldoc/css/wrmldoc.tmp.css
  20. +30 −2 wrmldoc/js/app/Wrmldoc.coffee
  21. +2 −2 wrmldoc/js/app/apps/api/show/ApiShowController.coffee
  22. +75 −0 wrmldoc/js/app/apps/api/show/ApiShowView.coffee
  23. +18 −12 wrmldoc/js/app/apps/api/show/templates/api_show.eco
  24. +1 −1 wrmldoc/js/app/apps/apiNotFound/show/templates/apiNotFound_show.eco
  25. +1 −1 wrmldoc/js/app/apps/documentNotFound/show/templates/documentNotFound_show.eco
  26. +5 −4 wrmldoc/js/app/apps/header/show/HeaderShowView.coffee
  27. +2 −3 wrmldoc/js/app/apps/model/show/ModelShowController.coffee
  28. +8 −0 wrmldoc/js/app/apps/model/show/ModelShowView.coffee
  29. +6 −6 wrmldoc/js/app/apps/model/show/templates/model_show.eco
  30. +1 −1 wrmldoc/js/app/apps/registration/show/templates/registration_show.eco
  31. +2 −2 wrmldoc/js/app/apps/relation/show/RelationShowController.coffee
  32. +7 −0 wrmldoc/js/app/apps/relation/show/RelationShowView.coffee
  33. +3 −3 wrmldoc/js/app/apps/relation/show/templates/relation_show.eco
  34. +1 −1 wrmldoc/js/app/apps/resourceNotFound/show/templates/resourceNotFound_show.eco
  35. +2 −2 wrmldoc/js/app/apps/schema/show/SchemaShowController.coffee
  36. +19 −0 wrmldoc/js/app/apps/schema/show/SchemaShowView.coffee
  37. +83 −108 wrmldoc/js/app/apps/schema/show/templates/schema_show.eco
  38. +285 −133 wrmldoc/js/wrmldoc.js
  39. +176 −166 wrmldoc/js/wrmldoc.min.js
  40. +1 −1 wrmldoc/swagger/index.html
@@ -258,6 +258,8 @@ private String formatKey(final Keys keys, final Dimensions dimensions) {
private Model getModel(String s3Key, Keys keys, Dimensions dimensions) {
+ LOG.debug("S3 Service getModel looking for: {}", s3Key);
+
final GetObjectRequest getObjectRequest = new GetObjectRequest(_BucketName, s3Key);
final S3Object s3Object;
try {
@@ -283,6 +285,8 @@ private Model getModel(String s3Key, Keys keys, Dimensions dimensions) {
IOUtils.closeQuietly(in);
}
+ LOG.debug("S3 Service getModel returning: {}", model);
+
return model;
}
@@ -749,7 +749,6 @@ private void initManagedSlots(final Model model) {
if (model instanceof Document) {
final Document document = (Document) model;
- updateLinkSlots(document);
// Fetch and aggregate any link-embedded documents
embedLinkedDocuments(document);
@@ -760,63 +759,6 @@ private void initManagedSlots(final Model model) {
}
/**
- * Part of the HATEOAS automation. Uses the runtime's available REST API metadata to update the Links and Link href values in response to a change/initialization of the URI
- * slot value.
- */
- private void updateLinkSlots(final Document document) {
-
- final URI uri = document.getUri();
- if (uri == null) {
- return;
- }
-
- final ApiNavigator apiNavigator = _ApiLoader.getParentApiNavigator(uri);
-
- if (apiNavigator == null) {
- return;
- }
-
- final Resource resource = apiNavigator.getResource(uri);
- final Map<URI, LinkTemplate> linkTemplates = resource.getLinkTemplates();
- if (linkTemplates == null || linkTemplates.isEmpty()) {
- return;
- }
-
- final SortedMap<String, URI> prototypeLinkRelUris = document.getPrototype().getLinkRelationUris();
- final Set<String> linkSlotNames = prototypeLinkRelUris.keySet();
- for (final String linkSlotName : linkSlotNames) {
-
- Link link = (Link) document.getSlotValue(linkSlotName);
-
- final URI linkRelationUri = prototypeLinkRelUris.get(linkSlotName);
- final Resource endpointResource = apiNavigator.getEndpointResource(linkRelationUri, uri);
- if (endpointResource == null) {
- continue;
- }
-
- final URI href = endpointResource.getHrefUri(document, linkRelationUri);
- if (href == null) {
- // Exclude Links that have null href values.
-
- if (link != null) {
- document.setSlotValue(linkSlotName, null);
- }
-
- continue;
- }
-
- if (link == null) {
-
- link = newModel(_SchemaLoader.getLinkSchemaUri());
- link.setRel(linkRelationUri);
- document.setSlotValue(linkSlotName, link);
- }
-
- link.setHref(href);
- }
- }
-
- /**
* Part of the HATEOAS automation. For Documents that have a one or more embedded Link slots, this method embeds each of the referenced Documents within the Links.
*/
private void embedLinkedDocuments(final Document document) {
@@ -30,8 +30,13 @@
import org.slf4j.LoggerFactory;
import org.wrml.model.Model;
import org.wrml.model.rest.Document;
+import org.wrml.model.rest.Link;
+import org.wrml.model.rest.LinkTemplate;
import org.wrml.model.schema.Schema;
import org.wrml.model.schema.ValueType;
+import org.wrml.runtime.rest.ApiLoader;
+import org.wrml.runtime.rest.ApiNavigator;
+import org.wrml.runtime.rest.Resource;
import org.wrml.runtime.schema.LinkProtoSlot;
import org.wrml.runtime.schema.ProtoSlot;
import org.wrml.runtime.schema.Prototype;
@@ -96,7 +101,6 @@
* @param modelState The state for the model.
*/
DefaultModel(final Context context, final ModelState modelState) {
-
_Context = context;
_ModelState = modelState;
}
@@ -561,7 +565,7 @@ private Object getSlotValue(final String slotName, final URI schemaUri, final bo
private void initKeySlots(final Model model, final Keys keys) {
- final SchemaLoader schemaLoader = getContext().getSchemaLoader();
+ final SchemaLoader schemaLoader = model.getContext().getSchemaLoader();
final URI documentSchemaUri = schemaLoader.getDocumentSchemaUri();
URI uri = null;
@@ -596,7 +600,9 @@ else if (keyValue instanceof CompositeKey) {
// See comment above regarding saving the uri key slot for last.
if (uri != null) {
setSlotValue(model, Document.SLOT_NAME_URI, uri, documentSchemaUri, false);
+ updateLinkSlots((Document) model);
}
+
}
private Object invokeReference(final Model model, final LinkProtoSlot linkProtoSlot, final Object[] args) {
@@ -659,6 +665,68 @@ private Object setSlotValue(final String slotName, final Object newValue, final
return context.visitLink(model, linkSlotName, dimensionsBuilder, parameter);
}
+
+ /**
+ * Part of the HATEOAS automation. Uses the runtime's available REST API metadata to update the Links and Link href
+ * values in response to a change/initialization of the URI slot value.
+ */
+ private void updateLinkSlots(Document document) {
+
+ final URI uri = document.getUri();
+ if (uri == null) {
+ return;
+ }
+
+ final Prototype prototype = document.getPrototype();
+ final Context context = document.getContext();
+ final SchemaLoader schemaLoader = context.getSchemaLoader();
+ final ApiLoader apiLoader = context.getApiLoader();
+ final ApiNavigator apiNavigator = apiLoader.getParentApiNavigator(uri);
+
+ if (apiNavigator == null) {
+ return;
+ }
+
+ final Resource resource = apiNavigator.getResource(uri);
+ final Map<URI, LinkTemplate> linkTemplates = resource.getLinkTemplates();
+ if (linkTemplates == null || linkTemplates.isEmpty()) {
+ return;
+ }
+
+ final SortedMap<String, URI> prototypeLinkRelUris = prototype.getLinkRelationUris();
+ final Set<String> linkSlotNames = prototypeLinkRelUris.keySet();
+ for (final String linkSlotName : linkSlotNames) {
+
+ Link link = (Link) document.getSlotValue(linkSlotName);
+
+ final URI linkRelationUri = prototypeLinkRelUris.get(linkSlotName);
+ final Resource endpointResource = apiNavigator.getEndpointResource(linkRelationUri, uri);
+ if (endpointResource == null) {
+ continue;
+ }
+
+ final URI href = endpointResource.getHrefUri(document, linkRelationUri);
+ if (href == null) {
+ // Exclude Links that have null href values.
+
+ if (link != null) {
+ document.setSlotValue(linkSlotName, null);
+ }
+
+ continue;
+ }
+
+ if (link == null) {
+
+ link = context.newModel(schemaLoader.getLinkSchemaUri());
+ link.setRel(linkRelationUri);
+ document.setSlotValue(linkSlotName, link);
+ }
+
+ link.setHref(href);
+ }
+ }
+
@Override
public boolean equals(final Object obj) {
@@ -172,7 +172,7 @@ public void init(final Context context) {
@Override
public void loadInitialState() {
-
+ initSystemFormatKeys();
loadConfiguredFormats();
final FormatLoaderConfiguration config = getConfig();
@@ -360,12 +360,11 @@ private void loadSystemFormats() throws FormatLoaderException {
for (final SystemFormat systemFormat : SystemFormat.values()) {
final URI formatUri = systemFormat.getFormatUri();
-
final UniqueName formatUniqueName = systemFormat.getUniqueName();
final String mediaTypeString = formatUniqueName.toString();
final Format format = context.newModel(Format.class);
-
+ format.setUri(formatUri);
format.setUniqueName(formatUniqueName);
format.setDescription(systemFormat.getDescription());
format.setTitle(mediaTypeString);
@@ -374,8 +373,6 @@ private void loadSystemFormats() throws FormatLoaderException {
format.setMediaType(systemFormat.getMediaType());
format.setFileExtension(systemFormat.getFileExtension());
- format.setUri(formatUri);
-
loadFormat(format);
final Formatter formatter = createSystemFormatter(systemFormat);
@@ -385,4 +382,9 @@ private void loadSystemFormats() throws FormatLoaderException {
}
+ private void initSystemFormatKeys() {
+ for (Format format : _Formats.values()) {
+ format.initKeySlots(format.getKeys());
+ }
+ }
}
@@ -532,6 +532,8 @@ private Object convertRawModelValue(final Model model) {
// Set the Embedded's document uri slot
final URI uri = (URI) documentModel.getSlotMap().get(Document.SLOT_NAME_URI);
typedModel.setSlotValue(Embedded.SLOT_NAME_DOCUMENT_URI, uri);
+ // TODO: BUG!!! - With refactor to initialize hypermedia in initKeys, embedded Document links may not be
+ // generated correctly
}
if (_ModelStack.isEmpty()) {
@@ -61,8 +61,6 @@ public ObjectNode buildCompleteApi(final ObjectMapper objectMapper, final Api ap
final Context context = api.getContext();
final URI apiUri = api.getUri();
- final ApiLoader apiLoader = context.getApiLoader();
- final ApiNavigator apiNavigator = apiLoader.getLoadedApiNavigator(apiUri);
final ObjectNode apiNode = objectMapper.createObjectNode();
apiNode.put(PropertyName.uri.name(), apiUri.toString());
@@ -73,20 +71,36 @@ public ObjectNode buildCompleteApi(final ObjectMapper objectMapper, final Api ap
final Map<URI, ObjectNode> schemaNodes = new HashMap<>();
final Map<URI, LinkRelation> linkRelationCache = new HashMap<>();
- final Map<UUID, Resource> allResources = apiNavigator.getAllResources();
- final SortedMap<String, Resource> orderedResources = new TreeMap<>();
+ final ArrayNode allResourcesNode = objectMapper.createArrayNode();
+ apiNode.put(PropertyName.allResources.name(), allResourcesNode);
- for (final Resource resource : allResources.values()) {
- orderedResources.put(resource.getPathText(), resource);
+ final ApiLoader apiLoader = context.getApiLoader();
+ final ApiNavigator apiNavigator;
+
+ if (apiLoader.getLoadedApiUris().contains(apiUri)) {
+ apiNavigator = apiLoader.getLoadedApiNavigator(apiUri);
+ }
+ else if (ApiNavigator.isApiNavigable(api)){
+ apiNavigator = new ApiNavigator(api);
+ }
+ else {
+ apiNavigator = null;
}
- final ArrayNode allResourcesNode = objectMapper.createArrayNode();
- for (final Resource resource : orderedResources.values()) {
- final ObjectNode resourceNode = buildResourceNode(objectMapper, schemaNodes, linkRelationCache, apiNavigator, resource);
- allResourcesNode.add(resourceNode);
+ if (apiNavigator != null) {
+ final Map<UUID, Resource> allResources = apiNavigator.getAllResources();
+ final SortedMap<String, Resource> orderedResources = new TreeMap<>();
+
+ for (final Resource resource : allResources.values()) {
+ orderedResources.put(resource.getPathText(), resource);
+ }
+
+ for (final Resource resource : orderedResources.values()) {
+ final ObjectNode resourceNode = buildResourceNode(objectMapper, schemaNodes, linkRelationCache, apiNavigator, resource);
+ allResourcesNode.add(resourceNode);
+ }
}
- apiNode.put(PropertyName.allResources.name(), allResourcesNode);
return apiNode;
}
@@ -53,7 +53,19 @@ public ObjectNode buildSwaggerApi(final ObjectMapper objectMapper, final Api api
final ObjectNode rootNode = objectMapper.createObjectNode();
final URI apiUri = api.getUri();
- final ApiNavigator apiNavigator = apiLoader.getLoadedApiNavigator(apiUri);
+
+
+ final ApiNavigator apiNavigator;
+
+ if (apiLoader.getLoadedApiUris().contains(apiUri)) {
+ apiNavigator = apiLoader.getLoadedApiNavigator(apiUri);
+ }
+ else if (ApiNavigator.isApiNavigable(api)){
+ apiNavigator = new ApiNavigator(api);
+ }
+ else {
+ apiNavigator = null;
+ }
rootNode.put("swagger", "2.0");
@@ -89,41 +101,43 @@ public ObjectNode buildSwaggerApi(final ObjectMapper objectMapper, final Api api
rootNode.put("schemes", schemesNode);
schemesNode.add("http");
- final Map<UUID, Resource> allResources = apiNavigator.getAllResources();
- final Map<URI, LinkRelation> allLinkRelations = new HashMap<>();
+ if (apiNavigator != null) {
+ final Map<UUID, Resource> allResources = apiNavigator.getAllResources();
+ final Map<URI, LinkRelation> allLinkRelations = new HashMap<>();
- if (allResources.size() > 0) {
- final SortedMap<String, Resource> displayOrderResources = new TreeMap<>();
+ if (allResources.size() > 0) {
+ final SortedMap<String, Resource> displayOrderResources = new TreeMap<>();
- for (final Resource resource : allResources.values()) {
- displayOrderResources.put(resource.getPathText(), resource);
- }
+ for (final Resource resource : allResources.values()) {
+ displayOrderResources.put(resource.getPathText(), resource);
+ }
- final ObjectNode pathsNode = objectMapper.createObjectNode();
+ final ObjectNode pathsNode = objectMapper.createObjectNode();
- for (final Resource resource : displayOrderResources.values()) {
- if (resource.getReferenceMethods().size() > 0) {
- addPathObjectNode(context, objectMapper, pathsNode, resource, allLinkRelations, tagDefinitionsNode);
+ for (final Resource resource : displayOrderResources.values()) {
+ if (resource.getReferenceMethods().size() > 0) {
+ addPathObjectNode(context, objectMapper, pathsNode, resource, allLinkRelations, tagDefinitionsNode);
+ }
+ }
+
+ if (pathsNode.size() > 0) {
+ rootNode.put("paths", pathsNode);
}
- }
- if (pathsNode.size() > 0) {
- rootNode.put("paths", pathsNode);
}
- }
+ final Set<Schema> allSchemas = apiNavigator.getApiSchemas();
+ if (allSchemas.size() > 0) {
+ final ObjectNode definitionsNode = objectMapper.createObjectNode();
+ rootNode.put("definitions", definitionsNode);
- final Set<Schema> allSchemas = apiNavigator.getApiSchemas();
- if (allSchemas.size() > 0) {
- final ObjectNode definitionsNode = objectMapper.createObjectNode();
- rootNode.put("definitions", definitionsNode);
+ for (final Schema schema : allSchemas) {
+ addSchemaDefinitionObjectNode(objectMapper, definitionsNode, schema);
+ addSchemaTagDefinitionObjectNode(objectMapper, tagDefinitionsNode, schema);
+ }
- for (final Schema schema : allSchemas) {
- addSchemaDefinitionObjectNode(objectMapper, definitionsNode, schema);
- addSchemaTagDefinitionObjectNode(objectMapper, tagDefinitionsNode, schema);
}
-
}
// TODO Add this to WRML API?
Oops, something went wrong.

0 comments on commit 5ebfb07

Please sign in to comment.