From 04147ac22a8384ec8989100ec4954af4374ceaa9 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Tue, 2 Aug 2016 11:26:05 -0400 Subject: [PATCH] NIFI-2458: - Fixing issue with timezone when the initial provenance result was cancelled. This closes #773. Signed-off-by: Bryan Bende --- .../org/apache/nifi/web/api/dto/AboutDTO.java | 20 ++++++++ .../web/api/dto/util/TimezoneAdapter.java | 46 +++++++++++++++++++ .../org/apache/nifi/web/api/FlowResource.java | 1 + .../js/nf/provenance/nf-provenance-table.js | 3 -- .../webapp/js/nf/provenance/nf-provenance.js | 3 ++ 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimezoneAdapter.java diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java index fca8d96558..72840d018e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AboutDTO.java @@ -17,8 +17,11 @@ package org.apache.nifi.web.api.dto; import com.wordnik.swagger.annotations.ApiModelProperty; +import org.apache.nifi.web.api.dto.util.TimezoneAdapter; import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Date; /** * Contains details about this NiFi including the title and version. @@ -31,6 +34,7 @@ public class AboutDTO { private String uri; private String contentViewerUrl; + private Date timezone; /* getters / setters */ /** @@ -92,4 +96,20 @@ public class AboutDTO { public void setContentViewerUrl(String contentViewerUrl) { this.contentViewerUrl = contentViewerUrl; } + + /** + * @return the timezone of the NiFi instance + */ + @XmlJavaTypeAdapter(TimezoneAdapter.class) + @ApiModelProperty( + value = "The timezone of the NiFi instance.", + readOnly = true + ) + public Date getTimezone() { + return timezone; + } + + public void setTimezone(Date timezone) { + this.timezone = timezone; + } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimezoneAdapter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimezoneAdapter.java new file mode 100644 index 0000000000..391da8994a --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/TimezoneAdapter.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.nifi.web.api.dto.util; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +/** + * XmlAdapter for (un)marshalling a date/time. + */ +public class TimezoneAdapter extends XmlAdapter { + + public static final String DEFAULT_DATE_TIME_FORMAT = "z"; + + @Override + public String marshal(Date date) throws Exception { + final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT, Locale.US); + formatter.setTimeZone(TimeZone.getDefault()); + return formatter.format(date); + } + + @Override + public Date unmarshal(String date) throws Exception { + final SimpleDateFormat parser = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT, Locale.US); + parser.setTimeZone(TimeZone.getDefault()); + return parser.parse(date); + } + +} diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java index 6cb29d0684..e48bdc3a69 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java @@ -1075,6 +1075,7 @@ public class FlowResource extends ApplicationResource { aboutDTO.setTitle("NiFi"); aboutDTO.setVersion(getProperties().getUiTitle()); aboutDTO.setUri(generateResourceUri()); + aboutDTO.setTimezone(new Date()); // get the content viewer url aboutDTO.setContentViewerUrl(getProperties().getProperty(NiFiProperties.CONTENT_VIEWER_URL)); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-table.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-table.js index c0bdb96c52..2eb6e02f4a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-table.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-table.js @@ -960,9 +960,6 @@ nf.ng.ProvenanceTable = function (provenanceLineageCtrl) { // update the oldest event available $('#oldest-event').html(nf.Common.formatValue(provenanceResults.oldestEvent)); - // set the timezone for the start and end time - $('.timezone').text(nf.Common.substringAfterLast(provenanceResults.generated, ' ')); - // record the server offset provenanceTableCtrl.serverTimeOffset = provenanceResults.timeOffset; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance.js index 0c691730b8..9a7d3833d4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance.js @@ -94,6 +94,9 @@ nf.ng.Provenance = function (provenanceTableCtrl) { // store the controller name $('#nifi-controller-uri').text(aboutDetails.uri); + // set the timezone for the start and end time + $('.timezone').text(aboutDetails.timezone); + // store the content viewer url if available if (!nf.Common.isBlank(aboutDetails.contentViewerUrl)) { $('#nifi-content-viewer-url').text(aboutDetails.contentViewerUrl);