コード例 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="readerToEntityAdapter">Adapter for reading content and storing in entities.</param>
        /// <param name="entitySaver">Service for saving entities in bulk.</param>
        /// <param name="importReporter">Service for receiving import progress.</param>
        /// <param name="resourceMapping">The resource mapping, to provde settings such as merging and workflow suppression.</param>
        /// <param name="testRun">Indicates that the importer is performing test runs.</param>
        public RecordImporter(IReaderToEntityAdapter readerToEntityAdapter, IEntitySaver entitySaver, IImportReporter importReporter, ApiResourceMapping resourceMapping, bool testRun)
        {
            if (readerToEntityAdapter == null)
            {
                throw new ArgumentNullException(nameof(readerToEntityAdapter));
            }
            if (entitySaver == null)
            {
                throw new ArgumentNullException(nameof(entitySaver));
            }
            if (importReporter == null)
            {
                throw new ArgumentNullException(nameof(importReporter));
            }
            if (resourceMapping == null)
            {
                throw new ArgumentNullException(nameof(resourceMapping));
            }

            _entitySaver          = entitySaver;
            ReaderToEntityAdapter = readerToEntityAdapter;
            Reporter           = importReporter;
            _resourceMapping   = resourceMapping;
            _mergeRecords      = resourceMapping.ImportMergeExisting == true;
            _suppressWorkflows = resourceMapping.MappingSuppressWorkflows == true;
            _testRun           = testRun;
        }
コード例 #2
0
        public IEntity RunTest(string json, ApiResourceMapping mapping, ReaderToEntityAdapterSettings settings = null)
        {
            if (json != null)
            {
                json = json.Replace("'", @"""");
            }

            // Get dynamic object from JSON
            object raw = JilHelpers.Deserialize <object>(json);

            Assert.That(raw, Is.InstanceOf <IDynamicMetaObjectProvider>( ), "Dynamic object should be IDynamicMetaObjectProvider");
            IDynamicMetaObjectProvider dynamicProvider = ( IDynamicMetaObjectProvider )raw;

            // Get object reader
            IDynamicObjectReaderService objectReaderService = Factory.Current.Resolve <IDynamicObjectReaderService>( );
            IObjectReader reader = objectReaderService.GetObjectReader(dynamicProvider);

            // Settings
            ReaderToEntityAdapterSettings settingsToUse = settings ?? new ReaderToEntityAdapterSettings();

            // Run adapter provider
            IReaderToEntityAdapterProvider adapterProvider = Factory.Current.Resolve <IReaderToEntityAdapterProvider>( );
            IReaderToEntityAdapter         adapter         = adapterProvider.GetAdapter(mapping.Id, settingsToUse);

            IEntity entity = adapter.CreateEntity(reader, ConnectorRequestExceptionReporter.Instance);

            return(entity);
        }
コード例 #3
0
        /// <summary>
        /// Update
        /// </summary>
        private ConnectorResponse HandlePut(ConnectorRequest request, ApiResourceMapping mapping)
        {
            IReaderToEntityAdapter adapter = GetReaderAdapter(mapping);
            IObjectReader          reader  = request.Payload;
            IEntity instance;

            // Check payload
            CheckPayload(reader);

            // Get instance
            ConnectorResponse errorResponse;

            instance = LocateResource(request, mapping, out errorResponse);
            if (errorResponse != null)
            {
                return(errorResponse);
            }

            // Modify instance
            instance = instance.AsWritable( );
            adapter.FillEntity(reader, instance, ConnectorRequestExceptionReporter.Instance);
            SaveInstance(instance);

            return(new ConnectorResponse(HttpStatusCode.OK, "Updated"));
        }
コード例 #4
0
        private IReaderToEntityAdapter GetReaderAdapter(ApiResourceMapping mapping)
        {
            using (new SecurityBypassContext( ))
            {
                var settings = new ReaderToEntityAdapterSettings( );

                // Get adapter
                IReaderToEntityAdapter adapter = _readerToEntityAdapterProvider.GetAdapter(mapping.Id, settings);

                return(adapter);
            }
        }
コード例 #5
0
        /// <summary>
        /// Get an adapter for writing entities.
        /// </summary>
        private IReaderToEntityAdapter GetEntityAdapter(ImportConfig importConfig)
        {
            ApiResourceMapping mapping = importConfig.ImportConfigMapping;

            ReaderToEntityAdapterSettings settings = new ReaderToEntityAdapterSettings( );

            settings.UseTargetMemberNameForReporting = true;

            //settings.TimeZoneName
            IReaderToEntityAdapter entityAdapter = _readerToEntityAdapterProvider.GetAdapter(mapping.Id, settings);

            return(entityAdapter);
        }
コード例 #6
0
        /// <summary>
        /// Create
        /// </summary>
        private ConnectorResponse HandlePost(ConnectorRequest request, ApiResourceMapping mapping)
        {
            IReaderToEntityAdapter adapter = GetReaderAdapter(mapping);
            IObjectReader          reader  = request.Payload;

            // Check payload
            CheckPayload(reader);

            // Create instance
            IEntity instance = adapter.CreateEntity(reader, ConnectorRequestExceptionReporter.Instance);

            SaveInstance(instance);

            // Create URI to identify instance
            string instanceUri = _resourceUriGenerator.CreateResourceUri(instance, request, mapping);

            var response = new ConnectorResponse(HttpStatusCode.Created, "Created");

            response.Headers.Add("Location", instanceUri);
            return(response);
        }