Skip to content

Commit 07314e0

Browse files
shaileshmishrashaileshmishra
authored andcommitted
testcases added
1 parent c141ba8 commit 07314e0

File tree

16 files changed

+283
-193
lines changed

16 files changed

+283
-193
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
3+
4+
name: Maven Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up JDK 1.8
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 1.8
21+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
22+
settings-path: ${{ github.workspace }} # location for the settings.xml file
23+
24+
- name: Build with Maven
25+
run: mvn -B package --file pom.xml
26+
27+
- name: Publish to GitHub Packages Apache Maven
28+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
29+
env:
30+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/maven.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up JDK 1.8
20-
uses: actions/setup-java@v1
21-
with:
22-
java-version: 1.8
23-
- name: Build with Maven
24-
run: mvn -B package --file pom.xml
18+
- uses: actions/checkout@v2
19+
- name: Set up JDK 1.8
20+
uses: actions/setup-java@v1
21+
with:
22+
java-version: 1.8
23+
- name: Build with Maven
24+
run: mvn -B package --file pom.xml

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Contentstack-Utils-Java
2+
3+
###Embedded Objects
4+
5+
![Test Coverage](target/site/jacoco/jacoco.csv)

Test Results - test_covarage.html

Lines changed: 17 additions & 17 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>com.contentstack</groupId>
7+
<groupId>com.contentstack.sdk</groupId>
88
<artifactId>util</artifactId>
99
<version>0.0.1-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

12-
<name>Contentstack-CMS</name>
12+
<name>Contentstack-util</name>
1313
<url>https://www.***REMOVED***</url>
1414
<properties>
1515
<!-- package version -->
@@ -110,8 +110,11 @@
110110
<goal>report</goal>
111111
</goals>
112112
</execution>
113+
113114
</executions>
114115
</plugin>
116+
117+
115118
<plugin>
116119
<groupId>org.apache.maven.plugins</groupId>
117120
<artifactId>maven-compiler-plugin</artifactId>
@@ -202,7 +205,7 @@
202205
Sometimes when you may need to compile a certain project to a different
203206
version than what you are currently using. The javac can accept such command
204207
using -source and -target. The Compiler Plugin can also be configured to
205-
provide these options during compilation
208+
provide these optionsCallback during compilation
206209
-->
207210

208211
<!--Provides support to access staging functionality in a remote Nexus Professional server.-->

src/main/java/com/contentstack/utils/Utils.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.contentstack.utils;
22

