Search in sources :

Example 1 with AbstractBusinessObject

use of org.mifos.framework.business.AbstractBusinessObject in project head by mifos.

the class InterceptHelper method hibernateMeta.

public Map hibernateMeta(Object object, String state) {
    logger.debug("object : " + object);
    ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(object.getClass());
    Object[] propertyValues = customMeta.getPropertyValues(object, EntityMode.POJO);
    String[] propertyNames = customMeta.getPropertyNames();
    Type[] propertyTypes = customMeta.getPropertyTypes();
    if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
        // locale=((BusinessObject)object).getUserContext().getMfiLocale();
        locale = ((AbstractBusinessObject) object).getUserContext().getCurrentLocale();
        // localeId=((BusinessObject)object).getUserContext().getMfiLocaleId();
        localeId = ((AbstractBusinessObject) object).getUserContext().getLocaleId();
        logger.debug("initial path class: " + AuditConfiguration.getEntityToClassPath(object.getClass().getName()));
        entityName = AuditConfiguration.getEntityToClassPath(object.getClass().getName());
        entityId = Integer.valueOf(customMeta.getIdentifier(object, EntityMode.POJO).toString());
    }
    setPrimaryKeyValues(customMeta, object, customMeta.getIdentifierPropertyName(), state);
    for (int i = 0; i < propertyNames.length; i++) {
        if (!propertyTypes[i].isEntityType() && !propertyTypes[i].isCollectionType() && !propertyTypes[i].isComponentType()) {
            if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
                String name = propertyNames[i];
                if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                    String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
                    initialValues.put(propertyNames[i], value);
                } else {
                    if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                        initialValues.put(propertyNames[i], ((Calendar) propertyValues[i]).getTime());
                    } else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
                        initialValues.put(propertyNames[i], new String((byte[]) propertyValues[i]));
                    } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                        try {
                            Date date = (Date) propertyValues[i];
                            initialValues.put(propertyNames[i], DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
                        } catch (Exception e) {
                            initialValues.put(propertyNames[i], propertyValues[i].toString());
                        }
                    } else {
                        initialValues.put(propertyNames[i], propertyValues[i]);
                    }
                }
                String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
                if (columnName != null && !columnName.equals("")) {
                    columnNames.put(propertyNames[i], columnName);
                } else {
                    columnNames.put(propertyNames[i], propertyNames[i]);
                }
            } else {
                String name = propertyNames[i];
                logger.debug("c hibernateMeta " + name + " : " + propertyValues[i]);
                if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                    String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
                    changedValues.put(propertyNames[i], value);
                } else {
                    if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                        changedValues.put(propertyNames[i], ((Calendar) propertyValues[i]).getTime());
                    } else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
                        changedValues.put(propertyNames[i], new String((byte[]) propertyValues[i]));
                    } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                        try {
                            Date date = (Date) propertyValues[i];
                            changedValues.put(propertyNames[i], DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
                        } catch (Exception e) {
                            changedValues.put(propertyNames[i], propertyValues[i].toString());
                        }
                    } else {
                        changedValues.put(propertyNames[i], propertyValues[i]);
                    }
                }
                String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
                if (columnName != null && !columnName.equals("")) {
                    columnNames.put(propertyNames[i], columnName);
                } else {
                    columnNames.put(propertyNames[i], propertyNames[i]);
                }
            }
        }
        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && propertyValues[i] instanceof MasterDataEntity && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null)) {
            String personnelStatusName = AuditConstants.PERSONNELSTATUSPATH;
            String personnelLevelName = AuditConstants.PERSONNELLEVELPATH;
            if (propertyValues[i].getClass().getName().startsWith(personnelStatusName)) {
                Short id = ((PersonnelStatusEntity) propertyValues[i]).getId();
                populateValueForObjectsOfTypeMasterDataEntity(id, state, propertyNames[i]);
            } else if (propertyValues[i].getClass().getName().startsWith(personnelLevelName)) {
                Short id = ((PersonnelLevelEntity) propertyValues[i]).getId();
                populateValueForObjectsOfTypeMasterDataEntity(id, state, propertyNames[i]);
            } else {
                populateValueForObjectsOfTypeMasterDataEntity(propertyValues[i], state, propertyNames[i]);
            }
        }
        // Reading Collection Types
        if (propertyTypes[i].isCollectionType() && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null) && AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], null)) {
            populateAndMergeCollectionTypes(state, propertyValues[i], propertyNames[i], null);
        }
        if (propertyTypes[i].isCollectionType() && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null) && !AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], null)) {
            Iterator iterator = ((Set) propertyValues[i]).iterator();
            while (iterator.hasNext()) {
                Object obj = iterator.next();
                if (obj != null) {
                    if (obj instanceof LoanOfferingFeesEntity) {
                        LoanOfferingFeesEntity loanOfferingFeesEntity = (LoanOfferingFeesEntity) obj;
                        if (propertyNames[i].equalsIgnoreCase("loanOfferingFees") && loanOfferingFeesEntity.getPrdOfferingFeeId() != null) {
                            readLoanOfferingFeesCollection(loanOfferingFeesEntity, state);
                        } else {
                            readFurtherMetaForCollectionType(obj, propertyNames[i], state);
                        }
                    } else {
                        readFurtherMetaForCollectionType(obj, propertyNames[i], state);
                    }
                }
            }
        }
        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null)) {
            Object obj = propertyValues[i];
            if (obj != null) {
                readFurtherMeta(obj, propertyNames[i], state);
            }
        }
        // Reading further Money type
        if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && (propertyValues[i] instanceof Money)) {
            Object obj1 = propertyValues[i];
            if (obj1 != null) {
                readFurtherMoneyType(obj1, propertyNames[i], state);
            }
        }
        // Reading further component type
        if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], null)) {
            Object obj1 = propertyValues[i];
            if (obj1 != null) {
                readFurtherComponenetMeta(obj1, propertyNames[i], state, propertyTypes[i]);
            }
        }
    }
    if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
        return initialValues;
    } else {
        return changedValues;
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Set(java.util.Set) LoanOfferingFeesEntity(org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) Calendar(java.util.Calendar) Date(java.util.Date) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) Money(org.mifos.framework.util.helpers.Money) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) Iterator(java.util.Iterator) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject)

