Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6FD5D200B57 for ; Sat, 6 Aug 2016 14:51:33 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6E4CB160A89; Sat, 6 Aug 2016 12:51:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8F745160A77 for ; Sat, 6 Aug 2016 14:51:32 +0200 (CEST) Received: (qmail 23737 invoked by uid 500); 6 Aug 2016 12:51:31 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 23728 invoked by uid 99); 6 Aug 2016 12:51:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Aug 2016 12:51:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6228E78B2; Sat, 6 Aug 2016 12:51:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gnagar@apache.org To: commits@ambari.apache.org Message-Id: <90e0376a43c3466db0b7f55849e97e7e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: Revert "AMBARI-18045. Pig view - Pig script creation fails.(gauravn7)" Date: Sat, 6 Aug 2016 12:51:31 +0000 (UTC) archived-at: Sat, 06 Aug 2016 12:51:33 -0000 Repository: ambari Updated Branches: refs/heads/trunk 61b37d815 -> e5d35e752 Revert "AMBARI-18045. Pig view - Pig script creation fails.(gauravn7)" This reverts commit 61b37d815b77fa9d9946db62190e724ca6cdfbbd. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e5d35e75 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e5d35e75 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e5d35e75 Branch: refs/heads/trunk Commit: e5d35e752448a9c40e73bc0b7d21b3ccc1846da0 Parents: 61b37d8 Author: Gaurav Nagar Authored: Sat Aug 6 18:21:07 2016 +0530 Committer: Gaurav Nagar Committed: Sat Aug 6 18:21:07 2016 +0530 ---------------------------------------------------------------------- .../ambari/server/api/DateJsonDeserializer.java | 93 -------------------- .../ambari/server/api/GsonJsonProvider.java | 4 +- .../ambari/server/api/TestDateDeserializer.java | 89 ------------------- 3 files changed, 1 insertion(+), 185 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e5d35e75/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java b/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java deleted file mode 100644 index 69fed88..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.ambari.server.api; - - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSyntaxException; -import com.google.gson.internal.bind.util.ISO8601Utils; - -import java.lang.reflect.Type; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -/** - * Custom deserializer for date conversion. - * This will support following formats: - *
    - *
  • Epoch
  • - *
  • Local Date
  • - *
  • US Date
  • - *
  • ISO8601 Date
  • - *
- */ -public class DateJsonDeserializer implements JsonDeserializer { - - /** - * Date Format for US Date. - */ - private static final DateFormat EN_US_FORMAT = DateFormat.getDateTimeInstance(2, 2, Locale.US); - - /** - * Date Format for local Date - */ - private static final DateFormat LOCAL_FORMAT = DateFormat.getDateTimeInstance(2, 2); - - @Override - public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - if (json.isJsonNull()) { - return null; - } - - return deserializeToDate(json); - } - - /** - * Convert {@link JsonElement} to {@link Date} object - * - * @param json - * @return - * @throws JsonSyntaxException - */ - private synchronized Date deserializeToDate(JsonElement json) throws JsonSyntaxException { - try { - return new Date(json.getAsJsonPrimitive().getAsLong()); - } catch (Exception ex1) { - try { - return LOCAL_FORMAT.parse(json.getAsJsonPrimitive().getAsString()); - } catch (ParseException ex2) { - try { - return EN_US_FORMAT.parse(json.getAsJsonPrimitive().getAsString()); - } catch (ParseException ex3) { - try { - return ISO8601Utils.parse(json.getAsJsonPrimitive().getAsString(), new ParsePosition(0)); - } catch (ParseException ex4) { - throw new JsonSyntaxException(json.getAsJsonPrimitive().getAsString(), ex4); - } - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e5d35e75/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java index 53f07f9..8ba9ff7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java @@ -35,7 +35,6 @@ import javax.ws.rs.ext.Provider; import java.io.*; import java.lang.annotation.Annotation; import java.lang.reflect.Type; -import java.util.Date; @Provider @Consumes({MediaType.APPLICATION_JSON, "text/json"}) @@ -47,8 +46,7 @@ public class GsonJsonProvider implements MessageBodyReader, static final Gson gson = new GsonBuilder() // .setPrettyPrinting() - .registerTypeAdapter(Date.class, new DateJsonDeserializer()) - .create(); + .create(); @Override public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { http://git-wip-us.apache.org/repos/asf/ambari/blob/e5d35e75/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java b/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java deleted file mode 100644 index 244094a..0000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.ambari.server.api; - -import com.google.gson.Gson; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSyntaxException; -import com.google.gson.internal.bind.util.ISO8601Utils; -import org.junit.Test; -import org.mockito.Mockito; - -import java.lang.reflect.Type; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -import static org.junit.Assert.assertEquals; - -public class TestDateDeserializer { - - Gson gson = new Gson(); - DateJsonDeserializer deserializer = new DateJsonDeserializer(); - - @Test - public void testDeserializeWithEpochDate() { - String date = "1470301497"; - assertEquals(parseDate(date), new Date(1470301497)); - } - - @Test - public void testDeserializeWithLocalDate() throws ParseException { - String date = "12 Aug, 2016 11:02:47 PM"; - assertEquals(parseDate(date), DateFormat.getDateTimeInstance(2, 2).parse(date)); - } - - @Test - public void testDeserializeWithUSDate() throws ParseException { - String date = "Aug 12, 2016 11:01:21 PM"; - assertEquals(parseDate(date), DateFormat.getDateTimeInstance(2, 2, Locale.US).parse(date)); - } - - @Test - public void testDeserializeWithISODate() throws ParseException { - String dateString = "2016-07-07T15:15:15Z"; - assertEquals(parseDate(dateString), ISO8601Utils.parse(dateString, new ParsePosition(0))); - } - - @Test(expected = JsonSyntaxException.class) - public void testDeserializeWithInvalidDate() { - String date = "nopattern"; - parseDate(date); - } - - @Test - public void testDeserializeWithNullDate() { - String json = "{\"date\" : null}"; - JsonElement jsonDate = new JsonParser().parse(json).getAsJsonObject().get("date"); - Date date = deserializer.deserialize(jsonDate, - Mockito.mock(Type.class), Mockito.mock(JsonDeserializationContext.class)); - assertEquals(date, null); - } - - private Date parseDate(String date) { - return deserializer.deserialize(new JsonPrimitive(date), - Mockito.mock(Type.class), Mockito.mock(JsonDeserializationContext.class)); - } -}