This is an automated email from the git hooks/post-receive script. New commit to branch feature/component_choice_editor in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 8463c379e06ef9502789a273adb7f61c265c7454 Author: Kevin Morin <morin@codelutin.com> Date: Thu Mar 9 16:38:00 2017 +0100 modification du parsing des dates : maintenant on attend le timestamp pour les types date et datetime --- .../chorem/pollen/services/bean/ChoiceBean.java | 54 +--------------------- .../pollen/services/service/ChoiceService.java | 49 ++++++-------------- 2 files changed, 16 insertions(+), 87 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java index 6a68116..61df736 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java @@ -51,37 +51,13 @@ public class ChoiceBean extends PollenBean<Choice> { @Override public void fromEntity(Choice entity) { - setEntityId(entity.getTopiaId()); if (entity.getCreator() == null || entity.getCreator().getPermission() == null) { - setPermission(null); - } else { - setPermission(entity.getCreator().getPermission().getToken()); - - } - - - //TODO agarandel 17/07/14 : review code : is switch case required - switch (entity.getChoiceType()) { - - case TEXT: - case DATE: - - setChoiceValue(entity.getChoiceValue()); - break; - - case RESOURCE: - - setChoiceValue(entity.getChoiceValue()); - break; - - default: - throw new UnsupportedOperationException("Unexpected value : " + entity.getChoiceType()); } - + setChoiceValue(entity.getChoiceValue()); setDescription(entity.getDescription()); setChoiceType(entity.getChoiceType()); setChoiceOrder(entity.getChoiceOrder()); @@ -90,35 +66,9 @@ public class ChoiceBean extends PollenBean<Choice> { @Override public Choice toEntity() { - Choice entity = new ChoiceImpl(); - entity.setTopiaId(getEntityId()); - - ChoiceType choiceType = getChoiceType(); - if (choiceType != null) { - - //TODO agarandel 17/07/14 : review code : is switch case required - switch (choiceType) { - case TEXT: - entity.setChoiceValue(getChoiceValue()); - - break; - - case DATE: - case RESOURCE: - - if (getChoiceValue() != null) { - entity.setChoiceValue(getChoiceValue()); - } - - break; - - default: - throw new UnsupportedOperationException("Unexpected value : " + choiceType); - } - } - + entity.setChoiceValue(getChoiceValue()); entity.setDescription(getDescription()); entity.setChoiceType(getChoiceType()); entity.setChoiceOrder(getChoiceOrder()); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java index 424f59a..ef396dc 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java @@ -33,9 +33,7 @@ import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.PollenEntityRef; import org.chorem.pollen.services.service.security.PermissionVerb; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.util.Calendar; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -51,9 +49,6 @@ import static org.nuiton.i18n.I18n.l; public class ChoiceService extends PollenServiceSupport { - private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("YYYY-MM-dd"); - private static final SimpleDateFormat DAY_TIME_FORMAT = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm"); - protected final Function<ChoiceBean, ChoiceBean> choiceBeanFunction = input -> { if (isNotPermitted(PermissionVerb.editChoice, input.getEntityId())) { input.setPermission(null); @@ -228,23 +223,10 @@ public class ChoiceService extends PollenServiceSupport { toSave.setChoiceType(choice.getChoiceType()); - //TODO agarandel 17/07/14 : review code : is switch case required - switch (toSave.getChoiceType()) { - - case TEXT: - case DATE: - - toSave.setChoiceValue(choice.getChoiceValue()); - break; - - case RESOURCE: - - toSave.setChoiceValue(getPollenResourceService().getTopiaIdByReduceId(choice.getChoiceValue())); - break; - - default: - throw new UnsupportedOperationException("Unexpected value : " + toSave.getChoiceType()); - + if (ChoiceType.RESOURCE.equals(toSave.getChoiceType())) { + toSave.setChoiceValue(getPollenResourceService().getTopiaIdByReduceId(choice.getChoiceValue())); + } else { + toSave.setChoiceValue(choice.getChoiceValue()); } toSave.setDescription(choice.getDescription()); @@ -300,20 +282,18 @@ public class ChoiceService extends PollenServiceSupport { } break; - case DATE: - Date choiceDate = null; + case DATE: + case DATETIME: + Calendar choiceDate = null; if (choice.getChoiceValue() != null) { try { - choiceDate = DAY_FORMAT.parse(choice.getChoiceValue()); - - } catch (ParseException e) { - try { - choiceDate = DAY_TIME_FORMAT.parse(choice.getChoiceValue()); - } catch (ParseException e1) { - e1.printStackTrace(); - check(errors, "choiceValue", false, l(getLocale(), "pollen.error.choice.choiceDateInvalid", choice.getChoiceValue())); - } + choiceDate = Calendar.getInstance(); + choiceDate.setTimeInMillis(Long.parseLong(choice.getChoiceValue())); + + } catch (NumberFormatException e) { + e.printStackTrace(); + check(errors, "choiceValue", false, l(getLocale(), "pollen.error.choice.choiceDateInvalid", choice.getChoiceValue())); } if (choiceDate != null) { boolean dateAdded = choiceNames.add(String.valueOf(choiceDate.getTime())); @@ -323,7 +303,6 @@ public class ChoiceService extends PollenServiceSupport { } else { check(errors, "choiceValue", false, l(getLocale(), "pollen.error.choice.choiceDateEmpty")); } - break; case RESOURCE: -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.