Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.jcatalog.businesspartner.GormCustomer
- import com.jcatalog.businesspartner.GormCustomer2Address
- import com.jcatalog.businesspartner.GormCustomerGroup
- import com.jcatalog.businesspartner.GormSupplier
- import com.jcatalog.businesspartner.GormSupplier2Address
- import com.jcatalog.businesspartner.GormSupplierGroup
- import com.jcatalog.businesspartner.GormSupplierProvisioning
- import com.jcatalog.businesspartner.classification.GormClassificationUsage
- import com.jcatalog.businesspartner.classification.GormSupplier2ClassificationGroup
- import com.jcatalog.classification.GormClassification
- import com.jcatalog.classification.GormClassificationGroup
- import com.jcatalog.core.DateRange
- import com.jcatalog.core.GormCurrency
- import com.jcatalog.core.i18n.GormLanguage
- import com.jcatalog.core.status.GormDefaultStatus
- import com.jcatalog.pim.masterdata.dataimport.xml.FlatMLImportUtils
- import com.jcatalog.termsofbusiness.GormMethodOfPayment
- import com.jcatalog.termsofbusiness.GormTermsOfDelivery
- import com.jcatalog.termsofbusiness.GormTermsOfPayment
- import groovy.util.slurpersupport.GPathResult
- import com.jcatalog.product.GormProductCatalog
- import com.jcatalog.product.GormCatalogCategory
- import com.jcatalog.product.GormCatalogUsage
- import com.jcatalog.product.GormCatalogProvisioning
- import javax.xml.stream.XMLStreamReader
- import java.text.DateFormat
- import java.text.DecimalFormat
- import java.text.NumberFormat
- import java.text.SimpleDateFormat
- Closure getNumberFormat = {
- return new DecimalFormat("#.#")
- }
- Closure getDateFormat = {
- return new SimpleDateFormat("MM/dd/yyyy")
- }
- def delete = {clazz, query, fields ->
- return { GPathResult pathResult ->
- clazz.withTransaction {
- def params = [:]
- fields.each { field -> params[field] = pathResult."${field}"?.text() }
- if (params.find { !it }) return "failed"
- def result = clazz.executeQuery(query, params)
- if (!result) return "failed"
- result[0].delete(flush: true)
- return "delete"
- }
- }
- }
- Closure insertOrUpdateCatalog = {GPathResult pathResult ->
- GormProductCatalog.withTransaction {
- NumberFormat numberFormat = getNumberFormat.call()
- DateFormat dateFormat = getDateFormat.call()
- String actionType = "undefined"
- def productCatalogId = pathResult.ProductCatalogId.text()
- def statusId = pathResult.Status.text()
- def catalogCategoryId = pathResult.CatalogCategoryId.text()
- if (!productCatalogId) {
- return "failed"
- }
- GormProductCatalog catalog = null
- if (updateType == "insert-update") {
- catalog = GormProductCatalog.findByProductCatalogId(productCatalogId)
- if (!catalog) {
- catalog = new GormProductCatalog(productCatalogId: productCatalogId)
- catalog.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- catalog = new GormProductCatalog(productCatalogId: productCatalogId)
- catalog = catalog.save()
- actionType = "insert"
- } else if (updateType == "update") {
- catalog = GormProductCatalog.findByProductCatalogId(productCatalogId)
- if (!catalog) {
- return "failed"
- }
- actionType = "update"
- }
- if(statusId){
- def status = GormDefaultStatus.findByStatusId()
- if(status) catalog.status = status
- }
- def validRange = new DateRange()
- FlatMLImportUtils.setDatePropertyFromPathResult(validRange, pathResult, dateFormat, "validFrom", "from")
- FlatMLImportUtils.setDatePropertyFromPathResult(validRange, pathResult, dateFormat, "validTo", "to")
- catalog.validRange = validRange
- FlatMLImportUtils.setNumberPropertyFromPathResult(catalog, pathResult, numberFormat, "version")
- FlatMLImportUtils.setStringPropertyFromPathResult(catalog, pathResult, "description")
- FlatMLImportUtils.setStringPropertyFromPathResult(catalog, pathResult, "type")
- FlatMLImportUtils.setBooleanPropertyFromPathResult(catalog, pathResult, "isPunchoutOnly")
- FlatMLImportUtils.setBooleanPropertyFromPathResult(catalog, pathResult, "requireSafetyCheck")
- FlatMLImportUtils.setBooleanPropertyFromPathResult(catalog, pathResult, "requireChemicalCheck")
- if(catalogCategoryId){
- def catalogCategory = GormCatalogCategory.get(catalogCategoryId)
- if(catalogCategory) catalog.catalogCategory = catalogCategory
- }
- catalog.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateCatalogUsage = {GPathResult pathResult ->
- GormCatalogUsage.withTransaction {
- String actionType = "undefined"
- def productCatalogId = pathResult.ProductCatalogID.text()
- def customerId = pathResult.CustomerID.text()
- if (!productCatalogId || !customerId) {
- return "failed"
- }
- def catalogUsage = null
- if (updateType == "insert-update") {
- catalogUsage = GormCatalogUsage.find("from GormCatalogUsage as cu where cu.catalog.productCatalogId='${productCatalogId}' and cu.customer.customerId='${customerId}' ")
- if (!catalogUsage) {
- catalogUsage = new GormCatalogUsage()
- catalogUsage.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- catalogUsage = new GormCatalogUsage()
- actionType = "insert"
- } else if (updateType == "update") {
- catalogUsage = GormCatalogUsage.find("from GormCatalogUsage as cu where cu.catalog.productCatalogId='${productCatalogId}' and cu.customer.customerId='${customerId}' ")
- if (!catalogUsage) {
- return "failed"
- }
- actionType = "update"
- }
- def catalog = GormProductCatalog.findByProductCatalogId(productCatalogId)
- if(catalog) catalogUsage.catalog = catalog
- def customer = GormCustomer.findByCustomerId(customerId)
- if(customer) catalogUsage.customer = customer
- catalogUsage.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateCatalogProvisioning = {GPathResult pathResult ->
- GormCatalogUsage.withTransaction {
- String actionType = "undefined"
- def productCatalogId = pathResult.ProductCatalogID.text()
- def supplierId = pathResult.SupplierID.text()
- if (!productCatalogId || !supplierId) {
- return "failed"
- }
- def catalogProvisioning = null
- if (updateType == "insert-update") {
- catalogProvisioning = GormCatalogProvisioning.find("from GormCatalogProvisioning as cu where cu.catalog.productCatalogId='${productCatalogId}' and cu.supplier.supplierId='${supplierId}' ")
- if (!catalogProvisioning) {
- catalogProvisioning = new GormCatalogProvisioning()
- catalogProvisioning.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- catalogProvisioning = new GormCatalogProvisioning()
- actionType = "insert"
- } else if (updateType == "update") {
- catalogProvisioning = GormCatalogProvisioning.find("from GormCatalogUsage as cu where cu.catalog.productCatalogId='${productCatalogId}' and cu.supplier.supplierId='${supplierId}' ")
- if (!catalogProvisioning) {
- return "failed"
- }
- actionType = "update"
- }
- def catalog = GormProductCatalog.findByProductCatalogId(productCatalogId)
- if(catalog) catalogProvisioning.catalog = catalog
- def supplier = GormCustomer.findBySupplierId(supplierId)
- if(supplier) catalogProvisioning.supplier = supplier
- catalogProvisioning.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateCustomerGroup = {GPathResult pathResult ->
- GormCustomerGroup.withTransaction {
- if (!pathResult.CustomerGroupId.text()) {
- return "failed"
- }
- String actionType = "undefined"
- GormCustomerGroup customerGroup = null
- if (updateType == "insert-update") {
- customerGroup = GormCustomerGroup.findByCustomerGroupId(pathResult.CustomerGroupId.text())
- if (!customerGroup) {
- customerGroup = new GormCustomerGroup(customerGroupId: pathResult.CustomerGroupId.text())
- customerGroup = customerGroup.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- customerGroup = new GormCustomerGroup(customerGroupId: pathResult.CustomerGroupId.text())
- customerGroup = customerGroup.save()
- actionType = "insert"
- } else if (updateType == "update") {
- customerGroup = GormCustomerGroup.findByCustomerGroupId(pathResult.CustomerGroupId.text())
- if (!customerGroup) {
- return "failed"
- }
- actionType = "update"
- }
- FlatMLImportUtils.setStringPropertyFromPathResult(customerGroup, pathResult, "name")
- customerGroup.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateCustomer = {GPathResult pathResult ->
- GormCustomer.withTransaction {
- NumberFormat numberFormat = getNumberFormat.call()
- String actionType = "undefined"
- if (!pathResult.CustomerId.text()) {
- return "failed"
- }
- GormCustomer customer = null
- if (updateType == "insert-update") {
- customer = GormCustomer.findByCustomerId(pathResult.CustomerId.text())
- if (!customer) {
- customer = new GormCustomer(customerId: pathResult.CustomerId.text())
- customer = customer.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- customer = new GormCustomer(customerId: pathResult.CustomerId.text())
- customer = customer.save()
- actionType = "insert"
- } else if (updateType == "update") {
- customer = GormCustomer.findByCustomerId(pathResult.CustomerId.text())
- if (!customer) {
- return "failed"
- }
- actionType = "update"
- }
- if (pathResult.CustomerGroupId.text()) {
- GormCustomerGroup customerGroup = GormCustomerGroup.findByCustomerGroupId(pathResult.CustomerGroupId.text())
- if (customerGroup) {
- customer.customerGroup = customerGroup
- }
- }
- if (pathResult.ParentCustomerId.text()) {
- GormCustomer parentCustomer = GormCustomer.findByCustomerId(pathResult.ParentCustomerId.text())
- if (parentCustomer) {
- customer.parentCustomer = parentCustomer
- }
- }
- if (pathResult.Tax.text()) {
- GormTax tax = GormTax.findByTaxId(pathResult.Tax.text())
- if (tax) {
- customer.tax = tax
- }
- }
- if (pathResult.LanguageID.text()) {
- GormLanguage language = GormLanguage.get(pathResult.LanguageID.text())
- if (language) {
- customer.language = language
- }
- }
- if (pathResult.CurrencyID.text()) {
- GormCurrency currency = GormCurrency.get(pathResult.CurrencyID.text())
- if (currency) {
- customer.currency = currency
- }
- }
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "customerName")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "dunsNo")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "information", "CustomerInfo")
- FlatMLImportUtils.setNumberPropertyFromPathResult(customer, pathResult, numberFormat, "invTolerancePercent")
- FlatMLImportUtils.setNumberPropertyFromPathResult(customer, pathResult, numberFormat, "invToleranceAbs")
- FlatMLImportUtils.setBooleanPropertyFromPathResult(customer, pathResult, "isLocked")
- FlatMLImportUtils.setBooleanPropertyFromPathResult(customer, pathResult, "isCustomerGrpMaster")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "extAccountCode","ExtAcctCode")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "extShortName")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "extName")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "extGlobalId")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "logo")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "headerText")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer, pathResult, "footerText")
- customer.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateCustomer2Address = {GPathResult pathResult ->
- GormCustomer2Address.withTransaction {
- String actionType = "undefined"
- if (!pathResult.CustomerID.text() || !pathResult.AddressID.text()) {
- return "failed"
- }
- GormCustomer customer = GormCustomer.findByCustomerId(pathResult.CustomerID.text())
- GormAddress address = GormAddress.findByAddressId(pathResult.AddressID.text())
- if (!customer || !address) {
- return "failed"
- }
- GormCustomer2Address customer2Address = null
- if (updateType == "insert-update") {
- customer2Address = GormCustomer2Address.findByCustomerAndAddress(customer, address)
- if (!customer2Address) {
- customer2Address = new GormCustomer2Address(customer: customer, address: address)
- customer2Address = customer2Address.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- customer2Address = new GormCustomer2Address(customer: customer, address: address)
- customer2Address = customer2Address.save()
- actionType = "insert"
- } else if (updateType == "update") {
- customer2Address = GormCustomer2Address.findByCustomerAndAddress(customer, address)
- if (!customer2Address) {
- return "failed"
- }
- actionType = "update"
- }
- FlatMLImportUtils.setBooleanPropertyFromPathResult(customer2Address, pathResult, "isDefault")
- FlatMLImportUtils.setStringPropertyFromPathResult(customer2Address, pathResult, "type")
- customer2Address.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateClassificationUsage = {GPathResult pathResult ->
- GormClassificationUsage.withTransaction {
- String actionType = "undefined"
- if (!pathResult.ClassificationID.text() || !pathResult.CustomerID.text()) {
- return "failed"
- }
- GormCustomer customer = GormCustomer.findByCustomerId(pathResult.CustomerID.text())
- GormClassification classification = GormClassification.findByClassificationId(pathResult.ClassificationID.text())
- if (!customer || !classification) {
- return "failed"
- }
- GormClassificationUsage classificationUsage = null
- if (updateType == "insert-update") {
- classificationUsage = GormClassificationUsage.findByCustomerAndClassification(customer, classification)
- if (!classificationUsage) {
- classificationUsage = new GormClassificationUsage(customer: customer, classification: classification)
- classificationUsage = classificationUsage.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- classificationUsage = new GormClassificationUsage(customer: customer, address: address)
- classificationUsage = classificationUsage.save()
- actionType = "insert"
- } else if (updateType == "update") {
- classificationUsage = GormClassificationUsage.findByCustomerAndClassification(customer, classification)
- if (!classificationUsage) {
- return "failed"
- }
- actionType = "update"
- }
- FlatMLImportUtils.setBooleanPropertyFromPathResult(classificationUsage, pathResult, "isMaster")
- classificationUsage.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateSupplierGroup = {GPathResult pathResult ->
- GormSupplierGroup.withTransaction {
- String actionType = "undefined"
- if (!pathResult.SupplierGroupID.text()) {
- return "failed"
- }
- GormSupplierGroup supplierGroup = null
- if (updateType == "insert-update") {
- supplierGroup = GormSupplierGroup.findBySupplierGroupId(pathResult.SupplierGroupID.text())
- if (!supplierGroup) {
- supplierGroup = new GormSupplierGroup(supplierGroupId: pathResult.SupplierGroupID.text())
- supplierGroup = supplierGroup.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- supplierGroup = new GormSupplierGroup(supplierGroupId: pathResult.SupplierGroupID.text())
- supplierGroup = supplierGroup.save()
- actionType = "insert"
- } else if (updateType == "update") {
- supplierGroup = GormSupplierGroup.findBySupplierGroupId(pathResult.SupplierGroupID.text())
- if (!supplierGroup) {
- return "failed"
- }
- actionType = "update"
- }
- FlatMLImportUtils.setStringPropertyFromPathResult(supplierGroup, pathResult, "name")
- supplierGroup.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateSupplier = {GPathResult pathResult ->
- GormSupplier.withTransaction {
- String actionType = "undefined"
- if (!pathResult.SupplierId.text()) {
- return "failed"
- }
- GormSupplier supplier = null
- if (updateType == "insert-update") {
- supplier = GormSupplier.findBySupplierId(pathResult.SupplierId.text())
- if (!supplier) {
- supplier = new GormSupplier(supplierId: pathResult.SupplierId.text())
- supplier = supplier.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- supplier = new GormSupplier(supplierId: pathResult.SupplierId.text())
- supplier = supplier.save()
- actionType = "insert"
- } else if (updateType == "update") {
- supplier = GormSupplier.findBySupplierId(pathResult.SupplierId.text())
- if (!supplier) {
- return "failed"
- }
- actionType = "update"
- }
- if (pathResult.SupplierGroupId.text()) {
- GormSupplierGroup supplierGroup = GormSupplierGroup.findBySupplierGroupId(pathResult.SupplierGroupId.text())
- if (supplierGroup) {
- supplier.supplierGroup = supplierGroup
- }
- }
- if (pathResult.Language.text()) {
- GormLanguage language = GormLanguage.get(pathResult.Language.text())
- if (language) {
- supplier.language = language
- }
- }
- if (pathResult.CurrencyID.text()) {
- GormCurrency currency = GormCurrency.get(pathResult.CurrencyID.text())
- if (currency) {
- supplier.currency = currency
- }
- }
- if (pathResult.Status.text()) {
- GormDefaultStatus status = GormDefaultStatus.findByStatusIdAndObjectClass(pathResult.Status.text(),"SUPPLIER")
- if (status) {
- supplier.status = status
- }
- }
- if (pathResult.TermsOfPaymentID.text()) {
- GormTermsOfPayment termsOfPayment = GormTermsOfPayment.get(pathResult.TermsOfPaymentID.text())
- if (termsOfPayment) {
- supplier.termsOfPayment = termsOfPayment
- }
- }
- if (pathResult.TermsOfDeliveryID.text()) {
- GormTermsOfDelivery termsOfDelivery = GormTermsOfDelivery.get(pathResult.TermsOfDeliveryID.text())
- if (termsOfDelivery) {
- supplier.termsOfDelivery = termsOfDelivery
- }
- }
- if (pathResult.MethodOfPaymentID.text()) {
- GormMethodOfPayment methodOfPayment = GormMethodOfPayment.get(pathResult.MethodOfPaymentID.text())
- if (methodOfPayment) {
- supplier.methodOfPayment = methodOfPayment
- }
- }
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "supplierName")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "dunsNo")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "extAccountCode","ExtAcctCode")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "extName")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "extShortName")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "extGlobalId")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "extSupplierID")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "accountNumber")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "bankIdentificationCode")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier, pathResult, "logo")
- supplier.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateSupplier2Address = {GPathResult pathResult ->
- GormSupplier2Address.withTransaction {
- String actionType = "undefined"
- if (!pathResult.SupplierID.text() || !pathResult.AddressID.text()) {
- return "failed"
- }
- GormSupplier supplier = GormSupplier.findBySupplierId(pathResult.SupplierID.text())
- GormAddress address = GormAddress.findByAddressId(pathResult.AddressID.text())
- if (!supplier || !address) {
- return "failed"
- }
- GormSupplier2Address supplier2Address = null
- if (updateType == "insert-update") {
- supplier2Address = GormSupplier2Address.findBySupplierAndAddress(supplier, address)
- if (!supplier2Address) {
- supplier2Address = new GormSupplier2Address(supplier: supplier, address: address)
- supplier2Address = supplier2Address.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- supplier2Address = new GormSupplier2Address(supplier: supplier, address: address)
- supplier2Address = supplier2Address.save()
- actionType = "insert"
- } else if (updateType == "update") {
- supplier2Address = GormSupplier2Address.findBySupplierAndAddress(supplier, address)
- if (!supplier2Address) {
- return "failed"
- }
- actionType = "update"
- }
- FlatMLImportUtils.setBooleanPropertyFromPathResult(supplier2Address, pathResult, "isDefault")
- FlatMLImportUtils.setStringPropertyFromPathResult(supplier2Address, pathResult, "type")
- supplier2Address.save(flush:true)
- return actionType
- }
- }
- Closure insertOrUpdateSupplier2ClassificationGroup = { GPathResult pathResult ->
- GormSupplier2ClassificationGroup.withTransaction {
- if(!pathResult.SupplierID.text() || !pathResult.ClassificationID.text() || !pathResult.ClassificationGroupID.text() ||
- !pathResult.CustomerID.text()) {
- return "failed"
- }
- GormClassification classification = GormClassification.findByClassificationId(pathResult.ClassificationID.text())
- if(!classification) {
- return "failed"
- }
- GormSupplier supplier = GormSupplier.findBySupplierId(pathResult.SupplierID.text())
- GormCustomer customer = GormCustomer.findByCustomerId(pathResult.CustomerID.text())
- GormClassificationGroup classificationGroup = GormClassificationGroup.findByClassificationGroupIdAndClassification(pathResult.ClassificationGroupID.text(),
- classification)
- if(!supplier || !customer || !classificationGroup) {
- return "failed"
- }
- GormSupplier2ClassificationGroup supplier2ClassificationGroup = GormSupplier2ClassificationGroup.findByClassificationGroupAndCustomerAndSupplier(
- classificationGroup,customer,supplier)
- if(!supplier2ClassificationGroup && updateType == "update") {
- return "failed"
- } else if(supplier2ClassificationGroup && (updateType == "update" || updateType == "insert-update")) {
- return "update"
- } else {
- supplier2ClassificationGroup = new GormSupplier2ClassificationGroup(supplier: supplier, customer: customer, classificationGroup: classificationGroup)
- supplier2ClassificationGroup.save(flush:true)
- return "insert"
- }
- }
- }
- Closure insertOrUpdateSupplierProvisioning = { GPathResult pathResult ->
- GormSupplierProvisioning.withTransaction {
- String actionType = "undefined"
- if (!pathResult.SupplierId.text() || !pathResult.CustomerId.text()) {
- return "failed"
- }
- GormSupplier supplier = GormSupplier.findBySupplierId(pathResult.SupplierID.text())
- GormCustomer customer = GormCustomer.findByCustomerId(pathResult.AddressID.text())
- if (!supplier || !customer) {
- return "failed"
- }
- GormSupplierProvisioning supplierProvisioning = null
- if (updateType == "insert-update") {
- supplierProvisioning = GormSupplierProvisioning.findBySupplierAndCustomer(supplier, customer)
- if (!supplierProvisioning) {
- supplierProvisioning = new GormSupplierProvisioning(supplier: supplier, customer: customer)
- supplierProvisioning = supplierProvisioning.save()
- actionType = "insert"
- } else {
- actionType = "update"
- }
- } else if (updateType == "insert") {
- supplierProvisioning = new GormSupplierProvisioning(supplier: supplier, customer: customer)
- supplierProvisioning = supplierProvisioning.save()
- actionType = "insert"
- } else if (updateType == "update") {
- supplierProvisioning = supplierProvisioning = GormSupplierProvisioning.findBySupplierAndCustomer(supplier, customer)
- if (!supplierProvisioning) {
- return "failed"
- }
- actionType = "update"
- }
- supplierProvisioning.save(flush: true)
- return actionType
- }
- }
- def deleteCatalog = delete(GormProductCatalog, "from GormProductCatalog as c where c.productCatalogId=:ProductCatalogID", ["ProductCatalogID"])
- def deleteCatalogUsage = delete(GormCatalogUsage, "from GormCatalogUsage as c where c.productCatalogId=:ProductCatalogID and cu.customer.customerId=:CustomerID ", ["ProductCatalogID", "CustomerID"])
- def deleteCatalogProvisioning = delete(GormCatalogUsage, "from GormCatalogUsage as c where c.productCatalogId=:ProductCatalogID and cu.customer.customerId=:CustomerID ", ["ProductCatalogID", "CustomerID"])
- def deleteContract = delete(GormContract, "from GormContract as c where c.contractId=:ContractID", ["ContractID"])
- def deleteContractDesc = delete(GormContractTranslation, "from GormContractTranslation as ct where ct.contract.contractId=:ContractID and ct.language.id=:LanguageID and ct.descLong=:DescLong", ["ContractID", "LanguageID", "DescLong"])
- Map closureMap = [
- "ProductCatalog":[insertUpdate: insertOrUpdateCatalog, delete: deleteCatalog],
- "CatalogUsage":[insertUpdate:insertOrUpdateCatalogUsage, delete: deleteCatalogUsage],
- "CatalogProvisioning": [insertUpdate:insertOrUpdateCatalogProvisioning, delete:deleteCatalogProvisioning],
- "Contract": [insertUpdate:insertOrUpdateCustomer, delete:deleteContract],
- "ContractDesc": [insertUpdate:insertOrUpdateCustomer2Address, delete:deleteContractDesc],
- "ContractedCatalog": [insertUpdate:insertOrUpdateClassificationUsage, delete:deleteClassificationUsage],
- "ContractedClassificationGroup": [insertUpdate:insertOrUpdateSupplierGroup, delete:deleteSupplierGroup],
- "ContractUsage": [insertUpdate:insertOrUpdateSupplier, delete:deleteSupplier],
- "ContractProvisioning": [insertUpdate:insertOrUpdateSupplier2Address, delete:deleteSupplier2Address],
- "ContractEntitlement": [insertUpdate:insertOrUpdateSupplier2ClassificationGroup, delete:deleteSupplier2ClassificationGroup],
- "ContractAttributeValue": [insertUpdate:insertOrUpdateSupplierProvisioning, delete:deleteSupplierProvisioning],
- "ContractCategory": [insertUpdate:insertOrUpdateSupplierProvisioning, delete:deleteSupplierProvisioning],
- "CatalogAttributeValue": [insertUpdate:insertOrUpdateSupplierProvisioning, delete:deleteSupplierProvisioning],
- "CatalogCategory": [insertUpdate:insertOrUpdateSupplierProvisioning, delete:deleteSupplierProvisioning],
- ]
- List filesList = ["ProductCatalog", "Address", "CustomerGroup", "Customer","Customer2Address",
- "ClassificationUsage", "SupplierGroup", "Supplier", "Supplier2Address","Supplier2ClassificationGroup",
- "SupplierProvisioning",
- // "SupplierProfile", "SupplierConnectivity","SupplierAttributeValue"
- ]
- Map name2ClassName = ["ProductCatalog": GormProductCatalog, "Address":GormAddress, "CustomerGroup":GormCustomerGroup,
- "Customer":GormCustomer,"Customer2Address":GormCustomer2Address,
- "ClassificationUsage":GormClassificationUsage,
- "SupplierGroup":GormSupplierGroup, "Supplier":GormSupplier,
- "Supplier2Address":GormSupplier2Address,"Supplier2ClassificationGroup":GormSupplier2ClassificationGroup,
- "SupplierProvisioning":GormSupplierProvisioning,
- // todo ask about gorm supplier profile and SupplierConnectivity
- // "SupplierProfile":GormSupplier,"SupplierConnectivity":GormSupplierConnectivity,"SupplierAttributeValue":GormSupplier
- ]
- Map flatDataMap = FlatMLImportUtils.getFlatFilesDataMap(flatMLDir,filesList, logWriter)
- // read data and import to DB
- // todo do I need to check files existence ?
- for(String fileName : filesList) {
- XMLStreamReader reader = flatDataMap[fileName].reader
- GPathResult pathResult = FlatMLImportUtils.readRowElement(reader)
- while(pathResult) {
- if (updateType == "replace") {
- FlatMLImportUtils.replaceGormDataObject(fileName, pathResult, closureMap, name2ClassName,
- importStatistic, logWriter)
- } else if (updateType == "delete"){
- FlatMLImportUtils.deleteGormDataObject(fileName, pathResult, closureMap, name2ClassName,
- importStatistic, logWriter)
- }else {
- FlatMLImportUtils.insertOrUpdateGormDataObject(fileName, pathResult, closureMap, name2ClassName,
- importStatistic, logWriter, updateType)
- }
- pathResult = FlatMLImportUtils.readRowElement(reader)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement