diff --git a/applications/product/groovyScripts/product/product/ProductContentServices.groovy b/applications/product/groovyScripts/product/product/ProductContentServices.groovy new file mode 100644 index 0000000000..ee6951408f --- /dev/null +++ b/applications/product/groovyScripts/product/product/ProductContentServices.groovy @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.service.ServiceUtil + +/** + * Create Content For Product + * @return + */ +def createProductContent() { + Map result = success() + GenericValue newEntity = makeValue("ProductContent", parameters) + newEntity.create() + run service: "updateContent", with: parameters + result.contentId = newEntity.contentId + result.productId = newEntity.productId + result.productContentTypeId = newEntity.productContentTypeId + return result +} + +/** + * Update Content For Product + * @return + */ +def updateProductContent() { + GenericValue lookedUpValue = from("ProductContent").where(parameters).queryOne() + lookedUpValue.setNonPKFields(parameters) + lookedUpValue.store() + run service: "updateContent", with: parameters + return success() +} + +/** + * Create Email Content For Product + * @return + */ +def createEmailContentForProduct() { + Map result = success() + Map createProductContent = parameters + Map serviceResult = run service: "createEmailContent", with: parameters + if (!ServiceUtil.isSuccess(serviceResult)) { + return serviceResult + } + createProductContent.contentId = serviceResult.contentId + run service: "createProductContent", with: createProductContent + return result +} + +/** + * Create Download Content For Product + * @return + */ +def createDownloadContentForProduct() { + Map createProductContent = parameters + Map persistContentAndAssoc = parameters + persistContentAndAssoc.contentTypeId = "DOCUMENT" + persistContentAndAssoc.dataResourceTypeId = "IMAGE_OBJECT" + persistContentAndAssoc.contentName = parameters._imageData_fileName + persistContentAndAssoc.mimeTypeId = parameters._imageData_contentType + + Map serviceResult = run service: "persistContentAndAssoc", with: persistContentAndAssoc + if (!ServiceUtil.isSuccess(serviceResult)) { + return serviceResult + } + createProductContent.contentId = serviceResult.contentId + run service: "createProductContent", with: createProductContent + return success() +} + + +/** + * Create Simple Text Content For Product + * @return + */ +def createSimpleTextContentForProduct() { + Map serviceResult = run service: "createSimpleTextContent", with: parameters + Map createProductContentMap = parameters + createProductContentMap.contentId = serviceResult.contentId + run service: "createProductContent", with: createProductContentMap + return success() +} + +/** + * Create Simple Text Content For Alternate Locale + * @return + */ +def createSimpleTextContentForAlternateLocale() { + Map serviceResult = run service: "createSimpleTextContent", with: parameters + Map createContentAssocMap = [contentIdTo: serviceResult.contentId, + contentId: parameters.mainContentId, + contentAssocTypeId: "ALTERNATE_LOCALE"] + run service: "createContentAssoc", with: createContentAssocMap + return success() +} + +/** + * Method to upload multiple Additional View images for product + * @return + */ +def uploadProductAdditionalViewImages() { + Map result = success() + Map addAdditionalViewForProductMap = [productId: parameters.productId] + if (parameters.additionalImageOne) { + addAdditionalViewForProductMap.uploadedFile = parameters.additionalImageOne + addAdditionalViewForProductMap.productContentTypeId = "ADDITIONAL_IMAGE_1" + addAdditionalViewForProductMap._uploadedFile_fileName = parameters._additionalImageOne_contentType + run service: "addAdditionalViewForProduct", with: addAdditionalViewForProductMap + } + if (parameters.additionalImageTwo) { + addAdditionalViewForProductMap.uploadedFile = parameters.additionalImageTwo + addAdditionalViewForProductMap.productContentTypeId = "ADDITIONAL_IMAGE_2" + addAdditionalViewForProductMap._uploadedFile_fileName = parameters._additionalImageTwo_contentType + run service: "addAdditionalViewForProduct", with: addAdditionalViewForProductMap + } + if (parameters.additionalImageThree) { + addAdditionalViewForProductMap.uploadedFile = parameters.additionalImageThree + addAdditionalViewForProductMap.productContentTypeId = "ADDITIONAL_IMAGE_3" + addAdditionalViewForProductMap._uploadedFile_fileName = parameters._additionalImageThree_contentType + run service: "addAdditionalViewForProduct", with: addAdditionalViewForProductMap + } + if (parameters.additionalImageFour) { + addAdditionalViewForProductMap.uploadedFile = parameters.additionalImageFour + addAdditionalViewForProductMap.productContentTypeId = "ADDITIONAL_IMAGE_4" + addAdditionalViewForProductMap._uploadedFile_fileName = parameters._additionalImageFour_contentType + run service: "addAdditionalViewForProduct", with: addAdditionalViewForProductMap + } + result.productId = parameters.productId + return result +} + +/** + * Update Product SEO + * @return + */ +def updateContentSEOForProduct() { + GenericValue productContent + if (parameters.title) { + productContent = from("ProductContentAndInfo") + .where(productId: parameters.productId, + productContentTypeId: "PAGE_TITLE") + .queryFirst() + if (productContent) { + GenericValue electronicText = from("ElectronicText") + .where(dataResourceId: productContent.dataResourceId) + .queryOne() + if (electronicText) { + electronicText.textData = parameters.title + electronicText.store() + } + } else { + Map createTextContentMap = [productId: parameters.productId, + productContentTypeId: "PAGE_TITLE", + text: parameters.title] + run service: "createSimpleTextContentForProduct", with: createTextContentMap + } + } + if (parameters.metaKeyword) { + productContent = from("ProductContentAndInfo") + .where(productId: parameters.productId, + productContentTypeId: "META_KEYWORD") + .queryFirst() + if (productContent) { + GenericValue electronicText = from("ElectronicText") + .where(dataResourceId: productContent.dataResourceId) + .queryOne() + if (electronicText) { + electronicText.textData = parameters.metaKeyword + electronicText.store() + } + } else { + Map createTextContentMap = [productId: parameters.productId, + productContentTypeId: "META_KEYWORD", + text: parameters.metaKeyword] + run service: "createSimpleTextContentForProduct", with: createTextContentMap + } + } + if (parameters.metaDescription) { + productContent = from("ProductContentAndInfo") + .where(productId: parameters.productId, + productContentTypeId: "META_DESCRIPTION") + .queryFirst() + if (productContent) { + GenericValue electronicText = from("ElectronicText") + .where(dataResourceId: productContent.dataResourceId) + .queryOne() + if (electronicText) { + electronicText.textData = parameters.metaDescription + electronicText.store() + } + } else { + Map createTextContentMap = [productId: parameters.productId, + productContentTypeId: "META_DESCRIPTION", + text: parameters.metaDescription] + run service: "createSimpleTextContentForProduct", with: createTextContentMap + } + } + return success() +} diff --git a/applications/product/minilang/product/product/ProductContentServices.xml b/applications/product/minilang/product/product/ProductContentServices.xml deleted file mode 100644 index 141d6c61ea..0000000000 --- a/applications/product/minilang/product/product/ProductContentServices.xml +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/applications/product/servicedef/services.xml b/applications/product/servicedef/services.xml index e776379e3e..6015638847 100644 --- a/applications/product/servicedef/services.xml +++ b/applications/product/servicedef/services.xml @@ -361,30 +361,27 @@ under the License. - + Add Content To Product - - + - + Update Content To Product - + Remove Content From Product - - + @@ -393,20 +390,15 @@ under the License. - - - - - - - - - - + + Update Email Content For Product + + + + - + @@ -415,17 +407,16 @@ under the License. - - - - - - + + Update Download Content For Product + + + + - + @@ -433,16 +424,16 @@ under the License. - - - - - - + + Update Simple Text Content For Product + + + + - + @@ -460,8 +451,8 @@ under the License. - + Upload Additional View Images For Product @@ -479,8 +470,8 @@ under the License. - + Update Product SEO @@ -1362,8 +1353,7 @@ under the License. - + Cancel by the thru date a Product Promo Content