Skip to content

Commit d6b65b8

Browse files
authored
Merge pull request #1000 from commercetools/DEVX-640-helper-method-from-Coco-product-to-import-API-product
DEVX-640-helper-method-from-Coco-product-to-import-API-product
2 parents 136be4d + 5efe30b commit d6b65b8

34 files changed

+2345
-0
lines changed

.git-blame-ignore-revs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ de95c481329aa8b821e6e71ac35c1b8bc67e3e86
99
78c44064f4ec15091bde7a2dc590aa2b3a99341d
1010
03665b75a1e1c3a3cf28df1dec52e91b308e4368
1111
7e25c796da25ae080a952936de535a1228fed448
12+
a0945d605699e8e7aca9448767ba1286b7ebb2c1
1213
7ceb871552e5d9cb0379fbba014690aa067061eb
1314
af9205fa592e4ae32ceca951c560a48b512b7744
15+
6154ba1d1461d9279a305b52d8dd4b842e848545
16+
0b5dd8bee320456962d94cb845e9d27469a34091
17+
f58dd73747791edcd45722a4903da44da1b9b2d3
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id("java")
3+
}
4+
5+
group = "com.commercetools.sdk"
6+
version = "19.5.0-SNAPSHOT"
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
testImplementation(platform("org.junit:junit-bom:5.10.0"))
14+
testImplementation("org.junit.jupiter:junit-jupiter")
15+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
16+
17+
implementation(project(":commercetools:commercetools-sdk-java-api"))
18+
implementation(project(":commercetools:commercetools-sdk-java-importapi"))
19+
}
20+
21+
tasks.test {
22+
useJUnitPlatform()
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
package com.commercetools.sdk;
3+
4+
import java.util.Optional;
5+
6+
import com.commercetools.api.models.IdentifiableObjHolder;
7+
import com.commercetools.api.models.WithKey;
8+
import com.commercetools.api.models.common.Reference;
9+
10+
public class ExpandObjResolverService implements KeyResolverService {
11+
12+
@Override
13+
public <T extends IdentifiableObjHolder<TRes> & Reference, TRes extends WithKey> String resolveKey(T identifiable) {
14+
return Optional.ofNullable(identifiable).map(T::getObj).map(TRes::getKey).orElse(null);
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
package com.commercetools.sdk;
3+
4+
import com.commercetools.api.models.IdentifiableObjHolder;
5+
import com.commercetools.api.models.WithKey;
6+
import com.commercetools.api.models.common.Reference;
7+
8+
public interface KeyResolverService {
9+
public <T extends IdentifiableObjHolder<TRes> & Reference, TRes extends WithKey> String resolveKey(T identifiable);
10+
}

commercetools/commercetools-importapi-utils/src/main/java/com/commercetools/sdk/ProductUtil.java

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

commercetools/commercetools-importapi-utils/src/test/java/com/commercetools/sdk/ProductUtilTest.java

Lines changed: 292 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
package com.commercetools.sdk;
3+
4+
import java.io.IOException;
5+
import java.io.UncheckedIOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
9+
public class TestUtils {
10+
public static String stringFromResource(final String resourcePath) {
11+
try {
12+
return Files.readString(Path.of(resourcePath));
13+
}
14+
catch (final IOException e) {
15+
throw new UncheckedIOException(e);
16+
}
17+
}
18+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"key": "product-draft-key",
3+
"name": {
4+
"en": "blue shirt"
5+
},
6+
"slug": {
7+
"en": "blue-t-shirt"
8+
},
9+
"productType": {
10+
"typeId": "product-type",
11+
"key": "sample"
12+
},
13+
"masterVariant": {
14+
"key": "master-variant-key",
15+
"attributes": [
16+
{
17+
"type": "reference",
18+
"name": "product-ref-attribute",
19+
"value": {
20+
"key": "category-key",
21+
"typeId": "category"
22+
}
23+
},
24+
{
25+
"type": "reference",
26+
"name": "product-custom-object-ref-attribute",
27+
"value": {
28+
"key": "custom-object-key",
29+
"container": "custom-object-container-key",
30+
"typeId": "key-value-document"
31+
}
32+
}
33+
]
34+
}
35+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "attr1",
51+
"value": true
52+
}
53+
]
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "datetime",
51+
"value": "2020-01-01T13:15:00.123Z"
52+
}
53+
]
54+
}

0 commit comments

Comments
 (0)