Пример #1
0
        public void TestJsonReserializationSuccess()
        {
            AFDataHolder dataToTest = new AFDataHolder();
            dataToTest.addPropertyAndValue("name", "Pavel");
            dataToTest.addPropertyAndValue("lastName", "Matyáš");
            AFDataHolder innerClass = new AFDataHolder();
            innerClass.setClassName("adress");
            innerClass.addPropertyAndValue("Street", "Zikova");
            dataToTest.addInnerClass(innerClass);

            BaseRestBuilder restBuilder = new JSONBuilder();
            Object json = restBuilder.reselialize(dataToTest);
            Assert.IsNotNull(json);
        }
Пример #2
0
 /// <summary>
 /// Creates data from list item on given position which can be inserted to form.
 /// </summary>
 /// <param name="position">position of list item in list view</param>
 /// <returns> data of list item prepared to be inserted in form</returns>
 private AFDataHolder createFormDataFromList(int position)
 {
     AFDataHolder dataHolder = new AFDataHolder();
     foreach (AFField field in getFields())
     {
         String propertyName = field.getId();
         Object data = rows[position][propertyName];
         // Based on dot notation determine road. Road is used to add object to its right place
         String[] roadTrace = propertyName.Split(new [] {"."}, StringSplitOptions.None);
         if (roadTrace.Length > 1)
         {
             AFDataHolder startPoint = dataHolder;
             for (int i = 0; i < roadTrace.Length; i++)
             {
                 String roadPoint = roadTrace[i];
                 // If road end then add this property as inner propety
                 if (i + 1 == roadTrace.Length)
                 {
                     startPoint.addPropertyAndValue(roadPoint, (String) data);
                 }
                 else {
                     // Otherwise it will be inner class so add if doesn't exist continue.
                     AFDataHolder roadHolder = startPoint.getInnerClassByKey(roadPoint);
                     if (roadHolder == null)
                     {
                         roadHolder = new AFDataHolder();
                         roadHolder.setClassName(roadPoint);
                         startPoint.addInnerClass(roadHolder);
                     }
                     // Set start point on current possition in tree
                     startPoint = roadHolder;
                 }
             }
         }
         else {
             dataHolder.addPropertyAndValue(propertyName, (String) data);
         }
     }
     return dataHolder;
 }
Пример #3
0
        public override AFDataHolder reserialize()
        {
            AFDataHolder dataHolder = new AFDataHolder();
            foreach (AFField field in getFields())
            {
                Object data = field.getWidgetBuilder().getData();
                
                //little workaroud to fit in server //TODO if ever this thing will be released delete this!!
                if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.NUMBERDOUBLEFIELD))
                {
                    data = ((String) data).Replace(',', '.');
                }

                String propertyName = field.getId();
                // Based on dot notation determine road. Road is used to add object to its right place
                String[] roadTrace = propertyName.Split(new [] {"."}, StringSplitOptions.None);
                if (roadTrace.Length > 1)
                {
                    AFDataHolder startPoint = dataHolder;
                    for (int i = 0; i < roadTrace.Length; i++)
                    {
                        String roadPoint = roadTrace[i];
                        // If road end then add this property as inner propety
                        if (i + 1 == roadTrace.Length)
                        {
                            startPoint.addPropertyAndValue(roadPoint, (String) data);
                        }
                        else {
                            // Otherwise it will be inner class so add if doesn't exist continue.
                            AFDataHolder roadHolder = startPoint.getInnerClassByKey(roadPoint);
                            if (roadHolder == null)
                            {
                                roadHolder = new AFDataHolder();
                                roadHolder.setClassName(roadPoint);
                                startPoint.addInnerClass(roadHolder);
                            }
                            // Set start point on current possition in tree
                            startPoint = roadHolder;
                        }
                    }
                }
                else {
                    dataHolder.addPropertyAndValue(propertyName, data.ToString());
                }
            }
            return dataHolder;

        }