Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.s1.objects.schema;
 
 
 import java.util.List;
Web operation for object schema validating
public class ObjectSchemaWebOperation extends MapWebOperation {
    @Override
    protected Map<StringObjectprocess(String methodMap<StringObjectparamsHttpServletRequest requestHttpServletResponse responsethrows Exception {
        Map<String,Objectres = Objects.newHashMap();
        if("validate".equals(method)){
            Map<String,Objects = Objects.get(Map.class,params,"schema");
            Map<String,Objectd = Objects.get(Map.class,params,"data",Objects.newHashMap());
            Map<String,Objectc = Objects.get(Map.classparams"ctx");
            ObjectSchema schema = new ObjectSchema();
            schema.fromMap(s);
            ObjectSchema.ValidateResultBean vr = schema.validateQuite(dtruetruec);
            res.put("schema",vr.getResolvedSchema().toMap());
            res.put("data",vr.getValidatedData());
            if(Objects.get(Boolean.class,params,"dataDiff",false)){
                List<Map<String,Object>> list = Objects.newArrayList();
                List<ObjectDiff.DiffBeanl = Objects.diff(d,vr.getValidatedData());
                for(ObjectDiff.DiffBean b:l){
                    list.add(Objects.newHashMap(String.class,Object.class,
                            "path",b.getPath(),"old",b.getOldValue(),"new",b.getNewValue()
                            ));
                }
                res.put("dataDiff",list);
            }
            if(Objects.get(Boolean.class,params,"schemaDiff",false)){
                List<Map<String,Object>> list = Objects.newArrayList();
                List<ObjectDiff.DiffBeanl = Objects.diff(s,vr.getResolvedSchema().toMap());
                for(ObjectDiff.DiffBean b:l){
                    list.add(Objects.newHashMap(String.class,Object.class,
                            "path",b.getPath(),"old",b.getOldValue(),"new",b.getNewValue()
                    ));
                }
                res.put("schemaDiff",list);
            }
        }else{
            throwMethodNotFound(method);
        }
        return res;
    }
New to GrepCode? Check out our FAQ X