From 94f4d16d95f2808b100a28f8c9998cea6d36be6a Mon Sep 17 00:00:00 2001 From: sofyenne Date: Wed, 12 Jul 2023 14:30:54 +0100 Subject: [PATCH] remove else statment --- ...hedNewsImagesPermissionsUpgradePlugin.java | 85 +++++++++---------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/PublishedNewsImagesPermissionsUpgradePlugin.java b/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/PublishedNewsImagesPermissionsUpgradePlugin.java index 4b8e4621e..5661ff91a 100644 --- a/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/PublishedNewsImagesPermissionsUpgradePlugin.java +++ b/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/PublishedNewsImagesPermissionsUpgradePlugin.java @@ -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; } } }