Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed: Use data url scheme for logo in CompanyHeader
(OFBIZ-7327)

Use a data URL rather than a regular URL for company logos when a
logo has been specified as a Party Content item. This works around the
problem of Apache FOP failing to retrieve content from HTTPS URLs.

Thanks: Deepak Dixit for the review and suggestions
  • Loading branch information
danwatford committed Jan 24, 2021
1 parent da2ab82 commit edd7960
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
35 changes: 25 additions & 10 deletions applications/order/groovyScripts/order/CompanyHeader.groovy
Expand Up @@ -22,10 +22,11 @@
// if none of these parameters are available then fromPartyId is used or "ORGANIZATION_PARTY" from general.properties as fallback

import org.apache.ofbiz.base.util.UtilHttp
import org.apache.ofbiz.content.data.DataResourceWorker
import org.apache.ofbiz.entity.GenericValue
import org.apache.ofbiz.entity.util.EntityUtil
import org.apache.ofbiz.order.order.OrderReadHelper
import org.apache.ofbiz.party.content.PartyContentWrapper
import org.apache.ofbiz.entity.util.EntityUtilProperties

import java.sql.Timestamp

Expand Down Expand Up @@ -75,7 +76,7 @@ if (quoteId) {

// defaults:
def logoImageUrl = null // the default value, "/images/ofbiz_powered.gif", is set in the screen decorators
def partyId = null
String partyId = null
// reference date for filtering
Timestamp referenceDate = null
// get the logo partyId from order or invoice - note that it is better to do comparisons this way in case the there are null values
Expand Down Expand Up @@ -135,15 +136,29 @@ if (!partyId) {
}

// the logo
partyGroup = from("PartyGroup").where("partyId", partyId).queryOne()
GenericValue partyGroup = from("PartyGroup").where("partyId", partyId).queryOne()
if (partyGroup) {
partyContentWrapper = new PartyContentWrapper(dispatcher, partyGroup, locale, EntityUtilProperties.getPropertyValue("content", "defaultMimeType", "text/html; charset=utf-8", delegator))
partyContent = partyContentWrapper.getFirstPartyContentByType(partyGroup.partyId , partyGroup, "LGOIMGURL", delegator)
if (partyContent) {
logoImageUrl = "/content/control/stream?contentId=" + partyContent.contentId
} else {
if (partyGroup?.logoImageUrl) {
logoImageUrl = partyGroup.logoImageUrl
GenericValue partyContent = PartyContentWrapper.getFirstPartyContentByType(partyId, partyGroup, "LGOIMGURL", delegator)
GenericValue dataResource = partyContent?.getRelatedOne("Content", true)
?.getRelatedOne("DataResource", true)

if (dataResource) {
String dataResourceTypeId = dataResource.getString("dataResourceTypeId")
if (dataResourceTypeId.contains("_FILE")) {
File logoFile = DataResourceWorker.getContentFile(dataResource.getString("dataResourceTypeId"),
dataResource.getString("objectInfo"), "")
if (logoFile.exists()) {
def logoFileBase64 = logoFile.bytes.encodeBase64()
logoImageUrl = "data:" + dataResource.mimeTypeId + ";base64," + logoFileBase64
}
}
}

if (!logoImageUrl) {
if (partyContent) {
logoImageUrl = "/content/control/stream?contentId=" + partyContent.contentId
} else {
logoImageUrl = partyGroup?.logoImageUrl
}
}
}
Expand Down
Expand Up @@ -88,8 +88,8 @@ public void close() throws IOException {

String requestUrl = buf.toString();

// If the URL starts with http(s) then there is nothing for us to do here
if (requestUrl.startsWith("http")) {
// If the URL starts with http(s) or data then there is nothing for us to do here
if (requestUrl.startsWith("http") || requestUrl.startsWith("data")) {
out.write(requestUrl);
return;
}
Expand Down

0 comments on commit edd7960

Please sign in to comment.