AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
String siteId = site.getSiteId();
IeProfileHeader ieProfileHeader = new IeProfileHeader();
if (insertMode) {
Vector<IeProfileDetailDisplayForm> vector = new Vector<IeProfileDetailDisplayForm>();
for (ItemSimpleCsvMapping csvMapping : ItemSimpleCsvTransformation.FIELDS_GENERAL) {
IeProfileDetailDisplayForm ieProfileDetailDisplayForm = new IeProfileDetailDisplayForm();
ieProfileDetailDisplayForm.setIeProfileFieldName(csvMapping.getIeProfileFieldName());
vector.add(ieProfileDetailDisplayForm);
}
IeProfileDetailDisplayForm[] generalDisplayForms = new IeProfileDetailDisplayForm[vector.size()];
vector.copyInto(generalDisplayForms);
form.setIeProfileGeneralDetails(generalDisplayForms);
}
else {
ieProfileHeader = IeProfileHeaderDAO.load(siteId, Format.getLong(form.getIeProfileHeaderId()));
}
ActionMessages errors = validate(form, request);
if (errors.size() != 0) {
saveMessages(request, errors);
if (insertMode) {
FormUtils.setFormDisplayMode(request, form, FormUtils.CREATE_MODE);
}
else {
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
}
return mapping.findForward("error");
}
if (insertMode) {
ieProfileHeader.setSystemRecord(Constants.VALUE_NO);
ieProfileHeader.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileHeader.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
ieProfileHeader.setSite(site);
ieProfileHeader.setIeProfileType(form.getIeProfileType().charAt(0));
ieProfileHeader.setIeProfileHeaderName(form.getIeProfileHeaderName());
ieProfileHeader.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileHeader.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (insertMode) {
em.persist(ieProfileHeader);
}
for (IeProfileDetail ieProfileDetail : ieProfileHeader.getIeProfileDetails()) {
em.remove(ieProfileDetail);
}
int seqNum = 0;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileGeneralDetails()) {
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(Integer.valueOf(detailForm.getIeProfileGroupIndex()));
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
int groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileCategoryDetails()) {
if (detailForm.getIeProfileFieldName().equals("catId")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileItemRelatedDetails()) {
if (detailForm.getIeProfileFieldName().equals("itemId")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileItemUpSellDetails()) {
if (detailForm.getIeProfileFieldName().equals("itemId")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileItemCrossSellDetails()) {
if (detailForm.getIeProfileFieldName().equals("itemId")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileItemTierPriceDetails()) {
if (detailForm.getIeProfileFieldName().equals("custClassId")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileItemAttributeDetails()) {
if (detailForm.getIeProfileFieldName().equals("customAttribId")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileItemImageDetails()) {
if (detailForm.getIeProfileFieldName().equals("itemImageLocation")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
groupIndex = -1;
for (IeProfileDetailDisplayForm detailForm : form.getIeProfileOtherDetails()) {
if (detailForm.getIeProfileFieldName().equals("default")) {
groupIndex++;
}
IeProfileDetail ieProfileDetail = new IeProfileDetail();
ieProfileDetail.setIeProfileGroupName(detailForm.getIeProfileGroupName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileGroupIndex())) {
ieProfileDetail.setIeProfileGroupIndex(groupIndex);
}
ieProfileDetail.setIeProfileFieldName(detailForm.getIeProfileFieldName());
if (!Format.isNullOrEmpty(detailForm.getIeProfileFieldValue())) {
ieProfileDetail.setIeProfileFieldValue(detailForm.getIeProfileFieldValue());
}
ieProfileDetail.setSeqNum(Integer.valueOf(seqNum++));
if (!Format.isNullOrEmpty(detailForm.getIeProfilePosition())) {
ieProfileDetail.setIeProfilePosition(Integer.valueOf(detailForm.getIeProfilePosition()));
}
ieProfileDetail.setRecUpdateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
ieProfileDetail.setRecCreateBy(adminBean.getUser().getUserId());
ieProfileDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(ieProfileDetail);
ieProfileDetail.setIeProfileHeader(ieProfileHeader);
}
form.setIeProfileHeaderId(Format.getLong(ieProfileHeader.getIeProfileHeaderId()));
form.setMode("U");
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
return mapping.findForward("success");
}