Search in sources :

Example 21 with Calendar

use of java.util.Calendar in project elasticsearch by elastic.

the class BaseXContentTestCase method testObject.

public void testObject() throws Exception {
    Map<String, Object> object = new HashMap<>();
    object.put("{'object':false}", Boolean.FALSE);
    object.put("{'object':13}", (byte) 13);
    object.put("{'object':5.0}", 5.0d);
    object.put("{'object':8.0}", 8.0f);
    object.put("{'object':{'lat':45.759429931640625,'lon':4.8394775390625}}", GeoPoint.fromGeohash("u05kq4k"));
    object.put("{'object':3}", 3);
    object.put("{'object':2}", 2L);
    object.put("{'object':1}", (short) 1);
    object.put("{'object':'string'}", "string");
    object.put("{'object':'a'}", new Text("a"));
    object.put("{'object':'b'}", new Text(new BytesArray("b")));
    object.put("{'object':null}", null);
    object.put("{'object':'OPEN'}", IndexMetaData.State.OPEN);
    object.put("{'object':'NM'}", DistanceUnit.NAUTICALMILES);
    object.put("{'object':{'f1':'v1'}}", singletonMap("f1", "v1"));
    object.put("{'object':{'f1':{'f2':'v2'}}}", singletonMap("f1", singletonMap("f2", "v2")));
    object.put("{'object':[1,2,3]}", Arrays.asList(1, 2, 3));
    final String path = Constants.WINDOWS ? "{'object':'a\\\\b\\\\c'}" : "{'object':'a/b/c'}";
    object.put(path, PathUtils.get("a", "b", "c"));
    final DateTimeFormatter formatter = XContentBuilder.DEFAULT_DATE_PRINTER;
    final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
    object.put("{'object':'" + formatter.print(d1.getTime()) + "'}", d1);
    final DateTime d2 = DateTime.now();
    object.put("{'object':'" + formatter.print(d2) + "'}", d2);
    final Calendar c1 = new DateTime(2010, 1, 1, 0, 0, DateTimeZone.UTC).toCalendar(Locale.ROOT);
    object.put("{'object':'2010-01-01T00:00:00.000Z'}", c1);
    final ToXContent x1 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", 2).array("f3", 3, 4, 5).endObject();
    final ToXContent x2 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", x1).endObject();
    object.put("{'object':{'f1':'v1','f2':{'f1':'v1','f2':2,'f3':[3,4,5]}}}", x2);
    for (Map.Entry<String, Object> o : object.entrySet()) {
        final String expected = o.getKey();
        assertResult(expected, () -> builder().humanReadable(true).startObject().field("object", o.getValue()).endObject());
        assertResult(expected, () -> builder().humanReadable(true).startObject().field("object").value(o.getValue()).endObject());
    }
    assertResult("{'objects':[null,null,null]}", () -> builder().startObject().array("objects", null, null, null).endObject());
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Date(java.util.Date) HashMap(java.util.HashMap) Strings(org.elasticsearch.common.Strings) ArrayList(java.util.ArrayList) BytesArray(org.elasticsearch.common.bytes.BytesArray) Calendar(java.util.Calendar) ByteArrayInputStream(java.io.ByteArrayInputStream) Text(org.elasticsearch.common.text.Text) Locale(java.util.Locale) Map(java.util.Map) GeoPoint(org.elasticsearch.common.geo.GeoPoint) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) BigInteger(java.math.BigInteger) Collections.singletonMap(java.util.Collections.singletonMap) ESTestCase(org.elasticsearch.test.ESTestCase) ParseField(org.elasticsearch.common.ParseField) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Path(java.nio.file.Path) PathUtils(org.elasticsearch.common.io.PathUtils) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) Collections.emptyMap(java.util.Collections.emptyMap) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) BytesRef(org.apache.lucene.util.BytesRef) Matchers.allOf(org.hamcrest.Matchers.allOf) DateTime(org.joda.time.DateTime) Matchers(org.hamcrest.Matchers) ReadableInstant(org.joda.time.ReadableInstant) IOException(java.io.IOException) BytesReference(org.elasticsearch.common.bytes.BytesReference) Matchers.startsWith(org.hamcrest.Matchers.startsWith) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Constants(org.apache.lucene.util.Constants) DistanceUnit(org.elasticsearch.common.unit.DistanceUnit) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Token(org.elasticsearch.common.xcontent.XContentParser.Token) Matcher(org.hamcrest.Matcher) Instant(org.joda.time.Instant) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) Calendar(java.util.Calendar) Text(org.elasticsearch.common.text.Text) Matchers.containsString(org.hamcrest.Matchers.containsString) Date(java.util.Date) DateTime(org.joda.time.DateTime) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 22 with Calendar

