Skip to content

Commit

Permalink
#27008 include missing changes of StoryBlockAPIImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Dec 20, 2023
1 parent e4a4a32 commit 2742aa6
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.dotmarketing.exception.DotRuntimeException;
import com.google.common.collect.ImmutableList;
import com.liferay.util.StringPool;
import io.vavr.control.Try;
Expand Down Expand Up @@ -63,8 +64,11 @@ public StoryBlockReferenceResult refreshStoryBlockValueReferences(final Object s
boolean refreshed = false;
try {
final LinkedHashMap<String, Object> blockEditorMap = this.toMap(storyBlockValue);
final List<Map<String, Object>> contentsMap = (List) blockEditorMap.get(CONTENT_KEY);
for (final Map<String, Object> contentMap : contentsMap) {
final Object contentsMap = blockEditorMap.get(CONTENT_KEY);
if(!UtilMethods.isSet(contentsMap) || !(contentsMap instanceof List)) {
return new StoryBlockReferenceResult(true, storyBlockValue);
}
for (final Map<String, Object> contentMap : (List<Map<String, Object>>) contentsMap) {
if (UtilMethods.isSet(contentMap)) {
final String type = contentMap.get(TYPE_KEY).toString();
if (allowedTypes.contains(type)) { // if somebody adds a story block to itself, we don't want to refresh it
Expand All @@ -78,9 +82,8 @@ public StoryBlockReferenceResult refreshStoryBlockValueReferences(final Object s
} catch (final Exception e) {
final String errorMsg = String.format("An error occurred when refreshing Story Block Contentlet " +
"references: %s", e.getMessage());
Logger.error(StoryBlockAPIImpl.class, errorMsg);
Logger.debug(StoryBlockAPIImpl.class, errorMsg, e);
throw new RuntimeException(errorMsg, e);
Logger.warnAndDebug(StoryBlockAPIImpl.class, errorMsg,e);
throw new DotRuntimeException(errorMsg, e);
}
// Return the original value in case no data was refreshed
return new StoryBlockReferenceResult(false, storyBlockValue);
Expand All @@ -105,8 +108,8 @@ private boolean refreshStoryBlockMap(final Map<String, Object> contentMap, final
if (UtilMethods.isSet(attrsMap)) {
final Map<String, Object> dataMap = (Map) attrsMap.get(DATA_KEY);
if (UtilMethods.isSet(dataMap)) {
final String identifier = dataMap.get(IDENTIFIER_KEY).toString();
final String inode = dataMap.get(INODE_KEY).toString();
final String identifier = (String) dataMap.get(IDENTIFIER_KEY);
final String inode = (String) dataMap.get(INODE_KEY);
final long languageId = ConversionUtils.toLong(dataMap.get(LANGUAGE_ID_KEY), ()-> APILocator.getLanguageAPI().getDefaultLanguage().getId());
if (UtilMethods.isSet(identifier) && UtilMethods.isSet(inode)) {
if (!identifier.equals(parentContentletIdentifier)) { // if somebody adds a story block to itself, we don't want to refresh it
Expand All @@ -131,11 +134,9 @@ private boolean refreshStoryBlockMap(final Map<String, Object> contentMap, final
@Override
public List<String> getDependencies(final Contentlet contentlet) {
final ImmutableList.Builder<String> contentletIdList = new ImmutableList.Builder<>();
if (null != contentlet && null != contentlet.getContentType()) {
contentlet.getContentType().fields(StoryBlockField.class).forEach(field -> {
contentletIdList.addAll(this.getDependencies(contentlet.get(field.variable())));
});
}
contentlet.getContentType().fields(StoryBlockField.class).forEach(field ->
contentletIdList.addAll(this.getDependencies(contentlet.get(field.variable())))
);
return contentletIdList.build();
}

Expand All @@ -146,11 +147,15 @@ public List<String> getDependencies(final Object storyBlockValue) {
try {
if (null != storyBlockValue && JsonUtil.isValidJSON(storyBlockValue.toString())) {
final Map<String, Object> blockEditorMap = this.toMap(storyBlockValue);
final List<Map<String, Object>> contentsMap = (List) blockEditorMap.get(CONTENT_KEY);
for (final Map<String, Object> contentMapObject : contentsMap) {
Object contentsMap = blockEditorMap.getOrDefault(CONTENT_KEY, List.of());
if(!(contentsMap instanceof List)) {
return List.of();
}

for (final Map<String, Object> contentMapObject : (List<Map<String, Object>>) contentsMap) {
if (UtilMethods.isSet(contentMapObject)) {
final String type = contentMapObject.get(TYPE_KEY).toString();
if (allowedTypes.contains(type)) {
final String type = (String) contentMapObject.get(TYPE_KEY);
if (type !=null && allowedTypes.contains(type)) {
addDependencies(contentletIdList, contentMapObject);
}
}
Expand All @@ -159,9 +164,7 @@ public List<String> getDependencies(final Object storyBlockValue) {
} catch (final Exception e) {
final String errorMsg = String.format("An error occurred when retrieving Contentlet references from Story" +
" Block field: %s", e.getMessage());
Logger.error(StoryBlockAPIImpl.class, errorMsg);
Logger.debug(StoryBlockAPIImpl.class, errorMsg, e);
throw new RuntimeException(errorMsg, e);
Logger.warnAndDebug(StoryBlockAPIImpl.class, errorMsg,e);
}
return contentletIdList.build();
}
Expand All @@ -175,9 +178,8 @@ public Object addContentlet(final Object storyBlockValue, final Contentlet conte
} catch (final JsonProcessingException e) {
final String errorMsg = String.format("An error occurred when adding Contentlet '%s' to the Story Block " +
"field: %s", contentlet.getIdentifier(), e.getMessage());
Logger.error(StoryBlockAPIImpl.class, errorMsg);
Logger.debug(StoryBlockAPIImpl.class, errorMsg, e);
throw new RuntimeException(errorMsg, e);
Logger.warnAndDebug(StoryBlockAPIImpl.class, errorMsg, e);
return storyBlockValue;
}
}

Expand Down

0 comments on commit 2742aa6

Please sign in to comment.