25
25
import org .apache .commons .httpclient .HttpStatus ;
26
26
import org .apache .commons .lang3 .StringUtils ;
27
27
import org .apache .commons .lang3 .time .StopWatch ;
28
+ import org .apache .jackrabbit .JcrConstants ;
28
29
import org .apache .sling .api .SlingHttpServletRequest ;
29
30
import org .apache .sling .api .SlingHttpServletResponse ;
30
31
import org .apache .sling .api .resource .Resource ;
31
32
import org .apache .sling .api .resource .ResourceResolver ;
33
+ import org .apache .sling .api .resource .ValueMap ;
32
34
import org .apache .sling .api .servlets .HttpConstants ;
33
35
import org .apache .sling .api .servlets .SlingAllMethodsServlet ;
34
36
import org .apache .sling .servlets .annotations .SlingServletResourceTypes ;
48
50
import java .util .Optional ;
49
51
import java .util .concurrent .TimeUnit ;
50
52
53
+ import static com .day .cq .wcm .msm .api .MSMNameConstants .PN_LAST_ROLLEDOUT ;
54
+
51
55
/**
52
56
* Collects data related to eligible for synchronization live relationships for the given resource.
53
57
* The data is necessary for building 'Targets' tree in the UI dialog and further rollout in {@link RolloutServlet}
61
65
public class CollectLiveCopiesServlet extends SlingAllMethodsServlet {
62
66
private static final Logger LOG = LoggerFactory .getLogger (CollectLiveCopiesServlet .class );
63
67
68
+ private static final String JCR_CONTENT_NODE = "/" + JcrConstants .JCR_CONTENT ;
64
69
private static final String PATH_REQUEST_PARAM = "path" ;
65
70
66
71
private static final String MASTER_JSON_FIELD = "master" ;
@@ -69,6 +74,7 @@ public class CollectLiveCopiesServlet extends SlingAllMethodsServlet {
69
74
private static final String LIVE_COPIES_JSON_FIELD = "liveCopies" ;
70
75
private static final String IS_NEW_JSON_FIELD = "isNew" ;
71
76
private static final String HAS_ROLLOUT_TRIGGER_JSON_FIELD = "autoRolloutTrigger" ;
77
+ private static final String LAST_ROLLED_OUT_JSON_FIELD = "lastRolledOut" ;
72
78
73
79
@ Reference
74
80
private transient LiveRelationshipManager liveRelationshipManager ;
@@ -139,13 +145,15 @@ private JsonObject relationshipToJson(LiveRelationship relationship,
139
145
140
146
String liveCopyPath = liveCopy .getPath ();
141
147
boolean isNew = !resourceExists (resourceResolver , liveCopyPath + syncPath );
148
+
142
149
return Json .createObjectBuilder ()
143
150
.add (MASTER_JSON_FIELD , source + sourceSyncPath )
144
151
.add (PATH_JSON_FIELD , liveCopyPath + syncPath )
145
152
.add (DEPTH_JSON_FIELD , depth )
146
153
.add (LIVE_COPIES_JSON_FIELD , getLiveCopiesJsonArray (liveCopyPath , syncPath , resourceResolver , depth + 1 ))
147
154
.add (IS_NEW_JSON_FIELD , isNew )
148
155
.add (HAS_ROLLOUT_TRIGGER_JSON_FIELD , !isNew && hasAutoTrigger (liveCopy ))
156
+ .add (LAST_ROLLED_OUT_JSON_FIELD , getStringDate (resourceResolver , liveCopyPath + syncPath ))
149
157
.build ();
150
158
}
151
159
@@ -173,4 +181,12 @@ private boolean resourceExists(ResourceResolver resourceResolver, String path) {
173
181
return Optional .ofNullable (resourceResolver .getResource (path ))
174
182
.isPresent ();
175
183
}
184
+
185
+ private static String getStringDate (ResourceResolver resourceResolver , String resourcePath ) {
186
+ Resource syncResource = resourceResolver .getResource (resourcePath + JCR_CONTENT_NODE );
187
+ return Optional .ofNullable (syncResource )
188
+ .map (r -> r .adaptTo (ValueMap .class ))
189
+ .map (vm -> vm .get (PN_LAST_ROLLEDOUT , String .class ))
190
+ .orElse (StringUtils .EMPTY );
191
+ }
176
192
}
0 commit comments