You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2017/05/01 06:11:21 UTC

[30/50] [abbrv] openmeetings git commit: [OPENMEETINGS-1535] range method is fixed

[OPENMEETINGS-1535] range method is fixed


Project: http://git-wip-us.apache.org/repos/asf/openmeetings/repo
Commit: http://git-wip-us.apache.org/repos/asf/openmeetings/commit/1e406fcd
Tree: http://git-wip-us.apache.org/repos/asf/openmeetings/tree/1e406fcd
Diff: http://git-wip-us.apache.org/repos/asf/openmeetings/diff/1e406fcd

Branch: refs/heads/3.1.x
Commit: 1e406fcda4ebde595590a17aae57a91009f05ba5
Parents: 86e69e3
Author: Maxim Solodovnik <so...@apache.org>
Authored: Thu Jan 19 14:45:20 2017 +0000
Committer: Maxim Solodovnik <so...@apache.org>
Committed: Thu Jan 19 14:45:20 2017 +0000

----------------------------------------------------------------------
 .../db/dto/calendar/AppointmentDTO.java         | 51 +-------------
 .../openmeetings/util/CalendarPatterns.java     |  8 ++-
 .../apache/openmeetings/web/app/WebSession.java |  4 +-
 .../classes/openmeetings-applicationContext.xml |  3 +
 .../util/AppointmentParamConverter.java         | 74 ++++++++++++++++++++
 .../webservice/util/CalendarParamConverter.java | 46 ++++++++++++
 .../webservice/util/DateParamConverter.java     | 55 +++++++++++++++
 .../util/OmParamConverterProvider.java          | 45 ++++++++++++
 8 files changed, 232 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/calendar/AppointmentDTO.java
----------------------------------------------------------------------
diff --git a/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/calendar/AppointmentDTO.java b/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/calendar/AppointmentDTO.java
index a485a2f..eb8606a 100644
--- a/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/calendar/AppointmentDTO.java
+++ b/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/calendar/AppointmentDTO.java
@@ -18,10 +18,7 @@
  */
 package org.apache.openmeetings.db.dto.calendar;
 
-import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_FORMAT;
-
 import java.io.Serializable;
-import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -39,7 +36,6 @@ import org.apache.openmeetings.db.dto.user.UserDTO;
 import org.apache.openmeetings.db.entity.calendar.Appointment;
 import org.apache.openmeetings.db.entity.calendar.Appointment.Reminder;
 import org.apache.openmeetings.db.entity.calendar.MeetingMember;
-import org.apache.wicket.ajax.json.JSONArray;
 import org.apache.wicket.ajax.json.JSONObject;
 
 @XmlRootElement
@@ -284,53 +280,8 @@ public class AppointmentDTO implements Serializable {
 		this.password = password;
 	}
 
