Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
Fixes possible null dereferencings in EbayHelper::createPayment, AbstractPricatParser::writeCommentsToFile SolrProductSearch::getSideDeepCategories WebPosEvents::getProductType
This commit is contained in:
@@ -264,7 +264,9 @@ public class EbayHelper {
|
||||
}
|
||||
|
||||
if ((results == null) || (results.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR))) {
|
||||
Debug.logError((String) results.get(ModelService.ERROR_MESSAGE), MODULE);
|
||||
if ((results != null)) {
|
||||
Debug.logError((String) results.get(ModelService.ERROR_MESSAGE), MODULE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -395,25 +395,27 @@ public abstract class AbstractPricatParser implements InterfacePricatParser {
|
||||
}
|
||||
}
|
||||
// set comments in the new error sheet
|
||||
XSSFDrawing errorPatriarch = errorSheet.getDrawingPatriarch();
|
||||
int newRowNum = getHeaderRowNo() + 1;
|
||||
Map<Integer, Integer> rowMapping = new HashMap<>();
|
||||
for (CellReference cell : errorMessages.keySet()) {
|
||||
if (cell != null && errorMessages.get(cell) != null) {
|
||||
XSSFRow row = sheet.getRow(cell.getRow());
|
||||
Integer rowNum = row.getRowNum();
|
||||
int errorRow = newRowNum;
|
||||
if (rowMapping.containsKey(rowNum)) {
|
||||
errorRow = rowMapping.get(rowNum);
|
||||
} else {
|
||||
XSSFRow newRow = errorSheet.getRow(errorRow);
|
||||
if (newRow == null) {
|
||||
newRow = errorSheet.createRow(errorRow);
|
||||
if (errorSheet != null) {
|
||||
XSSFDrawing errorPatriarch = errorSheet.getDrawingPatriarch();
|
||||
int newRowNum = getHeaderRowNo() + 1;
|
||||
Map<Integer, Integer> rowMapping = new HashMap<>();
|
||||
for (CellReference cell : errorMessages.keySet()) {
|
||||
if (cell != null && errorMessages.get(cell) != null) {
|
||||
XSSFRow row = sheet.getRow(cell.getRow());
|
||||
Integer rowNum = row.getRowNum();
|
||||
int errorRow = newRowNum;
|
||||
if (rowMapping.containsKey(rowNum)) {
|
||||
errorRow = rowMapping.get(rowNum);
|
||||
} else {
|
||||
XSSFRow newRow = errorSheet.getRow(errorRow);
|
||||
if (newRow == null) {
|
||||
newRow = errorSheet.createRow(errorRow);
|
||||
}
|
||||
rowMapping.put(rowNum, errorRow);
|
||||
newRow.setHeight(row.getHeight());
|
||||
copyRow(row, newRow, factory, errorPatriarch);
|
||||
newRowNum++;
|
||||
}
|
||||
rowMapping.put(rowNum, errorRow);
|
||||
newRow.setHeight(row.getHeight());
|
||||
copyRow(row, newRow, factory, errorPatriarch);
|
||||
newRowNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,52 +584,57 @@ public abstract class SolrProductSearch {
|
||||
? CategoryUtil.getCategoryNameWithTrail((String) context.get("productCategoryId"), dctx) : null;
|
||||
result = ServiceUtil.returnSuccess();
|
||||
Map<String, List<Map<String, Object>>> catLevel = new HashMap<>();
|
||||
Debug.logInfo("productCategoryId: " + productCategoryId, MODULE);
|
||||
|
||||
//Add toplevel categories
|
||||
String[] trailElements = productCategoryId.split("/");
|
||||
String[] trailElements = null;
|
||||
if (productCategoryId != null) {
|
||||
Debug.logInfo("productCategoryId: " + productCategoryId, MODULE);
|
||||
// Add toplevel categories
|
||||
trailElements = productCategoryId.split("/");
|
||||
}
|
||||
|
||||
//iterate over actual results
|
||||
for (String elements : trailElements) {
|
||||
//catIds must be greater than 3 chars
|
||||
if (elements.length() > 3) {
|
||||
Debug.logInfo("elements: " + elements, MODULE);
|
||||
String categoryPath = CategoryUtil.getCategoryNameWithTrail(elements, dctx);
|
||||
String[] categoryPathArray = categoryPath.split("/");
|
||||
int level = Integer.parseInt(categoryPathArray[0]);
|
||||
String facetQuery = CategoryUtil.getFacetFilterForCategory(categoryPath, dctx);
|
||||
Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, categoryPath, null, facetQuery, false, 0, 0, solrIndexName);
|
||||
QueryResponse cat = (QueryResponse) query.get("rows");
|
||||
List<Map<String, Object>> categories = new ArrayList<>();
|
||||
if (trailElements != null) {
|
||||
for (String elements : trailElements) {
|
||||
// catIds must be greater than 3 chars
|
||||
if (elements.length() > 3) {
|
||||
Debug.logInfo("elements: " + elements, MODULE);
|
||||
String categoryPath = CategoryUtil.getCategoryNameWithTrail(elements, dctx);
|
||||
String[] categoryPathArray = categoryPath.split("/");
|
||||
int level = Integer.parseInt(categoryPathArray[0]);
|
||||
String facetQuery = CategoryUtil.getFacetFilterForCategory(categoryPath, dctx);
|
||||
Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, categoryPath, null, facetQuery, false, 0, 0,
|
||||
solrIndexName);
|
||||
QueryResponse cat = (QueryResponse) query.get("rows");
|
||||
List<Map<String, Object>> categories = new ArrayList<>();
|
||||
|
||||
List<FacetField> catList = cat.getFacetFields();
|
||||
for (Iterator<FacetField> catIterator = catList.iterator(); catIterator.hasNext();) {
|
||||
FacetField field = catIterator.next();
|
||||
List<Count> catL = field.getValues();
|
||||
if (catL != null) {
|
||||
for (Iterator<Count> catIter = catL.iterator(); catIter.hasNext();) {
|
||||
FacetField.Count f = catIter.next();
|
||||
if (f.getCount() > 0) {
|
||||
Map<String, Object> catMap = new HashMap<>();
|
||||
LinkedList<String> iName = new LinkedList<>();
|
||||
iName.addAll(Arrays.asList(f.getName().split("/")));
|
||||
catMap.put("catId", iName.getLast());
|
||||
iName.removeFirst();
|
||||
String path = f.getName();
|
||||
catMap.put("path", path);
|
||||
if (level > 0) {
|
||||
iName.removeLast();
|
||||
catMap.put("parentCategory", StringUtils.join(iName, "/"));
|
||||
} else {
|
||||
catMap.put("parentCategory", null);
|
||||
List<FacetField> catList = cat.getFacetFields();
|
||||
for (Iterator<FacetField> catIterator = catList.iterator(); catIterator.hasNext();) {
|
||||
FacetField field = catIterator.next();
|
||||
List<Count> catL = field.getValues();
|
||||
if (catL != null) {
|
||||
for (Iterator<Count> catIter = catL.iterator(); catIter.hasNext();) {
|
||||
FacetField.Count f = catIter.next();
|
||||
if (f.getCount() > 0) {
|
||||
Map<String, Object> catMap = new HashMap<>();
|
||||
LinkedList<String> iName = new LinkedList<>();
|
||||
iName.addAll(Arrays.asList(f.getName().split("/")));
|
||||
catMap.put("catId", iName.getLast());
|
||||
iName.removeFirst();
|
||||
String path = f.getName();
|
||||
catMap.put("path", path);
|
||||
if (level > 0) {
|
||||
iName.removeLast();
|
||||
catMap.put("parentCategory", StringUtils.join(iName, "/"));
|
||||
} else {
|
||||
catMap.put("parentCategory", null);
|
||||
}
|
||||
catMap.put("count", Long.toString(f.getCount()));
|
||||
categories.add(catMap);
|
||||
}
|
||||
catMap.put("count", Long.toString(f.getCount()));
|
||||
categories.add(catMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
catLevel.put("menu-" + level, categories);
|
||||
}
|
||||
catLevel.put("menu-" + level, categories);
|
||||
}
|
||||
}
|
||||
result.put("categories", catLevel);
|
||||
|
||||
@@ -46,8 +46,8 @@ import org.apache.ofbiz.product.store.ProductStoreWorker;
|
||||
import org.apache.ofbiz.securityext.login.LoginEvents;
|
||||
import org.apache.ofbiz.service.GenericServiceException;
|
||||
import org.apache.ofbiz.service.LocalDispatcher;
|
||||
import org.apache.ofbiz.webpos.session.WebPosSession;
|
||||
import org.apache.ofbiz.service.ServiceUtil;
|
||||
import org.apache.ofbiz.webpos.session.WebPosSession;
|
||||
|
||||
public class WebPosEvents {
|
||||
|
||||
@@ -201,12 +201,13 @@ public class WebPosEvents {
|
||||
List<String> featureOrder = new LinkedList<>(featureSet);
|
||||
for (int i = 0; i < featureOrder.size(); i++) {
|
||||
String featureKey = featureOrder.get(i);
|
||||
GenericValue featureValue = EntityQuery.use(delegator).from("ProductFeatureType").where(
|
||||
"productFeatureTypeId", featureOrder.get(i)).cache().queryOne();
|
||||
GenericValue featureValue = EntityQuery.use(delegator)
|
||||
.from("ProductFeatureType")
|
||||
.where("productFeatureTypeId", featureOrder.get(i))
|
||||
.cache().queryOne();
|
||||
if (featureValue != null
|
||||
&& UtilValidate.isNotEmpty(featureValue.get("description"))) {
|
||||
featureTypes.put(featureKey, featureValue.get("description"));
|
||||
} else {
|
||||
featureTypes.put(featureKey, featureValue.get("productFeatureTypeId"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user