Search in sources :

Example 11 with MasterDataEntity

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

the class LoanProductDaoHibernate 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());
    }
    return masterEntities;
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) Session(org.hibernate.Session)

Example 12 with MasterDataEntity

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

the class SavingsProductDaoHibernate 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());
    }
    return masterEntities;
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) Session(org.hibernate.Session)

Example 13 with MasterDataEntity

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

the class LegacyMasterDaoIntegrationTest method testRetrieveMasterDataEntity.

@Test
public void testRetrieveMasterDataEntity() throws Exception {
    List<AccountStateEntity> masterDataList = legacyMasterDao.findMasterDataEntities(AccountStateEntity.class);
    Assert.assertEquals(18, masterDataList.size());
    for (MasterDataEntity masterDataEntity : masterDataList) {
        for (LookUpValueLocaleEntity lookUpValueLocaleEntity : masterDataEntity.getLookUpValue().getLookUpValueLocales()) {
            Assert.assertEquals(Short.valueOf("1"), lookUpValueLocaleEntity.getLocaleId());
        }
    }
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) LookUpValueLocaleEntity(org.mifos.application.master.business.LookUpValueLocaleEntity) Test(org.junit.Test)

Example 14 with MasterDataEntity

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

the class InterceptHelper method readFurtherMeta.

private void readFurtherMeta(Object obj, String firstName, String state) {
    Class clazz = getClazz(obj);
    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);
            }
        }
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Set(java.util.Set) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) 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) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity)

Example 15 with MasterDataEntity

use of org.mifos.application.master.business.MasterDataEntity 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)

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