List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:com.workplacesystems.queuj.process.ProcessWrapper.java
public GregorianCalendar getNextRunTime() { Date initialStartDate = process.getScheduledTimestamp() == null ? process.getCreationTimestamp() : process.getScheduledTimestamp(); GregorianCalendar initialStart = new GregorianCalendar(); initialStart.setTime(initialStartDate); return process.getResilience().getNextRunTime(process.getOccurrence(), isFailed(), process.getAttempt(), initialStart, process.getRunCount()); }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileBES.java
protected QualifyingPropertiesType createXAdESQualifyingProperties(SignatureParameters params, String signedInfoId, List<Reference> documentReferences, Document document) { // QualifyingProperties QualifyingPropertiesType qualifyingProperties = xades13ObjectFactory.createQualifyingPropertiesType(); SignedPropertiesType signedProperties = xades13ObjectFactory.createSignedPropertiesType(); qualifyingProperties.setSignedProperties(signedProperties); signedProperties.setId(signedInfoId); SignedSignaturePropertiesType signedSignatureProperties = xades13ObjectFactory .createSignedSignaturePropertiesType(); signedProperties.setSignedSignatureProperties(signedSignatureProperties); // SigningTime GregorianCalendar signingTime = new GregorianCalendar(TimeZone.getTimeZone("Z")); signingTime.setTime(params.getSigningDate()); XMLGregorianCalendar xmlGregorianCalendar = getDataFactory().newXMLGregorianCalendar(signingTime); xmlGregorianCalendar.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); signedSignatureProperties.setSigningTime(xmlGregorianCalendar); X509Certificate signingCertificate = params.getSigningCertificate(); CertIDType signingCertificateId = getCertID(signingCertificate); CertIDListType signingCertificates = xades13ObjectFactory.createCertIDListType(); signingCertificates.getCert().add(signingCertificateId); signedSignatureProperties.setSigningCertificate(signingCertificates); // DataObjectProperties SignedDataObjectPropertiesType dataObjectProperties = new SignedDataObjectPropertiesType(); Iterator<Reference> refIt = documentReferences.iterator(); Iterator<Document> docIt = documentIterator(document); while (refIt.hasNext() && docIt.hasNext()) { Reference ref = refIt.next(); Document doc = docIt.next(); if (ref.getId() != null && doc.getMimeType() != null) { DataObjectFormatType dataFormat = new DataObjectFormatType(); dataFormat.setObjectReference("#" + ref.getId()); dataFormat.setMimeType(doc.getMimeType().getCode()); dataObjectProperties.getDataObjectFormat().add(dataFormat); }//from w w w .ja v a 2s . c om } if (dataObjectProperties.getDataObjectFormat().size() > 0) { signedProperties.setSignedDataObjectProperties(dataObjectProperties); } // SignerRole if (params.getClaimedSignerRole() != null) { SignerRoleType signerRole = xades13ObjectFactory.createSignerRoleType(); ClaimedRolesListType claimedRoles = xades13ObjectFactory.createClaimedRolesListType(); /* * Add only one role */ AnyType role = xades13ObjectFactory.createAnyType(); role.getContent().add(params.getClaimedSignerRole()); claimedRoles.getClaimedRole().add(role); signerRole.setClaimedRoles(claimedRoles); signedSignatureProperties.setSignerRole(signerRole); } return qualifyingProperties; }
From source file:org.opendatakit.services.sync.service.logic.HttpRestProtocolWrapper.java
/** * Simple Request for all server interactions. * * @param uri/*w ww . j a va 2 s .c om*/ * @param request * @return */ public void buildBasicRequest(URI uri, HttpRequestBase request) { String agg_uri = uri.toString(); log.i(LOGTAG, "buildBasicRequest: agg_uri is " + agg_uri); if (uri == null) { throw new IllegalArgumentException("buildBasicRequest: URI cannot be null"); } if (request == null) { throw new IllegalArgumentException("buildBasicRequest: HttpRequest cannot be null"); } request.setURI(uri); // report our locale... (not currently used by server) request.addHeader("Accept-Language", Locale.getDefault().getLanguage()); request.addHeader(ApiConstants.OPEN_DATA_KIT_VERSION_HEADER, ApiConstants.OPEN_DATA_KIT_VERSION); request.addHeader(ApiConstants.ACCEPT_CONTENT_ENCODING_HEADER, ApiConstants.GZIP_CONTENT_ENCODING); request.addHeader(HttpHeaders.USER_AGENT, sc.getUserAgent()); GregorianCalendar g = new GregorianCalendar(TimeZone.getTimeZone("GMT")); Date now = new Date(); g.setTime(now); SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz", Locale.US); formatter.setCalendar(g); request.addHeader(ApiConstants.DATE_HEADER, formatter.format(now)); }
From source file:org.webical.test.web.component.WeekViewPanelTest.java
/** * Test week view with less then 7 days//w ww. j a v a 2 s.co m * @throws WebicalException */ public void testNonWeekUse() throws WebicalException { MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock .getBean("calendarManager"); Calendar calendar1 = mockCalendarManager.getCalendarById("1"); MockEventManager mockEventManager = new MockEventManager(); annotApplicationContextMock.putBean("eventManager", mockEventManager); // Define the current date final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); currentDate.setFirstDayOfWeek(GregorianCalendar.MONDAY); // The list containing the different events List<Event> allEvents = new ArrayList<Event>(); GregorianCalendar refcal = CalendarUtils.duplicateCalendar(currentDate); refcal.add(GregorianCalendar.DAY_OF_MONTH, 1); refcal.set(GregorianCalendar.HOUR_OF_DAY, 12); refcal.set(GregorianCalendar.MINUTE, 0); refcal.set(GregorianCalendar.SECOND, 0); GregorianCalendar cal = CalendarUtils.duplicateCalendar(currentDate); // Add a normal event tomorrow Event event = new Event(); event.setUid("e1"); event.setCalendar(calendar1); event.setSummary("Normal Event Description"); event.setLocation("Normal Event Location"); event.setDescription("Event e1"); cal.setTime(refcal.getTime()); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a short recurring event, starting today, ending tomorrow event = new Event(); event.setUid("e2"); event.setCalendar(calendar1); event.setSummary("Recurring Event Today"); event.setLocation("Recurring Event Location"); event.setDescription("Event e2"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.DAY_OF_MONTH, 2); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a long recurring event, starting last week, ending next week event = new Event(); event.setUid("e3"); event.setCalendar(calendar1); event.setSummary("Recurring Event Last Month"); event.setLocation("Recurring Event Location"); event.setDescription("Event e3"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.WEEK_OF_YEAR, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.WEEK_OF_YEAR, 3); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a (pseudo) all day event, starting day + 1 midnight, ending day + 2 00:00 hours event = new Event(); event.setUid("e4"); event.setCalendar(calendar1); event.setSummary("Pseudo All Day Event"); event.setLocation("All Day Event Location"); event.setDescription("Starting day + 1, ending day + 2 00:00 hours"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); cal.set(GregorianCalendar.MILLISECOND, 0); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Create test page with a WeekViewPanel wicketTester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return new PanelTestPage(new WeekViewPanel(PanelTestPage.PANEL_MARKUP_ID, 4, currentDate) { private static final long serialVersionUID = 1L; @Override public void onAction(IAction action) { /* NOTHING TO DO */ } }); } }); // Basic assertions wicketTester.assertRenderedPage(PanelTestPage.class); wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, WeekViewPanel.class); // Assert number of days rendered // Set the correct dates to find the first and last day of the week GregorianCalendar viewFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate); // Assert the first day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + viewFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); GregorianCalendar viewLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate); viewLastDayCalendar.add(GregorianCalendar.DAY_OF_MONTH, 3); // Assert the last day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + viewLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); // Events for days in this 4 day period List<Event> dayEvents = new ArrayList<Event>(); // Assert weekday events GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate); for (int i = 0; i < 4; ++i) { WeekDayPanel weekDayEventsListView = (WeekDayPanel) wicketTester.getLastRenderedPage() .get(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekCal.get(GregorianCalendar.DAY_OF_YEAR)); switch (i) { case 0: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case 1: dayEvents.clear(); dayEvents.add(allEvents.get(0)); // e1 dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case 2: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(3)); // e4 break; case 3: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 break; } String path = weekDayEventsListView.getPageRelativePath() + ":eventItem"; wicketTester.assertListView(path, dayEvents); ListView listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path); Iterator<?> lvIt = listView.iterator(); while (lvIt.hasNext()) { ListItem item = (ListItem) lvIt.next(); Event evt = (Event) item.getModelObject(); List<?> bhvs = item.getBehaviors(); if (evt.getUid().equals("e4")) assertEquals(1, bhvs.size()); // e4 all day event else assertEquals(0, bhvs.size()); } weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1); } }
From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java
@Override protected String encode(Date theValue) { if (theValue == null) { return null; } else {/*from w w w . j a va2s . c om*/ GregorianCalendar cal; if (myTimeZoneZulu) { cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); } else if (myTimeZone != null) { cal = new GregorianCalendar(myTimeZone); } else { cal = new GregorianCalendar(); } cal.setTime(theValue); StringBuilder b = new StringBuilder(); leftPadWithZeros(cal.get(Calendar.YEAR), 4, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.YEAR.ordinal()) { b.append('-'); leftPadWithZeros(cal.get(Calendar.MONTH) + 1, 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.MONTH.ordinal()) { b.append('-'); leftPadWithZeros(cal.get(Calendar.DATE), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.DAY.ordinal()) { b.append('T'); leftPadWithZeros(cal.get(Calendar.HOUR_OF_DAY), 2, b); b.append(':'); leftPadWithZeros(cal.get(Calendar.MINUTE), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.MINUTE.ordinal()) { b.append(':'); leftPadWithZeros(cal.get(Calendar.SECOND), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.SECOND.ordinal()) { b.append('.'); b.append(myFractionalSeconds); for (int i = myFractionalSeconds.length(); i < 3; i++) { b.append('0'); } } } if (myTimeZoneZulu) { b.append('Z'); } else if (myTimeZone != null) { int offset = myTimeZone.getOffset(theValue.getTime()); if (offset >= 0) { b.append('+'); } else { b.append('-'); offset = Math.abs(offset); } int hoursOffset = (int) (offset / DateUtils.MILLIS_PER_HOUR); leftPadWithZeros(hoursOffset, 2, b); b.append(':'); int minutesOffset = (int) (offset % DateUtils.MILLIS_PER_HOUR); minutesOffset = (int) (minutesOffset / DateUtils.MILLIS_PER_MINUTE); leftPadWithZeros(minutesOffset, 2, b); } } } } return b.toString(); } }
From source file:net.sourceforge.eclipsetrader.yahoo.Feed.java
private void update() { // Builds the url for quotes download String host = "quote.yahoo.com"; //$NON-NLS-1$ StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); //$NON-NLS-1$ //$NON-NLS-2$ for (Iterator iter = map.values().iterator(); iter.hasNext();) url = url.append((String) iter.next() + "+"); //$NON-NLS-1$ if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); //$NON-NLS-1$ log.debug(url.toString());/*from w ww . ja v a2 s. c om*/ // Read the last prices String line = ""; //$NON-NLS-1$ try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = YahooPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); //$NON-NLS-1$ if (line.indexOf(";") != -1) //$NON-NLS-1$ item = line.split(";"); //$NON-NLS-1$ Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); //$NON-NLS-1$ usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) //$NON-NLS-1$ date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) //$NON-NLS-1$ time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); //$NON-NLS-1$ c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { log.error(e.getMessage() + ": " + line); //$NON-NLS-1$ } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase((String) map.get(security))) { security.setQuote(quote, open, high, low, close); } } } in.close(); } catch (Exception e) { log.error(e); } }
From source file:eu.europa.fisheries.uvms.rules.service.mapper.fact.ActivityFactMapperTest.java
@Before @SneakyThrows//from ww w. j av a 2s. c om public void before() { SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss"); date = sdf.parse("31-08-1982 10:20:56"); idType = new IDType(); idType.setValue("value"); idType.setSchemeID("schemeId"); codeType = new CodeType(); codeType.setValue("value"); quantityType = new QuantityType(); quantityType.setUnitCode("unitCode"); quantityType.setValue(new BigDecimal(10)); measureType = new MeasureType(); measureType.setUnitCode("unitCode"); measureType.setValue(new BigDecimal(10)); delimitedPeriod = new DelimitedPeriod(); MeasureType durationMeasure = new MeasureType(); durationMeasure.setUnitCode("unitCode"); durationMeasure.setValue(new BigDecimal(10)); delimitedPeriod.setDurationMeasure(durationMeasure); GregorianCalendar c = new GregorianCalendar(); c.setTime(date); dateTimeType = new DateTimeType(); dateTimeType.setDateTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(c)); delimitedPeriod.setStartDateTime(dateTimeType); delimitedPeriod.setEndDateTime(dateTimeType); fluxLocation = new FLUXLocation(); fluxLocation.setID(idType); fishingTrip = new FishingTrip(); fishingTrip.setIDS(singletonList(idType)); faCatch = new FACatch(); faCatch.setTypeCode(codeType); fishingGear = new FishingGear(); fishingGear.setTypeCode(codeType); fishingGear.setRoleCodes(singletonList(codeType)); codeTypeList = singletonList(codeType); appliedAAPProcesses = new ArrayList<>(); AAPProcess aapProcess = new AAPProcess(); aapProcess.setTypeCodes(singletonList(codeType)); measureType = new MeasureType(); measureType.setUnitCode("unitCode"); measureType.setValue(new BigDecimal(10)); aapProduct = new AAPProduct(); aapProduct.setWeightMeasure(measureType); aapProduct.setPackagingUnitQuantity(quantityType); aapProcess.setResultAAPProducts(singletonList(aapProduct)); appliedAAPProcesses.add(aapProcess); GearCharacteristic gearCharacteristic = new GearCharacteristic(); gearCharacteristic.setTypeCode(codeType); gearCharacteristic.setValue(new TextType("testValue", null, null)); applicableGearCharacteristics = new ArrayList<>(); applicableGearCharacteristics.add(gearCharacteristic); fluxGeographicalCoordinate = new FLUXGeographicalCoordinate(); fluxGeographicalCoordinate.setAltitudeMeasure(measureType); fluxGeographicalCoordinate.setLatitudeMeasure(measureType); fluxLocation = new FLUXLocation(); fluxLocation.setTypeCode(codeType); faCatch = new FACatch(); faCatch.setTypeCode(codeType); specifiedFluxLocation = new ArrayList<>(); specifiedFluxLocation.add(fluxLocation); faCatch.setSpecifiedFLUXLocations(specifiedFluxLocation); specifiedFACatch = new ArrayList<>(); specifiedFACatch.add(faCatch); fluxFaTestMessage = loadTestData(); faQueryParameterList = new ArrayList<>(); FAQueryParameter faQueryParameter = new FAQueryParameter(); faQueryParameter.setTypeCode(codeType); faQueryParameter.setValueCode(codeType); faQueryParameter.setValueDateTime(dateTimeType); faQueryParameter.setValueID(idType); faQueryParameterList.add(faQueryParameter); faQuery = new FAQuery(); faQuery.setID(idType); faQuery.setSimpleFAQueryParameters(faQueryParameterList); faQuery.setSpecifiedDelimitedPeriod(delimitedPeriod); faQuery.setSubmittedDateTime(dateTimeType); faQuery.setTypeCode(codeType); flapDocumentList = new ArrayList<>(); flapDocumentList.add(RuleTestHelper.getFLAPDocument()); fluxResponseMessage = new FLUXResponseMessage(); FLUXResponseDocument fluxResponseDocument = new FLUXResponseDocument(); fluxResponseDocument.setResponseCode(codeType); fluxResponseDocument.setIDS(Arrays.asList(idType)); List<ValidationResultDocument> validationResultDocuments = new ArrayList<>(); validationResultDocument = new ValidationResultDocument(); validationResultDocument.setCreationDateTime(dateTimeType); validationResultDocument.setValidatorID(idType); List<ValidationQualityAnalysis> validationQualityAnalysisList = new ArrayList<>(); validationQualityAnalysis = new ValidationQualityAnalysis(); validationQualityAnalysis.setTypeCode(codeType); validationQualityAnalysis.setLevelCode(codeType); validationQualityAnalysis.setID(idType); validationQualityAnalysisList.add(validationQualityAnalysis); validationResultDocument.setRelatedValidationQualityAnalysises(validationQualityAnalysisList); validationResultDocuments.add(validationResultDocument); fluxResponseDocument.setRelatedValidationResultDocuments(validationResultDocuments); fluxResponseMessage.setFLUXResponseDocument(fluxResponseDocument); }
From source file:org.webical.test.web.component.WeekViewPanelTest.java
public void testWeekUse() throws WebicalException { MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock .getBean("calendarManager"); Calendar calendar1 = mockCalendarManager.getCalendarById("1"); MockEventManager mockEventManager = new MockEventManager(); annotApplicationContextMock.putBean("eventManager", mockEventManager); SimpleDateFormat dateFormat = new SimpleDateFormat( WebicalSession.getWebicalSession().getUserSettings().getTimeFormat(), getTestSession().getLocale()); final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); // All events for this week List<Event> allEvents = new ArrayList<Event>(); Date midWeek = CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek()); midWeek = CalendarUtils.addDays(midWeek, 3); /* CREATE EVENTS TO RENDER */ GregorianCalendar cal = CalendarUtils.duplicateCalendar(currentDate); // Add a normal event this week Event event = new Event(); event.setUid("e1"); event.setCalendar(calendar1);/*from w w w.j a va 2 s .co m*/ event.setSummary("Normal Event Description"); event.setLocation("Normal Event Location"); event.setDescription("Event e1"); cal.setTime(midWeek); cal.set(GregorianCalendar.HOUR_OF_DAY, 12); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a short recurring event, starting Tuesday, ending Friday event = new Event(); event.setUid("e2"); event.setCalendar(calendar1); event.setSummary("Recurring Event Yesterday"); event.setLocation("Recurring Event Location"); event.setDescription("Event e2"); cal.setTime(midWeek); cal.set(GregorianCalendar.HOUR_OF_DAY, 15); cal.add(GregorianCalendar.DAY_OF_MONTH, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 3); cal.add(GregorianCalendar.DAY_OF_MONTH, 3); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a long recurring event, starting last month, ending next month event = new Event(); event.setUid("e3"); event.setCalendar(calendar1); event.setSummary("Recurring Event Last Month"); event.setLocation("Recurring Event Location"); event.setDescription("Event e3"); cal.setTime(midWeek); cal.set(GregorianCalendar.HOUR_OF_DAY, 9); cal.add(GregorianCalendar.WEEK_OF_YEAR, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.WEEK_OF_YEAR, 3); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a (pseudo) all day event, starting Monday midnight, ending Tuesday 00:00 hours event = new Event(); event.setUid("e4"); event.setCalendar(calendar1); event.setSummary("Pseudo All Day Event"); event.setLocation("All Day Event Location"); event.setDescription("Starting Monday 00:00 hours, ending Tuesday 00:00 hours"); cal.setTime(midWeek); cal.add(GregorianCalendar.DAY_OF_MONTH, -2); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); cal.set(GregorianCalendar.MILLISECOND, 0); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a long event this week starting Friday 14.00 hours and ending Saturday 16.00 hours event = new Event(); event.setUid("e5"); event.setCalendar(calendar1); event.setSummary("Long Event Description"); event.setLocation("Long Event Location"); event.setDescription("Event e5"); cal.setTime(midWeek); cal.add(GregorianCalendar.DAY_OF_MONTH, 2); cal.set(GregorianCalendar.HOUR_OF_DAY, 14); cal.set(GregorianCalendar.MINUTE, 0); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Create test page with a WeekViewPanel wicketTester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return new PanelTestPage(new WeekViewPanel(PanelTestPage.PANEL_MARKUP_ID, 7, currentDate) { private static final long serialVersionUID = 1L; @Override public void onAction(IAction action) { /* NOTHING TO DO */ } }); } }); // Basic assertions wicketTester.assertRenderedPage(PanelTestPage.class); wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, WeekViewPanel.class); // Set the correct dates to find the first and last day of the week // Assert number of days rendered GregorianCalendar weekFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate); weekFirstDayCalendar.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); // Assert the first day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); GregorianCalendar weekLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate); weekLastDayCalendar.setTime(CalendarUtils.getLastDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); // Assert the last day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); // Events for days in this week List<Event> dayEvents = new ArrayList<Event>(); // Assert weekday events GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate); weekCal.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); for (int i = 0; i < 7; ++i) { WeekDayPanel weekDayEventsListView = (WeekDayPanel) wicketTester.getLastRenderedPage() .get(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekCal.get(GregorianCalendar.DAY_OF_YEAR)); int weekDay = getFirstDayOfWeek() + weekCal.get(GregorianCalendar.DAY_OF_WEEK) - 1; // First day of the week is 1 if (weekDay > 7) weekDay = 1; switch (weekDay) { case GregorianCalendar.SUNDAY: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.MONDAY: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(3)); // e4 break; case GregorianCalendar.TUESDAY: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.WEDNESDAY: dayEvents.clear(); dayEvents.add(allEvents.get(0)); // e1 dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.THURSDAY: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case GregorianCalendar.FRIDAY: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(4)); // e5 break; case GregorianCalendar.SATURDAY: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(4)); // e5 break; } String path = weekDayEventsListView.getPageRelativePath() + ":eventItem"; wicketTester.assertListView(path, dayEvents); ListView listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path); Iterator<?> lvIt = listView.iterator(); while (lvIt.hasNext()) { ListItem item = (ListItem) lvIt.next(); Event evt = (Event) item.getModelObject(); List<?> bhvs = item.getBehaviors(); if (evt.getUid().equals("e4")) assertEquals(1, bhvs.size()); // only e4 is an all day event else assertEquals(0, bhvs.size()); if (evt.getUid().equals("e5")) { // e5: Fri 14:00 to Sat 16:00 String timePath = item.getPageRelativePath() + ":eventLink:eventTime"; String timeLabelText = null; if (weekDay == GregorianCalendar.FRIDAY) timeLabelText = dateFormat.format(evt.getDtStart()); else timeLabelText = dateFormat.format(midWeek); // time 00:00 wicketTester.assertLabel(timePath, timeLabelText); } } weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1); } }
From source file:Presentacion.FUsuarios.java
private void btnRegistrarClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRegistrarClienteMouseClicked if (fc == null || !fc.getSelectedFile().isFile()) { JOptionPane.showMessageDialog(this, "Debe seleccionar una imagen", "Alerta", JOptionPane.WARNING_MESSAGE); } else {// w w w . j a v a 2s. co m if (txtApellido.getText().isEmpty() || txtDireccion.getText().isEmpty() || txtEmail.getText().isEmpty() || txtNickName.getText().isEmpty() || txtNombre.getText().isEmpty()) { JOptionPane.showMessageDialog(this, "Debe ingresar todos los datos", "Alerta", JOptionPane.WARNING_MESSAGE); } else { webservice.Cliente user = new Cliente(); user.setDireccion(txtDireccion.getText()); user.setEmail(txtEmail.getText()); user.setNickname(txtNickName.getText()); user.setNombre(txtNombre.getText()); user.setApellido(txtApellido.getText()); //PORCEDIMIENTO PARA ENCRIPTAR LA CLAVE INGRESADA CUANDO INICIA SESIN UN USUARIO. String pass = jPasswordField2.getText(); String encriptMD5 = DigestUtils.md5Hex(pass); pass = "md5:" + encriptMD5; user.setPassword(pass); try { int year = Integer.getInteger(drpYear.getToolTipText()); int day = Integer.getInteger(drpDay.getModel().getValue().toString()); int month = Integer.getInteger(drpMes.getValue().toString()); GregorianCalendar c = new GregorianCalendar(); c.setTime(new Date(year, month, day)); XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); user.setFechaNac(date2); } catch (Exception ex) { GregorianCalendar c = new GregorianCalendar(); c.setTime(Date.from(Instant.EPOCH)); try { XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); user.setFechaNac(date2); } catch (Exception ex2) { System.out.println("Error en fecha"); } } user.setImagen(txtNickName.getText() + ".jpg"); QuickOrderWebService webService = new QuickOrderWebService(); ControllerInterface port = webService.getQuickOrderWebServicePort(); String result = port.registrarCliente(user); if (result.isEmpty()) { JOptionPane.showMessageDialog(this, "Usuario ingresado correctamente"); txtApellido.setText(""); txtDireccion.setText(""); txtEmail.setText(""); txtNickName.setText(""); txtNombre.setText(""); jPasswordField2.setText(""); } else { if (result.equals("emailError1")) { JOptionPane.showMessageDialog(this, "El email ya se encuentra registrado, por favor ingrese otro.", "Alerta", JOptionPane.WARNING_MESSAGE); } if (result.equals("nicknameError1")) { JOptionPane.showMessageDialog(this, "El nickname no se encuentra disponible, por favor ingrese otro.", "Alerta", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(this, "Error al ingresar el cliente", "Error", JOptionPane.ERROR_MESSAGE); } } } } }
From source file:net.sourceforge.eclipsetrader.opentick.Feed.java
public void snapshot() { SimpleDateFormat usDateTimeParser = new SimpleDateFormat("MM/dd/yyyy h:mma"); SimpleDateFormat usDateParser = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat usTimeParser = new SimpleDateFormat("h:mma"); NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); // Builds the url for quotes download String host = "quote.yahoo.com"; StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) { Security security = (Security) iter.next(); url = url.append(security.getCode() + "+"); }/*w ww . ja v a 2 s .c o m*/ if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); // Read the last prices String line = ""; try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = OpenTickPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); if (line.indexOf(";") != -1) item = line.split(";"); Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { System.out.println(e.getMessage() + ": " + line); } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase(security.getCode())) security.setQuote(quote, open, high, low, close); } } in.close(); } catch (Exception e) { System.out.println(e.getMessage() + ": " + line); e.printStackTrace(); } }