2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.analytics.model.runtime;
40 import java.text.DateFormat;
41 import java.text.ParseException;
42 import java.text.SimpleDateFormat;
44 import javax.servlet.http.*;
46 import org.onap.portalsdk.analytics.model.base.*;
47 import org.onap.portalsdk.analytics.system.Globals;
48 import org.onap.portalsdk.analytics.util.*;
49 import org.onap.portalsdk.analytics.xmlobj.*;
51 public class ReportParamDateValueParser {
53 /*public static final SimpleDateFormat[] dateFormats;
56 dateFormats = new SimpleDateFormat[5];
57 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
59 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
61 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
63 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
65 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
69 public static boolean isDateHrParam(String param) {
70 SimpleDateFormat[] dateFormats = new SimpleDateFormat[2];
71 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR))
73 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR))
75 for (int i = 0; i < dateFormats.length; i++) {
77 if (dateFormats[i].parse(param) != null) {
80 } catch (ParseException pe) {
81 // do nothing, continue to check param against other dates
83 catch (NumberFormatException pe) {
84 // do nothing, continue to check param against other dates
89 public static boolean isDateParam(String param) {
90 SimpleDateFormat[] dateFormats = new SimpleDateFormat[5];
91 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
93 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
95 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
97 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
99 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
102 for (int i = 0; i < dateFormats.length; i++) {
104 if (dateFormats[i].parse(param) != null) {
107 } catch (ParseException pe) {
108 // do nothing, continue to check param against other dates
110 catch (NumberFormatException pe) {
111 // do nothing, continue to check param against other dates
117 public static String formatDateParamValue(String param) {
118 return ReportParamDateValueParser.formatDateParamValue(param, null);
121 public static String formatDateHrParamValue(String param) {
122 return ReportParamDateValueParser.formatDateHrParamValue(param, null);
125 public static String formatDateHrParamValue(String param, String dateHrFormatPattern) {
126 String formattedDate = null;
127 Date parsedDate = null;
129 dateHrFormatPattern = (dateHrFormatPattern != null) ? dateHrFormatPattern
132 SimpleDateFormat[] dateFormats = new SimpleDateFormat[2];
133 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR))
135 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR))
138 for (int i = 0; i < dateFormats.length; i++) {
140 if (dateFormats[i].parse(param) != null) {
141 SimpleDateFormat newDateFormat = new SimpleDateFormat(dateHrFormatPattern);
142 parsedDate = dateFormats[i].parse(param);
143 formattedDate = newDateFormat.format(parsedDate);
146 return formattedDate;
148 } catch (ParseException pe) {
149 // do nothing, continue to check param against other dates and
150 // format accordingly
152 catch (NumberFormatException pe) {
153 // do nothing, continue to check param against other dates
160 public static String formatDateParamValue(String param, String dateFormatPattern) {
161 String formattedDate = null;
162 Date parsedDate = null;
164 dateFormatPattern = (dateFormatPattern != null) ? dateFormatPattern
165 : AppConstants.JAVA_DATE_FORMAT_MMDDYYYY;
167 SimpleDateFormat[] dateFormats = new SimpleDateFormat[5];
168 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
170 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
172 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
174 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
176 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
179 for (int i = 0; i < dateFormats.length; i++) {
181 if (dateFormats[i].parse(param) != null) {
182 SimpleDateFormat newDateFormat = new SimpleDateFormat(dateFormatPattern);
183 parsedDate = dateFormats[i].parse(param);
184 formattedDate = newDateFormat.format(parsedDate);
186 if (Globals.getMonthFormatUseLastDay()
187 && (dateFormats[i].toPattern().equals(
188 AppConstants.JAVA_DATE_FORMAT_MMYYYY) || dateFormats[i]
190 AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))) {
192 GregorianCalendar gc = new GregorianCalendar();
193 gc.setTime(parsedDate);
194 int day = gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
195 formattedDate = Utils.replaceInString(formattedDate, "/01/", "/"
196 + String.valueOf(day) + "/");
200 return formattedDate;
202 } catch (ParseException pe) {
203 // do nothing, continue to check param against other dates and
204 // format accordingly
206 catch (NumberFormatException pe) {
207 // do nothing, continue to check param against other dates
213 } // ReportParamValues