-	private static Date optDate(JSONObject o, String prop) throws ParseException {
-		return ISO8601_FORMAT.parse(o.optString(prop));
-	}
-
-	private static Calendar optCal(AppointmentDTO a, JSONObject o, String prop) throws ParseException {
-		Calendar c = Calendar.getInstance(TimeZone.getTimeZone(a.owner.getTimeZoneId()));
-		c.setTime(ISO8601_FORMAT.parse(o.optString(prop)));
-		return c;
-	}
-
-	public static AppointmentDTO fromString(String s) throws ParseException {
-		JSONObject o = new JSONObject(s);
-		AppointmentDTO a = new AppointmentDTO();
-		a.id = o.optLong("id");
-		a.title = o.optString("title");
-		a.location = o.optString("location");
-		a.owner = UserDTO.get(o.optJSONObject("owner"));
-		a.start = optCal(a, o, "start");
-		a.end = optCal(a, o, "end");
-		a.description = o.optString("description");
-		a.inserted = optDate(o, "inserted");
-		a.updated = optDate(o, "updated");
-		a.deleted = o.optBoolean("inserted");
-		a.reminder = Reminder.valueOf(o.optString("reminder"));
-		a.room = RoomDTO.get(o.optJSONObject("room"));
-		a.icalId = o.optString("icalId");
-		JSONArray mm = o.optJSONArray("meetingMembers");
-		if (mm != null) {
-			for (int i = 0; i < mm.length(); ++i) {
-				a.meetingMembers.add(MeetingMemberDTO.get(mm.getJSONObject(i)));
-			}
-		}
-		a.languageId = o.optLong("languageId");
-		a.password = o.optString("password");
-		a.passwordProtected = o.optBoolean("passwordProtected");
-		a.connectedEvent = o.optBoolean("connectedEvent");
-		a.reminderEmailSend = o.optBoolean("reminderEmailSend");
-		return a;
-	}
-
 	@Override
 	public String toString() {
-		return new JSONObject(this)
-			.put("start", ISO8601_FORMAT.format(start))
-			.put("end", ISO8601_FORMAT.format(end))
-			.put("inserted", ISO8601_FORMAT.format(inserted))
-			.put("updated", ISO8601_FORMAT.format(updated))
-			.toString();
+		return new JSONObject(this).toString();
 	}
 }

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-util/src/main/java/org/apache/openmeetings/util/CalendarPatterns.java
----------------------------------------------------------------------
diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/CalendarPatterns.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/CalendarPatterns.java
index e74020d..84da5df 100644
--- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/CalendarPatterns.java
+++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/CalendarPatterns.java
@@ -41,9 +41,13 @@ public class CalendarPatterns {
 	public static final FastDateFormat dateFormat__yyyyMMddHHmmss = FastDateFormat.getInstance("yyyy.MM.dd HH:mm:ss");
 	public static final FastDateFormat STREAM_DATE_FORMAT = FastDateFormat.getInstance("yyyy_MM_dd_HH_mm_ss");
 	public static final String FULL_DF_PATTERN = "dd.MM.yyyy HH:mm:ss z (Z)";
-	public static final String ISO8601_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ssZ";
+	public static final String ISO8601_FULL_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ssZ";
+	public static final String ISO8601_DATETIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";
+	public static final String ISO8601_DATE_FORMAT_STRING = "yyyy-MM-dd";
 	public static final FastDateFormat FULL_DATE_FORMAT = FastDateFormat.getInstance(FULL_DF_PATTERN);
-	public static final FastDateFormat ISO8601_FORMAT = FastDateFormat.getInstance(ISO8601_FORMAT_STRING);
+	public static final FastDateFormat ISO8601_FULL_FORMAT = FastDateFormat.getInstance(ISO8601_FULL_FORMAT_STRING);
+	public static final FastDateFormat ISO8601_DATETIME_FORMAT = FastDateFormat.getInstance(ISO8601_DATETIME_FORMAT_STRING);
+	public static final FastDateFormat ISO8601_DATE_FORMAT = FastDateFormat.getInstance(ISO8601_DATE_FORMAT_STRING);
 
 	public static String getDateByMiliSeconds(Date t) {
 		return dateFormat__yyyyMMddHHmmss.format(t);

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/WebSession.java
----------------------------------------------------------------------
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/WebSession.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/WebSession.java
index dd7d2c0..9bd0757 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/WebSession.java
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/WebSession.java
@@ -19,7 +19,7 @@
 package org.apache.openmeetings.web.app;
 
 import static java.text.DateFormat.SHORT;
-import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_FORMAT_STRING;
+import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_FULL_FORMAT_STRING;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DASHBOARD_SHOW_MYROOMS_KEY;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DASHBOARD_SHOW_RSS_KEY;
 import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DEFAULT_LANG_KEY;
@@ -311,7 +311,7 @@ public class WebSession extends AbstractAuthenticatedWebSession implements IWebS
 		languageId = u.getLanguageId();
 		externalType = u.getExternalType();
 		tz = getBean(TimezoneUtil.class).getTimeZone(u);
-		ISO8601FORMAT = FastDateFormat.getInstance(ISO8601_FORMAT_STRING, tz);
+		ISO8601FORMAT = FastDateFormat.getInstance(ISO8601_FULL_FORMAT_STRING, tz);
 		setLocale(getLocale(u));
 		sdf = FastDateFormat.getDateTimeInstance(SHORT, SHORT, getLocale());
 	}

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings-applicationContext.xml
----------------------------------------------------------------------
diff --git a/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings-applicationContext.xml b/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings-applicationContext.xml
index 18808ff..f073274 100644
--- a/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings-applicationContext.xml
+++ b/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings-applicationContext.xml
@@ -283,6 +283,9 @@
 			<ref bean="userWebService"/>
 			<ref bean="netTestWebService"/> <!-- JaxRs only -->
 		</jaxrs:serviceBeans>
+		<jaxrs:providers>
+			<bean id="omParamProvider" class="org.apache.openmeetings.webservice.util.OmParamConverterProvider"/>
+		</jaxrs:providers>
 	</jaxrs:server>
 	<jaxws:endpoint id="calendarServiceWS" address="/CalendarService" implementor="#calendarWebService"/>
 	<jaxws:endpoint id="errorServiceWS" address="/ErrorService" implementor="#errorWebService" />

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/AppointmentParamConverter.java
----------------------------------------------------------------------
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/AppointmentParamConverter.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/AppointmentParamConverter.java
new file mode 100644
index 0000000..76f69fc
--- /dev/null
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/AppointmentParamConverter.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.webservice.util;
+
+import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_FULL_FORMAT;
+
+import javax.ws.rs.ext.ParamConverter;
+
+import org.apache.openmeetings.db.dto.calendar.AppointmentDTO;
+import org.apache.openmeetings.db.dto.calendar.MeetingMemberDTO;
+import org.apache.openmeetings.db.dto.room.RoomDTO;
+import org.apache.openmeetings.db.dto.user.UserDTO;
+import org.apache.openmeetings.db.entity.calendar.Appointment.Reminder;
+import org.apache.wicket.ajax.json.JSONArray;
+import org.apache.wicket.ajax.json.JSONObject;
+
+public class AppointmentParamConverter implements ParamConverter<AppointmentDTO> {
+	@Override
+	public AppointmentDTO fromString(String val) {
+		JSONObject o = new JSONObject(val);
+		AppointmentDTO a = new AppointmentDTO();
+		a.setId(o.optLong("id"));
+		a.setTitle(o.optString("title"));
+		a.setLocation(o.optString("location"));
+		a.setOwner(UserDTO.get(o.optJSONObject("owner")));
+		a.setStart(CalendarParamConverter.get(o.optString("start"), a.getOwner().getTimeZoneId()));
+		a.setEnd(CalendarParamConverter.get(o.optString("end"), a.getOwner().getTimeZoneId()));
+		a.setDescription(o.optString("description"));
+		a.setInserted(DateParamConverter.get(o.optString("inserted")));
+		a.setInserted(DateParamConverter.get(o.optString("updated")));
+		a.setDeleted(o.optBoolean("inserted"));
+		a.setReminder(Reminder.valueOf(o.optString("reminder")));
+		a.setRoom(RoomDTO.get(o.optJSONObject("room")));
+		a.setIcalId(o.optString("icalId"));
+		JSONArray mm = o.optJSONArray("meetingMembers");
+		if (mm != null) {
+			for (int i = 0; i < mm.length(); ++i) {
+				a.getMeetingMembers().add(MeetingMemberDTO.get(mm.getJSONObject(i)));
+			}
+		}
+		a.setLanguageId(o.optLong("languageId"));
+		a.setPassword(o.optString("password"));
+		a.setPasswordProtected(o.optBoolean("passwordProtected"));
+		a.setConnectedEvent(o.optBoolean("connectedEvent"));
+		a.setReminderEmailSend(o.optBoolean("reminderEmailSend"));
+		return a;
+	}
+
+	@Override
+	public String toString(AppointmentDTO val) {
+		return new JSONObject(this)
+				.put("start", ISO8601_FULL_FORMAT.format(val.getStart()))
+				.put("end", ISO8601_FULL_FORMAT.format(val.getEnd()))
+				.put("inserted", ISO8601_FULL_FORMAT.format(val.getInserted()))
+				.put("updated", ISO8601_FULL_FORMAT.format(val.getUpdated()))
+				.toString();
+	}
+}

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/CalendarParamConverter.java
----------------------------------------------------------------------
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/CalendarParamConverter.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/CalendarParamConverter.java
new file mode 100644
index 0000000..0f0ff70
--- /dev/null
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/CalendarParamConverter.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.webservice.util;
+
+import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_FULL_FORMAT;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import javax.ws.rs.ext.ParamConverter;
+
+public class CalendarParamConverter implements ParamConverter<Calendar> {
+	public static Calendar get(String val, String tzId) {
+		Calendar c = Calendar.getInstance(TimeZone.getTimeZone(tzId));
+		c.setTime(DateParamConverter.get(val));
+		return c;
+	}
+
+	@Override
+	public Calendar fromString(String val) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(DateParamConverter.get(val));
+		return c;
+	}
+
+	@Override
+	public String toString(Calendar val) {
+		return ISO8601_FULL_FORMAT.format(val);
+	}
+}

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/DateParamConverter.java
----------------------------------------------------------------------
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/DateParamConverter.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/DateParamConverter.java
new file mode 100644
index 0000000..f0411cd
--- /dev/null
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/DateParamConverter.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.webservice.util;
+
+import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_DATETIME_FORMAT;
+import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_DATE_FORMAT;
+import static org.apache.openmeetings.util.CalendarPatterns.ISO8601_FULL_FORMAT;
+
+import java.text.ParseException;
+import java.util.Date;
+
+import javax.ws.rs.ext.ParamConverter;
+
+import org.apache.commons.lang3.time.FastDateFormat;
+
+public class DateParamConverter implements ParamConverter<Date> {
+	private final static FastDateFormat[] formats = new FastDateFormat[] { ISO8601_FULL_FORMAT, ISO8601_DATETIME_FORMAT, ISO8601_DATE_FORMAT };
+
+	static Date get(String val) {
+		for (FastDateFormat df : formats) {
+			try {
+				return df.parse(val);
+			} catch (ParseException e) {
+				// no-op
+			}
+		}
+		throw new IllegalArgumentException("Unparsable format");
+	}
+
+	@Override
+	public Date fromString(String val) {
+		return get(val);
+	}
+
+	@Override
+	public String toString(Date val) {
+		return ISO8601_FULL_FORMAT.format(val);
+	}
+}

http://git-wip-us.apache.org/repos/asf/openmeetings/blob/1e406fcd/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/OmParamConverterProvider.java
----------------------------------------------------------------------
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/OmParamConverterProvider.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/OmParamConverterProvider.java
new file mode 100644
index 0000000..2432e84
--- /dev/null
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/util/OmParamConverterProvider.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.webservice.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
+
+import org.apache.openmeetings.db.dto.calendar.AppointmentDTO;
+
+public class OmParamConverterProvider implements ParamConverterProvider {
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
+		if (Calendar.class.isAssignableFrom(rawType)) {
+			return (ParamConverter<T>)new CalendarParamConverter();
+		} else if (Date.class.isAssignableFrom(rawType)) {
+			return (ParamConverter<T>)new DateParamConverter();
+		} else if (AppointmentDTO.class.isAssignableFrom(rawType)) {
+			return (ParamConverter<T>)new DateParamConverter();
+		}
+		return null;
+	}
+}