use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method buildStackableProperty.
protected Property buildStackableProperty(Property offerItemTargetRuleType) {
boolean stackable = isTargetType(offerItemTargetRuleType) || isQualifierTargetType(offerItemTargetRuleType);
Property property = new Property();
property.setName(STACKABLE);
property.setValue(String.valueOf(stackable));
return property;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method addIsActiveStatus.
protected void addIsActiveStatus(RecordHelper helper, Entity entity) {
if (isActiveFilter) {
try {
boolean isActive = false;
Property startDate = entity.findProperty("startDate");
if (startDate != null && StringUtils.isNotBlank(startDate.getValue())) {
Property endDate = entity.findProperty("endDate");
Date end = null;
if (endDate != null && StringUtils.isNotBlank(endDate.getValue())) {
end = helper.getSimpleDateFormatter().parse(endDate.getValue());
}
Date date = helper.getSimpleDateFormatter().parse(startDate.getValue());
isActive = DateUtil.isActive(date, end, true);
}
entity.addProperty(buildIsActiveProperty(isActive));
} catch (ParseException e) {
throw ExceptionHelper.refineException(e);
}
}
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method buildOfferItemTargetRuleTypeProperty.
protected Property buildOfferItemTargetRuleTypeProperty(Property stackable) {
String offerItemTargetRuleType;
boolean isStackable = stackable == null ? false : Boolean.parseBoolean(stackable.getValue());
if (isStackable) {
offerItemTargetRuleType = OfferItemRestrictionRuleType.QUALIFIER_TARGET.getType();
} else {
offerItemTargetRuleType = OfferItemRestrictionRuleType.NONE.getType();
}
Property property = new Property();
property.setName(OFFER_ITEM_TARGET_RULE_TYPE);
property.setValue(offerItemTargetRuleType);
return property;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class SkuBundleItemCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
// sort it
if (foreignKey != null && foreignKey.getSortField() != null) {
FilterAndSortCriteria sortCriteria = cto.get(foreignKey.getSortField());
sortCriteria.setSortAscending(foreignKey.getSortAscending());
}
// get the default properties from Inventory and its subclasses
Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(SkuBundleItem.class.getName(), persistencePerspective);
// Pull back the Inventory based on the criteria from the client
List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
// attach the product option criteria
skuPersistenceHandler.applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, "sku");
List<Serializable> records = helper.getPersistentRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
// Convert Skus into the client-side Entity representation
Entity[] payload = helper.getRecords(originalProps, records);
int totalRecords = helper.getTotalRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings);
for (int i = 0; i < payload.length; i++) {
Entity entity = payload[i];
SkuBundleItem bundleItem = (SkuBundleItem) records.get(i);
Sku bundleSku = bundleItem.getSku();
entity.findProperty("sku").setDisplayValue(bundleSku.getName());
List<ProductOptionValue> productOptionValues = new ArrayList<>();
for (SkuProductOptionValueXref skuProductOptionValueXref : bundleSku.getProductOptionValueXrefs()) {
productOptionValues.add(skuProductOptionValueXref.getProductOptionValue());
}
Property optionsProperty = skuPersistenceHandler.getConsolidatedOptionProperty(productOptionValues);
entity.addProperty(optionsProperty);
}
return new DynamicResultSet(null, payload, totalRecords);
} catch (Exception e) {
throw new ServiceException("There was a problem fetching inventory. See server logs for more details", e);
}
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method validateUniqueProductOptionValueCombination.
/**
* Ensures that the given list of {@link ProductOptionValue} IDs is unique for the given {@link Product}.
*
* If sku browsing is enabled, then it is assumed that a single combination of {@link ProductOptionValue} IDs
* is not unique and more than one {@link Sku} could have the exact same combination of {@link ProductOptionValue} IDs.
* In this case, the following validation is skipped.
*
* @param product
* @param productOptionProperties
* @param currentSku - for update operations, this is the current Sku that is being updated; should be excluded from
* attempting validation
* @return <b>null</b> if successfully validation, the error entity otherwise
*/
protected Entity validateUniqueProductOptionValueCombination(Product product, List<Property> productOptionProperties, Sku currentSku) {
if (useSku) {
return null;
}
// do not attempt POV validation if no PO properties were passed in
if (CollectionUtils.isNotEmpty(productOptionProperties)) {
List<Long> productOptionValueIds = new ArrayList<>();
for (Property property : productOptionProperties) {
productOptionValueIds.add(Long.parseLong(property.getValue()));
}
boolean validated = true;
for (Sku sku : product.getAdditionalSkus()) {
if (currentSku == null || !sku.getId().equals(currentSku.getId())) {
List<Long> testList = new ArrayList<>();
for (ProductOptionValue optionValue : sku.getProductOptionValues()) {
testList.add(optionValue.getId());
}
if (CollectionUtils.isNotEmpty(testList) && productOptionValueIds.containsAll(testList) && productOptionValueIds.size() == testList.size()) {
validated = false;
break;
}
}
}
if (!validated) {
Entity errorEntity = new Entity();
for (Property productOptionProperty : productOptionProperties) {
errorEntity.addValidationError(productOptionProperty.getName(), "uniqueSkuError");
}
return errorEntity;
}
}
return null;
}
Aggregations