public void showReasonForm(
     final StateChangeContext stateChangeContext, final ViewContextHolder viewContext) {
   final Entity order = stateChangeContext.getOwner();
   final Entity parameter = parameterService.getParameter();
   Long differenceForDateFrom = getEffectiveDateFromDifference(parameter, order);
   Long differenceForDateTo = getEffectiveDateToDifference(parameter, order);
   final Entity stateChangeEntity = stateChangeContext.getStateChangeEntity();
   String additionalInfoKey = null;
   String additionalInfo = null;
   // EFFECTIVE_DATE_FROM
   if (parameter.getBooleanField(ParameterFieldsO.REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_FROM)
       && differenceForDateFrom > 0L) {
     final String differenceAsString =
         TimeConverterService.convertTimeToString(String.valueOf(Math.abs(differenceForDateFrom)));
     additionalInfoKey = "orders.order.stateChange.additionalInfo.startTooLate";
     additionalInfo =
         translationService.translate(
             additionalInfoKey, LocaleContextHolder.getLocale(), differenceAsString);
   }
   if (parameter.getBooleanField(ParameterFieldsO.REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_FROM)
       && differenceForDateFrom < 0L) {
     final String differenceAsString =
         TimeConverterService.convertTimeToString(String.valueOf(Math.abs(differenceForDateFrom)));
     additionalInfoKey = "orders.order.stateChange.additionalInfo.startTooEarly";
     additionalInfo =
         translationService.translate(
             additionalInfoKey, LocaleContextHolder.getLocale(), differenceAsString);
   }
   // EFFECTIVE_DATE_TO
   if (parameter.getBooleanField(ParameterFieldsO.REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_TO)
       && differenceForDateTo > 0L) {
     final String differenceAsString =
         TimeConverterService.convertTimeToString(String.valueOf(Math.abs(differenceForDateTo)));
     additionalInfoKey = "orders.order.stateChange.additionalInfo.endTooLate";
     additionalInfo =
         translationService.translate(
             additionalInfoKey, LocaleContextHolder.getLocale(), differenceAsString);
   }
   if (parameter.getBooleanField(ParameterFieldsO.REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_TO)
       && differenceForDateTo < 0L) {
     final String differenceAsString =
         TimeConverterService.convertTimeToString(String.valueOf(Math.abs(differenceForDateTo)));
     additionalInfoKey = "orders.order.stateChange.additionalInfo.endTooEarly";
     additionalInfo =
         translationService.translate(
             additionalInfoKey, LocaleContextHolder.getLocale(), differenceAsString);
   }
   if (additionalInfo != null) {
     stateChangeEntity.setField(OrderStateChangeFields.ADDITIONAL_INFO, additionalInfo);
     stateChangeContext.save();
   }
   stateChangeContext.setStatus(StateChangeStatus.PAUSED);
   stateChangeContext.save();
   viewContext
       .getViewDefinitionState()
       .openModal(
           "../page/orders/orderStateChangeReasonDialog.html?context={\"form.id\": "
               + stateChangeContext.getStateChangeEntity().getId()
               + "}");
 }
 public void checkIfTimesIsSet(final StateChangeContext stateChangeContext) {
   final Entity productionRecord = stateChangeContext.getOwner();
   Entity orderEntity = productionRecord.getBelongsToField(ProductionTrackingFields.ORDER);
   Entity parameter = parameterService.getParameter();
   if (parameter.getBooleanField(ParameterFieldsPC.VALIDATE_PRODUCTION_RECORD_TIMES)
       && orderEntity.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME)) {
     Integer machineTimie =
         productionRecord.getIntegerField(ProductionTrackingFields.MACHINE_TIME);
     if (machineTimie == null || machineTimie == 0) {
       stateChangeContext.addFieldValidationError(
           ProductionTrackingFields.MACHINE_TIME, "qcadooView.validate.field.error.missing");
     }
     Integer laborTime = productionRecord.getIntegerField(ProductionTrackingFields.LABOR_TIME);
     if (laborTime == null || laborTime == 0) {
       stateChangeContext.addFieldValidationError(
           ProductionTrackingFields.LABOR_TIME, "qcadooView.validate.field.error.missing");
     }
   }
 }
  public void updateCache(
      final DataDefinition customTranslationDD, final Entity customTranslation) {
    boolean active = customTranslation.getBooleanField(ACTIVE);

    String key = customTranslation.getStringField(KEY);
    String locale = customTranslation.getStringField(LOCALE);
    String translation = (active) ? customTranslation.getStringField(CUSTOM_TRANSLATION) : null;

    customTranslationCacheService.manageCustomTranslation(key, locale, translation);
  }
 private boolean databaseHasToBePrepared() {
   Entity parameter = parameterService.getParameter();
   return !parameter.getBooleanField(SAMPLES_WERE_LOADED);
 }
 private boolean needForDelayedDateTo(final Entity parameter) {
   return parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_TO);
 }
 private boolean needForEarlierDateTo(final Entity parameter) {
   return parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_TO);
 }