Search in sources :

Example 91 with Calendar

use of java.util.Calendar in project head by mifos.

the class AccountingServiceFacadeWebTier method processMisPostings.

@Override
public boolean processMisPostings(Date lastProcessDate, Date processTillDate, Short createdBy, String globalOfficeNumber) {
    boolean flag = false;
    while (lastProcessDate.compareTo(processTillDate) < 0) {
        Calendar c = Calendar.getInstance();
        c.setTime(lastProcessDate);
        c.add(Calendar.DATE, 1);
        Date newDate = c.getTime();
        lastProcessDate = newDate;
        processListOfTransactions(accountingDao.processMisPostings(lastProcessDate, globalOfficeNumber), createdBy);
        //accountingDao.updateLastProcessDate(lastProcessDate);
        accountingDao.updateLastProcessUpdatedDate(lastProcessDate, globalOfficeNumber);
    }
    return flag;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 92 with Calendar

use of java.util.Calendar in project head by mifos.

the class InterceptHelper method readComponenetTypeInCollectionTypeWithoutMerge.

private void readComponenetTypeInCollectionTypeWithoutMerge(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 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]);
            }
        }
    }
}
Also used : ComponentType(org.hibernate.type.ComponentType) Calendar(java.util.Calendar) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) Date(java.util.Date)

Example 93 with Calendar

use of java.util.Calendar 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 94 with Calendar

use of java.util.Calendar in project qksms by moezbhatti.

the class NightModeAutoReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) {
        Calendar calendar = Calendar.getInstance();
        // add 5 mins in case receiver is called early
        calendar.setTimeInMillis(System.currentTimeMillis() + 300000);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
        Calendar day = Calendar.getInstance();
        Calendar night = Calendar.getInstance();
        try {
            day.setTime(simpleDateFormat.parse(prefs.getString(SettingsFragment.DAY_START, "6:00")));
            night.setTime(simpleDateFormat.parse(prefs.getString(SettingsFragment.NIGHT_START, "21:00")));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if ((calendar.get(Calendar.HOUR_OF_DAY) > night.get(Calendar.HOUR_OF_DAY)) || (calendar.get(Calendar.HOUR_OF_DAY) == night.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) >= night.get(Calendar.MINUTE)) || (calendar.get(Calendar.HOUR_OF_DAY) < day.get(Calendar.HOUR_OF_DAY)) || (calendar.get(Calendar.HOUR_OF_DAY) == day.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) <= day.get(Calendar.MINUTE))) {
            Log.i(TAG, "Switching to night mode");
            prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_GREY).apply();
            ThemeManager.setTheme(ThemeManager.Theme.DARK);
        } else {
            Log.i(TAG, "Switching to day mode");
            prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_OFFWHITE).apply();
            ThemeManager.setTheme(ThemeManager.Theme.LIGHT);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 95 with Calendar

use of java.util.Calendar in project qksms by moezbhatti.

the class DeleteOldMessagesService method deleteOldReadMessages.

private void deleteOldReadMessages(Context context) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_READ)));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    int count = deleteOldMessages(context, SmsHelper.READ_SELECTION + "=" + SmsHelper.READ, calendar.getTimeInMillis());
    Log.i(TAG, "Deleted read messages: " + count);
}
Also used : Calendar(java.util.Calendar)

Aggregations

Calendar (java.util.Calendar)9446 Date (java.util.Date)2436 GregorianCalendar (java.util.GregorianCalendar)2130 Test (org.junit.Test)1735 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)353 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)194 List (java.util.List)187 File (java.io.File)167 Map (java.util.Map)149 BigDecimal (java.math.BigDecimal)134 Locale (java.util.Locale)134 Test (org.testng.annotations.Test)118 Identity (org.olat.core.id.Identity)112 Date (java.sql.Date)110