for (ItemTierPrice p : removeTierPriceList) {
item.getItemTierPrices().remove(p);
}
}
CustomAttributeGroup customAttributeGroup = null;
if (customAttributeGroupId != null || !Format.isNullOrEmpty(customAttributeGroupName)) {
if (customAttributeGroupId != null) {
customAttributeGroup = CustomAttributeGroupDAO.load(siteId, customAttributeGroupId);
}
else {
customAttributeGroup = CustomAttributeGroupDAO.loadByName(siteId, customAttributeGroupName);
}
if (customAttributeGroup == null) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E109",
"customAttributeGroup",
"customAttributeGroupId and customAttributeGroupName",
customAttributeGroupId + " and " + customAttributeGroupName));
}
if (item.getCustomAttributeGroup() != null) {
if (!item.getCustomAttributeGroup().getCustomAttribGroupId().equals(customAttributeGroup.getCustomAttribGroupId())) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E123", customAttributeGroup.getCustomAttribGroupId(), customAttributeGroup.getCustomAttribGroupName()));
}
}
else {
item.setCustomAttributeGroup(customAttributeGroup);
}
for (CustomAttributeDetail customAttributeDetail : customAttributeGroup.getCustomAttributeDetails()) {
CustomAttribute customAttribute = customAttributeDetail.getCustomAttribute();
ItemAttributeDetail itemAttributeDetailImport = null;
boolean found = false;
for (ItemAttributeDetail detail : this.getItemAttributeDetails()) {
if (detail.getCustomAttribId() != null) {
if (detail.getCustomAttribId().equals(customAttribute.getCustomAttribId())) {
itemAttributeDetailImport = detail;
found = true;
break;
}
}
else {
if (detail.getCustomAttribName().equals(customAttribute.getCustomAttribName())) {
itemAttributeDetailImport = detail;
found = true;
break;
}
}
}
if (!found) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E113",
customAttribute.getCustomAttribId(),
customAttribute.getCustomAttribName()));
}
if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_CUST_SELECT_DROPDOWN) {
if (itemAttributeDetailImport.getItemAttributeDetailLanguages().size() > 0) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E121", customAttribute.getCustomAttribName()));
}
}
else if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_CUST_INPUT) {
if (itemAttributeDetailImport.getCustomAttribId() != null ||
Format.isNullOrEmpty(itemAttributeDetailImport.getCustomAttribName())) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E117", customAttribute.getCustomAttribName()));
}
if (itemAttributeDetailImport.getItemAttributeDetailLanguages().size() > 0) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E121", customAttribute.getCustomAttribName()));
}
}
else if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_SELECT_DROPDOWN) {
if (itemAttributeDetailImport.getCustomAttribOptionId() == null &&
Format.isNullOrEmpty(itemAttributeDetailImport.getCustomAttribValue())) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E115", customAttribute.getCustomAttribName()));
}
if (itemAttributeDetailImport.getItemAttributeDetailLanguages().size() > 0) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E121", customAttribute.getCustomAttribName()));
}
}
else if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_INPUT) {
if (itemAttributeDetailImport.getCustomAttribOptionId() != null ||
!Format.isNullOrEmpty(itemAttributeDetailImport.getCustomAttribValue())) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E117", customAttribute.getCustomAttribName()));
}
if (this.isDefaultProfile()) {
boolean valueFound = false;
for (ItemAttributeDetailLanguage itemAttributeDetailLanguage : itemAttributeDetailImport.getItemAttributeDetailLanguages()) {
if (itemAttributeDetailLanguage.getSiteProfileClassId().equals(siteProfileClassDefault.getSiteProfileClassId())) {
if (Format.isNullOrEmpty(itemAttributeDetailLanguage.getItemAttribDetailValue())) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E122", customAttribute.getCustomAttribName()));
}
valueFound = true;
}
}
if (!valueFound) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E122", customAttribute.getCustomAttribName()));
}
}
}
else if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_SKU_MAKEUP) {
if (itemAttributeDetailImport.getCustomAttribOptionId() == null &&
Format.isNullOrEmpty(itemAttributeDetailImport.getCustomAttribValue())) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E115", customAttribute.getCustomAttribName()));
}
}
}
for (ItemAttributeDetail detail : this.getItemAttributeDetails()) {
boolean found = false;
for (CustomAttributeDetail customAttributeDetail : customAttributeGroup.getCustomAttributeDetails()) {
CustomAttribute customAttribute = customAttributeDetail.getCustomAttribute();
if (detail.getCustomAttribId() != null) {
if (detail.getCustomAttribId().equals(customAttribute.getCustomAttribId())) {
found = true;
break;
}
}
else {
if (detail.getCustomAttribName().equals(customAttribute.getCustomAttribName())) {
found = true;
break;
}
}
}
if (!found) {
throw new ItemSaveException(resources.getMessage("IE.ERROR.E119", detail.getCustomAttribId(), detail.getCustomAttribName()));
}
}
for (ItemAttributeDetail itemAttributeDetailImport : this.getItemAttributeDetails()) {
com.jada.jpa.entity.ItemAttributeDetail itemAttributeDetail = null;
boolean foundDetail = false;
for (com.jada.jpa.entity.ItemAttributeDetail detail : item.getItemAttributeDetails()) {
CustomAttribute customAttribute = detail.getCustomAttributeDetail().getCustomAttribute();
if (itemAttributeDetailImport.getCustomAttribId() != null) {
if (itemAttributeDetailImport.getCustomAttribId().equals(customAttribute.getCustomAttribId())) {
itemAttributeDetail = detail;
foundDetail = true;
}
}
else {
if (itemAttributeDetailImport.getCustomAttribName().equals(customAttribute.getCustomAttribName())) {
itemAttributeDetail = detail;
foundDetail = true;
}
}
}
if (!foundDetail) {
itemAttributeDetail = new com.jada.jpa.entity.ItemAttributeDetail();
CustomAttributeDetail customAttributeDetail = null;
for (CustomAttributeDetail d : customAttributeGroup.getCustomAttributeDetails()) {
CustomAttribute customAttribute = d.getCustomAttribute();
if (itemAttributeDetailImport.getCustomAttribOptionId() != null) {
if (itemAttributeDetailImport.getCustomAttribId() == customAttribute.getCustomAttribId()) {
customAttributeDetail = d;
break;
}
}
else {
if (itemAttributeDetailImport.getCustomAttribName() == customAttribute.getCustomAttribName()) {
customAttributeDetail = d;
break;
}
}
}
itemAttributeDetail.setCustomAttributeDetail(customAttributeDetail);
itemAttributeDetail.setRecCreateBy(Constants.USERNAME_IMPORT);
itemAttributeDetail.setRecCreateDatetime(new Date());
itemAttributeDetail.setItem(item);
}
if (itemAttributeDetailImport.getCustomAttribId() != null) {
for (CustomAttributeDetail customAttributeDetail : customAttributeGroup.getCustomAttributeDetails()) {
if (customAttributeDetail.getCustomAttribute().getCustomAttribId().equals(itemAttributeDetailImport.getCustomAttribId())) {
itemAttributeDetail.setCustomAttributeDetail(customAttributeDetail);
break;
}
}
}
if (!Format.isNullOrEmpty(itemAttributeDetailImport.getCustomAttribName())) {
for (CustomAttributeDetail customAttributeDetail : customAttributeGroup.getCustomAttributeDetails()) {
if (customAttributeDetail.getCustomAttribute().getCustomAttribName().equals(itemAttributeDetailImport.getCustomAttribName())) {
itemAttributeDetail.setCustomAttributeDetail(customAttributeDetail);
break;
}
}