Skip to content

Commit

Permalink
remove else statment
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne committed Jul 12, 2023
1 parent b6d071a commit 94f4d16
Showing 1 changed file with 41 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,51 +129,48 @@ private void updateNewsImagesPermissions(Node newsNode, Session session) throws
Matcher matcher = Pattern.compile(IMAGE_SRC_REGEX).matcher(getStringProperty(newsNode, "exo:body"));
int imagesCount = 0;
ExtendedNode image = null;
if (matcher.find()) {
do {
String match = matcher.group(1);
String imageUUID = match.substring(match.lastIndexOf("/") + 1);
image = (ExtendedNode) session.getNodeByUUID(imageUUID);
if (image != null) {
if (image.canAddMixin(EXO_PRIVILEGEABLE)) {
image.addMixin(EXO_PRIVILEGEABLE);
}
boolean isPublicImage = image.getACL()
.getPermissionEntries()
.stream()
.anyMatch(accessControlEntry -> accessControlEntry.getIdentity()
.equals(PLATFORM_USERS_GROUP_IDENTITY));
if (!isPublicImage) {
// make news images public
image.setPermission(PLATFORM_USERS_GROUP_IDENTITY, READ_PERMISSIONS);
image.save();
imagesCount += 1;
}
while (matcher.find()) {
String match = matcher.group(1);
String imageUUID = match.substring(match.lastIndexOf("/") + 1);
image = (ExtendedNode) session.getNodeByUUID(imageUUID);
if (image != null) {
if (image.canAddMixin(EXO_PRIVILEGEABLE)) {
image.addMixin(EXO_PRIVILEGEABLE);
}
} while (matcher.find());
} else {
String existingUploadImagesSrcRegex = "src=\"" + CommonsUtils.getCurrentDomain() + "/"
+ PortalContainer.getCurrentPortalContainerName() + "/" + CommonsUtils.getRestContextName() + "/jcr/?(.+)?\"";
matcher = Pattern.compile(existingUploadImagesSrcRegex).matcher(getStringProperty(newsNode, "exo:body"));
while (matcher.find()) {
String match = matcher.group(1);
String imagePath = match.substring(match.indexOf("/Groups"));
image = (ExtendedNode) getNodeByPath(imagePath, session);
if (image != null) {
if (image.canAddMixin(EXO_PRIVILEGEABLE)) {
image.addMixin(EXO_PRIVILEGEABLE);
}
boolean isPublicImage = image.getACL()
.getPermissionEntries()
.stream()
.anyMatch(accessControlEntry -> accessControlEntry.getIdentity()
.equals(PLATFORM_USERS_GROUP_IDENTITY));
if (!isPublicImage) {
// make news images public
image.setPermission(PLATFORM_USERS_GROUP_IDENTITY, READ_PERMISSIONS);
image.save();
imagesCount += 1;
}
boolean isPublicImage = image.getACL()
.getPermissionEntries()
.stream()
.anyMatch(accessControlEntry -> accessControlEntry.getIdentity()
.equals(PLATFORM_USERS_GROUP_IDENTITY));
if (!isPublicImage) {
// make news images public
image.setPermission(PLATFORM_USERS_GROUP_IDENTITY, READ_PERMISSIONS);
image.save();
imagesCount += 1;
}
}
}
String existingUploadImagesSrcRegex = "src=\"" + CommonsUtils.getCurrentDomain() + "/"
+ PortalContainer.getCurrentPortalContainerName() + "/" + CommonsUtils.getRestContextName() + "/jcr/?(.+)?\"";
matcher = Pattern.compile(existingUploadImagesSrcRegex).matcher(getStringProperty(newsNode, "exo:body"));
while (matcher.find()) {
String match = matcher.group(1);
String imagePath = match.substring(match.indexOf("/Groups"));
image = (ExtendedNode) getNodeByPath(imagePath, session);
if (image != null) {
if (image.canAddMixin(EXO_PRIVILEGEABLE)) {
image.addMixin(EXO_PRIVILEGEABLE);
}
boolean isPublicImage = image.getACL()
.getPermissionEntries()
.stream()
.anyMatch(accessControlEntry -> accessControlEntry.getIdentity()
.equals(PLATFORM_USERS_GROUP_IDENTITY));
if (!isPublicImage) {
// make news images public
image.setPermission(PLATFORM_USERS_GROUP_IDENTITY, READ_PERMISSIONS);
image.save();
imagesCount += 1;
}
}
}
Expand Down

0 comments on commit 94f4d16

Please sign in to comment.