use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ProductCategoryServiceImpl method fetchParentCategoryList.
public List<ProductCategory> fetchParentCategoryList(ProductCategory productCategory) throws AxelorException {
// security in case of code error to avoid infinite loop
int i = 0;
List<ProductCategory> parentProductCategoryList = new ArrayList<>();
if (productCategory.getId() != null) {
productCategory = productCategoryRepository.find(productCategory.getId());
}
ProductCategory parentProductCategory = productCategory.getParentProductCategory();
while (parentProductCategory != null && i < MAX_ITERATION) {
if (parentProductCategoryList.contains(parentProductCategory) || parentProductCategory.equals(productCategory)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_PARENTS_CIRCULAR_DEPENDENCY), parentProductCategory.getCode());
}
parentProductCategoryList.add(parentProductCategory);
parentProductCategory = parentProductCategory.getParentProductCategory();
i++;
}
return parentProductCategoryList;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ProductCategoryServiceImpl method fetchChildrenCategoryList.
public List<ProductCategory> fetchChildrenCategoryList(ProductCategory productCategory) throws AxelorException {
// security in case of code error to avoid infinite loop
int i = 0;
List<ProductCategory> descendantsProductCategoryList = new ArrayList<>();
if (productCategory.getId() == null) {
// if product category is not saved, then it cannot have children
return descendantsProductCategoryList;
}
List<ProductCategory> childrenProductCategoryList = fetchChildren(productCategory);
while (!childrenProductCategoryList.isEmpty() && i < MAX_ITERATION) {
List<ProductCategory> nextChildrenProductCategoryList = new ArrayList<>();
for (ProductCategory childProductCategory : childrenProductCategoryList) {
if (descendantsProductCategoryList.contains(childProductCategory) || childProductCategory.equals(productCategory)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_CHILDREN_CIRCULAR_DEPENDENCY), childProductCategory.getCode());
}
descendantsProductCategoryList.add(childProductCategory);
nextChildrenProductCategoryList.addAll(fetchChildren(childProductCategory));
}
childrenProductCategoryList.clear();
childrenProductCategoryList.addAll(nextChildrenProductCategoryList);
nextChildrenProductCategoryList.clear();
i++;
}
return descendantsProductCategoryList;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ConvertLeadWizardController method createContactData.
@SuppressWarnings("unchecked")
private Partner createContactData(Context context, Partner partner) throws AxelorException {
Partner contactPartner = null;
Integer leadToContactSelect = (Integer) context.get("leadToContactSelect");
ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
if (leadToContactSelect == null) {
return null;
}
if (leadToContactSelect == LeadRepository.CONVERT_LEAD_CREATE_CONTACT && partner.getPartnerTypeSelect() != PartnerRepository.PARTNER_TYPE_INDIVIDUAL) {
Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_CONTACT_MISSING_ADDRESS));
}
contactPartner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("contactPartner"), primaryAddress);
contactPartner.setIsContact(true);
// TODO check all required fields...
} else if (leadToContactSelect == LeadRepository.CONVERT_LEAD_SELECT_CONTACT && partner.getPartnerTypeSelect() != PartnerRepository.PARTNER_TYPE_INDIVIDUAL) {
Map<String, Object> selectContactContext = (Map<String, Object>) context.get("selectContact");
contactPartner = Beans.get(PartnerRepository.class).find(((Integer) selectContactContext.get("id")).longValue());
}
return contactPartner;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ConvertLeadWizardController method convertLead.
@SuppressWarnings("unchecked")
public void convertLead(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
Partner partner = createPartnerData(context);
Partner contactPartner = null;
if (partner != null) {
contactPartner = createContactData(context, partner);
}
try {
lead = Beans.get(LeadService.class).convertLead(lead, partner, contactPartner);
} catch (Exception e) {
TraceBackService.trace(e);
}
if (lead.getPartner() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CONVERT_LEAD_ERROR));
}
openPartner(response, lead);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ConvertLeadWizardController method createPartnerData.
@SuppressWarnings("unchecked")
private Partner createPartnerData(Context context) throws AxelorException {
Integer leadToPartnerSelect = (Integer) context.get("leadToPartnerSelect");
ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
Partner partner = null;
if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_CREATE_PARTNER) {
Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_PARTNER_MISSING_ADDRESS));
}
partner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("partner"), primaryAddress);
// TODO check all required fields...
} else if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_SELECT_PARTNER) {
Map<String, Object> selectPartnerContext = (Map<String, Object>) context.get("selectPartner");
partner = Beans.get(PartnerRepository.class).find(((Integer) selectPartnerContext.get("id")).longValue());
if (!partner.getIsCustomer()) {
partner.setIsProspect(true);
}
}
return partner;
}
Aggregations