private async Task ResolveEntity(int groupId, XElement entity)
        {
            logger.LogDebug("Start ResolveEntity");
            ObjectDefinition definition = new ObjectDefinition();

            definition.ObjectDefinitionKey     = entity.Attribute("key").Value;
            definition.ObjectDefinitionGroupID = groupId;
            definition.ObjectDefinitionName    = entity.Attribute("name").Value;
            var requestUser = await GetLoginUser();

            definition.ObjectOwner = requestUser;
            definition.UpdatedBy   = requestUser;

            var currentObjectDefinition = this.objectService.GetObjectDefinitionByName(definition.ObjectDefinitionName);

            definition.IsFeildsUpdateOnly = currentObjectDefinition != null;

            //if there is already a object there, do not register it.
            if (currentObjectDefinition == null)
            {
                logger.LogWarning(string.Format("NOT FOUND {0} in system, create new one", definition.ObjectDefinitionName));
                foreach (XElement prop in entity.Descendants("property"))
                {
                    ObjectDefinitionField objDefField = ParseObjectDefinitionField(prop);
                    if (objDefField != null)
                    {
                        definition.ObjectFields.Add(objDefField);
                    }
                }

                this.objectService.CreateORUpdateObjectDefinition(definition);
            }
            logger.LogDebug("End ResolveEntity");
        }
Example #2
0
        private static ObjectDefinitionField Convert2FileDefinitionField(GeneralObjectDefinitionField field)
        {
            var svcDefField = new ObjectDefinitionField(GeneralObjectDefinitionFieldType.File);

            svcDefField.GeneralObjectDefinitionFiledType = field.GeneralObjectDefinitionFiledType;
            svcDefField.ObjectDefinitionFieldID          = field.GeneralObjectDefinitionFieldID;
            svcDefField.ObjectDefinitionFieldKey         = field.GeneralObjectDefinitionFieldKey;
            svcDefField.ObjectDefinitionFieldName        = field.GeneralObjectDefinitionFieldName;

            return(svcDefField);
        }
        private void DeserializeFields(List <ObjectDefinitionField> fields, IEnumerable <JToken> jObjects)
        {
            foreach (JObject obj in jObjects)
            {
                ObjectDefinitionField field = null;
                var fieldType = obj.Value <int>("generalObjectDefinitionFiledType");
                switch ((GeneralObjectDefinitionFieldType)fieldType)
                {
                case GeneralObjectDefinitionFieldType.PrimeType:
                    field = new PrimeDefinitionField();
                    ((PrimeDefinitionField)field).PrimeDataType = (PrimeFieldDataType)obj.Value <int>("primeDataType");
                    break;

                case GeneralObjectDefinitionFieldType.ObjectReference:
                    field = new ObjRefDefinitionField();
                    ((ObjRefDefinitionField)field).ReferedObjectDefinitionID = obj.Value <int>("referedObjectDefinitionID");
                    break;

                case GeneralObjectDefinitionFieldType.SingleSelection:
                    field = new SingleSDefinitionField();
                    ((SingleSDefinitionField)field).SelectionItems.AddRange(ParseSelectionItems(obj));
                    break;

                default:
                    field = new ObjectDefinitionField((GeneralObjectDefinitionFieldType)fieldType);
                    break;
                }

                if (field != null)
                {
                    field.ObjectDefinitionFieldID   = obj.Value <int>("objectDefinitionFieldID");
                    field.ObjectDefinitionFieldKey  = obj.Value <string>("objectDefinitionFieldKey");
                    field.ObjectDefinitionFieldName = obj.Value <string>("objectDefinitionFieldName");
                    fields.Add(field);
                }
            }
        }
Example #4
0
        private static GeneralObjectDefinitionField ParseGeneralObjectDefinitionField(ObjectDefinitionField f, GeneralObjectDefinitionField field)
        {
            if (field == null)
            {
                field = new GeneralObjectDefinitionField();
            }

            field.GeneralObjectDefinitionFieldKey  = f.ObjectDefinitionFieldKey;
            field.GeneralObjectDefinitionFieldName = f.ObjectDefinitionFieldName;
            field.GeneralObjectDefinitionFiledType = f.GeneralObjectDefinitionFiledType;

            return(field);
        }
