2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.model.runtime;
22 import java.text.DateFormat;
23 import java.text.ParseException;
24 import java.text.SimpleDateFormat;
26 import javax.servlet.http.*;
28 import org.openecomp.portalsdk.analytics.model.base.*;
29 import org.openecomp.portalsdk.analytics.system.Globals;
30 import org.openecomp.portalsdk.analytics.util.*;
31 import org.openecomp.portalsdk.analytics.xmlobj.*;
33 public class ReportParamDateValueParser {
35 /*public static final SimpleDateFormat[] dateFormats;
38 dateFormats = new SimpleDateFormat[5];
39 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
41 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
43 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
45 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
47 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
51 public static boolean isDateHrParam(String param) {
52 SimpleDateFormat[] dateFormats = new SimpleDateFormat[2];
53 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR))
55 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR))
57 for (int i = 0; i < dateFormats.length; i++) {
59 if (dateFormats[i].parse(param) != null) {
62 } catch (ParseException pe) {
63 // do nothing, continue to check param against other dates
65 catch (NumberFormatException pe) {
66 // do nothing, continue to check param against other dates
71 public static boolean isDateParam(String param) {
72 SimpleDateFormat[] dateFormats = new SimpleDateFormat[5];
73 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
75 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
77 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
79 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
81 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
84 for (int i = 0; i < dateFormats.length; i++) {
86 if (dateFormats[i].parse(param) != null) {
89 } catch (ParseException pe) {
90 // do nothing, continue to check param against other dates
92 catch (NumberFormatException pe) {
93 // do nothing, continue to check param against other dates
99 public static String formatDateParamValue(String param) {
100 return ReportParamDateValueParser.formatDateParamValue(param, null);
103 public static String formatDateHrParamValue(String param) {
104 return ReportParamDateValueParser.formatDateHrParamValue(param, null);
107 public static String formatDateHrParamValue(String param, String dateHrFormatPattern) {
108 String formattedDate = null;
109 Date parsedDate = null;
111 dateHrFormatPattern = (dateHrFormatPattern != null) ? dateHrFormatPattern
114 SimpleDateFormat[] dateFormats = new SimpleDateFormat[2];
115 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR))
117 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR))
120 for (int i = 0; i < dateFormats.length; i++) {
122 if (dateFormats[i].parse(param) != null) {
123 SimpleDateFormat newDateFormat = new SimpleDateFormat(dateHrFormatPattern);
124 parsedDate = dateFormats[i].parse(param);
125 formattedDate = newDateFormat.format(parsedDate);
128 return formattedDate;
130 } catch (ParseException pe) {
131 // do nothing, continue to check param against other dates and
132 // format accordingly
134 catch (NumberFormatException pe) {
135 // do nothing, continue to check param against other dates
142 public static String formatDateParamValue(String param, String dateFormatPattern) {
143 String formattedDate = null;
144 Date parsedDate = null;
146 dateFormatPattern = (dateFormatPattern != null) ? dateFormatPattern
147 : AppConstants.JAVA_DATE_FORMAT_MMDDYYYY;
149 SimpleDateFormat[] dateFormats = new SimpleDateFormat[5];
150 (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))
152 (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY))
154 (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY))
156 (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY))
158 (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY))
161 for (int i = 0; i < dateFormats.length; i++) {
163 if (dateFormats[i].parse(param) != null) {
164 SimpleDateFormat newDateFormat = new SimpleDateFormat(dateFormatPattern);
165 parsedDate = dateFormats[i].parse(param);
166 formattedDate = newDateFormat.format(parsedDate);
168 if (Globals.getMonthFormatUseLastDay()
169 && (dateFormats[i].toPattern().equals(
170 AppConstants.JAVA_DATE_FORMAT_MMYYYY) || dateFormats[i]
172 AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))) {
174 GregorianCalendar gc = new GregorianCalendar();
175 gc.setTime(parsedDate);
176 int day = gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
177 formattedDate = Utils.replaceInString(formattedDate, "/01/", "/"
178 + String.valueOf(day) + "/");
182 return formattedDate;
184 } catch (ParseException pe) {
185 // do nothing, continue to check param against other dates and
186 // format accordingly
188 catch (NumberFormatException pe) {
189 // do nothing, continue to check param against other dates
195 } // ReportParamValues