in ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayEvents.java [152:271]
public static String addProductListing(HttpServletRequest request, HttpServletResponse response) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
Map<String, Object> requestParams = UtilHttp.getParameterMap(request);
Locale locale = UtilHttp.getLocale(request);
if (UtilValidate.isEmpty(requestParams.get("productStoreId"))) {
request.setAttribute("_ERROR_MESSAGE_", "Required productStoreId and selected products.");
return "error";
}
List<String> productIds = UtilGenerics.checkList(requestParams.get("productIds"));
if (UtilValidate.isNotEmpty(requestParams.get("productIds"))) {
productIds = UtilGenerics.checkList(requestParams.get("productIds"));
} else if (UtilValidate.isNotEmpty(requestParams.get("selectResult"))) {
try {
productIds = UtilGenerics.checkList(requestParams.get("selectResult"));
} catch (ClassCastException e) {
if (UtilValidate.isEmpty(productIds)) productIds = new LinkedList<>();
productIds.add((String) requestParams.get("selectResult"));
}
} else {
request.setAttribute("_ERROR_MESSAGE_", "Required productStoreId and selected products.");
return "error";
}
String productStoreId = (String) requestParams.get("productStoreId");
ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
//String webSiteUrl = (String) requestParams.get("webSiteUrl");
String webSiteUrl = "https://demo-trunk.ofbiz.apache.org";
Map<String, Object> addItemObject = getAddItemListingObject(request, apiContext);
List<Map<String, Object>> itemObjs = null;
if (UtilValidate.isNotEmpty(addItemObject.get("itemListings"))) {
itemObjs = UtilGenerics.checkList(addItemObject.get("itemListings"));
} else {
itemObjs = new LinkedList<>();
}
if (UtilValidate.isNotEmpty(productIds)) {
try {
// check add new product obj ? to export
for (String productId : productIds) {
for (Map<String, Object> itObj : itemObjs) {
if (UtilValidate.isNotEmpty(itObj.get(productId.concat("_Obj")))) {
productIds.remove(productId);
}
}
}
Debug.logInfo("run in with productIds " + productIds, MODULE);
for (String productId : productIds) {
AddItemCall addItemCall = new AddItemCall(apiContext);
ItemType item = new ItemType();
GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
item.setTitle(product.getString("internalName"));
item.setCurrency(CurrencyCodeType.USD);
String productDescription = "";
String description = product.getString("description");
String longDescription = product.getString("longDescription");
if (UtilValidate.isNotEmpty(description)) {
productDescription = description;
} else if (UtilValidate.isNotEmpty(longDescription)) {
productDescription = longDescription;
} else if (UtilValidate.isNotEmpty(product.getString("productName"))) {
productDescription = product.getString("productName");
}
item.setDescription(productDescription);
item.setSKU(product.getString("productId"));
item.setApplicationData(product.getString("productId"));
item.setCountry(CountryCodeType.US);
item.setQuantity(1);
String smallImage = product.getString("smallImageUrl");
String mediumImage = product.getString("mediumImageUrl");
String largeImage = product.getString("largeImageUrl");
String ebayImage = null;
if (UtilValidate.isNotEmpty(largeImage)) {
ebayImage = largeImage;
} else if (UtilValidate.isNotEmpty(mediumImage)) {
ebayImage = mediumImage;
} else if (UtilValidate.isNotEmpty(smallImage)) {
ebayImage = smallImage;
}
if (UtilValidate.isNotEmpty(ebayImage)) {
PictureDetailsType pic = new PictureDetailsType();
String pictureUrl = webSiteUrl + ebayImage;
String[] picURL = new String[1];
picURL[0] = pictureUrl;
//String[] picURL = {webSiteUrl + ebayImage};
//pic.setPictureURL(picURL);
pic.setPictureURL(picURL);
item.setPictureDetails(pic);
}
item.setCategoryMappingAllowed(true);
item.setSite(apiContext.getSite());
addItemCall.setSite(apiContext.getSite());
addItemCall.setItem(item);
addItemCall.setWarningLevel(WarningLevelCodeType.HIGH);
Map<String, Object> itemListing = null;
for (Map<String, Object> itemObj : itemObjs) {
if (UtilValidate.isNotEmpty(itemObj.get(productId.concat("_Obj")))) {
itemListing = UtilGenerics.checkMap(itemObj.get(productId.concat("_Obj")));
itemListing.put("addItemCall", addItemCall);
itemListing.put("productId", productId);
break;
}
}
if (UtilValidate.isEmpty(itemListing)) {
itemListing = new HashMap<>();
itemListing.put("addItemCall", addItemCall);
itemListing.put("productId", productId);
}
itemObjs.add(itemListing);
}
addItemObject.put("itemListing", itemObjs);
} catch (Exception e) {
Debug.logError(e.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(e.getMessage()));
return "error";
}
}
return "success";
}