Example #5
0
        public static GeneralObjectDefinitionField ConvertSvcField2ObjDefinitionField(ObjectDefinitionField f, GeneralObjectDefinitionField field)
        {
            switch (f.GeneralObjectDefinitionFiledType)
            {
            case GeneralObjectDefinitionFieldType.PrimeType:
                return(ParsePrimeDefinitionField(f as PrimeDefinitionField, field as PrimeObjectDefintionField));

            case GeneralObjectDefinitionFieldType.SingleSelection:
                return(ParseSingleSelectionDefinitionField(f as SingleSDefinitionField, field as SingleSelectionDefinitionField));

            case GeneralObjectDefinitionFieldType.ObjectReference:
                return(ParseObjectReferenceDefinitionField(f as ObjRefDefinitionField, field as ObjRefObjectDefinitionField));

            case GeneralObjectDefinitionFieldType.File:
                return(ParseGeneralObjectDefinitionField(f, field));

            default:
                throw new NotSupportedException(string.Format("{0} is not supported!", f.GeneralObjectDefinitionFiledType));
            }
        }
        private ObjectDefinitionField ParseObjectDefinitionField(XElement property)
        {
            string typeString = property.Attribute("type").Value;

            switch (typeString)
            {
            case "String":
            case "Integer":
            case "Long":
            case "Datetime":
            case "Number":
            case "Binary":
                logger.LogDebug("Parse Binary field.");
                PrimeDefinitionField field = new PrimeDefinitionField();
                field.PrimeDataType             = (ObjectRepository.EntityModels.PrimeFieldDataType)Enum.Parse(typeof(ObjectRepository.EntityModels.PrimeFieldDataType), typeString);
                field.ObjectDefinitionFieldName = property.Attribute("name").Value;
                field.ObjectDefinitionFieldKey  = property.Attribute("key").Value;
                logger.LogDebug(string.Format("{0} = {1}", field.ObjectDefinitionFieldName, field.ObjectDefinitionFieldKey));
                return(field);

            case "File":

                ObjectDefinitionField fileField = new ObjectDefinitionField(ObjectRepository.EntityModels.GeneralObjectDefinitionFieldType.File);
                fileField.ObjectDefinitionFieldKey  = property.Attribute("key").Value;
                fileField.ObjectDefinitionFieldName = property.Attribute("name").Value;
                logger.LogDebug("Parse File field " + fileField.ObjectDefinitionFieldName);

                return(fileField);

            case "ObjRef":
                logger.LogDebug("Parse ObjRef field.");
                ObjRefDefinitionField refField = new ObjRefDefinitionField();
                refField.ObjectDefinitionFieldKey  = property.Attribute("key").Value;
                refField.ObjectDefinitionFieldName = property.Attribute("name").Value;
                refField.ReferedObjectDefinitionID = this.objectService.GetObjectDefinitionByName(property.Attribute("refName").Value).ObjectDefinitionID;

                logger.LogDebug(string.Format("{0} = {1}", refField.ObjectDefinitionFieldName, refField.ReferedObjectDefinitionID));

                return(refField);

            case "SingleSelection":
                SingleSDefinitionField ssField = new SingleSDefinitionField();
                ssField.ObjectDefinitionFieldKey  = property.Attribute("key").Value;
                ssField.ObjectDefinitionFieldName = property.Attribute("name").Value;

                foreach (XElement item in property.Descendants("choice"))
                {
                    ssField.SelectionItems.Add(new DefinitionSelectItem()
                    {
                        SelectDisplayName = item.Attribute("displayName").Value,
                        SelectItemKey     = item.Attribute("value").Value
                    });
                }
                logger.LogDebug("Parse SingleSelection field : " + ssField.ObjectDefinitionFieldName);
                return(ssField);

            default:
                break;
            }

            return(null);
        }