Example 2 with AbstractBusinessObject

use of org.mifos.framework.business.AbstractBusinessObject in project head by mifos.

the class HeaderTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    AbstractBusinessObject obj = null;
    Object randomNum = pageContext.getSession().getAttribute(Constants.RANDOMNUM);
    try {
        obj = (AbstractBusinessObject) SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
    } catch (PageExpiredException pex) {
        obj = (AbstractBusinessObject) pageContext.getSession().getAttribute(Constants.BUSINESS_KEY);
    }
    try {
        String linkStr;
        if (selfLink != null && selfLink != "") {
            linkStr = TagGenerator.createHeaderLinks(obj, Boolean.getBoolean(selfLink), randomNum);
        } else {
            linkStr = TagGenerator.createHeaderLinks(obj, true, randomNum);
        }
        pageContext.getOut().write(linkStr);
    } catch (PageExpiredException e) {
        new JspException(e);
    } catch (IOException e) {
        new JspException(e);
    }
    return SKIP_BODY;
}
Also used : JspException(javax.servlet.jsp.JspException) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) IOException(java.io.IOException)

Example 3 with AbstractBusinessObject

use of org.mifos.framework.business.AbstractBusinessObject in project head by mifos.

the class BaseAction method preExecute.

protected void preExecute(ActionForm actionForm, HttpServletRequest request, TransactionDemarcate annotation) throws SystemException, ApplicationException {
    if (null != request.getParameter(Constants.CURRENTFLOWKEY)) {
        request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    }
    preHandleTransaction(request, annotation);
    UserContext userContext = (UserContext) request.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
    Locale locale = getLocale(userContext);
    if (!skipActionFormToBusinessObjectConversion(request.getParameter("method"))) {
        try {
            AbstractBusinessObject businessObject = getBusinessObjectFromSession(request);
            ConversionUtil.populateBusinessObject(actionForm, businessObject, locale);
        } catch (ValueObjectConversionException e) {
            logger.debug("Value object conversion exception while validating BusinessObject: " + new LogUtils().getStackTrace(e));
        }
    }
}
Also used : Locale(java.util.Locale) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) UserContext(org.mifos.security.util.UserContext) LogUtils(org.mifos.framework.business.LogUtils) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException)

Example 4 with AbstractBusinessObject

use of org.mifos.framework.business.AbstractBusinessObject in project head by mifos.

the class BaseAction method getBusinessObjectFromSession.

private AbstractBusinessObject getBusinessObjectFromSession(HttpServletRequest request) throws ServiceException {
    AbstractBusinessObject object = null;
    if (isNewBizRequired(request)) {
        UserContext userContext = (UserContext) request.getSession().getAttribute("UserContext");
        object = getService().getBusinessObject(userContext);
        request.getSession().setAttribute(Constants.BUSINESS_KEY, object);
    } else {
        object = (AbstractBusinessObject) request.getSession().getAttribute(Constants.BUSINESS_KEY);
    }
    return object;
}
Also used : AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) UserContext(org.mifos.security.util.UserContext)

Aggregations

AbstractBusinessObject (org.mifos.framework.business.AbstractBusinessObject)4 UserContext (org.mifos.security.util.UserContext)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 Set (java.util.Set)1 JspException (javax.servlet.jsp.JspException)1 ClassMetadata (org.hibernate.metadata.ClassMetadata)1 ComponentType (org.hibernate.type.ComponentType)1 Type (org.hibernate.type.Type)1 LoanOfferingFeesEntity (org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity)1 MasterDataEntity (org.mifos.application.master.business.MasterDataEntity)1 PersonnelStatusEntity (org.mifos.customers.personnel.business.PersonnelStatusEntity)1 LogUtils (org.mifos.framework.business.LogUtils)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 ValueObjectConversionException (org.mifos.framework.exceptions.ValueObjectConversionException)1 Money (org.mifos.framework.util.helpers.Money)1