use of java.util.Calendar in project hibernate-orm by hibernate.

the class JdbcTimestampCustomSessionLevelTimeZoneTest method testTimeZone.

@Test
public void testTimeZone() {
    connectionProvider.clear();
    doInHibernateSessionBuilder(() -> {
        return sessionFactory().withOptions().jdbcTimeZone(TIME_ZONE);
    }, s -> {
        Person person = new Person();
        person.id = 1L;
        s.persist(person);
    });
    assertEquals(1, connectionProvider.getPreparedStatements().size());
    PreparedStatement ps = connectionProvider.getPreparedStatements().get(0);
    try {
        ArgumentCaptor<Calendar> calendarArgumentCaptor = ArgumentCaptor.forClass(Calendar.class);
        verify(ps, times(1)).setTimestamp(anyInt(), any(Timestamp.class), calendarArgumentCaptor.capture());
        assertEquals(TIME_ZONE, calendarArgumentCaptor.getValue().getTimeZone());
    } catch (SQLException e) {
        fail(e.getMessage());
    }
    connectionProvider.clear();
    doInHibernateSessionBuilder(() -> {
        return sessionFactory().withOptions().jdbcTimeZone(TIME_ZONE);
    }, s -> {
        s.doWork(connection -> {
            try (Statement st = connection.createStatement()) {
                try (ResultSet rs = st.executeQuery("select createdOn from Person")) {
                    while (rs.next()) {
                        Timestamp timestamp = rs.getTimestamp(1);
                        int offsetDiff = TimeZone.getDefault().getOffset(0) - TIME_ZONE.getOffset(0);
                        assertEquals(Math.abs(Long.valueOf(offsetDiff).longValue()), Math.abs(timestamp.getTime()));
                    }
                }
            }
        });
        Person person = s.find(Person.class, 1L);
        assertEquals(0, person.createdOn.getTime());
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Calendar(java.util.Calendar) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 23 with Calendar

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

the class RepaymentScheduleInstallment method getDueDateValueAsCalendar.

public Calendar getDueDateValueAsCalendar() {
    if (dueDateValue == null) {
        return null;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(dueDateValue);
    return calendar;
}
Also used : Calendar(java.util.Calendar)

Example 24 with Calendar

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

the class PictureFormFile method editFamilyInfo.

@TransactionDemarcate(joinToken = true)
public ActionForward editFamilyInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    actionForm.clearMostButNotAllFieldsOnActionForm();
    ClientBO clientFromSession = getClientFromSession(request);
    ClientFamilyInfoDto clientFamilyInfo = this.clientServiceFacade.retrieveFamilyInfoForEdit(clientFromSession.getGlobalCustNum());
    SessionUtils.setCollectionAttribute(ClientConstants.LIVING_STATUS_ENTITY, clientFamilyInfo.getClientDropdowns().getLivingStatus(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.GENDER_ENTITY, clientFamilyInfo.getClientDropdowns().getGenders(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, new ArrayList<CustomFieldDto>(), request);
    UserContext userContext = getUserContext(request);
    List<SpouseFatherLookupEntity> spouseFather = legacyMasterDao.findMasterDataEntitiesWithLocale(SpouseFatherLookupEntity.class);
    SessionUtils.setCollectionAttribute(ClientConstants.SPOUSE_FATHER_ENTITY, spouseFather, request);
    SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_MANDATORY, isFamilyDetailsMandatory(), request);
    // customer specific
    actionForm.setCustomerId(clientFamilyInfo.getCustomerDetail().getCustomerId().toString());
    actionForm.setLoanOfficerId(clientFamilyInfo.getCustomerDetail().getLoanOfficerIdAsString());
    actionForm.setGlobalCustNum(clientFamilyInfo.getCustomerDetail().getGlobalCustNum());
    actionForm.setExternalId(clientFamilyInfo.getCustomerDetail().getExternalId());
    // client specific
    actionForm.setGovernmentId(clientFamilyInfo.getClientDetail().getGovernmentId());
    actionForm.setDateOfBirth(clientFamilyInfo.getClientDetail().getDateOfBirth());
    actionForm.initializeFamilyMember();
    actionForm.setClientDetailView(clientFamilyInfo.getClientDetail().getCustomerDetail());
    actionForm.setClientName(clientFamilyInfo.getClientDetail().getClientName());
    actionForm.setSpouseName(clientFamilyInfo.getClientDetail().getSpouseName());
    actionForm.setCustomFields(new ArrayList<CustomFieldDto>());
    // client family specific
    int familyMemberCount = 0;
    for (ClientNameDetailDto familyMember : clientFamilyInfo.getFamilyMembers()) {
        actionForm.addFamilyMember();
        actionForm.setFamilyPrimaryKey(familyMemberCount, familyMember.getCustomerNameId());
        actionForm.setFamilyFirstName(familyMemberCount, familyMember.getFirstName());
        actionForm.setFamilyMiddleName(familyMemberCount, familyMember.getMiddleName());
        actionForm.setFamilyLastName(familyMemberCount, familyMember.getLastName());
        actionForm.setFamilySecondLastName(familyMemberCount, familyMember.getSecondLastName());
        actionForm.setFamilyRelationship(familyMemberCount, familyMember.getNameType());
        Map<Integer, List<ClientFamilyDetailDto>> clientFamilyDetailsMap = clientFamilyInfo.getClientFamilyDetails();
        Integer key = Integer.valueOf(familyMemberCount);
        List<ClientFamilyDetailDto> clientFamilyDetails = clientFamilyDetailsMap.get(key);
        if (clientFamilyDetails != null) {
            for (ClientFamilyDetailDto clientFamilyDetailDto : clientFamilyDetails) {
                Calendar cal = Calendar.getInstance();
                if (clientFamilyDetailDto.getDateOfBirth() != null) {
                    String date1 = DateUtils.makeDateAsSentFromBrowser(clientFamilyDetailDto.getDateOfBirth());
                    java.util.Date date = DateUtils.getDate(date1);
                    cal.setTime(date);
                    actionForm.setFamilyDateOfBirthDD(familyMemberCount, String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
                    actionForm.setFamilyDateOfBirthMM(familyMemberCount, String.valueOf(cal.get(Calendar.MONTH) + 1));
                    actionForm.setFamilyDateOfBirthYY(familyMemberCount, String.valueOf(cal.get(Calendar.YEAR)));
                }
                actionForm.setFamilyGender(familyMemberCount, clientFamilyDetailDto.getGender());
                actionForm.setFamilyLivingStatus(familyMemberCount, clientFamilyDetailDto.getLivingStatus());
            }
        }
        familyMemberCount++;
    }
    ClientBO client = this.customerDao.findClientBySystemId(clientFromSession.getGlobalCustNum());
    actionForm.setAddress(Address.toAddress(client.getAddress()));
    SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, client, request);
    return mapping.findForward(ActionForwards.editFamilyInfo_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) Calendar(java.util.Calendar) ClientFamilyDetailDto(org.mifos.dto.screen.ClientFamilyDetailDto) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) SpouseFatherLookupEntity(org.mifos.application.master.business.SpouseFatherLookupEntity) List(java.util.List) ArrayList(java.util.ArrayList) ClientFamilyInfoDto(org.mifos.dto.screen.ClientFamilyInfoDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 25 with Calendar

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

the class BulkEntryActionForm method setTransactionDate.

public void setTransactionDate(java.util.Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    // note that Calendar retrieves 0-based month, so increment month field
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH) + 1;
    int year = c.get(Calendar.YEAR);
    setTransactionDateDD(Integer.toString(day));
    setTransactionDateMM(Integer.toString(month));
    setTransactionDateYY(Integer.toString(year));
}
Also used : Calendar(java.util.Calendar)

Aggregations

Calendar (java.util.Calendar)9441 Date (java.util.Date)2433 GregorianCalendar (java.util.GregorianCalendar)2129 Test (org.junit.Test)1734 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)352 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)192 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