List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:com.fluidops.iwb.api.ReadDataManagerImpl.java
/** * RDF string to Java Object/* w w w. java2s.com*/ */ @SuppressWarnings({ "unchecked" }) @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION", justification = "Exception caught for robustness.") private <T> T convert(Value s, Class<T> t, Map<Value, Object> resourceStack) { if (s == null) return null; // avoid endless recursion if (resourceStack != null) { Object alreadySeen = resourceStack.get(s); if (alreadySeen != null) { if (alreadySeen.getClass().isAssignableFrom(t)) return (T) alreadySeen; else // TODO: theoretically, a subject could be accessed as Type // T1 and later // as Type T2. So really, the stack should be Map<String, // Map<Class, Object>> // but this seems like a bit of overkill, so we just return // null if the type // seen for this resource before in the stack does not match return null; } } try { if (t == short.class || t == Short.class) return (T) new Short(s.stringValue()); if (t == byte.class || t == Byte.class) return (T) new Byte(s.stringValue()); if (t == boolean.class || t == Boolean.class) return (T) Boolean.valueOf(s.stringValue()); if (t == long.class || t == Long.class) return (T) new Long(s.stringValue()); if (t == float.class || t == Float.class) return (T) new Float(s.stringValue()); if (t == double.class || t == Double.class) return (T) new Double(s.stringValue()); if (t == int.class || t == Integer.class) return (T) new Integer(s.stringValue()); if (t == String.class) return (T) s.stringValue(); if (t == Date.class) return (T) literal2HumanDate(s.stringValue()); if (t == Calendar.class) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(literal2HumanDate(s.stringValue())); return (T) cal; } if (t == URL.class) return (T) new URL(s.stringValue()); if (t == java.net.URI.class) return (T) new java.net.URI(s.stringValue()); if (t == org.openrdf.model.URI.class) return (T) s; /* * todo // interface - use dynamic proxy if ( t.isInterface() || * Proxy.class.isAssignableFrom( t ) ) return (T)Proxy.newInstance( * s, this, t ); */ T instance = t.newInstance(); // create object only if it is necessary if (resourceStack == null) resourceStack = new HashMap<Value, Object>(); resourceStack.put(s, instance); for (Field f : t.getFields()) { if (Modifier.isStatic(f.getModifiers())) continue; if (Modifier.isFinal(f.getModifiers())) continue; if (List.class.isAssignableFrom(f.getType())) { @SuppressWarnings("rawtypes") Class listTypeValue = String.class; if (f.getGenericType() instanceof ParameterizedType) listTypeValue = (Class<?>) ((ParameterizedType) f.getGenericType()) .getActualTypeArguments()[0]; if (f.getAnnotation(RDFMapping.class) == null ? false : f.getAnnotation(RDFMapping.class).inverse()) { List<String> x = getInverseProps(s, RDFMappingUtil.uri(f), listTypeValue, false); f.set(instance, x); } else { List<T> x = new ArrayList<T>(); for (Value v : getProps((Resource) s, RDFMappingUtil.uri(f))) x.add((T) convert(v, listTypeValue, resourceStack)); f.set(instance, x); } } else { if (f.getName().equals("__resource")) f.set(instance, s); else if (f.getAnnotation(RDFMapping.class) == null ? false : f.getAnnotation(RDFMapping.class).inverse()) { Object x = getInversePropInternal(s, RDFMappingUtil.uri(f), f.getType(), resourceStack); f.set(instance, x); } else if (s instanceof Resource) { // for Resources, traverse deeper, for Literals, there // is no substructure Object x = getPropInternal(getProp((Resource) s, RDFMappingUtil.uri(f)), f.getType(), resourceStack); f.set(instance, x); } } } return instance; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.java
/** * *//*from w w w. jav a2 s. c o m*/ public Date getPasswordExpirationTime(String userName) throws UserStoreException { if (userName != null && userName.contains(CarbonConstants.DOMAIN_SEPARATOR)) { return super.getPasswordExpirationTime(userName); } Connection dbConnection = null; ResultSet rs = null; PreparedStatement prepStmt = null; String sqlstmt = null; Date date = null; try { dbConnection = getDBConnection(); dbConnection.setAutoCommit(false); if (isCaseSensitiveUsername()) { sqlstmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.SELECT_USER); } else { sqlstmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.SELECT_USER_CASE_INSENSITIVE); } if (log.isDebugEnabled()) { log.debug(sqlstmt); } prepStmt = dbConnection.prepareStatement(sqlstmt); prepStmt.setString(1, userName); if (sqlstmt.contains(UserCoreConstants.UM_TENANT_COLUMN)) { prepStmt.setInt(2, tenantId); } rs = prepStmt.executeQuery(); if (rs.next() == true) { boolean requireChange = rs.getBoolean(5); Timestamp changedTime = rs.getTimestamp(6); if (requireChange) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(changedTime); gc.add(GregorianCalendar.HOUR, 24); date = gc.getTime(); } } } catch (SQLException e) { String msg = "Error occurred while retrieving password expiration time for user : " + userName; if (log.isDebugEnabled()) { log.debug(msg, e); } throw new UserStoreException(msg, e); } finally { DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt); } return date; }
From source file:com.flexoodb.common.FlexUtils.java
static public XMLGregorianCalendar getCalendar(Date d) { GregorianCalendar gcfield_time = new GregorianCalendar(); gcfield_time.setTime(d); return (new com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl()) .newXMLGregorianCalendar(gcfield_time); }
From source file:org.socraticgrid.docmgr.DocumentManagerImpl.java
/** * Parse metadata query result for getMessages() return. * * @param msgType/*from w w w.ja v a 2 s.c om*/ * @param metadata result * @return */ private GetMessagesResponseType parseMetadataMessageResponse(String userId, String msgType, String location, oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse result) { GetMessagesResponseType response = new GetMessagesResponseType(); try { GetMessageResponse msgResponse; //Check for errors if (result.getRegistryErrorList() != null) { msgResponse = new GetMessageResponse(); List<RegistryError> errorList = result.getRegistryErrorList().getRegistryError(); for (RegistryError error : errorList) { msgResponse.setStatusMessage(error.getValue()); break; } msgResponse.setSuccessStatus(false); response.getGetMessageResponse().add(msgResponse); } List<JAXBElement<? extends IdentifiableType>> objectList = result.getRegistryObjectList() .getIdentifiable(); log.debug("Found metadata for documents: " + objectList.size()); for (JAXBElement<? extends IdentifiableType> object : objectList) { IdentifiableType identifiableType = object.getValue(); if (identifiableType instanceof ExtrinsicObjectType) { msgResponse = new GetMessageResponse(); msgResponse.setSuccessStatus(true); //Poplulate summary data object GregorianCalendar cal = new GregorianCalendar(); String author = null; String institution = null; msgResponse.setMessageType(msgType); msgResponse.setMessageStatus(KMR_INBOX_UNREAD); ExtrinsicObjectType extrinsic = (ExtrinsicObjectType) identifiableType; try { msgResponse .setDescription(extrinsic.getDescription().getLocalizedString().get(0).getValue()); } catch (Exception e) { msgResponse.setDescription(""); } msgResponse.setTitle(extrinsic.getName().getLocalizedString().get(0).getValue()); for (SlotType1 metaSlot : extrinsic.getSlot()) { //Set only if not already set, we use the creation date if special kmr // metadata tag is not found. if (XDS_CREATION_TIME.equals(metaSlot.getName()) && (msgResponse.getMessageDate() == null)) { try { cal.setTime(parseXDSDate(metaSlot.getValueList().getValue().get(0))); if (msgResponse.getMessageDate() == null) msgResponse.setMessageDate( DatatypeFactory.newInstance().newXMLGregorianCalendar(cal)); } catch (Exception pe) { String msg = "Error parsing: " + XDS_CREATION_TIME; log.error(msg, pe); msgResponse.setStatusMessage(msg + ". " + pe.getMessage()); msgResponse.setSuccessStatus(false); } } else if ((XDS_KMR_READ + ":" + userId).equals(metaSlot.getName())) { try { if (Boolean.TRUE .equals(Boolean.valueOf(metaSlot.getValueList().getValue().get(0)))) { msgResponse.setMessageStatus(KMR_INBOX_READ); } else { msgResponse.setMessageStatus(KMR_INBOX_UNREAD); } } catch (Exception e) { String msg = "Error parsing: " + XDS_KMR_READ + ":" + userId; log.error(msg, e); msgResponse.setStatusMessage(msg + ". " + e.getMessage()); msgResponse.setSuccessStatus(false); } } else if ((XDS_KMR_STARRED + ":" + userId).equals(metaSlot.getName())) { try { if (Boolean.TRUE .equals(Boolean.valueOf(metaSlot.getValueList().getValue().get(0)))) { msgResponse.getLabels().add(KMR_INBOX_STARRED); } } catch (Exception e) { String msg = "Error parsing: " + XDS_KMR_STARRED + ":" + userId; log.error(msg, e); msgResponse.setStatusMessage(msg + ". " + e.getMessage()); msgResponse.setSuccessStatus(false); } } else if ((XDS_KMR_ARCHIVE + ":" + userId).equals(metaSlot.getName())) { try { if (Boolean.TRUE .equals(Boolean.valueOf(metaSlot.getValueList().getValue().get(0)))) { //Set archive if location value not already set (trash) if ((msgResponse.getLocation() == null) || msgResponse.getLocation().isEmpty()) { msgResponse.setLocation(KMR_INBOX_ARCHIVE); } } } catch (Exception e) { String msg = "Error parsing: " + XDS_KMR_ARCHIVE + ":" + userId; log.error(msg, e); msgResponse.setStatusMessage(msg + ". " + e.getMessage()); msgResponse.setSuccessStatus(false); } } else if ((XDS_KMR_DELETE + ":" + userId).equals(metaSlot.getName())) { try { if (Boolean.TRUE .equals(Boolean.valueOf(metaSlot.getValueList().getValue().get(0)))) { msgResponse.setLocation(KMR_INBOX_USERTRASH); } } catch (Exception e) { String msg = "Error parsing: " + XDS_KMR_DELETE + ":" + userId; log.error(msg, e); msgResponse.setStatusMessage(msg + ". " + e.getMessage()); msgResponse.setSuccessStatus(false); } } else if ((XDS_KMR_STOREDATE).equals(metaSlot.getName())) { try { cal.setTime(parseXDSDate(metaSlot.getValueList().getValue().get(0))); msgResponse .setMessageDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal)); } catch (Exception pe) { String msg = "Error parsing: " + XDS_KMR_STOREDATE; log.error(msg, pe); msgResponse.setStatusMessage(msg + ". " + pe.getMessage()); msgResponse.setSuccessStatus(false); } } } //end for meta slots for (ExternalIdentifierType identifier : extrinsic.getExternalIdentifier()) { if (XDS_DOC_ID.equals(identifier.getName().getLocalizedString().get(0).getValue())) { msgResponse.setMessageId(identifier.getValue()); } } for (ClassificationType classification : extrinsic.getClassification()) { if (XDS_CLASS_AUTHOR.equals(classification.getClassificationScheme())) { for (SlotType1 authorSlot : classification.getSlot()) { if (XDS_SLOT_AUTHOR.equals(authorSlot.getName())) { author = authorSlot.getValueList().getValue().get(0); } } for (SlotType1 authorSlot : classification.getSlot()) { if (XDS_SLOT_INSTITUTION.equals(authorSlot.getName())) { institution = authorSlot.getValueList().getValue().get(0); } } } } //Set From field as combo of author and institution if ((institution != null) && !institution.isEmpty()) { msgResponse.setFrom(institution + " - " + author); } else { msgResponse.setFrom(author); } msgResponse.setPriority(""); msgResponse.setTasksComplete(0); msgResponse.setTasksCount(0); //Filter documents not in requested location if ((location == null) || location.isEmpty() || KMR_INBOX.equalsIgnoreCase(location)) { //If we're here, we want inbox only items, // which means an empty location value if ((msgResponse.getLocation() != null) && !msgResponse.getLocation().isEmpty()) { continue; } } else { //A location has been specified that is not Inbox, // so, make sure location mathces if (!location.equalsIgnoreCase(msgResponse.getLocation())) { continue; } } //Add the document to the response response.getGetMessageResponse().add(msgResponse); } //end if extrinisc object } //end for result object list } catch (Exception e) { log.error("Error parsing metadata result.", e); GetMessageResponse msgResponse = new GetMessageResponse(); msgResponse.setStatusMessage(e.getMessage()); msgResponse.setSuccessStatus(false); response.getGetMessageResponse().add(msgResponse); } return response; }
From source file:de.innovationgate.wga.server.api.WGA.java
/** * Modifies a date by adding/substracting a certain timespan * This is a utility method for simple modifications to dates without the use of {@link Calendar} objects. it returns a new {@link Date} object which represents the date of the parameter "date" plus/minus a given timespan. * In order to add a timespan one is first to choose which time unit to use via argument "unit" and then the amount of units to add via argument "amount". In order to substract a timespan from the date a negative amount value is to be used. * The unit is determined by the date string character that would be used by {@link SimpleDateFormat} for the time unit: * <ul>/*from w w w . ja va2s . co m*/ * <li> d" or "D" - Day * <li> "M" - Month * <li> "w" or "W" - Week * <li> "y" - Year * <li> "H" or "h" - Hour * <li> "m" - Minute * <li> "s" - Second * <li> "S" - Millisecond * <ul> * @param date Date to modify * @param unit Modify unit. See table above. * @param amount Amount of date units to add to the date. Specify negative amounts to substract. * @return The modified date * @throws WGAServerException */ public Date modifyDate(Date date, String unit, int amount) throws WGException { int field; switch (unit.charAt(0)) { case 'd': case 'D': field = GregorianCalendar.DAY_OF_MONTH; break; case 'M': field = GregorianCalendar.MONTH; break; case 'w': case 'W': field = GregorianCalendar.WEEK_OF_YEAR; break; case 'y': field = GregorianCalendar.YEAR; break; case 'H': case 'h': field = GregorianCalendar.HOUR; break; case 'm': field = GregorianCalendar.MINUTE; break; case 's': field = GregorianCalendar.SECOND; break; case 'S': field = GregorianCalendar.MILLISECOND; break; default: throw new WGAServerException("Unknown date field literal: " + unit); } GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(field, amount); return cal.getTime(); }
From source file:org.apache.lens.server.metastore.TestMetastoreService.java
private XDimension createDimension(String dimName) throws Exception { GregorianCalendar c = new GregorianCalendar(); c.setTime(new Date()); final XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); c.add(GregorianCalendar.DAY_OF_MONTH, 7); final XMLGregorianCalendar endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); XDimension dimension = cubeObjectFactory.createXDimension(); dimension.setName(dimName);/*from w w w . j a v a2 s .c o m*/ dimension.setAttributes(new XDimAttributes()); dimension.setExpressions(new XExpressions()); dimension.setJoinChains(new XJoinChains()); dimension.setProperties(new XProperties().withProperty( new XProperty().withName(MetastoreUtil.getDimTimedDimensionKey(dimName)).withValue("dt"))); XDimAttribute xd1 = cubeObjectFactory.createXDimAttribute(); xd1.setName("col1"); xd1.setType("STRING"); xd1.setDescription("first column"); xd1.setDisplayString("Column1"); // Don't set endtime on this dim to validate null handling on server side xd1.setStartTime(startDate); XDimAttribute xd2 = cubeObjectFactory.createXDimAttribute(); xd2.setName("col2"); xd2.setType("INT"); xd2.setDescription("second column"); xd2.setDisplayString("Column2"); // Don't set start time on this dim to validate null handling on server side xd2.setEndTime(endDate); dimension.getAttributes().getDimAttribute().add(xd1); dimension.getAttributes().getDimAttribute().add(xd2); XExprColumn xe1 = new XExprColumn(); xe1.setName("dimexpr"); xe1.setType("STRING"); xe1.setDescription("dimension expression"); xe1.setDisplayString("Dim Expression"); XExprSpec es = new XExprSpec(); es.setExpr("substr(col1, 3)"); xe1.getExprSpec().add(es); dimension.getExpressions().getExpression().add(xe1); XProperty xp1 = cubeObjectFactory.createXProperty(); xp1.setName("dimension.foo"); xp1.setValue("dim.bar"); dimension.getProperties().getProperty().add(xp1); return dimension; }
From source file:com.ext.portlet.epsos.EpsosHelperService.java
public static boolean writeConsent(SpiritEhrWsClientInterface webservice, EhrPatientClientDto patient, String country, String language, String policy, String fromdate, String todate) { boolean consentCreated = false; PatientConsentObject result = null;/*from w ww. j a v a2 s .co m*/ if (true) { //upload consent document try { List<PolicySetGroup> objGroupList = webservice.queryPolicySetsForPatient(patient).getGroupList(); String[] policyids = new String[] { policy }; if (policyids != null && objGroupList != null) { for (PolicySetGroup g : objGroupList) { // first unselect all policies: for (PolicySetItem i : g.getPolicySetItemList()) { i.setSelected(false); } // then only select the ones selected by the user in the interface for (String id : policyids) { String groupCode = id.substring(0, id.indexOf("$$$")); _log.info("groupode=" + groupCode); if (groupCode.equals(g.getCode())) { String policyId = id.substring(id.indexOf("$$$") + 3); _log.info("policyid=" + policyId); for (PolicySetItem i : g.getPolicySetItemList()) { if (i.getPolicySetId().equals(policyId)) { i.setSelected(true); GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); Date fromDate = GetterUtil.getDate(fromdate, dateTimeFormat, null); if (fromDate != null) { cal.setTime(fromDate); XMLGregorianCalendar fromCal = DatatypeFactory.newInstance() .newXMLGregorianCalendar(cal); i.setEffectiveDateFrom(fromCal); } Date toDate = GetterUtil.getDate(todate, dateTimeFormat, null); if (toDate != null) { cal.setTime(toDate); XMLGregorianCalendar toCal = DatatypeFactory.newInstance() .newXMLGregorianCalendar(cal); i.setEffectiveDateTo(toCal); } } } } } } } EpsosHelperService.getInstance() .createLog("CREATE PATIENT CONSENT REQUEST:" + patient.getGivenName(), null); webservice.saveConsent(patient, language, "Patient Consent", objGroupList); consentCreated = true; EpsosHelperService.getInstance() .createLog("CREATE PATIENT CONSENT RESPONSE OK:" + patient.getGivenName(), null); } catch (Exception e1) { EpsosHelperService.getInstance().createLog("CREATE PATIENT CONSENT RESPONSE FAILURE:" + patient.getGivenName() + ".ERROR: " + e1.getMessage(), null); e1.printStackTrace(); } //result = object; } return consentCreated; }
From source file:org.openmrs.api.PatientServiceTest.java
/** * @see PatientService#mergePatients(Patient,Patient) * @verifies audit prior date of birth estimated *//*from w ww .java 2 s.co m*/ @Test public void mergePatients_shouldAuditPriorDateOfBirthEstimated() throws Exception { //retrieve preferred patient and set a date of birth GregorianCalendar cDate = new GregorianCalendar(); cDate.setTime(new Date()); Patient preferred = patientService.getPatient(999); preferred.setBirthdate(cDate.getTime()); preferred.setBirthdateEstimated(true); preferred.addName(new PersonName("givenName", "middleName", "familyName")); patientService.savePatient(preferred); Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); Assert.assertTrue("prior estimated date of birth was not audited", audit.getPersonMergeLogData().isPriorDateOfBirthEstimated()); }
From source file:org.openmrs.api.PatientServiceTest.java
/** * @see PatientService#mergePatients(Patient,Patient) * @verifies audit prior date of death estimated *///from w w w .j ava 2 s . c om @Test public void mergePatients_shouldAuditPriorDateOfDeathEstimated() throws Exception { //retrieve preferred patient and set a date of death GregorianCalendar cDate = new GregorianCalendar(); cDate.setTime(new Date()); Patient preferred = patientService.getPatient(999); preferred.setDeathDate(cDate.getTime()); preferred.setDeathdateEstimated(true); preferred.addName(new PersonName("givenName", "middleName", "familyName")); patientService.savePatient(preferred); Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); Assert.assertTrue("prior estimated date of death was not audited", audit.getPersonMergeLogData().getPriorDateOfDeathEstimated()); }