Example usage for org.hibernate EntityMode POJO

List of usage examples for org.hibernate EntityMode POJO

Introduction

In this page you can find the example usage for org.hibernate EntityMode POJO.

Prototype

EntityMode POJO

To view the source code for org.hibernate EntityMode POJO.

Click Source Link

Document

The pojo entity mode describes an entity model made up of entity classes (loosely) following the java bean convention.

Usage

From source file:org.jdal.hibernate.HibernateUtils.java

License:Apache License

/** 
 * Initialize Object for use with closed Session. 
 * //from w  w w.  ja  v a2 s.c o m
 * @param sessionFactory max depth in recursion
 * @param obj Object to initialize
 * @param initializedObjects list with already initialized Objects
 * @param depth max depth in recursion
 */
private static void initialize(SessionFactory sessionFactory, Object obj, List<Object> initializedObjects,
        int depth) {

    // return on nulls, depth = 0 or already initialized objects
    if (obj == null || depth == 0) {
        return;
    }

    if (!Hibernate.isInitialized(obj)) {
        // if collection, initialize objects in collection too. Hibernate don't do it.
        if (obj instanceof Collection) {
            initializeCollection(sessionFactory, obj, initializedObjects, depth);
            return;
        }

        sessionFactory.getCurrentSession().buildLockRequest(LockOptions.NONE).lock(obj);
        Hibernate.initialize(obj);
    }

    // now we can call equals safely. If object are already initializated, return
    if (initializedObjects.contains(obj))
        return;

    initializedObjects.add(obj);

    // initialize all persistent associaciations.
    ClassMetadata classMetadata = getClassMetadata(sessionFactory, obj);

    if (classMetadata == null) {
        return; // Not persistent object
    }

    Object[] pvs = classMetadata.getPropertyValues(obj, EntityMode.POJO);

    for (Object pv : pvs) {
        initialize(sessionFactory, pv, initializedObjects, depth - 1);
    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

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(//from   w ww . ja  va2  s. co  m
                "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;
    }

}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void readFurtherMeta(Object obj, String firstName, String state) {
    Class clazz = getClazz(obj);//ww w .j  a v a2 s  . c o m
    ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(clazz);
    Object[] propertyValues = customMeta.getPropertyValues(obj, EntityMode.POJO);
    String[] propertyNames = customMeta.getPropertyNames();
    Type[] propertyTypes = customMeta.getPropertyTypes();
    String prdStatusName = AuditConstants.PRDSTATUSPATH;
    if (obj.getClass().getName().startsWith(prdStatusName)) {
        Short id = ((PrdStatusEntity) obj).getOfferingStatusId();
        setPrimaryKeyValues(id, firstName.concat(customMeta.getIdentifierPropertyName()), state);
    } else {
        setPrimaryKeyValues(customMeta, obj, firstName.concat(customMeta.getIdentifierPropertyName()), state);
    }

    for (int i = 0; i < propertyNames.length; i++) {
        logger.debug("readFurtherMeta property : " + propertyNames[i]);
        setColumnValues(propertyTypes[i], propertyNames[i], firstName, state, propertyValues[i]);

        // Reading masterdata Types
        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && propertyValues[i] instanceof MasterDataEntity
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            populateValueForObjectsOfTypeMasterDataEntity(propertyValues[i], state,
                    firstName.concat(propertyNames[i]));
        }

        // Reading Collection Types
        if (propertyTypes[i].isCollectionType()
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)
                && !AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], firstName)) {
            Iterator iterator = ((Set) propertyValues[i]).iterator();
            while (iterator.hasNext()) {
                Object valueFromSet = iterator.next();
                readFurtherMetaForCollectionType(valueFromSet, propertyNames[i], state);
            }
        }

        // Reading Collection Types
        if (propertyTypes[i].isCollectionType()
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)
                && AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], firstName)) {
            populateAndMergeCollectionTypes(state, propertyValues[i], propertyNames[i], firstName);
        }

        // Reading further entity type
        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && !(propertyValues[i] instanceof MasterDataEntity)
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            Object obj1 = propertyValues[i];
            if (obj1 != null) {
                if (obj1 instanceof MeetingBO) {
                    MeetingBO meeting = (MeetingBO) obj1;
                    if (propertyNames[i].equalsIgnoreCase("meeting") && meeting.getMeetingId() != null) {
                        readMeetingEntity(meeting, propertyNames[i], state);
                    } else {
                        readFurtherMeta(obj1, propertyNames[i], state);
                    }
                } else {
                    readFurtherMeta(obj1, propertyNames[i], state);
                }
            }
        }

        // Reading further component type
        if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType()
                && !(propertyValues[i] instanceof MasterDataEntity)
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            Object obj1 = propertyValues[i];
            if (obj1 != null) {
                readFurtherComponenetMeta(obj1, propertyNames[i], state, propertyTypes[i]);
            }
        }

        // 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, firstName.concat(propertyNames[i]), state);
            }
        }

    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void readFurtherComponenetMeta(Object obj, String firstName, String state, Type propertyType) {

    ComponentType componentType = (ComponentType) propertyType;

    Object[] propertyValues = componentType.getPropertyValues(obj, EntityMode.POJO);
    String[] propertyNames = componentType.getPropertyNames();

    for (int i = 0; i < propertyNames.length; i++) {

        if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
            String name = firstName.concat(propertyNames[i]);
            logger.debug("i setColumnValues " + name + " : " + propertyValues[i]);
            if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i],
                        localeId);/*from   ww  w.j a  v a  2s .c  om*/
                initialValues.put(name, value);
            } else {
                if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                    initialValues.put(name, ((Calendar) propertyValues[i]).getTime());
                } else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
                    initialValues.put(name, new String((byte[]) propertyValues[i]));
                } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                    try {
                        Date date = (Date) propertyValues[i];
                        initialValues.put(name, DateUtils.getUserLocaleDate(locale,
                                new java.sql.Date(date.getTime()).toString()));
                    } catch (Exception e) {
                        initialValues.put(name, propertyValues[i].toString());
                    }
                } else {
                    initialValues.put(name, propertyValues[i]);
                }
            }
            String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
            if (columnName != null && !columnName.equals("")) {
                columnNames.put(name, columnName);
            } else {
                columnNames.put(name, propertyNames[i]);
            }
        } else {
            String name = firstName.concat(propertyNames[i]);
            logger.debug("c setColumnValues " + name + " : " + propertyValues[i]);
            if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i],
                        localeId);
                changedValues.put(name, value);
            } else {
                if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                    changedValues.put(name, ((Calendar) propertyValues[i]).getTime());
                } else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
                    changedValues.put(name, new String((byte[]) propertyValues[i]));
                } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                    Date date = (Date) propertyValues[i];
                    changedValues.put(name,
                            DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
                } else {
                    changedValues.put(name, propertyValues[i]);
                }
            }
            String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
            if (columnName != null && !columnName.equals("")) {
                columnNames.put(name, columnName);
            } else {
                columnNames.put(name, propertyNames[i]);
            }
        }
    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void readFurtherMetaForCollectionType(Object obj, String firstName, String state) {
    Class l = getClazz(obj);/*from  w w w.j a  v  a2 s .  co m*/

    ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(l);

    Object[] propertyValues = customMeta.getPropertyValues(obj, EntityMode.POJO);
    String[] propertyNames = customMeta.getPropertyNames();
    Type[] propertyTypes = customMeta.getPropertyTypes();

    setPrimaryKeyValueForCollectionType(customMeta, obj,
            firstName.concat(customMeta.getIdentifierPropertyName()), state);

    for (int i = 0; i < propertyNames.length; i++) {
        if (!propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && !propertyTypes[i].isCollectionType()) {
            if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
                String name = firstName.concat(propertyNames[i]);
                logger.debug("i readFurtherMetaForCollectionType : " + name + " : " + propertyValues[i]);
                String oldValue = getOldValueToKey(initialValues, name);

                if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                    String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                            propertyValues[i], localeId);
                    if (!oldValue.equals("")) {
                        initialValues.put(name, value.concat(",").concat(oldValue));
                    } else {
                        initialValues.put(name, value);
                    }
                } else {
                    if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                        if (!oldValue.equals("")) {
                            initialValues.put(name, ((Calendar) propertyValues[i]).getTime().toString()
                                    .concat(",").concat(oldValue));
                        } else {
                            initialValues.put(name, ((Calendar) propertyValues[i]).getTime());
                        }
                    } else if (!(propertyValues[i] instanceof Calendar) && !(propertyValues[i] instanceof Date)
                            && propertyValues[i] != null) {
                        if (!oldValue.equals("")) {
                            initialValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
                        } else {
                            initialValues.put(name, propertyValues[i]);
                        }
                    } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                        if (!oldValue.equals("")) {
                            try {
                                Date date = (Date) propertyValues[i];
                                initialValues.put(name, DateUtils
                                        .getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString())
                                        .toString().concat(",").concat(oldValue));
                            } catch (Exception e) {
                                initialValues.put(name,
                                        propertyValues[i].toString().concat(",").concat(oldValue));
                            }
                        } else {
                            try {
                                Date date = (Date) propertyValues[i];
                                initialValues.put(name, DateUtils.getUserLocaleDate(locale,
                                        new java.sql.Date(date.getTime()).toString()));
                            } catch (Exception e) {
                                initialValues.put(name, propertyValues[i].toString());
                            }
                        }
                    } else {
                        if (!oldValue.equals("")) {
                            initialValues.put(name, oldValue);
                        } else {
                            initialValues.put(name, propertyValues[i]);
                        }
                    }
                }
                String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
                if (columnName != null && !columnName.equals("")) {
                    columnNames.put(name, columnName);
                } else {
                    columnNames.put(name, propertyNames[i]);
                }
            } else {
                String name = firstName.concat(propertyNames[i].toString());
                logger.debug("c readFurtherMetaForCollectionType : " + name + " : " + propertyValues[i]);
                String oldValue = getOldValueToKey(changedValues, name);

                if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                    String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                            propertyValues[i], localeId);
                    if (!value.equals("")) {
                        changedValues.put(name, value.concat(",").concat(oldValue));
                    } else {
                        changedValues.put(name, oldValue);
                    }
                } else {
                    if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                        if (!oldValue.equals("")) {
                            changedValues.put(name, ((Calendar) propertyValues[i]).getTime().toString()
                                    .concat(",").concat(oldValue));
                        } else {
                            changedValues.put(name, ((Calendar) propertyValues[i]).getTime());
                        }
                    } else if (!(propertyValues[i] instanceof Calendar) && !(propertyValues[i] instanceof Date)
                            && propertyValues[i] != null) {
                        if (!oldValue.equals("")) {
                            changedValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
                        } else {
                            changedValues.put(name, propertyValues[i]);
                        }
                    } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                        if (!oldValue.equals("")) {
                            try {
                                Date date = (Date) propertyValues[i];
                                changedValues.put(name, DateUtils
                                        .getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString())
                                        .toString().concat(",").concat(oldValue));
                            } catch (Exception e) {
                                changedValues.put(name,
                                        propertyValues[i].toString().concat(",").concat(oldValue));
                            }
                        } else {
                            try {
                                Date date = (Date) propertyValues[i];
                                changedValues.put(name, DateUtils.getUserLocaleDate(locale,
                                        new java.sql.Date(date.getTime()).toString()));
                            } catch (Exception e) {
                                changedValues.put(name, propertyValues[i].toString());
                            }
                        }
                    } else {
                        if (!oldValue.equals("")) {
                            changedValues.put(name, oldValue);
                        } else {
                            changedValues.put(name, propertyValues[i]);
                        }
                    }
                }
                String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
                if (columnName != null && !columnName.equals("")) {
                    columnNames.put(name, columnName);
                } else {
                    columnNames.put(name, propertyNames[i]);
                }
            }
        }

        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && propertyValues[i] instanceof MasterDataEntity
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            populateValueForObjectsOfTypeMasterDataEntityInCollections(propertyValues[i], state,
                    firstName.concat(propertyNames[i]));
        }

        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && !(propertyValues[i] instanceof MasterDataEntity)
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            Object object = propertyValues[i];
            if (object != null) {
                if (object instanceof MeetingBO) {
                    MeetingBO meeting = (MeetingBO) object;
                    if (propertyNames[i].equalsIgnoreCase("meeting") && meeting.getMeetingId() != null) {
                        readMeetingCollection(meeting, propertyNames[i], state);
                    } else {
                        readFurtherMetaForCollectionType(object, propertyNames[i], state);
                    }
                } else {
                    readFurtherMetaForCollectionType(object, 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,
         * firstName.concat(propertyNames[i]),state); } }
         */

        // Reading further component type
        if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType()
                && !(propertyValues[i] instanceof MasterDataEntity)
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            Object obj1 = propertyValues[i];
            if (obj1 != null) {
                readComponenetTypeInCollectionTypeWithoutMerge(obj1, propertyNames[i], state, propertyTypes[i]);
            }
        }

    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void readAndMergeCollectionTypes(Object obj, String firstName, String parentName, String state) {
    Class l = getClazz(obj);/*from  ww w .  j ava 2s  .  co  m*/

    ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(l);

    Object[] propertyValues = customMeta.getPropertyValues(obj, EntityMode.POJO);
    String[] propertyNames = customMeta.getPropertyNames();
    Type[] propertyTypes = customMeta.getPropertyTypes();

    setPrimaryKeyValueForCollectionTypeAndMerge(customMeta, obj,
            firstName.concat(customMeta.getIdentifierPropertyName()), state);

    for (int i = 0; i < propertyNames.length; i++) {
        logger.debug("property Name : " + propertyNames[i] + " value : " + propertyValues[i]);
        if (!propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && !propertyTypes[i].isCollectionType()) {
            if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
                String name = firstName.concat(propertyNames[i]);
                logger.debug("i readFurtherMetaForCollectionType " + name + " value : " + propertyValues[i]);
                if (isValueLoggable(propertyNames[i], firstName)) {
                    if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                        String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                                propertyValues[i], localeId);
                        if (initialArray.toString().trim().length() == 0
                                || initialArray.toString().endsWith(",")) {
                            initialArray.append(value);
                        } else if (value.trim().length() != 0) {
                            initialArray.append("-").append(value);
                        }
                    } else {
                        if (propertyValues[i] != null) {
                            if (initialArray.toString().trim().length() == 0
                                    || initialArray.toString().endsWith(",")) {
                                initialArray.append(propertyValues[i]);
                            } else if (propertyValues[i].toString().trim().length() != 0) {
                                initialArray.append("-").append(propertyValues[i]);
                            }
                        }

                    }
                }
            } else {
                String name = firstName.concat(propertyNames[i].toString());
                logger.debug("c readFurtherMetaForCollectionType " + name + " value : " + propertyValues[i]);
                if (isValueLoggable(propertyNames[i], firstName)) {
                    if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                        String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                                propertyValues[i], localeId);
                        if (changeArray.toString().trim().length() == 0
                                || changeArray.toString().endsWith(",")) {
                            changeArray.append(value);
                        } else if (value.trim().length() != 0) {
                            changeArray.append("-").append(value);
                        }
                    } else {
                        if (propertyValues[i] != null) {
                            if (changeArray.toString().trim().length() == 0
                                    || changeArray.toString().endsWith(",")) {
                                changeArray.append(propertyValues[i]);
                            } else if (propertyValues[i].toString().trim().length() != 0) {
                                changeArray.append("-").append(propertyValues[i]);
                            }
                        }
                    }
                }
            }
        }

        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && propertyValues[i] instanceof MasterDataEntity
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {

            populateAndMergeValueForObjectsOfTypeMasterDataEntityInCollections(propertyValues[i], state,
                    firstName.concat(propertyNames[i]));
        }
        if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType()
                && !(propertyValues[i] instanceof MasterDataEntity)
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            Object object = propertyValues[i];
            if (object != null) {
                if (object instanceof MeetingBO) {
                    MeetingBO meeting = (MeetingBO) object;
                    if (propertyNames[i].equalsIgnoreCase("meeting") && meeting.getMeetingId() != null) {
                        readAndMergeMeetingCollection(meeting, propertyNames[i], state);
                    } else {
                        readAndMergeCollectionTypes(object, propertyNames[i], firstName, state);
                    }
                } else {
                    readAndMergeCollectionTypes(object, propertyNames[i], firstName, 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,
         * firstName.concat(propertyNames[i]),state); } }
         */

        // Reading further component type
        if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType()
                && !(propertyValues[i] instanceof MasterDataEntity)
                && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
            Object obj1 = propertyValues[i];
            if (obj1 != null) {
                readComponenetTypeInCollectionTypeWithMerge(obj1, propertyNames[i], state, propertyTypes[i]);
            }
        }
    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void readComponenetTypeInCollectionTypeWithMerge(Object obj, String firstName, String state,
        Type propertyType) {/*from w  w w  .j  a v a 2s  . c om*/

    ComponentType componentType = (ComponentType) propertyType;

    Object[] propertyValues = componentType.getPropertyValues(obj, EntityMode.POJO);
    String[] propertyNames = componentType.getPropertyNames();

    for (int i = 0; i < propertyNames.length; i++) {
        logger.debug("property Name : " + propertyNames[i] + "  value  : " + propertyValues[i]);
        if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
            String name = firstName.concat(propertyNames[i]);
            logger.debug(
                    "i readComponenetTypeInCollectionTypeWithMerge " + name + " value : " + propertyValues[i]);
            if (isValueLoggable(propertyNames[i], firstName)) {
                if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                    String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                            propertyValues[i], localeId);
                    if (initialArray.toString().trim().length() == 0 || initialArray.toString().endsWith(",")) {
                        initialArray.append(value);
                    } else if (value.trim().length() != 0) {
                        initialArray.append("-").append(value);
                    }
                } else {
                    if (propertyValues[i] != null) {
                        if (initialArray.toString().trim().length() == 0
                                || initialArray.toString().endsWith(",")) {
                            initialArray.append(propertyValues[i]);
                        } else if (propertyValues[i].toString().trim().length() != 0) {
                            initialArray.append("-").append(propertyValues[i]);
                        }
                    }

                }
            }
        } else {
            String name = firstName.concat(propertyNames[i].toString());
            logger.debug(
                    "c readComponenetTypeInCollectionTypeWithMerge " + name + " value : " + propertyValues[i]);
            if (isValueLoggable(propertyNames[i], firstName)) {
                if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                    String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                            propertyValues[i], localeId);
                    if (changeArray.toString().trim().length() == 0 || changeArray.toString().endsWith(",")) {
                        changeArray.append(value);
                    } else if (value.trim().length() != 0) {
                        changeArray.append("-").append(value);
                    }
                } else {
                    if (propertyValues[i] != null) {
                        if (changeArray.toString().trim().length() == 0
                                || changeArray.toString().endsWith(",")) {
                            changeArray.append(propertyValues[i]);
                        } else if (propertyValues[i].toString().trim().length() != 0) {
                            changeArray.append("-").append(propertyValues[i]);
                        }
                    }
                }
            }
        }

    }

}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void readComponenetTypeInCollectionTypeWithoutMerge(Object obj, String firstName, String state,
        Type propertyType) {//  w w  w  .  j a  v  a2  s . co  m

    ComponentType componentType = (ComponentType) propertyType;

    Object[] propertyValues = componentType.getPropertyValues(obj, EntityMode.POJO);
    String[] propertyNames = componentType.getPropertyNames();

    for (int i = 0; i < propertyNames.length; i++) {
        if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
            String name = firstName.concat(propertyNames[i]);
            logger.debug("i readComponenetTypeInCollectionTypeWithoutMerge : " + name + " value : "
                    + propertyValues[i]);
            String oldValue = getOldValueToKey(initialValues, name);

            if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i],
                        localeId);
                if (!oldValue.equals("")) {
                    initialValues.put(name, value.concat(",").concat(oldValue));
                } else {
                    initialValues.put(name, value);
                }
            } else {
                if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                    if (!oldValue.equals("")) {
                        initialValues.put(name, ((Calendar) propertyValues[i]).getTime().toString().concat(",")
                                .concat(oldValue));
                    } else {
                        initialValues.put(name, ((Calendar) propertyValues[i]).getTime());
                    }
                } else if (!(propertyValues[i] instanceof Calendar) && !(propertyValues[i] instanceof Date)
                        && propertyValues[i] != null) {
                    if (!oldValue.equals("")) {
                        initialValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
                    } else {
                        initialValues.put(name, propertyValues[i]);
                    }
                } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                    if (!oldValue.equals("")) {
                        try {
                            Date date = (Date) propertyValues[i];
                            initialValues.put(name, DateUtils
                                    .getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString())
                                    .toString().concat(",").concat(oldValue));
                        } catch (Exception e) {
                            initialValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
                        }
                    } else {
                        try {
                            Date date = (Date) propertyValues[i];
                            initialValues.put(name, DateUtils.getUserLocaleDate(locale,
                                    new java.sql.Date(date.getTime()).toString()));
                        } catch (Exception e) {
                            initialValues.put(name, propertyValues[i].toString());
                        }
                    }
                } else {
                    if (!oldValue.equals("")) {
                        initialValues.put(name, oldValue);
                    } else {
                        initialValues.put(name, propertyValues[i]);
                    }
                }
            }
            String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
            if (columnName != null && !columnName.equals("")) {
                columnNames.put(name, columnName);
            } else {
                columnNames.put(name, propertyNames[i]);
            }
        } else {
            String name = firstName.concat(propertyNames[i].toString());
            logger.debug("c readComponenetTypeInCollectionTypeWithoutMerge : " + name + " value : "
                    + propertyValues[i]);
            String oldValue = getOldValueToKey(changedValues, name);

            if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i],
                        localeId);
                if (!value.equals("")) {
                    changedValues.put(name, value.concat(",").concat(oldValue));
                } else {
                    changedValues.put(name, oldValue);
                }
            } else {
                if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
                    if (!oldValue.equals("")) {
                        changedValues.put(name, ((Calendar) propertyValues[i]).getTime().toString().concat(",")
                                .concat(oldValue));
                    } else {
                        changedValues.put(name, ((Calendar) propertyValues[i]).getTime());
                    }
                } else if (!(propertyValues[i] instanceof Calendar) && !(propertyValues[i] instanceof Date)
                        && propertyValues[i] != null) {
                    if (!oldValue.equals("")) {
                        changedValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
                    } else {
                        changedValues.put(name, propertyValues[i]);
                    }
                } else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
                    if (!oldValue.equals("")) {
                        try {
                            Date date = (Date) propertyValues[i];
                            changedValues.put(name, DateUtils
                                    .getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString())
                                    .toString().concat(",").concat(oldValue));
                        } catch (Exception e) {
                            changedValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
                        }
                    } else {
                        try {
                            Date date = (Date) propertyValues[i];
                            changedValues.put(name, DateUtils.getUserLocaleDate(locale,
                                    new java.sql.Date(date.getTime()).toString()));
                        } catch (Exception e) {
                            changedValues.put(name, propertyValues[i].toString());
                        }
                    }
                } else {
                    if (!oldValue.equals("")) {
                        changedValues.put(name, oldValue);
                    } else {
                        changedValues.put(name, propertyValues[i]);
                    }
                }
            }
            String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
            if (columnName != null && !columnName.equals("")) {
                columnNames.put(name, columnName);
            } else {
                columnNames.put(name, propertyNames[i]);
            }
        }
    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void setPrimaryKeyValueForCollectionType(ClassMetadata customMeta, Object obj, String name,
        String state) {/*from   w  ww  .j  ava 2s.c o  m*/
    if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
        String oldValue = getOldValueToKey(initialValues, name);
        logger.debug("i setPrimaryKeyValueForCollectionType : " + name + " value : "
                + customMeta.getIdentifier(obj, EntityMode.POJO));
        if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
            String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                    customMeta.getIdentifier(obj, EntityMode.POJO), localeId);
            if (!oldValue.equals("")) {
                initialValues.put(name, value.concat(",").concat(oldValue));
            } else {
                initialValues.put(name, value);
            }
        } else {
            if (customMeta.getIdentifier(obj, EntityMode.POJO) != null) {
                if (!oldValue.equals("")) {
                    initialValues.put(name, customMeta.getIdentifier(obj, EntityMode.POJO).toString()
                            .concat(",").concat(oldValue));
                } else {
                    initialValues.put(name, customMeta.getIdentifier(obj, EntityMode.POJO));
                }
            }
        }
        String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
        if (columnName != null && !columnName.equals("")) {
            columnNames.put(name, columnName);
        } else {
            columnNames.put(name, customMeta.getIdentifierPropertyName());
        }
    } else {
        String oldValue = getOldValueToKey(changedValues, name);
        logger.debug("c setPrimaryKeyValueForCollectionType : " + name + " value : "
                + customMeta.getIdentifier(obj, EntityMode.POJO));
        if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
            String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                    customMeta.getIdentifier(obj, EntityMode.POJO), localeId);
            if (!oldValue.equals("")) {
                changedValues.put(name, value.concat(",").concat(oldValue));
            } else {
                changedValues.put(name, value);
            }
        } else {
            if (customMeta.getIdentifier(obj, EntityMode.POJO) != null) {
                if (!oldValue.equals("")) {
                    changedValues.put(name, customMeta.getIdentifier(obj, EntityMode.POJO).toString()
                            .concat(",").concat(oldValue));
                } else {
                    changedValues.put(name, customMeta.getIdentifier(obj, EntityMode.POJO));
                }
            }
        }
        String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
        if (columnName != null && !columnName.equals("")) {
            columnNames.put(name, columnName);
        } else {
            columnNames.put(name, customMeta.getIdentifierPropertyName());
        }
    }
}

