ProductUpdateActionFactory.java
4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.commerce.common.AbstractJcrProduct
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.ActionConfig
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveActionFactory
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveStatus
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.commerce.pim.impl;
import com.adobe.cq.commerce.common.AbstractJcrProduct;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.ActionConfig;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveActionFactory;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveStatus;
import javax.jcr.Node;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service
@Property(name="service.description", value={"MSM action which updates product pages in a live copy of a product catalog"})
public class ProductUpdateActionFactory
implements LiveActionFactory<LiveAction> {
protected static final Logger log = LoggerFactory.getLogger(ProductUpdateActionFactory.class);
@Property(name="liveActionName")
private static final String[] LIVE_ACTION_NAME = new String[]{ProductUpdateAction.class.getSimpleName(), "productUpdate"};
public String createsAction() {
return LIVE_ACTION_NAME[0];
}
public ProductUpdateAction createAction(Resource resource) {
return new ProductUpdateAction();
}
private static class ProductUpdateAction
implements LiveAction {
private ProductUpdateAction() {
}
public void execute(Resource source, Resource target, LiveRelationship relation, boolean autoSave, boolean reset) throws WCMException {
if (source != null && AbstractJcrProduct.isABaseProduct((Resource)source) && target != null && !relation.getStatus().isCancelled()) {
try {
Node sourceNode = (Node)source.adaptTo(Node.class);
Node targetNode = (Node)target.adaptTo(Node.class);
if (sourceNode != null && targetNode != null && sourceNode.hasProperty("productData")) {
JcrUtil.copy((javax.jcr.Property)sourceNode.getProperty("productData"), (Node)targetNode, (String)null);
if (autoSave) {
targetNode.getSession().save();
}
}
}
catch (Exception e) {
ProductUpdateActionFactory.log.error("Failed to update product.", (Throwable)e);
}
}
}
public String getName() {
return this.getClass().getSimpleName();
}
public String getTitle() {
return this.getName();
}
public void write(JSONWriter jsonWriter) throws JSONException {
jsonWriter.object();
jsonWriter.key("name").value((Object)this.getName());
jsonWriter.key("title").value((Object)this.getTitle());
jsonWriter.endObject();
}
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config, boolean autoSave) throws WCMException {
throw new UnsupportedOperationException();
}
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config, boolean autoSave, boolean isResetRollout) throws WCMException {
throw new UnsupportedOperationException();
}
public int getRank() {
throw new UnsupportedOperationException();
}
public String[] getPropertiesNames() {
throw new UnsupportedOperationException();
}
public String getParameterName() {
return null;
}
}
}