use of org.apache.ofbiz.entity.condition.EntityCondition in project ofbiz-framework by apache.
the class CategoryWorker method getCategoryTrail.
/**
* Returns a complete category trail - can be used for exporting proper category trees.
* This is mostly useful when used in combination with bread-crumbs, for building a
* faceted index tree, or to export a category tree for migration to another system.
* Will create the tree from root point to categoryId.
*
* This method is not meant to be run on every request.
* Its best use is to generate the trail every so often and store somewhere
* (a lucene/solr tree, entities, cache or so).
*
* @param dctx The DispatchContext that this service is operating in
* @param context Map containing the input parameters
* @return Map organized trail from root point to categoryId.
*/
public static Map getCategoryTrail(DispatchContext dctx, Map context) {
String productCategoryId = (String) context.get("productCategoryId");
Map<String, Object> results = ServiceUtil.returnSuccess();
Delegator delegator = dctx.getDelegator();
List<String> trailElements = new LinkedList<String>();
trailElements.add(productCategoryId);
String parentProductCategoryId = productCategoryId;
while (UtilValidate.isNotEmpty(parentProductCategoryId)) {
// find product category rollup
try {
List<EntityCondition> rolllupConds = new LinkedList<EntityCondition>();
rolllupConds.add(EntityCondition.makeCondition("productCategoryId", parentProductCategoryId));
rolllupConds.add(EntityUtil.getFilterByDateExpr());
List<GenericValue> productCategoryRollups = EntityQuery.use(delegator).from("ProductCategoryRollup").where(rolllupConds).orderBy("sequenceNum").cache(true).queryList();
if (UtilValidate.isNotEmpty(productCategoryRollups)) {
// add only categories that belong to the top category to trail
for (GenericValue productCategoryRollup : productCategoryRollups) {
String trailCategoryId = productCategoryRollup.getString("parentProductCategoryId");
parentProductCategoryId = trailCategoryId;
if (trailElements.contains(trailCategoryId)) {
break;
} else {
trailElements.add(trailCategoryId);
}
}
} else {
parentProductCategoryId = null;
}
} catch (GenericEntityException e) {
Map<String, String> messageMap = UtilMisc.toMap("errMessage", ". Cannot generate trail from product category. ");
String errMsg = UtilProperties.getMessage("CommonUiLabels", "CommonDatabaseProblem", messageMap, (Locale) context.get("locale"));
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
}
Collections.reverse(trailElements);
results.put("trail", trailElements);
return results;
}
use of org.apache.ofbiz.entity.condition.EntityCondition in project ofbiz-framework by apache.
the class CategoryServices method getPreviousNextProducts.
public static Map<String, Object> getPreviousNextProducts(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
String categoryId = (String) context.get("categoryId");
String productId = (String) context.get("productId");
boolean activeOnly = (context.get("activeOnly") != null ? ((Boolean) context.get("activeOnly")).booleanValue() : true);
Integer index = (Integer) context.get("index");
Timestamp introductionDateLimit = (Timestamp) context.get("introductionDateLimit");
Timestamp releaseDateLimit = (Timestamp) context.get("releaseDateLimit");
Locale locale = (Locale) context.get("locale");
if (index == null && productId == null) {
return ServiceUtil.returnFailure(UtilProperties.getMessage(resourceError, "categoryservices.problems_getting_next_products", locale));
}
List<String> orderByFields = UtilGenerics.checkList(context.get("orderByFields"));
if (orderByFields == null)
orderByFields = new LinkedList<String>();
String entityName = getCategoryFindEntityName(delegator, orderByFields, introductionDateLimit, releaseDateLimit);
GenericValue productCategory;
List<GenericValue> productCategoryMembers;
try {
productCategory = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId", categoryId).cache().queryOne();
productCategoryMembers = EntityQuery.use(delegator).from(entityName).where("productCategoryId", categoryId).orderBy(orderByFields).cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logInfo(e, "Error finding previous/next product info: " + e.toString(), module);
return ServiceUtil.returnFailure(UtilProperties.getMessage(resourceError, "categoryservices.error_find_next_products", UtilMisc.toMap("errMessage", e.getMessage()), locale));
}
if (activeOnly) {
productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true);
}
List<EntityCondition> filterConditions = new LinkedList<EntityCondition>();
if (introductionDateLimit != null) {
EntityCondition condition = EntityCondition.makeCondition(EntityCondition.makeCondition("introductionDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("introductionDate", EntityOperator.LESS_THAN_EQUAL_TO, introductionDateLimit));
filterConditions.add(condition);
}
if (releaseDateLimit != null) {
EntityCondition condition = EntityCondition.makeCondition(EntityCondition.makeCondition("releaseDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("releaseDate", EntityOperator.LESS_THAN_EQUAL_TO, releaseDateLimit));
filterConditions.add(condition);
}
if (!filterConditions.isEmpty()) {
productCategoryMembers = EntityUtil.filterByCondition(productCategoryMembers, EntityCondition.makeCondition(filterConditions, EntityOperator.AND));
}
if (productId != null && index == null) {
for (GenericValue v : productCategoryMembers) {
if (v.getString("productId").equals(productId)) {
index = Integer.valueOf(productCategoryMembers.indexOf(v));
}
}
}
if (index == null) {
// this is not going to be an error condition because we don't want it to be so critical, ie rolling back the transaction and such
return ServiceUtil.returnFailure(UtilProperties.getMessage(resourceError, "categoryservices.product_not_found", locale));
}
Map<String, Object> result = ServiceUtil.returnSuccess();
result.put("category", productCategory);
String previous = null;
String next = null;
if (index.intValue() - 1 >= 0 && index.intValue() - 1 < productCategoryMembers.size()) {
previous = productCategoryMembers.get(index.intValue() - 1).getString("productId");
result.put("previousProductId", previous);
} else {
previous = productCategoryMembers.get(productCategoryMembers.size() - 1).getString("productId");
result.put("previousProductId", previous);
}
if (index.intValue() + 1 < productCategoryMembers.size()) {
next = productCategoryMembers.get(index.intValue() + 1).getString("productId");
result.put("nextProductId", next);
} else {
next = productCategoryMembers.get(0).getString("productId");
result.put("nextProductId", next);
}
return result;
}
use of org.apache.ofbiz.entity.condition.EntityCondition in project ofbiz-framework by apache.
the class ContentJsonEvents method deleteWebPathAliases.
private static void deleteWebPathAliases(Delegator delegator, String contentId) throws GenericEntityException {
Timestamp now = UtilDateTime.nowTimestamp();
EntityCondition condition = EntityCondition.makeCondition(EntityCondition.makeCondition(UtilMisc.toMap("contentId", contentId)), EntityUtil.getFilterByDateExpr());
List<GenericValue> pathAliases = delegator.findList("WebSitePathAlias", condition, null, null, null, true);
for (GenericValue alias : pathAliases) {
alias.set("thruDate", now);
delegator.store(alias);
}
List<GenericValue> subContents = delegator.findList("ContentAssoc", condition, null, null, null, true);
for (GenericValue subContentAssoc : subContents) {
deleteWebPathAliases(delegator, subContentAssoc.getString("contentIdTo"));
}
}
use of org.apache.ofbiz.entity.condition.EntityCondition in project ofbiz-framework by apache.
the class MrpServices method executeMrp.
/**
* Launch the MRP.
* <ul>
* <li>PreConditions : none</li>
* <li>Result : The date when we must order or begin to build the products and subproducts we need are calculated</li>
* <li>INPUT : parameters to get from the context: <ul><li>String mrpName</li></ul></li>
* <li>OUTPUT : Result to put in the map : <ul><li>none</li></ul></li>
* </ul>
*
* @param ctx The DispatchContext that this service is operating in.
* @param context Map containing the input parameters, productId routingId, quantity, startDate.
* @return Map with the result of the service, the output parameters.
*/
public static Map<String, Object> executeMrp(DispatchContext ctx, Map<String, ? extends Object> context) {
Debug.logInfo("executeMrp called", module);
Delegator delegator = ctx.getDelegator();
LocalDispatcher dispatcher = ctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Timestamp now = UtilDateTime.nowTimestamp();
Locale locale = (Locale) context.get("locale");
String mrpName = (String) context.get("mrpName");
Integer defaultYearsOffset = (Integer) context.get("defaultYearsOffset");
String facilityGroupId = (String) context.get("facilityGroupId");
String facilityId = (String) context.get("facilityId");
String manufacturingFacilityId = null;
if (UtilValidate.isEmpty(facilityId) && UtilValidate.isEmpty(facilityGroupId)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpFacilityNotAvailable", locale));
}
if (UtilValidate.isEmpty(facilityId)) {
try {
GenericValue facilityGroup = EntityQuery.use(delegator).from("FacilityGroup").where("facilityGroupId", facilityGroupId).queryOne();
if (UtilValidate.isEmpty(facilityGroup)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpFacilityGroupIsNotValid", UtilMisc.toMap("facilityGroupId", facilityGroupId), locale));
}
List<GenericValue> facilities = facilityGroup.getRelated("FacilityGroupMember", null, UtilMisc.toList("sequenceNum"), false);
if (UtilValidate.isEmpty(facilities)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpFacilityGroupIsNotAssociatedToFacility", UtilMisc.toMap("facilityGroupId", facilityGroupId), locale));
}
for (GenericValue facilityMember : facilities) {
GenericValue facility = facilityMember.getRelatedOne("Facility", false);
if ("WAREHOUSE".equals(facility.getString("facilityTypeId")) && UtilValidate.isEmpty(facilityId)) {
facilityId = facility.getString("facilityId");
}
if ("PLANT".equals(facility.getString("facilityTypeId")) && UtilValidate.isEmpty(manufacturingFacilityId)) {
manufacturingFacilityId = facility.getString("facilityId");
}
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpFacilityGroupCannotBeLoad", UtilMisc.toMap("errorString", e.getMessage()), locale));
}
} else {
manufacturingFacilityId = facilityId;
}
if (UtilValidate.isEmpty(facilityId) || UtilValidate.isEmpty(manufacturingFacilityId)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpFacilityOrManufacturingFacilityNotAvailable", locale));
}
int bomLevelWithNoEvent = 0;
BigDecimal stockTmp = BigDecimal.ZERO;
String oldProductId = null;
String productId = null;
GenericValue product = null;
GenericValue productFacility = null;
BigDecimal eventQuantity = BigDecimal.ZERO;
Timestamp eventDate = null;
BigDecimal reorderQuantity = BigDecimal.ZERO;
BigDecimal minimumStock = BigDecimal.ZERO;
int daysToShip = 0;
List<BOMNode> components = null;
boolean isBuilt = false;
GenericValue routing = null;
String mrpId = delegator.getNextSeqId("MrpEvent");
Map<String, Object> result = null;
Map<String, Object> parameters = null;
List<GenericValue> listInventoryEventForMRP = null;
ListIterator<GenericValue> iteratorListInventoryEventForMRP = null;
// Initialization of the MrpEvent table, This table will contain the products we want to buy or build.
parameters = UtilMisc.<String, Object>toMap("mrpId", mrpId, "reInitialize", Boolean.TRUE, "defaultYearsOffset", defaultYearsOffset, "userLogin", userLogin);
parameters.put("facilityId", facilityId);
parameters.put("manufacturingFacilityId", manufacturingFacilityId);
try {
result = dispatcher.runSync("initMrpEvents", parameters);
if (ServiceUtil.isError(result)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
}
} catch (GenericServiceException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorRunningInitMrpEvents", UtilMisc.toMap("errorString", e.getMessage()), locale));
}
long bomLevel = 0;
do {
// Find all products in MrpEventView, ordered by bom and eventDate
EntityCondition filterByConditions = null;
if (bomLevel == 0) {
filterByConditions = EntityCondition.makeCondition(EntityCondition.makeCondition("billOfMaterialLevel", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("billOfMaterialLevel", EntityOperator.EQUALS, Long.valueOf(bomLevel)));
} else {
filterByConditions = EntityCondition.makeCondition("billOfMaterialLevel", EntityOperator.EQUALS, Long.valueOf(bomLevel));
}
try {
listInventoryEventForMRP = EntityQuery.use(delegator).from("MrpEventView").where(filterByConditions).orderBy("productId", "eventDate").queryList();
} catch (GenericEntityException e) {
Long bomLevelToString = new Long(bomLevel);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorForBomLevel", UtilMisc.toMap("bomLevel", bomLevelToString.toString(), "errorString", e.getMessage()), locale));
}
if (UtilValidate.isNotEmpty(listInventoryEventForMRP)) {
bomLevelWithNoEvent = 0;
oldProductId = "";
int eventCount = 0;
for (GenericValue inventoryEventForMRP : listInventoryEventForMRP) {
eventCount++;
productId = inventoryEventForMRP.getString("productId");
boolean isLastEvent = (eventCount == listInventoryEventForMRP.size() || !productId.equals(listInventoryEventForMRP.get(eventCount).getString("productId")));
eventQuantity = inventoryEventForMRP.getBigDecimal("quantity");
if (!productId.equals(oldProductId)) {
BigDecimal positiveEventQuantity = eventQuantity.compareTo(BigDecimal.ZERO) > 0 ? eventQuantity : eventQuantity.negate();
// It's a new product, so it's necessary to read the MrpQoh
try {
product = inventoryEventForMRP.getRelatedOne("Product", true);
productFacility = EntityUtil.getFirst(product.getRelated("ProductFacility", UtilMisc.toMap("facilityId", facilityId), null, true));
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindProductForEvent", locale));
}
stockTmp = findProductMrpQoh(mrpId, product, facilityId, dispatcher, delegator);
try {
InventoryEventPlannedServices.createOrUpdateMrpEvent(UtilMisc.<String, Object>toMap("mrpId", mrpId, "productId", product.getString("productId"), "mrpEventTypeId", "INITIAL_QOH", "eventDate", now), stockTmp, facilityId, null, false, delegator);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCreateOrUpdateEvent", UtilMisc.toMap("parameters", parameters), locale));
}
// days to ship is only relevant for sales order to plan for preparatory days to ship. Otherwise MRP will push event dates for manufacturing parts
// as well and cause problems
daysToShip = 0;
if (productFacility != null) {
reorderQuantity = (productFacility.getBigDecimal("reorderQuantity") != null ? productFacility.getBigDecimal("reorderQuantity") : BigDecimal.ONE.negate());
minimumStock = (productFacility.getBigDecimal("minimumStock") != null ? productFacility.getBigDecimal("minimumStock") : BigDecimal.ZERO);
if ("SALES_ORDER_SHIP".equals(inventoryEventForMRP.getString("mrpEventTypeId"))) {
daysToShip = (productFacility.getLong("daysToShip") != null ? productFacility.getLong("daysToShip").intValue() : 0);
}
} else {
minimumStock = BigDecimal.ZERO;
reorderQuantity = BigDecimal.ONE.negate();
}
// -----------------------------------------------------
// The components are also loaded thru the configurator
Map<String, Object> serviceResponse = null;
try {
serviceResponse = dispatcher.runSync("getManufacturingComponents", UtilMisc.<String, Object>toMap("productId", product.getString("productId"), "quantity", positiveEventQuantity, "excludeWIPs", Boolean.FALSE, "userLogin", userLogin));
if (ServiceUtil.isError(serviceResponse)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResponse));
}
} catch (GenericServiceException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorExplodingProduct", UtilMisc.toMap("productId", product.getString("productId")), locale));
} catch (Exception e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorExplodingProduct", UtilMisc.toMap("productId", product.getString("productId")), locale));
}
components = UtilGenerics.checkList(serviceResponse.get("components"));
if (UtilValidate.isNotEmpty(components)) {
BOMNode node = (components.get(0)).getParentNode();
isBuilt = node.isManufactured();
} else {
isBuilt = false;
}
// #####################################################
oldProductId = productId;
}
stockTmp = stockTmp.add(eventQuantity);
if (stockTmp.compareTo(minimumStock) < 0 && (eventQuantity.compareTo(BigDecimal.ZERO) < 0 || isLastEvent)) {
// No need to create a supply event/requirement if the current event is not a demand and there are other events to process
BigDecimal qtyToStock = minimumStock.subtract(stockTmp);
// need to buy or build the product as we have not enough stock
eventDate = inventoryEventForMRP.getTimestamp("eventDate");
// to be just before the requirement
eventDate.setTime(eventDate.getTime() - 1);
ProposedOrder proposedOrder = new ProposedOrder(product, facilityId, manufacturingFacilityId, isBuilt, eventDate, qtyToStock);
proposedOrder.setMrpName(mrpName);
// calculate the ProposedOrder quantity and update the quantity object property.
proposedOrder.calculateQuantityToSupply(reorderQuantity, minimumStock, iteratorListInventoryEventForMRP);
// -----------------------------------------------------
// The components are also loaded thru the configurator
Map<String, Object> serviceResponse = null;
try {
serviceResponse = dispatcher.runSync("getManufacturingComponents", UtilMisc.<String, Object>toMap("productId", product.getString("productId"), "quantity", proposedOrder.getQuantity(), "excludeWIPs", Boolean.FALSE, "userLogin", userLogin));
if (ServiceUtil.isError(serviceResponse)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResponse));
}
} catch (GenericServiceException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorExplodingProduct", UtilMisc.toMap("productId", product.getString("productId")), locale));
} catch (Exception e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorExplodingProduct", UtilMisc.toMap("productId", product.getString("productId")), locale));
}
components = UtilGenerics.checkList(serviceResponse.get("components"));
String routingId = (String) serviceResponse.get("workEffortId");
if (routingId != null) {
try {
routing = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", routingId).queryOne();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindProductForEvent", locale));
}
} else {
routing = null;
}
if (UtilValidate.isNotEmpty(components)) {
BOMNode node = (components.get(0)).getParentNode();
isBuilt = node.isManufactured();
} else {
isBuilt = false;
}
// #####################################################
// calculate the ProposedOrder requirementStartDate and update the requirementStartDate object property.
Map<String, Object> routingTaskStartDate = proposedOrder.calculateStartDate(daysToShip, routing, delegator, dispatcher, userLogin);
if (isBuilt) {
// process the product components
processBomComponent(mrpId, product, proposedOrder.getQuantity(), proposedOrder.getRequirementStartDate(), routingTaskStartDate, components);
}
// create the ProposedOrder (only if the product is warehouse managed), and the MrpEvent associated
String requirementId = null;
if (productFacility != null) {
requirementId = proposedOrder.create(ctx, userLogin);
}
if (UtilValidate.isEmpty(productFacility) && !isBuilt) {
logMrpError(mrpId, productId, now, "No ProductFacility record for [" + facilityId + "]; no requirement created.", delegator);
}
String eventName = null;
if (UtilValidate.isNotEmpty(requirementId)) {
eventName = "*" + requirementId + " (" + proposedOrder.getRequirementStartDate() + ")*";
}
Map<String, Object> eventMap = UtilMisc.<String, Object>toMap("productId", product.getString("productId"), "mrpId", mrpId, "eventDate", eventDate, "mrpEventTypeId", (isBuilt ? "PROP_MANUF_O_RECP" : "PROP_PUR_O_RECP"));
try {
InventoryEventPlannedServices.createOrUpdateMrpEvent(eventMap, proposedOrder.getQuantity(), null, eventName, (proposedOrder.getRequirementStartDate().compareTo(now) < 0), delegator);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCreateOrUpdateEvent", UtilMisc.toMap("parameters", parameters), locale));
}
//
stockTmp = stockTmp.add(proposedOrder.getQuantity());
}
}
} else {
bomLevelWithNoEvent += 1;
}
bomLevel += 1;
// if there are 3 levels with no inventoryEvenPanned we stop
} while (bomLevelWithNoEvent < 3);
result = new HashMap<String, Object>();
List<Object> msgResult = new LinkedList<Object>();
result.put("msgResult", msgResult);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
Debug.logInfo("return from executeMrp", module);
return result;
}
use of org.apache.ofbiz.entity.condition.EntityCondition in project ofbiz-framework by apache.
the class ContentServicesComplex method getAssocAndContentAndDataResourceCacheMethod.
public static Map<String, Object> getAssocAndContentAndDataResourceCacheMethod(Delegator delegator, String contentId, String mapKey, String direction, Timestamp fromDate, String fromDateStr, List<String> assocTypes, List<String> contentTypes, Boolean nullThruDatesOnly, String contentAssocPredicateId, String orderBy) throws GenericEntityException, MiniLangException {
EntityExpr joinExpr = null;
String viewName = null;
String contentFieldName = null;
if (direction != null && "From".equalsIgnoreCase(direction)) {
contentFieldName = "caContentIdTo";
joinExpr = EntityCondition.makeCondition("caContentIdTo", EntityOperator.EQUALS, contentId);
} else {
contentFieldName = "caContentId";
joinExpr = EntityCondition.makeCondition("contentId", EntityOperator.EQUALS, contentId);
}
if (direction != null && "From".equalsIgnoreCase(direction)) {
viewName = "ContentAssocDataResourceViewFrom";
} else {
viewName = "ContentAssocDataResourceViewTo";
}
List<EntityCondition> conditionList = new ArrayList<EntityCondition>();
conditionList.add(joinExpr);
if (UtilValidate.isNotEmpty(mapKey)) {
String mapKeyValue = "is null".equalsIgnoreCase(mapKey) ? null : mapKey;
conditionList.add(EntityCondition.makeCondition("caMapKey", mapKeyValue));
}
if (UtilValidate.isNotEmpty(contentAssocPredicateId)) {
String contentAssocPredicateIdValue = "is null".equalsIgnoreCase(contentAssocPredicateId) ? null : contentAssocPredicateId;
conditionList.add(EntityCondition.makeCondition("caMapKey", contentAssocPredicateIdValue));
}
if (nullThruDatesOnly != null && nullThruDatesOnly) {
conditionList.add(EntityCondition.makeCondition("caThruDate", null));
}
if (UtilValidate.isNotEmpty(assocTypes)) {
conditionList.add(EntityCondition.makeCondition("caContentAssocTypeId", EntityOperator.IN, assocTypes));
}
List<GenericValue> contentAssocsTypeFiltered = EntityQuery.use(delegator).from(viewName).where(conditionList).orderBy("caSequenceNum", "-caFromDate").cache().queryList();
String assocRelationName = null;
if (direction != null && "To".equalsIgnoreCase(direction)) {
assocRelationName = "ToContent";
} else {
assocRelationName = "FromContent";
}
GenericValue contentAssocDataResourceView = null;
GenericValue content = null;
GenericValue dataResource = null;
List<GenericValue> contentAssocDataResourceList = new LinkedList<GenericValue>();
// TODO: this needs to be passed in
Locale locale = Locale.getDefault();
try {
for (GenericValue contentAssocView : contentAssocsTypeFiltered) {
GenericValue contentAssoc = EntityQuery.use(delegator).from("ContentAssoc").where(UtilMisc.toMap("contentId", contentAssocView.getString("contentId"), "contentIdTo", contentAssocView.getString(contentFieldName), "contentAssocTypeId", contentAssocView.getString("caContentAssocTypeId"), "fromDate", contentAssocView.getTimestamp("caFromDate"))).queryOne();
content = contentAssoc.getRelatedOne(assocRelationName, true);
if (UtilValidate.isNotEmpty(contentTypes)) {
String contentTypeId = (String) content.get("contentTypeId");
if (contentTypes.contains(contentTypeId)) {
contentAssocDataResourceView = delegator.makeValue(viewName);
contentAssocDataResourceView.setAllFields(content, true, null, null);
}
} else {
contentAssocDataResourceView = delegator.makeValue(viewName);
contentAssocDataResourceView.setAllFields(content, true, null, null);
}
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocOut", contentAssoc, contentAssocDataResourceView, new LinkedList<Object>(), locale);
String dataResourceId = content.getString("dataResourceId");
if (UtilValidate.isNotEmpty(dataResourceId))
dataResource = content.getRelatedOne("DataResource", true);
if (dataResource != null) {
SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceOut", dataResource, contentAssocDataResourceView, new LinkedList<Object>(), locale);
}
contentAssocDataResourceList.add(contentAssocDataResourceView);
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
if (UtilValidate.isNotEmpty(orderBy)) {
List<String> orderByList = StringUtil.split(orderBy, "|");
contentAssocDataResourceList = EntityUtil.orderBy(contentAssocDataResourceList, orderByList);
}
Map<String, Object> results = new HashMap<String, Object>();
results.put("entityList", contentAssocDataResourceList);
if (UtilValidate.isNotEmpty(contentAssocDataResourceList)) {
results.put("view", contentAssocDataResourceList.get(0));
}
return results;
}
Aggregations