From source file:org.mifos.framework.components.audit.util.helpers.InterceptHelper.java

License:Open Source License

private void setPrimaryKeyValueForCollectionTypeAndMerge(ClassMetadata customMeta, Object obj, String name,
        String state) {/*  w w w  . j a v  a2s  .c o  m*/
    if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
        logger.debug("i setPrimaryKeyValueForCollectionTypeAndMerge : " + name + " value : "
                + customMeta.getIdentifier(obj, EntityMode.POJO));
        if (isValueLoggable(name, null)) {
            if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                        customMeta.getIdentifier(obj, EntityMode.POJO), localeId);
                if (initialArray.toString().trim().length() == 0 || initialArray.toString().endsWith(",")) {
                    initialArray.append(value);
                } else if (value.trim().length() != 0) {
                    initialArray.append("-").append(value);
                }
            } else {
                if (initialArray.toString().trim().length() == 0 || initialArray.toString().endsWith(",")) {
                    initialArray.append(customMeta.getIdentifier(obj, EntityMode.POJO));
                } else if (customMeta.getIdentifier(obj, EntityMode.POJO).toString().trim().length() != 0) {
                    initialArray.append("-").append(customMeta.getIdentifier(obj, EntityMode.POJO));
                }
            }
        }
    } else {
        logger.debug("c setPrimaryKeyValueForCollectionTypeAndMerge : " + name + " value : "
                + customMeta.getIdentifier(obj, EntityMode.POJO));
        if (isValueLoggable(name, null)) {
            if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
                String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name,
                        customMeta.getIdentifier(obj, EntityMode.POJO), localeId);
                if (changeArray.toString().trim().length() == 0 || changeArray.toString().endsWith(",")) {
                    changeArray.append(value);
                } else if (value.trim().length() != 0) {
                    changeArray.append("-").append(value);
                }
            } else {
                if (changeArray.toString().trim().length() == 0 || changeArray.toString().endsWith(",")) {
                    changeArray.append(customMeta.getIdentifier(obj, EntityMode.POJO));
                } else if (customMeta.getIdentifier(obj, EntityMode.POJO).toString().trim().length() != 0) {
                    changeArray.append("-").append(customMeta.getIdentifier(obj, EntityMode.POJO));
                }
            }
        }
    }
}