Ejemplo n.º 1
0
        public long?UpdateEditionNote(long projectId, long bookVersionId, int userId, BookData bookData)
        {
            if (!bookData.ContainsEditionNote)
            {
                return(null);
            }

            var now         = DateTime.UtcNow;
            var project     = m_resourceRepository.Load <Project>(projectId);
            var user        = m_resourceRepository.Load <User>(userId);
            var bookVersion = m_resourceRepository.Load <BookVersionResource>(bookVersionId);

            var dbEditionNoteResource = m_resourceRepository.GetLatestEditionNote(projectId);

            if (dbEditionNoteResource == null)
            {
                var newDbResource = new Resource
                {
                    Name         = "Edition note",
                    ContentType  = ContentTypeEnum.None,
                    ResourceType = ResourceTypeEnum.EditionNote,
                    Project      = project,
                };
                return(CreateEditionNoteResource(newDbResource, 1, user, now, bookVersion));
            }
            else
            {
                return(CreateEditionNoteResource(dbEditionNoteResource.Resource, dbEditionNoteResource.VersionNumber + 1, user, now, bookVersion));
            }
        }
Ejemplo n.º 2
0
        protected override long ExecuteWorkImplementation()
        {
            var now  = DateTime.UtcNow;
            var user = m_resourceRepository.Load <User>(m_userId);
            var latestEditionNote = m_resourceRepository.GetLatestEditionNote(m_projectId);

            if (latestEditionNote != null && latestEditionNote.Id != m_data.OriginalVersionId)
            {
                throw new MainServiceException(
                          MainServiceErrorCode.EditionNoteConflict,
                          $"Conflict. Current latest versionId is {latestEditionNote.Id}, but originalVersionId was specified {m_data.OriginalVersionId}",
                          HttpStatusCode.Conflict
                          );
            }

            if (latestEditionNote == null)
            {
                latestEditionNote = new EditionNoteResource
                {
                    Resource = new Resource
                    {
                        Project      = m_resourceRepository.Load <Project>(m_projectId),
                        ContentType  = ContentTypeEnum.None,
                        ResourceType = ResourceTypeEnum.EditionNote,
                        Name         = "Edition note"
                    },
                    VersionNumber = 0
                };
            }

            var newEditionNote = new EditionNoteResource
            {
                Resource      = latestEditionNote.Resource,
                CreateTime    = now,
                CreatedByUser = user,
                Comment       = m_data.Comment,
                VersionNumber = latestEditionNote.VersionNumber + 1,
                Text          = m_data.Text
            };

            newEditionNote.Resource.LatestVersion = newEditionNote;

            var resourceVersionId = (long)m_resourceRepository.Create(newEditionNote);

            return(resourceVersionId);
        }
Ejemplo n.º 3
0
        protected override long ExecuteWorkImplementation()
        {
            var now     = DateTime.UtcNow;
            var user    = m_projectRepository.Load <User>(m_userId);
            var project = m_projectRepository.Load <Project>(m_projectId);

            var latestSnapshot  = m_projectRepository.GetLatestSnapshot(m_projectId);
            var bookTypes       = m_bookTypes.Select(bookTypeEnum => m_projectRepository.GetBookTypeByEnum(bookTypeEnum)).ToList();
            var defaultBookType = m_projectRepository.GetBookTypeByEnum(m_defaultBookType);
            var versionNumber   = latestSnapshot?.VersionNumber ?? 0;

            // Get all resources (specified in request)

            var resourceVersions = new List <ResourceVersion>();

            var textResourceVersions = BatchGetResourceVersions <TextResource>(m_resourceVersionIds);

            resourceVersions.AddRange(textResourceVersions);

            var imageResourceVersions = BatchGetResourceVersions <ImageResource>(m_resourceVersionIds);

            resourceVersions.AddRange(imageResourceVersions);

            var audioResourceVersions = BatchGetResourceVersions <AudioResource>(m_resourceVersionIds);

            resourceVersions.AddRange(audioResourceVersions);

            // Get required related resources

            var trackResourceVersions = GetTrackResourceVersions(audioResourceVersions);

            resourceVersions.AddRange(trackResourceVersions);

            var pageResourceVersions = GetPageResourceVersions(textResourceVersions, imageResourceVersions, trackResourceVersions);

            resourceVersions.AddRange(pageResourceVersions);

            var chapterResourceVersions = GetChapterResourceVersions(pageResourceVersions);

            resourceVersions.AddRange(chapterResourceVersions);

            // Get all required resources

            var metadataResourceVersion = m_resourceRepository.GetLatestMetadata(m_projectId);

            resourceVersions.Add(metadataResourceVersion);
            if (metadataResourceVersion == null)
            {
                throw new MainServiceException(MainServiceErrorCode.SnapshotMustContainMetadata, $"Project ID={m_projectId} does not contain required Metadata resource");
            }

            var editionNote = m_resourceRepository.GetLatestEditionNote(m_projectId);

            if (editionNote != null)
            {
                resourceVersions.Add(editionNote);
            }

            // Headwords are not loaded because they are not supported in project editor
            // BinaryResource is not used at all now
            // BookVersionResource is not used in publish process (it is used only for eXist-db)

            // Create snapshot

            var newDbSnapshot = new DataEntities.Database.Entities.Snapshot
            {
                Project          = project,
                BookTypes        = bookTypes,
                DefaultBookType  = defaultBookType,
                Comment          = m_comment,
                CreateTime       = now,
                PublishTime      = now,
                CreatedByUser    = user,
                VersionNumber    = versionNumber + 1,
                ResourceVersions = resourceVersions
            };

            project.LatestPublishedSnapshot = newDbSnapshot;
            m_projectRepository.Update(project);

            var snapshotId = (long)m_projectRepository.Create(newDbSnapshot);

            // Publish snapshot to fulltext database
            var orderedTextResourceVersions =
                textResourceVersions.OrderBy(x => ((PageResource)x.ResourcePage.LatestVersion).Position).ToList();

            m_fulltextStorage.CreateSnapshot(newDbSnapshot, orderedTextResourceVersions, metadataResourceVersion);

            return(snapshotId);
        }