generated from axonivy-market/market-product
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cdb75d
commit d21ea94
Showing
4 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...alyser/src/com/axonivy/solutions/process/analyser/converter/DateCustomFieldConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.axonivy.solutions.process.analyser.converter; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.faces.application.FacesMessage; | ||
import javax.faces.component.UIComponent; | ||
import javax.faces.context.FacesContext; | ||
import javax.faces.convert.Converter; | ||
import javax.faces.convert.ConverterException; | ||
import javax.faces.convert.FacesConverter; | ||
|
||
import ch.ivyteam.ivy.environment.Ivy; | ||
|
||
@FacesConverter("dateCustomFieldConverter") | ||
public class DateCustomFieldConverter implements Converter { | ||
@Override | ||
public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException { | ||
Ivy.log().warn("stringValue " + value); | ||
if (value == null || value.trim().isEmpty()) { | ||
return null; | ||
} | ||
|
||
try { | ||
String[] dateRange = value.split(","); | ||
Ivy.log().warn("dateRange " + dateRange.length); | ||
if (dateRange.length == 1) { | ||
Ivy.log().warn("here "); | ||
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Selection", | ||
"Please select either no dates or two dates.")); | ||
} | ||
|
||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); | ||
List<LocalDate> dateList = | ||
Arrays.stream(dateRange).map(date -> LocalDate.parse(date.trim(), formatter)).collect(Collectors.toList()); | ||
|
||
return dateList; | ||
|
||
} catch (Exception e) { | ||
throw new ConverterException( | ||
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Invalid date format")); | ||
} | ||
} | ||
|
||
@Override | ||
public String getAsString(FacesContext context, UIComponent component, Object value) { | ||
Ivy.log().warn("value " + value); | ||
if (value == null) { | ||
return ""; | ||
} | ||
|
||
if (value instanceof List) { | ||
List<?> dateList = (List<?>) value; | ||
return dateList.stream().map(Object::toString).collect(Collectors.joining(", ")); | ||
} | ||
throw new ConverterException( | ||
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Invalid date object.")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters