Exemple #1
0
        public override Response Post(IList<IDataObject> dataObjects)
        {
            Response response = new Response();
              Proxy proxy = null;
              Session session = null;

              try
              {
            if (dataObjects.Count <= 0)
            {
              response.Level = StatusLevel.Error;
              response.Messages.Add("No data objects to update.");
              return response;
            }

            string objType = ((GenericDataObject)dataObjects[0]).ObjectType;
            DataObject objDef = GetObjectDefinition(objType);
            Configuration config = GetConfiguration(objDef);

            Connect(ref proxy, ref session);

            foreach (IDataObject dataObject in dataObjects)
            {
              KeyProperty keyProp = objDef.keyProperties.FirstOrDefault();
              string keyValue = Convert.ToString(dataObject.GetPropertyValue(keyProp.keyPropertyName));

              string revision = string.Empty;
              Map revisionMap = config.Mappings.ToList<Map>().Find(x => x.Destination == (int)Destination.Revision);
              if (revisionMap != null)
              {
            string propertyName = Utilities.ToPropertyName(revisionMap.Column);
            revision = Convert.ToString(dataObject.GetPropertyValue(propertyName));
              }

              EqlClient eql = new EqlClient(session);
              int objectId = eql.GetObjectId(keyValue, revision, config.Template.ObjectType);
              org.iringtools.adapter.datalayer.eb.Template template = config.Template;

              if (objectId == 0)  // does not exist, create
              {
            string templateName = GetTemplateName(template, objDef, dataObject);
            int templateId = eql.GetTemplateId(templateName);

            if (templateId == 0)
            {
              Status status = new Status()
              {
                Identifier = keyValue,
                Level = StatusLevel.Error,
                Messages = new Messages() { string.Format("Template [{0}] does not exist.", templateName) }
              };

              response.StatusList.Add(status);
              response.Level = StatusLevel.Error;

              continue;
            }

            objectId = session.Writer.CreateFromTemplate(templateId, "", "");
              }

              string objectType = Enum.GetName(typeof(ObjectType), template.ObjectType);
              ebProcessor processor = new ebProcessor(session, config.Mappings.ToList<Map>(), _rules);

              if (objectType == ObjectType.Tag.ToString())
              {
            response.Append(processor.ProcessTag(objDef, dataObject, objectId, keyValue));
              }
              else if (objectType == ObjectType.Document.ToString())
              {
            response.Append(processor.ProcessDocument(objDef, dataObject, objectId, keyValue));

            //
            // post content like IW data layer
            //
            if (dataObject.GetType() == typeof(GenericContentObject))
            {
              response.Append(PostContents(new List<IContentObject>{(GenericContentObject) dataObject}, proxy, session));
            }
              }
              else
              {
            Status status = new Status()
            {
              Identifier = keyValue,
              Level = StatusLevel.Error,
              Messages = new Messages() { string.Format("Object type [{0}] not supported.", template.ObjectType) }
            };

            response.StatusList.Add(status);
            response.Level = StatusLevel.Error;
              }
            }
              }
              catch (Exception e)
              {
            _logger.Error("Error posting data objects: " + e);

            response.Level = StatusLevel.Error;
            response.Messages.Add("Error posting data objects: " + e);
              }
              finally
              {
            Disconnect(ref proxy, ref session);
              }

              return response;
        }
Exemple #2
0
        public override Response Delete(string objectType, IList<string> identifiers)
        {
            Response response = new Response() { Level = StatusLevel.Success };
              Proxy proxy = null;
              Session session = null;

              try
              {
            DataObject objDef = GetObjectDefinition(objectType);

            if (objDef != null)
            {
              try
              {
            Connect(ref proxy, ref session);

            EqlClient eqlClient = new EqlClient(session);
            Configuration config = GetConfiguration(objDef);
            int objType = (int)config.Template.ObjectType;

            foreach (string identifier in identifiers)
            {
              Status status = new Status()
              {
                Identifier = identifier,
                Level = StatusLevel.Success
              };

              int objId = eqlClient.GetObjectId(identifier, string.Empty, objType);

              if (objId != 0)
              {
                if (objType == (int)ObjectType.Tag)
                {
                  Tag tag = new Tag(session, objId);
                  tag.Delete();
                  status.Messages.Add(string.Format("Tag [{0}] deleted succesfully.", identifier));
                }
                else if (objType == (int)ObjectType.Document)
                {
                  Document doc = new Document(session, objId);
                  doc.Delete();
                  status.Messages.Add(string.Format("Document [{0}] deleted succesfully.", identifier));
                }
                else
                {
                  status.Level = StatusLevel.Error;
                  status.Messages.Add(string.Format("Object type [{0}] not supported.", objType));
                  response.Level = StatusLevel.Error;
                }
              }
              else
              {
                status.Level = StatusLevel.Error;
                status.Messages.Add(string.Format("Object [{0}] not found.", identifier));
                response.Level = StatusLevel.Error;
              }

              response.Append(status);
            }
              }
              finally
              {
            Disconnect(ref proxy, ref session);
              }
            }
            else
            {
              response.Level = StatusLevel.Error;
              response.Messages.Add(string.Format("Object type [{0}] does not exist.", objectType));
            }
              }
              catch (Exception e)
              {
            _logger.Error("Error deleting data object: " + e);

            response.Level = StatusLevel.Error;
            response.Messages.Add(e.Message);
              }

              return response;
        }