public ProductType convertProductTypeModelToEntity(ProductTypeModel model) { ProductType prodType = new ProductType(); // prodType.setId(model.getId()); prodType.setProdType(model.getProdType()); prodType.setProdTypeDesc(model.getProdTypeDesc()); if (null != model.getItems() && !model.getItems().isEmpty()) { Set<Item> itemSet = new HashSet<Item>(); for (ItemModel imM : model.getItems()) { Item im = convertItemModelToEntity(imM); im.setProductType(prodType); itemSet.add(im); } prodType.setItems(itemSet); } if (model.getAttributes() != null && model.getAttributes().size() > 0) { Set<Attribute> attributes = new HashSet<Attribute>(); for (AttributeModel attrModel : model.getAttributes()) { Attribute attrEntity = convertAttrModelToEntity(attrModel); attrEntity.setProductType(prodType); attributes.add(attrEntity); } prodType.setAttributes(attributes); } return prodType; }
public Item convertItemModelToEntity(ItemModel model) { Item item = new Item(); item.setItemName(model.getItemName()); item.setItemDescription(model.getItemDescription()); item.setLargeImg(model.getLargeImg()); item.setSmallImg(model.getSmallImg()); if (model.getAttValueModel() != null && model.getAttValueModel().size() > 0) { Set<AttributeValue> attrValues = new HashSet<AttributeValue>(); for (AttributeValueModel attrVal : model.getAttValueModel()) { AttributeValue val = convertAttrValueModelToEntity(attrVal); val.setItem(item); attrValues.add(val); } item.setAttributeValues(attrValues); } return item; }