This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/master by this push:
new 870a716c6e CAUSEWAY-3741: minor: adds some java-doc
870a716c6e is described below
commit 870a716c6e442b9b6f07c78c82b22bb963fb91d8
Author: andi-huber <[email protected]>
AuthorDate: Sun May 19 07:31:09 2024 +0200
CAUSEWAY-3741: minor: adds some java-doc
---
.../viewer/graphql/model/domain/TypeNames.java | 67 ++++++++++++++--------
.../viewer/graphql/model/domain/TypeNamesTest.java | 38 ++++++++++++
2 files changed, 80 insertions(+), 25 deletions(-)
diff --git
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/TypeNames.java
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/TypeNames.java
index d70fdadeff..59e8c37151 100644
---
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/TypeNames.java
+++
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/TypeNames.java
@@ -18,75 +18,80 @@
*/
package org.apache.causeway.viewer.graphql.model.domain;
-import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
-import org.apache.causeway.core.metamodel.spec.feature.*;
import java.util.Arrays;
import java.util.stream.Collectors;
-import java.lang.Character;
+
+import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectActionParameter;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectFeature;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectMember;
+import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
import lombok.experimental.UtilityClass;
@UtilityClass
public final class TypeNames {
- public static String objectTypeFieldNameFor(
+ public String objectTypeFieldNameFor(
final ObjectSpecification objectSpecification) {
return sanitized(objectSpecification.getLogicalTypeName());
}
- public static String objectTypeNameFor(
+ public String objectTypeNameFor(
final ObjectSpecification objectSpecification,
final SchemaType schemaType) {
return schemaType.name().toLowerCase() + "__" +
sanitized(objectSpecification.getLogicalTypeName());
}
- public static String metaTypeNameFor(
+ public String metaTypeNameFor(
final ObjectSpecification objectSpecification,
final SchemaType schemaType) {
return objectTypeNameFor(objectSpecification, schemaType) +
"__gqlv_meta";
}
- public static String inputTypeNameFor(
+ public String inputTypeNameFor(
final ObjectSpecification objectSpecification,
final SchemaType schemaType) {
return objectTypeNameFor(objectSpecification, schemaType) +
"__gqlv_input";
}
- public static String enumTypeNameFor(
+ public String enumTypeNameFor(
final ObjectSpecification objectSpec,
final SchemaType schemaType) {
return objectTypeNameFor(objectSpec, schemaType) + "__gqlv_enum";
}
- public static String actionTypeNameFor(
+ public String actionTypeNameFor(
final ObjectSpecification owningType,
final ObjectAction oa,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" + oa.asciiId()
+ "__gqlv_action";
}
- public static String actionInvokeTypeNameFor(
+ public String actionInvokeTypeNameFor(
final ObjectSpecification owningType,
final ObjectAction oa,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" + oa.asciiId()
+ "__gqlv_action_invoke";
}
- public static String actionParamsTypeNameFor(
+ public String actionParamsTypeNameFor(
final ObjectSpecification owningType,
final ObjectAction oa,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" + oa.asciiId()
+ "__gqlv_action_params";
}
- public static String actionArgsTypeNameFor(
+ public String actionArgsTypeNameFor(
final ObjectSpecification owningType,
final ObjectAction oa,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" + oa.asciiId()
+ "__gqlv_action_args";
}
- public static String actionParamTypeNameFor(
+ public String actionParamTypeNameFor(
final ObjectSpecification owningType,
final ObjectActionParameter oap,
final SchemaType schemaType) {
@@ -94,43 +99,55 @@ public final class TypeNames {
return objectTypeNameFor(owningType, schemaType) + "__" +
objectFeature.asciiId() + "__" + oap.asciiId() + "__gqlv_action_parameter";
}
- public static String propertyTypeNameFor(
+ public String propertyTypeNameFor(
final ObjectSpecification owningType,
final OneToOneAssociation otoa,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" +
otoa.asciiId() + "__gqlv_property";
}
- public static String propertyLobTypeNameFor(
+ public String propertyLobTypeNameFor(
final ObjectSpecification owningType,
final OneToOneAssociation otoa,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" +
otoa.asciiId() + "__gqlv_property_lob";
}
- public static String collectionTypeNameFor(
+ public String collectionTypeNameFor(
final ObjectSpecification owningType,
final OneToManyAssociation otma,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" +
otma.asciiId() + "__gqlv_collection";
}
- public static String memberTypeNameFor(
+ public String memberTypeNameFor(
final ObjectSpecification owningType,
final ObjectMember objectMember,
final SchemaType schemaType) {
return objectTypeNameFor(owningType, schemaType) + "__" +
objectMember.asciiId() + "__gqlv_member";
}
- private static String sanitized(final String name) {
- String result = name.replace('.', '_').replace("#",
"__").replace("()","");
- int hyphenStart = result.indexOf("-");
- if(hyphenStart > 0) {
- result = result.substring(0,hyphenStart) +
Arrays.stream(result.substring(hyphenStart + 1).split("-"))
- .map(word -> Character.toUpperCase(word.charAt(0)) +
word.substring(1))
- .collect(Collectors.joining());
- }
+ // -- HELPER
+
+ String sanitized(final String name) {
+ var result = name.replace('.', '_').replace("#", "__").replace("()",
"");
+ result = hyphenedToCamelCase(result);
return result;
}
+ /**
+ * Converts e.g. {@code a-b} to {@code aB}.
+ * Which allows namespaces that contain a hyphen like
+ * {@code university.calc.calculator-hyphenated} to be referenced from
QraphQL via
+ * {@code university.calc.calculatorHyphenated} say.
+ */
+ private String hyphenedToCamelCase(String string) {
+ final int hyphenStart = string.indexOf("-");
+ return hyphenStart > 0
+ ? string.substring(0,hyphenStart) +
Arrays.stream(string.substring(hyphenStart + 1).split("-"))
+ .map(word -> Character.toUpperCase(word.charAt(0)) +
word.substring(1))
+ .collect(Collectors.joining())
+ : string;
+ }
+
}
diff --git
a/viewers/graphql/model/src/test/java/org/apache/causeway/viewer/graphql/model/domain/TypeNamesTest.java
b/viewers/graphql/model/src/test/java/org/apache/causeway/viewer/graphql/model/domain/TypeNamesTest.java
new file mode 100644
index 0000000000..c575f4c021
--- /dev/null
+++
b/viewers/graphql/model/src/test/java/org/apache/causeway/viewer/graphql/model/domain/TypeNamesTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.causeway.viewer.graphql.model.domain;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class TypeNamesTest {
+
+ @Test
+ void typeNameSanitized() {
+ assertEquals("a", TypeNames.sanitized("a")); // identity operation
+ assertEquals("aB", TypeNames.sanitized("aB")); // identity operation
+ assertEquals("Ab", TypeNames.sanitized("Ab")); // identity operation
+
+ assertEquals("aB_Cd", TypeNames.sanitized("aB.Cd"));
+ assertEquals("a_b_cD", TypeNames.sanitized("a.b.c-d"));
+ assertEquals("aB_c_d", TypeNames.sanitized("a-b.c.d"));
+ }
+
+}