Skip to content

Commit

Permalink
feat(AI) fixes #30893 : Can not save content with binary fields (#30905)
Browse files Browse the repository at this point in the history
### Proposed Changes
* Added a simple check to just return a dummy Mock object when the
Contentlet's identifier has not been set yet; i.e., it's a brand new
Contentlet.
  • Loading branch information
jcastro-dotcms authored Dec 10, 2024
1 parent 01d2b24 commit e314f9d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.model.User;
import io.vavr.control.Try;
Expand All @@ -28,8 +29,11 @@ public static Context getMockContext(Contentlet contentlet) {
return getMockContext(contentlet, APILocator.systemUser());
}

public static Context getMockContext(Contentlet contentlet, User user) {
Host host = Try.of(() -> APILocator.getHostAPI().find(contentlet.getHost(), APILocator.systemUser(), true)).getOrElse(APILocator.systemHost());
public static Context getMockContext(final Contentlet contentlet, final User user) {
final Host host = UtilMethods.isSet(contentlet.getIdentifier()) ?
Try.of(() -> APILocator.getHostAPI().find(contentlet.getHost(),
APILocator.systemUser(), true)).getOrElse(APILocator.systemHost()) :
APILocator.systemHost();
String hostName = "SYSTEM_HOST".equalsIgnoreCase(host.getIdentifier())
? Try.of(() -> APILocator.getHostAPI().findDefaultHost(APILocator.systemUser(), false).getHostname()).getOrElseThrow(DotRuntimeException::new)
: host.getHostname();
Expand Down

0 comments on commit e314f9d

Please sign in to comment.