Search in sources :

Example 1 with MasterDataEntity

use of org.mifos.application.master.business.MasterDataEntity in project head by mifos.

the class LegacyMasterDao method findMasterDataEntitiesWithLocale.

/**
     * use Dao specific calls - see feeDao.doRetrieveFeeCategories
     */
@SuppressWarnings("unchecked")
@Deprecated
public <T extends MasterDataEntity> List<T> findMasterDataEntitiesWithLocale(final Class<T> type) {
    Session session = getSession();
    List<T> masterEntities = session.createQuery("from " + type.getName()).list();
    for (MasterDataEntity masterData : masterEntities) {
        Hibernate.initialize(masterData.getNames());
    }
    return masterEntities;
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) Session(org.hibernate.Session)

Example 2 with MasterDataEntity

use of org.mifos.application.master.business.MasterDataEntity in project head by mifos.

the class ApplicationConfigurationDaoHibernate method doFetchListOfMasterDataFor.

@SuppressWarnings("unchecked")
private <T extends MasterDataEntity> List<T> doFetchListOfMasterDataFor(Class<T> type) {
    Session session = StaticHibernateUtil.getSessionTL();
    List<T> masterEntities = session.createQuery("from " + type.getName()).list();
    for (MasterDataEntity masterData : masterEntities) {
        Hibernate.initialize(masterData.getNames());
        Hibernate.initialize(masterData.getLookUpValue());
        Hibernate.initialize(masterData.getLookUpValue().getLookUpValueLocales());
    }
    return masterEntities;
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) Session(org.hibernate.Session)

Example 3 with MasterDataEntity

use of org.mifos.application.master.business.MasterDataEntity in project head by mifos.

the class AuditConfiguration method fetchMasterData.

private void fetchMasterData(String entityName, Short localeId, String classPath) throws SystemException {
    Class clazz = null;
    try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(classPath);
    } catch (ClassNotFoundException e) {
        throw new SystemException(e);
    }
    List<MasterDataEntity> masterDataList = legacyMasterDao.findMasterDataEntities(clazz);
    for (MasterDataEntity masterDataEntity : masterDataList) {
        if (masterDataEntity instanceof PersonnelStatusEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((PersonnelStatusEntity) masterDataEntity).setName(name);
        }
        if (masterDataEntity instanceof PersonnelLevelEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((PersonnelLevelEntity) masterDataEntity).setName(name);
        }
        if (masterDataEntity instanceof OfficeLevelEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((OfficeLevelEntity) masterDataEntity).setName(name);
        }
        if (masterDataEntity instanceof OfficeStatusEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((OfficeStatusEntity) masterDataEntity).setName(name);
        }
        valueMap.put(masterDataEntity.getId().toString(), masterDataEntity.getName());
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) MessageLookup(org.mifos.application.master.MessageLookup) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) OfficeStatusEntity(org.mifos.customers.office.business.OfficeStatusEntity) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity)

Example 4 with MasterDataEntity

use of org.mifos.application.master.business.MasterDataEntity in project head by mifos.

the class InterceptHelper method readFurtherMetaForCollectionType.

private void readFurtherMetaForCollectionType(Object obj, String firstName, String state) {
    Class l = getClazz(obj);
    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 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]);
            }
        }
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Calendar(java.util.Calendar) Date(java.util.Date) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject)

Example 5 with MasterDataEntity

use of org.mifos.application.master.business.MasterDataEntity in project head by mifos.

the class InterceptHelper method readAndMergeCollectionTypes.

private void readAndMergeCollectionTypes(Object obj, String firstName, String parentName, String state) {
    Class l = getClazz(obj);
    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 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]);
            }
        }
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject)

Aggregations

MasterDataEntity (org.mifos.application.master.business.MasterDataEntity)21 Session (org.hibernate.Session)7 Test (org.junit.Test)5 ClassMetadata (org.hibernate.metadata.ClassMetadata)4 ComponentType (org.hibernate.type.ComponentType)4 Type (org.hibernate.type.Type)4 PersonnelLevelEntity (org.mifos.customers.personnel.business.PersonnelLevelEntity)4 PersonnelStatusEntity (org.mifos.customers.personnel.business.PersonnelStatusEntity)4 AbstractBusinessObject (org.mifos.framework.business.AbstractBusinessObject)4 ArrayList (java.util.ArrayList)3 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)3 MessageLookup (org.mifos.application.master.MessageLookup)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 FeeDto (org.mifos.accounts.fees.business.FeeDto)2