Exemple #1
0
 /**
  * Returns all validation constraints for a list of types.
  *
  * @param types a list of valid Para data types
  * @return a map of validation constraints for given types
  */
 public Map<String, Map<String, Map<String, Map<String, ?>>>> getAllValidationConstraints(
     String... types) {
   Map<String, Map<String, Map<String, Map<String, ?>>>> allConstr =
       new HashMap<String, Map<String, Map<String, Map<String, ?>>>>();
   if (types == null || types.length == 0) {
     types = ParaObjectUtils.getAllTypes(this).values().toArray(new String[0]);
   }
   try {
     for (String aType : types) {
       Map<String, Map<String, Map<String, ?>>> vc =
           new HashMap<String, Map<String, Map<String, ?>>>();
       // add all core constraints first
       if (ValidationUtils.getCoreValidationConstraints().containsKey(aType)) {
         vc.putAll(ValidationUtils.getCoreValidationConstraints().get(aType));
       }
       // also add the ones that are defined locally for this app
       Map<String, Map<String, Map<String, ?>>> appConstraints =
           getValidationConstraints().get(aType);
       if (appConstraints != null && !appConstraints.isEmpty()) {
         vc.putAll(appConstraints);
       }
       if (!vc.isEmpty()) {
         allConstr.put(aType, vc);
       }
     }
   } catch (Exception ex) {
     logger.error(null, ex);
   }
   return allConstr;
 }
Exemple #2
0
 /**
  * Adds a user-defined data type to the types map.
  *
  * @param pluralDatatype the plural form of the type
  * @param datatype a datatype, must not be null or empty
  */
 public void addDatatype(String pluralDatatype, String datatype) {
   pluralDatatype = Utils.noSpaces(Utils.stripAndTrim(pluralDatatype, " "), "-");
   datatype = Utils.noSpaces(Utils.stripAndTrim(datatype, " "), "-");
   if (getDatatypes().size() < Config.MAX_DATATYPES_PER_APP) {
     if (!StringUtils.isBlank(pluralDatatype)
         && !StringUtils.isBlank(datatype)
         && !getDatatypes().containsValue(datatype)
         && !ParaObjectUtils.getCoreTypes().containsKey(pluralDatatype)) {
       getDatatypes().putIfAbsent(pluralDatatype, datatype);
     }
   } else {
     LoggerFactory.getLogger(App.class)
         .warn("Maximum number of types per app reached - {}.", Config.MAX_DATATYPES_PER_APP);
   }
 }
Exemple #3
0
 @Override
 public String toString() {
   return ParaObjectUtils.toJSON(this);
 }