You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by mg...@apache.org on 2015/12/13 15:31:51 UTC
[44/52] [abbrv] isis git commit: ISIS-1237: sorting out tagging.
ISIS-1237: sorting out tagging.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/9ac72b58
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/9ac72b58
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/9ac72b58
Branch: refs/heads/ISIS-1224-select2-v4
Commit: 9ac72b58572343e8fac7110552687148248dde50
Parents: 4502dc1
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Dec 11 10:09:37 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Dec 11 10:09:37 2015 +0000
----------------------------------------------------------------------
.../_migration-notes_1.10.0-to-1.11.0.adoc | 4 +-
.../swagger/internal/SwaggerSpecGenerator.java | 158 +++++++++++++------
.../internal/SwaggerSpecGeneratorTest.java | 69 ++++++++
.../java/domainapp/dom/simple/SimpleObject.java | 8 -
4 files changed, 185 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/9ac72b58/adocs/documentation/src/main/asciidoc/_migration-notes_1.10.0-to-1.11.0.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/_migration-notes_1.10.0-to-1.11.0.adoc b/adocs/documentation/src/main/asciidoc/_migration-notes_1.10.0-to-1.11.0.adoc
index 6dbd3b3..44c1100 100644
--- a/adocs/documentation/src/main/asciidoc/_migration-notes_1.10.0-to-1.11.0.adoc
+++ b/adocs/documentation/src/main/asciidoc/_migration-notes_1.10.0-to-1.11.0.adoc
@@ -52,7 +52,7 @@ Update the `web.xml`:
</servlet-mapping>
----
+There is also an page to load the Swagger UI; this resides in `src/main/webapp/swagger-ui/index.html`. Copy the index page from the app generated by the xref:ugfun.adoc#_ugfun_getting-started_simpleapp-archetype[SimpleApp archetype].
-The text of the simple archetype's `about/index.html` has also changed; the `<li`> for the `/restful` URL has been
-replaced with a `/swagger-ui` URL.
+The text of the simple app's `about/index.html` has also changed (the `<li`> for the `/restful` URL has been replaced with a `/swagger-ui` URL). If you use this file, then update it.
http://git-wip-us.apache.org/repos/asf/isis/blob/9ac72b58/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGenerator.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
index c58ee23..b1eaf1d 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
@@ -18,22 +18,28 @@
*/
package org.apache.isis.core.metamodel.services.swagger.internal;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
import org.apache.isis.applib.annotation.ActionSemantics;
import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.fixturescripts.FixtureResult;
import org.apache.isis.applib.services.swagger.SwaggerService;
+import org.apache.isis.core.commons.exceptions.IsisException;
import org.apache.isis.core.commons.factory.InstanceUtil;
import org.apache.isis.core.metamodel.facets.actcoll.typeof.TypeOfFacet;
import org.apache.isis.core.metamodel.facets.object.domainservice.DomainServiceFacet;
import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
import org.apache.isis.core.metamodel.facets.object.objectspecid.ObjectSpecIdFacet;
-import org.apache.isis.core.metamodel.services.ServiceUtil;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.spec.SpecificationLoader;
import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
@@ -101,7 +107,8 @@ public class SwaggerSpecGenerator {
}
void appendServicePathsAndDefinitions(final Swagger swagger, final SwaggerService.Visibility visibility) {
- final Collection<ObjectSpecification> allSpecs = specificationLoader.allSpecifications();
+ // take copy to avoid concurrent modification exception
+ final Collection<ObjectSpecification> allSpecs = Lists.newArrayList(specificationLoader.allSpecifications());
for (final ObjectSpecification serviceSpec : allSpecs) {
final DomainServiceFacet domainServiceFacet = serviceSpec.getFacet(DomainServiceFacet.class);
@@ -130,7 +137,8 @@ public class SwaggerSpecGenerator {
}
void appendObjectPathsAndDefinitions(final Swagger swagger, final SwaggerService.Visibility visibility) {
- final Collection<ObjectSpecification> allSpecs = specificationLoader.allSpecifications();
+ // take copy to avoid concurrent modification exception
+ final Collection<ObjectSpecification> allSpecs = Lists.newArrayList(specificationLoader.allSpecifications());
for (final ObjectSpecification objectSpec : allSpecs) {
final DomainServiceFacet domainServiceFacet = objectSpec.getFacet(DomainServiceFacet.class);
@@ -150,6 +158,10 @@ public class SwaggerSpecGenerator {
if(objectSpec.isValue()) {
continue;
}
+ // special cases
+ if(objectSpec.getCorrespondingClass() == FixtureResult.class) {
+ continue;
+ }
final List<OneToOneAssociation> objectProperties = Util.propertiesOf(objectSpec, visibility);
final List<OneToManyAssociation> objectCollections = Util.collectionsOf(objectSpec, visibility);
@@ -191,17 +203,17 @@ public class SwaggerSpecGenerator {
newModel(Util.roSpec("5.2")));
swagger.path("/user",
- new Path()
- .get(new Operation()
- .tag(tag)
- .description(Util.roSpec("6.1"))
- .produces("application/json")
- .produces("application/json;profile=urn:org.restfulobjects:repr-types/user")
- .response(200,
- newResponse(Caching.USER_INFO)
- .description("OK")
- .schema(new RefProperty("#/definitions/RestfulObjectsSupportingUserModel"))
- )));
+ new Path()
+ .get(new Operation()
+ .tag(tag)
+ .description(Util.roSpec("6.1"))
+ .produces("application/json")
+ .produces("application/json;profile=urn:org.restfulobjects:repr-types/user")
+ .response(200,
+ newResponse(Caching.USER_INFO)
+ .description("OK")
+ .schema(new RefProperty("#/definitions/RestfulObjectsSupportingUserModel"))
+ )));
swagger.addDefinition("RestfulObjectsSupportingUserModel",
newModel(Util.roSpec("6.2"))
.property("userName", stringProperty())
@@ -211,17 +223,17 @@ public class SwaggerSpecGenerator {
.required("roles"));
swagger.path("/services",
- new Path()
- .get(new Operation()
- .tag(tag)
- .description(Util.roSpec("7.1"))
- .produces("application/json")
- .produces("application/json;profile=urn:org.restfulobjects:repr-types/services")
- .response(200,
- newResponse(Caching.USER_INFO)
- .description("OK")
- .schema(new RefProperty("#/definitions/RestfulObjectsSupportingServicesModel"))
- )));
+ new Path()
+ .get(new Operation()
+ .tag(tag)
+ .description(Util.roSpec("7.1"))
+ .produces("application/json")
+ .produces("application/json;profile=urn:org.restfulobjects:repr-types/services")
+ .response(200,
+ newResponse(Caching.USER_INFO)
+ .description("OK")
+ .schema(new RefProperty("#/definitions/RestfulObjectsSupportingServicesModel"))
+ )));
swagger.addDefinition("RestfulObjectsSupportingServicesModel",
newModel(Util.roSpec("7.2"))
.property("value", arrayOfLinks())
@@ -229,17 +241,17 @@ public class SwaggerSpecGenerator {
.required("roles"));
swagger.path("/version",
- new Path()
- .get(new Operation()
- .tag(tag)
- .description(Util.roSpec("8.1"))
- .produces("application/json")
- .produces("application/json;profile=urn:org.restfulobjects:repr-types/RestfulObjectsSupportingServicesModel")
- .response(200,
- newResponse(Caching.NON_EXPIRING)
- .description("OK")
- .schema(new ObjectProperty())
- )));
+ new Path()
+ .get(new Operation()
+ .tag(tag)
+ .description(Util.roSpec("8.1"))
+ .produces("application/json")
+ .produces("application/json;profile=urn:org.restfulobjects:repr-types/RestfulObjectsSupportingServicesModel")
+ .response(200,
+ newResponse(Caching.NON_EXPIRING)
+ .description("OK")
+ .schema(new ObjectProperty())
+ )));
swagger.addDefinition("RestfulObjectsSupportingServicesModel",
newModel(Util.roSpec("8.2"))
.property("specVersion", stringProperty())
@@ -290,9 +302,11 @@ public class SwaggerSpecGenerator {
swagger.path(String.format("/services/%s", serviceId), path);
final String serviceModelDefinition = serviceId + "Model";
+
+ final String tag = tagFor(serviceId);
path.get(
new Operation()
- .tag(serviceId)
+ .tag(tag)
.description(Util.roSpec("15.1"))
.produces("application/json")
.produces("application/json;profile=urn:org.restfulobjects:repr-types/object")
@@ -318,10 +332,9 @@ public class SwaggerSpecGenerator {
final Path path = new Path();
swagger.path(String.format("/objects/%s/{objectId}", objectType), path);
- final String tag = objectType.startsWith("org.apache.isis")? "> apache isis internals": objectType;
+ final String tag = tagFor(objectType);
final Operation operation = new Operation();
- path.get(
- operation);
+ path.get(operation);
operation
.tag(tag)
.description(Util.roSpec("14.1"))
@@ -399,9 +412,10 @@ public class SwaggerSpecGenerator {
final Path path = new Path();
swagger.path(String.format("/services/%s/actions/%s/invoke", serviceId, actionId), path);
+ final String tag = tagFor(serviceId);
final Operation invokeOperation =
new Operation()
- .tag(serviceId)
+ .tag(tag)
.description(Util.roSpec("19.1") + ": (invoke) resource of " + serviceId + "#" + actionId)
.produces("application/json;profile=urn:org.apache.isis/v1")
.produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
@@ -482,9 +496,10 @@ public class SwaggerSpecGenerator {
final Path path = new Path();
swagger.path(String.format("/objects/%s/{objectId}/collections/%s", objectType, collectionId), path);
+ final String tag = tagFor(objectType);
final Operation collectionOperation =
new Operation()
- .tag(objectType)
+ .tag(tag)
.description(Util.roSpec("17.1") + ": resource of " + objectType + "#" + collectionId)
.parameter(
new PathParameter()
@@ -522,9 +537,10 @@ public class SwaggerSpecGenerator {
final Path path = new Path();
swagger.path(String.format("/objects/%s/{objectId}/actions/%s/invoke", objectType, actionId), path);
+ final String tag = tagFor(objectType);
final Operation invokeOperation =
new Operation()
- .tag(objectType)
+ .tag(tag)
.description(Util.roSpec("19.1") + ": (invoke) resource of " + objectType + "#" + actionId)
.parameter(
new PathParameter()
@@ -712,7 +728,25 @@ public class SwaggerSpecGenerator {
// TODO: this is horrid, there ought to be a facet we can call instead...
static String serviceIdFor(final ObjectSpecification serviceSpec) {
Object tempServiceInstance = InstanceUtil.createInstance(serviceSpec.getCorrespondingClass());
- return ServiceUtil.id(tempServiceInstance);
+ return serviceId(tempServiceInstance);
+ }
+
+ static String serviceId(final Object object) {
+ final Class<?> cls = object.getClass();
+ try {
+ final Method m = cls.getMethod("getId", new Class[0]);
+ return (String) m.invoke(object, new Object[0]);
+ } catch (final SecurityException e) {
+ throw new IsisException(e);
+ } catch (final NoSuchMethodException e) {
+ return object.getClass().getName();
+ } catch (final IllegalArgumentException e) {
+ throw new IsisException(e);
+ } catch (final IllegalAccessException e) {
+ throw new IsisException(e);
+ } catch (final InvocationTargetException e) {
+ throw new IsisException(e);
+ }
}
static String objectTypeFor(final ObjectSpecification objectSpec) {
@@ -753,4 +787,40 @@ public class SwaggerSpecGenerator {
return Util.withCachingHeaders(new Response(), caching);
}
+ static Pattern tagPatternIsisAddons = Pattern.compile("^org\\.isisaddons\\.module\\.([^\\.]+)\\.(.+)$");
+ static Pattern tagPatternForFqcn = Pattern.compile("^.*\\.([^\\.]+)\\.([^\\.]+)$");
+ static Pattern tagPatternForSchemaTable = Pattern.compile("^([^\\.]+)\\.([^\\.]+)$");
+ static Pattern tagPatternForJaxbDto = Pattern.compile("^([^\\.]+)\\.(v[0-9][^\\.]*)([^\\.]+)$");
+ static String tagFor(final String str) {
+ if (str.startsWith("org.apache.isis")) {
+ return "> apache isis internals";
+ }
+
+ Matcher matcher;
+ matcher = tagPatternIsisAddons.matcher(str);
+ if (matcher.matches()) {
+ return "isisaddons " + matcher.group(1);
+ }
+ matcher = Pattern.compile("^.*\\.([^\\.]+)\\.(v[0-9][^\\.]*)\\.([^\\.]+)$").matcher(str);
+ if (matcher.matches()) {
+ return matcher.group(1);
+ }
+ matcher = tagPatternForFqcn.matcher(str);
+ if (matcher.matches()) {
+ return matcher.group(1);
+ }
+ matcher = tagPatternForSchemaTable.matcher(str);
+ if (matcher.matches()) {
+ // special cases for other Isis addons
+ if(str.startsWith("isis")) {
+ return "isisaddons " + str.substring(4, str.indexOf("."));
+ }
+ return matcher.group(1);
+ }
+
+
+ return str;
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/isis/blob/9ac72b58/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGeneratorTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGeneratorTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGeneratorTest.java
new file mode 100644
index 0000000..cbebd55
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/swagger/internal/SwaggerSpecGeneratorTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.core.metamodel.services.swagger.internal;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class SwaggerSpecGeneratorTest {
+
+ public static class TagFor extends SwaggerSpecGeneratorTest {
+
+ @Test
+ public void fullyQualifiedClass() throws Exception {
+ String tag = SwaggerSpecGenerator.tagFor("foo.bar.Abc");
+ assertThat(tag, is(equalTo("bar")));
+ }
+
+ @Test
+ public void jaxb() throws Exception {
+ String tag = SwaggerSpecGenerator.tagFor("todoapp.app.viewmodels.todoitem.v1_0.ToDoItemDto");
+ assertThat(tag, is(equalTo("todoitem")));
+ }
+
+ @Test
+ public void schemaClass() throws Exception {
+ String tag = SwaggerSpecGenerator.tagFor("bar.Abc");
+ assertThat(tag, is(equalTo("bar")));
+ }
+
+ @Test
+ public void noPackage() throws Exception {
+ String tag = SwaggerSpecGenerator.tagFor("Abc");
+ assertThat(tag, is(equalTo("Abc")));
+ }
+
+ @Test
+ public void isisAddons() throws Exception {
+ String tag = SwaggerSpecGenerator.tagFor("org.isisaddons.module.security.app.feature.ApplicationClass");
+ assertThat(tag, is(equalTo("isisaddons security")));
+ }
+
+ @Test
+ public void applib() throws Exception {
+ String tag = SwaggerSpecGenerator.tagFor("org.apache.isis.applib.fixturescripts.FixtureResult");
+ assertThat(tag, is(equalTo("> apache isis internals")));
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/9ac72b58/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
----------------------------------------------------------------------
diff --git a/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java b/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
index bee0af9..3057180 100644
--- a/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
+++ b/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
@@ -18,14 +18,10 @@
*/
package domainapp.dom.simple;
-import java.util.List;
-
import javax.jdo.JDOHelper;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.VersionStrategy;
-import com.google.common.collect.Lists;
-
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.BookmarkPolicy;
@@ -116,10 +112,6 @@ public class SimpleObject implements Comparable<SimpleObject> {
}
- public List<SimpleObject> getOthers() {
- return Lists.newArrayList();
- }
-
/**
* version (derived property)