-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from exadel-inc/release/3.2.0
Release/3.2.0
- Loading branch information
Showing
24 changed files
with
390 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
core/src/main/java/com/exadel/etoolbox/backpack/core/services/LiveCopyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.exadel.etoolbox.backpack.core.services; | ||
|
||
import org.apache.sling.api.resource.ResourceResolver; | ||
|
||
import java.util.List; | ||
|
||
public interface LiveCopyService { | ||
|
||
List<String> getPaths(ResourceResolver resourceResolver, String path, boolean includeLiveCopies); | ||
} |
75 changes: 75 additions & 0 deletions
75
core/src/main/java/com/exadel/etoolbox/backpack/core/services/impl/LiveCopyServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.exadel.etoolbox.backpack.core.services.impl; | ||
|
||
import com.day.cq.wcm.api.WCMException; | ||
import com.day.cq.wcm.msm.api.LiveCopy; | ||
import com.day.cq.wcm.msm.api.LiveRelationship; | ||
import com.day.cq.wcm.msm.api.LiveRelationshipManager; | ||
import com.exadel.etoolbox.backpack.core.services.LiveCopyService; | ||
import com.exadel.etoolbox.backpack.core.services.pckg.BasePackageService; | ||
import com.exadel.etoolbox.backpack.core.servlets.model.PackageModel; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.jcr.RangeIterator; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Component(service = LiveCopyService.class) | ||
public class LiveCopyServiceImpl implements LiveCopyService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LiveCopyServiceImpl.class); | ||
|
||
@Reference | ||
private LiveRelationshipManager liveRelationshipManager; | ||
|
||
/** | ||
* Called by {@link BasePackageService#getPackageInfo(ResourceResolver, PackageModel)} to adjust paths to resources | ||
* intended for the package | ||
* | ||
* @param path Resource path | ||
* @param includeLiveCopies Flag indicating if this resource's live copies must be included | ||
* @param resourceResolver Current {@code ResourceResolver} object | ||
* @return List of paths | ||
*/ | ||
@Override | ||
public List<String> getPaths(ResourceResolver resourceResolver, String path, boolean includeLiveCopies) { | ||
List<String> paths = new ArrayList<>(Collections.singletonList(path)); | ||
if (!includeLiveCopies) { | ||
return paths; | ||
} | ||
paths.addAll(getLiveCopies(resourceResolver, path)); | ||
return paths; | ||
} | ||
|
||
private List<String> getLiveCopies(ResourceResolver resourceResolver, String path) { | ||
List<String> paths = new ArrayList<>(); | ||
Resource resource = resourceResolver.getResource(path); | ||
if (resource == null) { | ||
return paths; | ||
} | ||
try { | ||
RangeIterator relationships = liveRelationshipManager.getLiveRelationships(resource, null, null); | ||
while (relationships.hasNext()) { | ||
LiveRelationship relationship = (LiveRelationship) relationships.next(); | ||
LiveCopy liveCopy = relationship.getLiveCopy(); | ||
if (liveCopy == null) { | ||
continue; | ||
} | ||
String liveCopyPath = liveCopy.getPath(); | ||
String syncPath = liveCopyPath + relationship.getSyncPath(); | ||
if (resourceResolver.getResource(syncPath) != null) { | ||
paths.add(syncPath); | ||
} | ||
paths.addAll(getLiveCopies(resourceResolver, liveCopyPath)); | ||
} | ||
} catch (WCMException e) { | ||
LOGGER.error("Can't get relationships of the resource {}", resource.getPath(), e); | ||
} | ||
return paths; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.