AnsweredAssumed Answered

Problem in service /form/form-data

Question asked by heamaya on Mar 21, 2016
I have developed a custom type that extends EnumFormType and I need to receive the enumValues using the service /form/form-data. I have tried several times with no success. I looked at the activiti rest-api code and found a class named org.activiti.rest.service.api.RestResponseFactory.java. I think there's a problem in line 680: if ("enum".equals(restFormProp.getType())) because here only enum types are accepted and I need all possible values in my custom type. Here's my code


package com.ilumno.example.types;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.impl.form.EnumFormType;

import com.ilumno.example.types.model.Importance;

public class ImportanceFormType extends EnumFormType {
   /**
    *
    */
   private static final long serialVersionUID = -77249930313355176L;
   private static final String TYPE_NAME = "importance";
   
   public ImportanceFormType(Map<String, String> values) {
      super(values());
   }
   
   public ImportanceFormType() {
      super(values());
   }

   private static Map<String, String> values() {
      Map<String, String> values = new LinkedHashMap<String, String>();
      List<Importance> importanceValues = Arrays.asList(Importance.values());

      for (Importance importance : importanceValues) {
         values.put(importance.getId().toString(), importance.getValue());
      }
      
      return values;
   }

   @Override
   public Object convertFormValueToModelValue(String formValue) {
      final Importance importance;

      switch (formValue) {

      case "1":
         importance = Importance.IMPORTANT;
         break;

      case "2":
         importance = Importance.URGENT;
         break;

      case "3":
         importance = Importance.IMPORTANT_AND_URGENT;
         break;

      case "4":
         importance = Importance.NON_IMPORTANT;
         break;

      default:
         importance = Importance.IMPORTANT;
         break;
      }

      return importance;
   }

   @Override
   public String convertModelValueToFormValue(Object modelValue) {
      return modelValue != null ? ((Importance) modelValue).getId().toString() : null;
   }

   @Override
   public String getName() {
      return TYPE_NAME;
   }
}


Thanks.

Outcomes