comparison artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java @ 9419:a31cb674ddd1

Fixed year extraction from date and message format for the years without group digit
author mschaefer
date Fri, 17 Aug 2018 09:22:16 +0200
parents b534a4f4e4f6
children 7369d6ae3f87
comparison
equal deleted inserted replaced
9418:9fe26f525ae3 9419:a31cb674ddd1
16 import javax.xml.xpath.XPathConstants; 16 import javax.xml.xpath.XPathConstants;
17 17
18 import org.dive4elements.artifacts.CallMeta; 18 import org.dive4elements.artifacts.CallMeta;
19 import org.dive4elements.artifacts.GlobalContext; 19 import org.dive4elements.artifacts.GlobalContext;
20 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; 20 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
21 import org.dive4elements.artifacts.common.utils.DateUtils;
21 import org.dive4elements.artifacts.common.utils.XMLUtils; 22 import org.dive4elements.artifacts.common.utils.XMLUtils;
22 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; 23 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
23 import org.dive4elements.river.artifacts.resources.Resources; 24 import org.dive4elements.river.artifacts.resources.Resources;
24 import org.dive4elements.river.artifacts.services.AbstractMainValuesService.MainValuesServiceException; 25 import org.dive4elements.river.artifacts.services.AbstractMainValuesService.MainValuesServiceException;
25 import org.dive4elements.river.model.Gauge; 26 import org.dive4elements.river.model.Gauge;
111 } 112 }
112 113
113 // common Range and correct errorMsg 114 // common Range and correct errorMsg
114 final List<GaugeInfoResult.GaugeInfo> gaugeResultsSecondTurn = new ArrayList<>(); 115 final List<GaugeInfoResult.GaugeInfo> gaugeResultsSecondTurn = new ArrayList<>();
115 for (final GaugeInfoResult.GaugeInfo gi : gaugeResults) { 116 for (final GaugeInfoResult.GaugeInfo gi : gaugeResults) {
116 gaugeResultsSecondTurn 117 gaugeResultsSecondTurn.add(new GaugeInfoResult.GaugeInfo(gi.errorMsg, gi.gauge, gi.startdate != null ? min : null,
117 .add(new GaugeInfoResult.GaugeInfo(gi.errorMsg, gi.gauge, gi.startdate != null ? min : null, gi.enddate != null ? max : null)); 118 gi.enddate != null ? max : null));
118 } 119 }
119 if (globalErrorMsg.isEmpty() && (min.getTime() > max.getTime())) 120 if (globalErrorMsg.isEmpty() && (min.getTime() > max.getTime()))
120 globalErrorMsg = getMsg(meta, "bundu.wst.gauge_timeranges_disjoint"); 121 globalErrorMsg = getMsg(meta, "bundu.wst.gauge_timeranges_disjoint");
121 final GaugeInfoResult result = new GaugeInfoResult(gaugeResultsSecondTurn, globalErrorMsg); 122 final GaugeInfoResult result = new GaugeInfoResult(gaugeResultsSecondTurn, globalErrorMsg);
122 123
123 return result; 124 return result;
124 } 125 }
125 126
126 private String makeDoesNotCoverErrorMsg(final Date start, final Date end, final CallMeta meta) { 127 private String makeDoesNotCoverErrorMsg(final Date start, final Date end, final CallMeta meta) {
127 final Calendar cal = Calendar.getInstance(); 128 final String msgkey = "bundu.wst.range_does_not_cover";
128 return Resources.getMsg(meta, "bundu.wst.range_does_not_cover", new Object[] { getYear(start, cal), getYear(end, cal) }); 129 return Resources.getMsg(meta, msgkey, msgkey, DateUtils.getYearFromDate(start), DateUtils.getYearFromDate(end));
129 }
130
131 private String getYear(final Date d, final Calendar cal) {
132 return String.valueOf(cal.get(Calendar.YEAR));
133 } 130 }
134 131
135 @Override 132 @Override
136 public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) { 133 public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
137 try { 134 try {

http://dive4elements.wald.intevation.org