List of usage examples for java.util SimpleTimeZone SimpleTimeZone
public SimpleTimeZone(int rawOffset, String ID)
From source file:edu.ucsb.nceas.MCTestCase.java
/** * Create a unique docid for testing insert and update. Does not * include the 'revision' part of the id. * //from w w w .j a v a 2 s . co m * @return a String docid based on the current date and time */ protected String generateDocumentId() { try { Thread.sleep(1010); } catch (InterruptedException ie) { debug("Could not sleep: " + ie.getMessage()); } StringBuffer docid = new StringBuffer(prefix); docid.append("."); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime); docid.append(calendar.get(Calendar.YEAR)); docid.append(calendar.get(Calendar.DAY_OF_YEAR)); docid.append(calendar.get(Calendar.HOUR_OF_DAY)); docid.append(calendar.get(Calendar.MINUTE)); docid.append(calendar.get(Calendar.SECOND)); return docid.toString(); }
From source file:edu.fullerton.ldvservlet.SrcList.java
private TimeSeries getTimeSeries(double[][] data, String legend) { TimeSeries ts;/*from www .j a v a2 s. c o m*/ ts = new TimeSeries(legend); SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC"); for (double[] data1 : data) { long gps = Math.round(data1[0]); long utcms = TimeAndDate.gps2utc(gps) * 1000; Date t = new Date(utcms); ts.addOrUpdate(new Millisecond(t, utctz, Locale.US), data1[1]); } return ts; }
From source file:com.servoy.j2db.util.Utils.java
/** * Format a given number of miliseconds in a formatted time * * Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone) * * @param msec the miliseconds (current time can be get by 'new java.util.Date().getTime()') * @param format the display format//from w w w .j a v a2s . c o m * @return the formatted time * @see java.text.SimpleDateFormat */ public static String formatTime(long msec, String format) { Date d = new Date(msec); SimpleDateFormat sdf = new SimpleDateFormat(format == null ? "yyyy.MM.dd G 'at' hh:mm:ss z" : format); //$NON-NLS-1$ if (msec < 2678400000L && msec >= 0) //if smaller than a ~month { //format the time without timezone (GMT +0) //now it is possible to format for example telephone calling seconds to a formatted time (hh:mm:ss) //otherwise the timezone is involed sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); //$NON-NLS-1$ } return sdf.format(d); }
From source file:org.nuxeo.ecm.directory.ldap.LDAPSession.java
@SuppressWarnings("unchecked") protected Object getFieldValue(Attribute attribute, String fieldName, String entryId, boolean fetchReferences) throws DirectoryException { Field field = schemaFieldMap.get(fieldName); Type type = field.getType();// w w w . ja v a 2s. c o m Object defaultValue = field.getDefaultValue(); String typeName = type.getName(); if (attribute == null) { return defaultValue; } Object value; try { value = attribute.get(); } catch (NamingException e) { throw new DirectoryException("Could not fetch value for " + attribute, e); } if (value == null) { return defaultValue; } String trimmedValue = value.toString().trim(); if ("string".equals(typeName)) { return trimmedValue; } else if ("integer".equals(typeName) || "long".equals(typeName)) { if ("".equals(trimmedValue)) { return defaultValue; } try { return Long.valueOf(trimmedValue); } catch (NumberFormatException e) { log.error(String.format( "field %s of type %s has non-numeric value found on server: '%s' (ignoring and using default value instead)", fieldName, typeName, trimmedValue)); return defaultValue; } } else if (type.isListType()) { List<String> parsedItems = new LinkedList<String>(); NamingEnumeration<Object> values = null; try { values = (NamingEnumeration<Object>) attribute.getAll(); while (values.hasMore()) { parsedItems.add(values.next().toString().trim()); } return parsedItems; } catch (NamingException e) { log.error(String.format( "field %s of type %s has non list value found on server: '%s' (ignoring and using default value instead)", fieldName, typeName, values != null ? values.toString() : trimmedValue)); return defaultValue; } finally { if (values != null) { try { values.close(); } catch (NamingException e) { log.error(e, e); } } } } else if ("date".equals(typeName)) { if ("".equals(trimmedValue)) { return defaultValue; } try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); dateFormat.setTimeZone(new SimpleTimeZone(0, "Z")); Date date = dateFormat.parse(trimmedValue); Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; } catch (ParseException e) { log.error(String.format( "field %s of type %s has invalid value found on server: '%s' (ignoring and using default value instead)", fieldName, typeName, trimmedValue)); return defaultValue; } } else if ("content".equals(typeName)) { return Blobs.createBlob((byte[]) value); } else { throw new DirectoryException("Field type not supported in directories: " + typeName); } }
From source file:com.sonyericsson.jenkins.plugins.bfa.db.MongoDBKnowledgeBase.java
/** * Generates a {@link TimePeriod} based on a MongoDB grouping aggregation result. * @param result the result to interpret * @param intervalSize the interval size, should be set to Calendar.HOUR_OF_DAY, * Calendar.DATE or Calendar.MONTH./* ww w.j a v a 2 s . c om*/ * @return TimePeriod */ private TimePeriod generateTimePeriodFromResult(DBObject result, int intervalSize) { BasicDBObject groupedAttrs = (BasicDBObject) result.get("_id"); int month = groupedAttrs.getInt("month"); int year = groupedAttrs.getInt("year"); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month - 1); // MongoDB timezone is UTC: c.setTimeZone(new SimpleTimeZone(0, "UTC")); TimePeriod period = null; if (intervalSize == Calendar.HOUR_OF_DAY) { int dayOfMonth = groupedAttrs.getInt("dayOfMonth"); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); int hour = groupedAttrs.getInt("hour"); c.set(Calendar.HOUR_OF_DAY, hour); period = new Hour(c.getTime()); } else if (intervalSize == Calendar.DATE) { int dayOfMonth = groupedAttrs.getInt("dayOfMonth"); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); period = new Day(c.getTime()); } else { period = new Month(c.getTime()); } return period; }
From source file:org.nuxeo.ecm.directory.ldap.LDAPSession.java
@SuppressWarnings("unchecked") protected Attribute getAttributeValue(String fieldName, Object value) throws DirectoryException { Attribute attribute = new BasicAttribute(getDirectory().getFieldMapper().getBackendField(fieldName)); Field field = schemaFieldMap.get(fieldName); if (field == null) { String message = String.format("Invalid field name '%s' for directory '%s' with schema '%s'", fieldName, directory.getName(), directory.getSchema()); throw new DirectoryException(message); }/*from www . j av a2 s.c o m*/ Type type = field.getType(); String typeName = type.getName(); if ("string".equals(typeName)) { attribute.add(value); } else if ("integer".equals(typeName) || "long".equals(typeName)) { attribute.add(value.toString()); } else if (type.isListType()) { Collection<String> valueItems; if (value instanceof String[]) { valueItems = Arrays.asList((String[]) value); } else if (value instanceof Collection) { valueItems = (Collection<String>) value; } else { throw new DirectoryException(String.format("field %s with value %s does not match type %s", fieldName, value.toString(), type.getName())); } for (String item : valueItems) { attribute.add(item); } } else if ("date".equals(typeName)) { Calendar cal = (Calendar) value; Date date = cal.getTime(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); dateFormat.setTimeZone(new SimpleTimeZone(0, "Z")); attribute.add(dateFormat.format(date)); } else if ("content".equals(typeName)) { try { attribute.add(((Blob) value).getByteArray()); } catch (IOException e) { throw new DirectoryException("Failed to get ByteArray value", e); } } else { throw new DirectoryException("Field type not supported in directories: " + typeName); } return attribute; }
From source file:com.qut.middleware.esoe.sso.impl.SSOProcessorImpl.java
private result validateSession(SSOProcessorData data) { String remoteAddr = data.getRemoteAddress(); try {//from w ww. ja v a 2 s . c om AuthnRequest authnRequest = data.getAuthnRequest(); // Make sure the handler isn't dodgy. if (authnRequest == null) { this.logger.error( "[SSO for {}] Calling SSO handler did not set AuthnRequest in the bean. Unable to continue processing.", remoteAddr); return SSOProcessor.result.SSOGenerationFailed; } // Check these so we can assume they're non-null if (authnRequest.getNameIDPolicy() == null || authnRequest.getNameIDPolicy().isAllowCreate() == null || authnRequest.getIssuer() == null || authnRequest.getIssuer().getValue() == null) { this.logger.error( "[SSO for {}] AuthnRequest was not complete - some required information was omitted. Unable to process."); return SSOProcessor.result.SSOGenerationFailed; } // Go to grab the session ID (and anything else we need) from the cookies. this.processCookies(data); String sessionID = data.getSessionID(); data.setIssuerID(authnRequest.getIssuer().getValue()); // If the user did not present a session cookie... if (sessionID == null || sessionID.length() <= 0) { if (authnRequest.getNameIDPolicy().isAllowCreate().booleanValue()) { this.logger.info( "[SSO for {}] Session not established, forcing authentication operation on principal", remoteAddr); return SSOProcessor.result.ForceAuthn; } this.logger.warn( "[SSO for {}] Session is not established and SPEP has prevented establishment from being allowed non passively, creating failure response", remoteAddr); createStatusAuthnResponse(data, StatusCodeConstants.requester, StatusCodeConstants.requestDenied, "Session could not be resolved from previous session establishment data and SPEP will not allow session establishment", true); return SSOProcessor.result.ForcePassiveAuthn; } this.logger.debug("[SSO for {}] Querying sessions processor for session ID {}", new Object[] { remoteAddr, sessionID }); Principal principal = this.sessionsProcessor.getQuery().queryAuthnSession(sessionID); // If the user's session cookie does not point to a valid session. if (principal == null) { // This is the same logic as when they do not have a session cookie, just that the log statements are different. if (authnRequest.getNameIDPolicy().isAllowCreate().booleanValue()) { this.logger.warn( "[SSO for {}] Could not locate a current session in the session cache. Forcing authentication operation on principal", remoteAddr); return SSOProcessor.result.ForceAuthn; } this.logger.warn( "[SSO for {}] Could not locate a current session in the session cache, and SPEP has prevented establishment from being allowed non passively, creating failure response", remoteAddr); createStatusAuthnResponse(data, StatusCodeConstants.responder, StatusCodeConstants.authnFailed, "Could not locate principal in local session for supposedly active session identifier", true); return SSOProcessor.result.ForcePassiveAuthn; } // Store principal in the bean for future use. data.setPrincipal(principal); this.logger.debug( "[SSO for {}] Retrieved principal for session ID {} - principal authn identifier is {}", new Object[] { remoteAddr, sessionID, principal.getPrincipalAuthnIdentifier() }); if (authnRequest.isForceAuthn() != null && authnRequest.isForceAuthn().booleanValue()) { TimeZone utc = new SimpleTimeZone(0, ConfigurationConstants.timeZone); GregorianCalendar cal = new GregorianCalendar(utc); long thisTime = cal.getTimeInMillis(); /* * The SP has indicated it wishes to force authn. If our principal authenticated more then allowed time skew * in the past then we have to auth them again, the invisible else case is that the principal has * authenticated within the allowed time skew window thus they can continue on their way */ if ((thisTime - principal.getAuthnTimestamp() > this.allowedTimeSkew)) { /* * The SP indicated it expects the interaction to be passive and it wishes to ensure the principal * undertakes authn, we can't grant this so return error */ if (authnRequest.isIsPassive() != null && authnRequest.isIsPassive().booleanValue()) { this.logger.debug( "[SSO for {}] SPEP has requested forced authn as part of this SSO operation and has also requested only passive session establishment which is not supported", remoteAddr); createStatusAuthnResponse(data, StatusCodeConstants.responder, StatusCodeConstants.noPassive, "ESOE does not support passive only session establishment", true); return SSOProcessor.result.ForcePassiveAuthn; } this.logger.info( "[SSO for {}] SPEP has requested forced authn as part of this SSO operation, forcing authentication", remoteAddr); return SSOProcessor.result.ForceAuthn; } } /* Determine if we have an identifier for this principal to use when communicating with remote SPEP's */ if (principal.getSAMLAuthnIdentifier() == null || principal.getSAMLAuthnIdentifier().length() <= 0) { createStatusAuthnResponse(data, StatusCodeConstants.responder, StatusCodeConstants.authnFailed, "The SAMLID identifying this principal to SPEP's is corrupted or invalid", true); this.sessionsProcessor.getTerminate().terminateSession(sessionID); return SSOProcessor.result.SSOGenerationFailed; } /* Generate SAML session index */ String sessionIndex = this.identifierGenerator.generateSAMLSessionID(); this.sessionsProcessor.getUpdate().addEntitySessionIndex(principal, data.getIssuerID(), sessionIndex); this.authnLogger.info( "[SSO for {}] Session established for SAML ID {} at SPEP {} and endpoint {} Principal authn identifier is {} New session index is {}", new Object[] { remoteAddr, principal.getSAMLAuthnIdentifier(), data.getIssuerID(), data.getResponseEndpoint(), principal.getPrincipalAuthnIdentifier(), sessionIndex }); data.setSessionIndex(sessionIndex); // Return null to indicate that there is no user agent interaction required. return null; } catch (SessionCacheUpdateException e) { this.logger.error("[SSO for {}] Failed to update session cache. Error was: {}", new Object[] { remoteAddr, e.getMessage() }); this.logger.debug(MessageFormatter .format("[SSO for {}] Failed to update session cache. Exception follows.", remoteAddr), e); return SSOProcessor.result.SSOGenerationFailed; } catch (SSOException e) { this.logger.error("[SSO for {}] Failed to perform SSO operation. Error was: {}", new Object[] { remoteAddr, e.getMessage() }); this.logger.debug(MessageFormatter .format("[SSO for {}] Failed to perform SSO operation. Exception follows.", remoteAddr), e); return SSOProcessor.result.SSOGenerationFailed; } }
From source file:xc.mst.manager.record.DefaultRecordService.java
@Override protected SolrInputDocument setFieldsOnDocument(Record record, SolrInputDocument doc, boolean generateNewId) throws DatabaseConfigException { if (log.isDebugEnabled()) log.debug("Set Field on Document"); boolean throttleSolr = false; // If we need to generate an ID, set the record's ID to the next available record ID if (generateNewId) { record.setId(getXcIdentifierForFrbrElementDAO() .getNextXcIdForFrbrElement(XcIdentifierForFrbrElementDAO.ELEMENT_ID_RECORD)); }/*from w w w . j a va 2 s . c o m*/ // If the oaiDatestamp is null, set it to the current time if (record.getOaiDatestamp() == null) record.setOaiDatestamp(generateNewId ? record.getCreatedAt() : record.getUpdatedAt()); // If the header is null, set it based on the identifier, datestamp, and sets if (record.getOaiHeader() == null || record.getOaiHeader().length() <= 0) { StringBuilder header = new StringBuilder(); header.append("<header>\n"); header.append("\t<identifier>").append(record.getOaiIdentifier()).append("</identifier>\n"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); header.append("\t<datestamp>").append(sdf.format(record.getOaiDatestamp())).append("</datestamp>\n"); // Get each set from the list of set IDs this record belongs to. If the set is // not null, add its setSpec to the header. for (Set set : record.getSets()) if (set != null) header.append("\t<setSpec>").append(set.getSetSpec()).append("</setSpec>\n"); header.append("</header>"); record.setOaiHeader(header.toString()); } // end if(header needs to be set) // TimingLogger.turnOff(); // Set the appropriate fields on it. doc.addField(FIELD_RECORD_ID, Long.toString(record.getId())); /* if (record.getType() != null) { doc.addField(FIELD_RECORD_TYPE, record.getType()); TimingLogger.add("SOLR-"+FIELD_RECORD_TYPE, record.getType().length()); } doc.addField(FIELD_FRBR_LEVEL_ID, Long.toString(record.getFrbrLevelId())); TimingLogger.add("SOLR-"+FIELD_FRBR_LEVEL_ID, Long.toString(record.getFrbrLevelId()).length()); */ if (record.getCreatedAt() != null) { doc.addField(FIELD_CREATED_AT, record.getCreatedAt()); TimingLogger.add("SOLR-" + FIELD_CREATED_AT, 10); } doc.addField(FIELD_DELETED, Boolean.toString(record.getDeleted())); TimingLogger.add("SOLR-" + FIELD_DELETED, Boolean.toString(record.getDeleted()).length()); doc.addField(FIELD_FORMAT_ID, Integer.toString(record.getFormat().getId())); TimingLogger.add("SOLR-" + FIELD_FORMAT_ID, Integer.toString(record.getFormat().getId()).length()); doc.addField(FIELD_FORMAT_NAME, record.getFormat().getName()); TimingLogger.add("SOLR-" + FIELD_FORMAT_NAME, record.getFormat().getName().length()); doc.addField(FIELD_PROVIDER_ID, (record.getProvider() == null ? "0" : Integer.toString(record.getProvider().getId()))); TimingLogger.add("SOLR-" + FIELD_PROVIDER_ID, (record.getProvider() == null ? "0" : Integer.toString(record.getProvider().getId())).length()); if (record.getProvider() != null) { if (!throttleSolr) { doc.addField(FIELD_PROVIDER_NAME, (record.getProvider().getName() == null ? "" : record.getProvider().getName())); TimingLogger.add("SOLR-" + FIELD_PROVIDER_NAME, (record.getProvider().getName() == null ? "" : record.getProvider().getName()).length()); doc.addField(FIELD_PROVIDER_URL, (record.getProvider().getOaiProviderUrl() == null ? "" : record.getProvider().getOaiProviderUrl())); TimingLogger.add("SOLR-" + FIELD_PROVIDER_URL, (record.getProvider().getOaiProviderUrl() == null ? "" : record.getProvider().getOaiProviderUrl()).length()); } } doc.addField(FIELD_HARVEST_ID, (record.getHarvest() == null ? "0" : Integer.toString(record.getHarvest().getId()))); TimingLogger.add("SOLR-" + FIELD_HARVEST_ID, (record.getHarvest() == null ? "0" : Integer.toString(record.getHarvest().getId())).length()); if (record.getHarvest() != null) { HarvestSchedule schedule = record.getHarvest().getHarvestSchedule(); if (schedule != null) { doc.addField(FIELD_HARVEST_SCHEDULE_NAME, schedule.getScheduleName()); TimingLogger.add("SOLR-" + FIELD_HARVEST_SCHEDULE_NAME, schedule.getScheduleName().length()); } } if (record.getHarvest() != null && record.getProvider() != null) { doc.addField(FIELD_HARVEST_START_TIME, record.getProvider().getName() + " " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(record.getHarvest().getStartTime())); TimingLogger.add("SOLR-" + FIELD_HARVEST_START_TIME, record.getProvider().getName().length() + 10); } doc.addField(FIELD_SERVICE_ID, (record.getService() == null ? "0" : Integer.toString(record.getService().getId()))); TimingLogger.add("SOLR-" + FIELD_SERVICE_ID, (record.getService() == null ? "0" : Integer.toString(record.getService().getId())).length()); if (record.getService() != null) { doc.addField(FIELD_SERVICE_NAME, record.getService().getName()); TimingLogger.add("SOLR-" + FIELD_SERVICE_NAME, record.getService().getName().length()); } doc.addField(FIELD_OAI_IDENTIFIER, record.getOaiIdentifier()); TimingLogger.add("SOLR-" + FIELD_OAI_IDENTIFIER, record.getOaiIdentifier().length()); if (record.getOaiDatestamp() != null) { // If the record is output of a harvest then the OAI date stamp is already in UTC format if (record.getProvider() != null) { doc.addField(FIELD_OAI_DATESTAMP, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(record.getOaiDatestamp())); TimingLogger.add("SOLR-" + FIELD_OAI_DATESTAMP, 10); } else { doc.addField(FIELD_OAI_DATESTAMP, record.getOaiDatestamp()); TimingLogger.add("SOLR-" + FIELD_OAI_DATESTAMP, 10); } } if (!throttleSolr) { doc.addField(FIELD_OAI_HEADER, record.getOaiHeader()); TimingLogger.add("SOLR-" + FIELD_OAI_HEADER, record.getOaiHeader().length()); doc.addField(FIELD_OAI_XML, record.getOaiXml()); TimingLogger.add("SOLR-" + FIELD_OAI_XML, record.getOaiXml().length()); // System.out.println(record.getOaiXml()); } if (record.getUpdatedAt() != null) { doc.addField(FIELD_UPDATED_AT, record.getUpdatedAt()); TimingLogger.add("SOLR-" + FIELD_UPDATED_AT, 10); } for (String upLink : record.getUpLinks()) { doc.addField(FIELD_UP_LINK, upLink); TimingLogger.add("SOLR-" + FIELD_UP_LINK, upLink.length()); } for (Set set : record.getSets()) { doc.addField(FIELD_SET_SPEC, set.getSetSpec()); TimingLogger.add("SOLR-" + FIELD_SET_SPEC, set.getSetSpec().length()); doc.addField(FIELD_SET_NAME, set.getDisplayName()); TimingLogger.add("SOLR-" + FIELD_SET_NAME, set.getDisplayName().length()); } // end loop over sets for (Record processedFrom : record.getProcessedFrom()) { doc.addField(FIELD_PROCESSED_FROM, Long.toString(processedFrom.getId())); TimingLogger.add("SOLR-" + FIELD_PROCESSED_FROM, Long.toString(processedFrom.getId()).length()); } for (RecordIfc successor : record.getSuccessors()) { doc.addField(FIELD_SUCCESSOR, Long.toString(successor.getId())); TimingLogger.add("SOLR-" + FIELD_SUCCESSOR, Long.toString(successor.getId()).length()); } for (Service inputForService : record.getInputForServices()) { doc.addField(FIELD_INPUT_FOR_SERVICE_ID, Long.toString(inputForService.getId())); TimingLogger.add("SOLR-" + FIELD_INPUT_FOR_SERVICE_ID, Long.toString(inputForService.getId()).length()); } for (Service processedByService : record.getProcessedByServices()) { doc.addField(FIELD_PROCESSED_BY_SERVICE_ID, Long.toString(processedByService.getId())); TimingLogger.add("SOLR-" + FIELD_PROCESSED_BY_SERVICE_ID, Long.toString(processedByService.getId()).length()); } for (String trait : record.getTraits()) { doc.addField(FIELD_TRAIT, trait.replaceAll(" ", "_")); TimingLogger.add("SOLR-" + FIELD_TRAIT, trait.length()); } /* for(RecordMessage error : record.getMessages()) { String message = error.getServiceId() + "-" + error.getMessageCode() + ":" + error.getMessage(); doc.addField(FIELD_ERROR, message); TimingLogger.add("SOLR-"+FIELD_ERROR, message.length()); } */ StringBuffer all = new StringBuffer(); if (record.getFormat() != null) { all.append(record.getFormat().getName()); all.append(" "); } if (record.getProvider() != null) { all.append(record.getProvider().getName()); all.append(" "); } for (Set set : record.getSets()) { all.append(set.getSetSpec()); all.append(" "); all.append(set.getDisplayName()); all.append(" "); } if (record.getService() != null) { all.append(record.getService().getName()); all.append(" "); } for (RecordMessage error : record.getMessages()) { // all.append(error.getServiceId() + "-" + error.getMessageCode() + ":" + error.getMessage()); all.append(" "); } if (record.getHarvest() != null) { all.append(record.getHarvest().getStartTime()); } all.append(record.getOaiIdentifier()); if (!throttleSolr) { doc.addField(FIELD_ALL, all.toString()); TimingLogger.add("SOLR-" + FIELD_ALL, all.length()); } TimingLogger.turnOn(); return doc; }
From source file:org.apache.jena.graph.test.TestTypedLiterals.java
public void testDateTime_18() { SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "America/Los_Angeles"); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone Calendar ncal = new GregorianCalendar(pdt); ncal.set(2004, 02, 21, 12, 50, 42);//before daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-03-21T20:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); ncal = new GregorianCalendar(pdt); ncal.set(2004, 03, 21, 12, 50, 42);//within daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); l1 = m.createTypedLiteral(ncal);//from ww w.j a v a 2 s. com assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-04-21T19:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); }
From source file:com.groupon.odo.Proxy.java
/** * Log modified request//from w w w . j av a 2s . c om * * @param httpMethodProxyRequest * @param httpServletResponse * @param history */ private void logRequestHistory(HttpMethod httpMethodProxyRequest, HttpServletResponse httpServletResponse, History history) { try { if (requestInformation.get().handle && requestInformation.get().client.getIsActive()) { logger.info("Storing history"); String createdDate; SimpleDateFormat sdf = new SimpleDateFormat(); sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); sdf.applyPattern("dd MMM yyyy HH:mm:ss"); createdDate = sdf.format(new Date()) + " GMT"; history.setCreatedAt(createdDate); history.setRequestURL(HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString())); history.setRequestParams(httpMethodProxyRequest.getQueryString() == null ? "" : httpMethodProxyRequest.getQueryString()); history.setRequestHeaders(HttpUtilities.getHeaders(httpMethodProxyRequest)); history.setResponseHeaders(HttpUtilities.getHeaders(httpServletResponse)); history.setResponseCode(Integer.toString(httpServletResponse.getStatus())); history.setResponseContentType(httpServletResponse.getContentType()); history.setResponseData(requestInformation.get().outputString); HistoryService.getInstance().addHistory(history); logger.info("Done storing"); } } catch (URIException e) { e.printStackTrace(); } }