Repository: incubator-streams Updated Branches: refs/heads/master eba589bfa -> c8e56dc55
new classes needed for juneau rest proxy across all providers Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/c8e56dc5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/c8e56dc5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/c8e56dc5 Branch: refs/heads/master Commit: c8e56dc55b5d8a8a14ec3b13ccd3e788db8eae77 Parents: eba589b Author: Steve Blackmon <sblack...@apache.org> Authored: Sat Jun 10 13:48:57 2017 -0500 Committer: Steve Blackmon <sblack...@apache.org> Committed: Sat Jun 10 13:55:41 2017 -0500 ---------------------------------------------------------------------- pom.xml | 21 +++++++ .../org/apache/streams/juneau/JodaDateSwap.java | 63 ++++++++++++++++++++ .../apache/streams/juneau/ListSerializer.java | 44 ++++++++++++++ 3 files changed, 128 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/c8e56dc5/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index f721b0d..96f1e5d 100644 --- a/pom.xml +++ b/pom.xml @@ -332,6 +332,7 @@ <jackson-xml-databind.version>0.6.2</jackson-xml-databind.version> <aalto.version>1.0.0</aalto.version> <joda-time.version>2.9.4</joda-time.version> + <juneau.version>6.2.1-incubating-SNAPSHOT</juneau.version> <rave.version>0.22</rave.version> <datastax.version>1.0.3</datastax.version> <jsonschema2pojo.version>0.4.10</jsonschema2pojo.version> @@ -988,6 +989,26 @@ <version>${httpcomponents.client.version}</version> </dependency> <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-core</artifactId> + <version>${juneau.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-core-rdf</artifactId> + <version>${juneau.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest</artifactId> + <version>${juneau.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest-client</artifactId> + <version>${juneau.version}</version> + </dependency> + <dependency> <groupId>com.typesafe</groupId> <artifactId>config</artifactId> <version>${typesafe.config.version}</version> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/c8e56dc5/streams-pojo/src/main/java/org/apache/streams/juneau/JodaDateSwap.java ---------------------------------------------------------------------- diff --git a/streams-pojo/src/main/java/org/apache/streams/juneau/JodaDateSwap.java b/streams-pojo/src/main/java/org/apache/streams/juneau/JodaDateSwap.java new file mode 100644 index 0000000..f716e25 --- /dev/null +++ b/streams-pojo/src/main/java/org/apache/streams/juneau/JodaDateSwap.java @@ -0,0 +1,63 @@ +/* + * 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 + * + * 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.streams.juneau; + +import org.apache.commons.lang3.StringUtils; +import org.apache.juneau.BeanSession; +import org.apache.juneau.ClassMeta; +import org.apache.juneau.parser.ParseException; +import org.apache.juneau.transform.StringSwap; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; + +/** + * Transforms {@link org.joda.time.DateTime} to {@link String Strings}. + */ +public class JodaDateSwap extends StringSwap<DateTime> { + + DateTimeFormatter dateFormatter; + + /** + * Constructor. + */ + public JodaDateSwap() { + dateFormatter = ISODateTimeFormat.dateTime(); + } + + @Override /* PojoSwap */ + public String swap(BeanSession session, DateTime o) { + DateTimeFormatter dateFormatter = this.dateFormatter; + if( StringUtils.isNotBlank(session.getProperty("format"))) { + dateFormatter = DateTimeFormat.forPattern(session.getProperty("format")); + } + return dateFormatter.print(o); + } + + @Override /* PojoSwap */ + public DateTime unswap(BeanSession session, String f, ClassMeta<?> hint) throws ParseException { + DateTimeFormatter dateFormatter = this.dateFormatter; + if( StringUtils.isNotBlank(session.getProperty("format"))) { + dateFormatter = DateTimeFormat.forPattern(session.getProperty("format")); + } + return dateFormatter.parseDateTime(f); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/c8e56dc5/streams-pojo/src/main/java/org/apache/streams/juneau/ListSerializer.java ---------------------------------------------------------------------- diff --git a/streams-pojo/src/main/java/org/apache/streams/juneau/ListSerializer.java b/streams-pojo/src/main/java/org/apache/streams/juneau/ListSerializer.java new file mode 100644 index 0000000..b85e49f --- /dev/null +++ b/streams-pojo/src/main/java/org/apache/streams/juneau/ListSerializer.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * 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.streams.juneau; + +import org.apache.commons.lang3.StringUtils; +import org.apache.juneau.serializer.PartSerializer; +import org.apache.juneau.serializer.PartType; + +import java.util.List; + +/** + * Serializes {@link java.util.List} as appropriately delimited {@link String Strings}. + */ +public class ListSerializer implements PartSerializer { + + @Override + public String serialize(PartType type, Object value) { + List list = (List) value; + if( list.size() > 0 ) { + if( type.equals(PartType.QUERY)) { + return StringUtils.join(list, ","); + } else if( type.equals(PartType.PATH)) { + return StringUtils.join(list, "/"); + } + } + return null; + } +}