String clusterId = null;
Calendar clusterIdDefinedAt = null;
String clusterIdDefinedBy = null;
final View currentlyEstablishedView = ViewHelper.getEstablishedView(resourceResolver, config);
if (currentlyEstablishedView != null) {
final ValueMap establishedViewValueMap = currentlyEstablishedView.getResource().adaptTo(ValueMap.class);
clusterId = establishedViewValueMap.get(VIEW_PROPERTY_CLUSTER_ID, String.class);
if (clusterId == null || clusterId.length() == 0) {
clusterId = currentlyEstablishedView.getResource().getName();
}
Date date = establishedViewValueMap.get(VIEW_PROPERTY_CLUSTER_ID_DEFINED_AT, Date.class);
if (date!=null) {
clusterIdDefinedAt = Calendar.getInstance();
clusterIdDefinedAt.setTime(date);
}
clusterIdDefinedBy = establishedViewValueMap.get(VIEW_PROPERTY_CLUSTER_ID_DEFINED_BY, String.class);
}
if (clusterId == null || clusterId.length() == 0) {
clusterId = newViewId;
clusterIdDefinedAt = Calendar.getInstance();
}