3+
import com.contentstack.utils.callbacks.ContentCallback;
4+
import com.contentstack.utils.callbacks.MetadataCallback;
35
import com.contentstack.utils.helper.Metadata;
4-
import com.contentstack.utils.render.DefaultOptions;
5-
import com.contentstack.utils.render.Options;
6+
import com.contentstack.utils.render.DefaultOptionsCallback;
7+
import com.contentstack.utils.callbacks.OptionsCallback;
68
import org.json.JSONArray;
79
import org.json.JSONObject;
810
import org.jsoup.Jsoup;
@@ -25,8 +27,7 @@ private interface MetadataCallback { void embeddedObject(Metadata metadata); }
2527
* @param keyPath keyPath
2628
* @param renderObject renderObject
2729
*/
28-
public static void render(JSONObject entryObj, String[] keyPath, Options renderObject){
29-
30+
public static void render(JSONObject entryObj, String[] keyPath, OptionsCallback renderObject){
3031
ContentCallback callback = content -> {
3132
if (content instanceof JSONArray) {
3233
JSONArray contentArray = (JSONArray) content;
@@ -39,12 +40,13 @@ public static void render(JSONObject entryObj, String[] keyPath, Options render
3940
};
4041

4142
if (entryObj!=null && entryObj.has("_embedded_items")){
43+
// when keyPath is provided by user
4244
if (keyPath!=null){
4345
for (String path : keyPath) {
4446
findContent(entryObj, path, callback);
4547
}
4648
}else {
47-
// if keyPath is not available
49+
// if keyPath is not given, extract all available keyPath from _embedded_items
4850
JSONObject embedKeys = entryObj.getJSONObject("_embedded_items");
4951
ArrayList<String> pathKeys = new ArrayList<>(embedKeys.keySet());
5052
for (String path : pathKeys) {
@@ -66,7 +68,7 @@ private JSONObject findEntryByPath(JSONObject entryObj, String path) {
6668
* @param keyPath String array keyPath
6769
* @param renderObject renderObjects
6870
*/
69-
public void render(JSONArray jsonArray, String[] keyPath, Options renderObject){
71+
public void render(JSONArray jsonArray, String[] keyPath, OptionsCallback renderObject){
7072
jsonArray.forEach(jsonObj-> render((JSONObject) jsonObj, keyPath, renderObject));
7173
}
7274

@@ -92,7 +94,7 @@ public static String renderContent(String rteStringify, JSONObject embedObject,
9294
}
9395
if (filteredContent.isPresent()) {
9496
JSONObject contentToPass = filteredContent.get();
95-
String stringOption = getStringOption(options, metadata, contentToPass);
97+
String stringOption = getStringOption(optionsCallback, metadata, contentToPass);
9698
sReplaceRTE[0] = html.body().html().replace(metadata.getOuterHTML(), stringOption);
9799
}
98100
});
@@ -105,14 +107,14 @@ public static String renderContent(String rteStringify, JSONObject embedObject,
105107
* Take below items to return updated string
106108
* @param rteArray JSONArray of the rte available for the embedding
107109
* @param entryObject JSONObject to get the _embedded_object (_embedded_entries/_embedded_assets)
108-
* @param options Options take takes input as (StyleType type, JSONObject embeddedObject)
110+
* @param optionsCallback Options take takes input as (StyleType type, JSONObject embeddedObject)
109111
* @return String of rte with replaced tag
110112
*/
111-
public static JSONArray renderContents(JSONArray rteArray, JSONObject entryObject, Options options) {
113+
public static JSONArray renderContents(JSONArray rteArray, JSONObject entryObject, OptionsCallback optionsCallback) {
112114
JSONArray jsonArrayRTEContent = new JSONArray();
113115
for (Object RTE : rteArray) {
114116
String stringify = (String) RTE;
115-
String renderContent = renderContent(stringify, entryObject, options);
117+
String renderContent = renderContent(stringify, entryObject, optionsCallback);
116118
jsonArrayRTEContent.put(renderContent);
117119
}
118120
return jsonArrayRTEContent;
@@ -156,7 +158,7 @@ private static Optional<JSONObject> findEmbeddedItems(JSONObject jsonObject, Met
156158
return Optional.empty();
157159
}
158160

159-
private static String getStringOption(Options options, Metadata metadata, JSONObject contentToPass) {
161+
private static String getStringOption(OptionsCallback optionsCallback, Metadata metadata, JSONObject contentToPass) {
160162
// TODO: Sending HashMap as HTML Attributes
161163
String stringOption = options.renderOptions(
162164
contentToPass, metadata);
@@ -182,7 +184,6 @@ private static void getEmbeddedObjects(Document html, MetadataCallback metadataC
182184
String style = entry.attr("sys-style-type");
183185
String outerHTML = entry.outerHtml();
184186
Metadata metadata = new Metadata(text, type, uid, contentType, style, outerHTML, entry.attributes());
185-
logger.info(metadata.toString());
186187
metadataCallback.embeddedObject(metadata);
187188
});
188189

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.contentstack.utils.callbacks;
2+
3+
public interface ContentCallback { Object contentObject(Object content); }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.contentstack.utils.callbacks;
2+
3+
import com.contentstack.utils.helper.Metadata;
4+
5+
public interface MetadataCallback { void embeddedObject(Metadata metadata); }

src/main/java/com/contentstack/utils/render/Options.java renamed to src/main/java/com/contentstack/utils/callbacks/OptionsCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.contentstack.utils.render;
1+
package com.contentstack.utils.callbacks;
22
import com.contentstack.utils.helper.Metadata;
33
import org.json.JSONObject;
44
import org.jsoup.nodes.Attributes;

src/main/java/com/contentstack/utils/helper/Metadata.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class Metadata {
99

1010
String text ;
1111
/* type of embedded object*/
12-
//TODO: itemType Enum type to be taken ( implementation incomplete)
1312
String itemType;
1413
/* itemUid of embedded object*/
1514
String itemUid;

0 commit comments

Comments
 (0)