[ARVADOS-WORKBENCH2] updated: 1.1.4-501-g50031c8

Git user git at public.curoverse.com
Fri Aug 3 02:07:40 EDT 2018


Summary of changes:
 src/models/collection-file.ts                      | 72 +---------------------
 src/models/keep-manifest.ts                        | 41 ------------
 .../collection-files-service.ts                    |  9 +++
 .../collection-manifest-mapper.test.ts}            |  4 +-
 .../collection-manifest-mapper.ts}                 | 49 ++-------------
 .../collection-manifest-parser.test.ts}            |  2 +-
 .../collection-manifest-parser.ts}                 | 14 +----
 .../collection-panel/collection-panel-action.ts    |  6 +-
 .../collection-panel-files-reducer.test.ts         | 22 +++----
 9 files changed, 36 insertions(+), 183 deletions(-)
 create mode 100644 src/services/collection-files-service/collection-files-service.ts
 rename src/{models/collection-file.test.ts => services/collection-files-service/collection-manifest-mapper.test.ts} (89%)
 copy src/{models/collection-file.ts => services/collection-files-service/collection-manifest-mapper.ts} (70%)
 rename src/{models/keep-manifest.test.ts => services/collection-files-service/collection-manifest-parser.test.ts} (97%)
 copy src/{models/keep-manifest.ts => services/collection-files-service/collection-manifest-parser.ts} (83%)

       via  50031c8c6aae1f325f81d71a6f5a8c1cb293aa46 (commit)
      from  ad5512c3aafbed2e97ea5c24442fcd2d17a35edf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 50031c8c6aae1f325f81d71a6f5a8c1cb293aa46
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Fri Aug 3 08:07:18 2018 +0200

    Move collection manifest parser and mapper to collection-files-service directory
    
    Feature #13855
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/models/collection-file.ts b/src/models/collection-file.ts
index 3a7e55c..a140080 100644
--- a/src/models/collection-file.ts
+++ b/src/models/collection-file.ts
@@ -2,9 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { uniqBy } from 'lodash';
-import { KeepManifestStream, KeepManifestStreamFile, KeepManifest } from "./keep-manifest";
-import { Tree, TreeNode, setNode, createTree } from './tree';
+import { Tree } from './tree';
 
 export type CollectionFilesTree = Tree<CollectionDirectory | CollectionFile>;
 
@@ -28,71 +26,7 @@ export interface CollectionFile {
     type: CollectionFileType.FILE;
 }
 
-export const mapManifestToCollectionFilesTree = (manifest: KeepManifest): CollectionFilesTree =>
-    manifestToCollectionFiles(manifest)
-        .map(mapCollectionFileToTreeNode)
-        .reduce((tree, node) => setNode(node)(tree), createTree<CollectionFile>());
-
-
-export const mapCollectionFileToTreeNode = (file: CollectionFile): TreeNode<CollectionFile> => ({
-    children: [],
-    id: file.id,
-    parent: file.parentId,
-    value: file
-});
-
-export const manifestToCollectionFiles = (manifest: KeepManifest): Array<CollectionDirectory | CollectionFile> => ([
-    ...mapManifestToDirectories(manifest),
-    ...mapManifestToFiles(manifest)
-]);
-
-export const mapManifestToDirectories = (manifest: KeepManifest): CollectionDirectory[] =>
-    uniqBy(
-        manifest
-            .map(mapStreamDirectory)
-            .map(splitDirectory)
-            .reduce((all, splitted) => ([...all, ...splitted]), []),
-        directory => directory.id);
-
-export const mapManifestToFiles = (manifest: KeepManifest): CollectionFile[] =>
-    manifest
-        .map(stream => stream.files.map(mapStreamFile(stream)))
-        .reduce((all, current) => ([...all, ...current]), []);
-
-const splitDirectory = (directory: CollectionDirectory): CollectionDirectory[] => {
-    return directory.name
-        .split('/')
-        .slice(1)
-        .map(mapPathComponentToDirectory);
-};
-
-const mapPathComponentToDirectory = (component: string, index: number, components: string[]): CollectionDirectory =>
-    createDirectory({
-        parentId: index === 0 ? '' : joinPathComponents(components, index),
-        id: joinPathComponents(components, index + 1),
-        name: component,
-    });
-
-const joinPathComponents = (components: string[], index: number) =>
-    `/${components.slice(0, index).join('/')}`;
-
-const mapStreamDirectory = (stream: KeepManifestStream): CollectionDirectory =>
-    createDirectory({
-        parentId: '',
-        id: stream.name,
-        name: stream.name,
-    });
-
-const mapStreamFile = (stream: KeepManifestStream) =>
-    (file: KeepManifestStreamFile): CollectionFile =>
-        createFile({
-            parentId: stream.name,
-            id: `${stream.name}/${file.name}`,
-            name: file.name,
-            size: file.size,
-        });
-
-export const createDirectory = (data: Partial<CollectionDirectory>): CollectionDirectory => ({
+export const createCollectionDirectory = (data: Partial<CollectionDirectory>): CollectionDirectory => ({
     id: '',
     name: '',
     parentId: '',
@@ -100,7 +34,7 @@ export const createDirectory = (data: Partial<CollectionDirectory>): CollectionD
     ...data
 });
 
-export const createFile = (data: Partial<CollectionFile>): CollectionFile => ({
+export const createCollectionFile = (data: Partial<CollectionFile>): CollectionFile => ({
     id: '',
     name: '',
     parentId: '',
diff --git a/src/models/keep-manifest.ts b/src/models/keep-manifest.ts
index 085d910..6dc6445 100644
--- a/src/models/keep-manifest.ts
+++ b/src/models/keep-manifest.ts
@@ -15,44 +15,3 @@ export interface KeepManifestStreamFile {
     position: string;
     size: number;
 }
-
-/**
- * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
- */
-export const parseKeepManifestText = (text: string) =>
-    text
-        .split(/\n/)
-        .filter(streamText => streamText.length > 0)
-        .map(parseKeepManifestStream);
-
-/**
- * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
- */
-export const parseKeepManifestStream = (stream: string): KeepManifestStream => {
-    const tokens = stream.split(' ');
-    return {
-        name: streamName(tokens),
-        locators: locators(tokens),
-        files: files(tokens)
-    };
-};
-
-const FILE_LOCATOR_REGEXP = /^([0-9a-f]{32})\+([0-9]+)(\+[A-Z][-A-Za-z0-9 at _]*)*$/;
-
-const FILE_REGEXP = /([0-9]+):([0-9]+):(.*)/;
-
-const streamName = (tokens: string[]) => tokens[0].slice(1);
-
-const locators = (tokens: string[]) => tokens.filter(isFileLocator);
-
-const files = (tokens: string[]) => tokens.filter(isFile).map(parseFile);
-
-const isFileLocator = (token: string) => FILE_LOCATOR_REGEXP.test(token);
-
-const isFile = (token: string) => FILE_REGEXP.test(token);
-
-const parseFile = (token: string): KeepManifestStreamFile => {
-    const match = FILE_REGEXP.exec(token);
-    const [position, size, name] = match!.slice(1);
-    return { name, position, size: parseInt(size, 10) };
-};
\ No newline at end of file
diff --git a/src/services/collection-files-service/collection-files-service.ts b/src/services/collection-files-service/collection-files-service.ts
new file mode 100644
index 0000000..fd17dc4
--- /dev/null
+++ b/src/services/collection-files-service/collection-files-service.ts
@@ -0,0 +1,9 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { CollectionService } from "../collection-service/collection-service";
+
+export class CollectionFilesService {
+    constructor(private collectionService: CollectionService){}
+}
\ No newline at end of file
diff --git a/src/models/collection-file.test.ts b/src/services/collection-files-service/collection-manifest-mapper.test.ts
similarity index 89%
rename from src/models/collection-file.test.ts
rename to src/services/collection-files-service/collection-manifest-mapper.test.ts
index 7feb13d..ad8f872 100644
--- a/src/models/collection-file.test.ts
+++ b/src/services/collection-files-service/collection-manifest-mapper.test.ts
@@ -2,8 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { parseKeepManifestText } from "./keep-manifest";
-import { mapManifestToFiles, mapManifestToDirectories } from './collection-file';
+import { parseKeepManifestText } from "./collection-manifest-parser";
+import { mapManifestToFiles, mapManifestToDirectories } from "./collection-manifest-mapper";
 
 test('mapManifestToFiles', () => {
     const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n./c d41d8cd98f00b204e9800998ecf8427e+0 0:0:d`;
diff --git a/src/models/collection-file.ts b/src/services/collection-files-service/collection-manifest-mapper.ts
similarity index 70%
copy from src/models/collection-file.ts
copy to src/services/collection-files-service/collection-manifest-mapper.ts
index 3a7e55c..c2a8ae8 100644
--- a/src/models/collection-file.ts
+++ b/src/services/collection-files-service/collection-manifest-mapper.ts
@@ -3,30 +3,9 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { uniqBy } from 'lodash';
-import { KeepManifestStream, KeepManifestStreamFile, KeepManifest } from "./keep-manifest";
-import { Tree, TreeNode, setNode, createTree } from './tree';
-
-export type CollectionFilesTree = Tree<CollectionDirectory | CollectionFile>;
-
-export enum CollectionFileType {
-    DIRECTORY = 'directory',
-    FILE = 'file'
-}
-
-export interface CollectionDirectory {
-    parentId: string;
-    id: string;
-    name: string;
-    type: CollectionFileType.DIRECTORY;
-}
-
-export interface CollectionFile {
-    parentId: string;
-    id: string;
-    name: string;
-    size: number;
-    type: CollectionFileType.FILE;
-}
+import { KeepManifestStream, KeepManifestStreamFile, KeepManifest } from "../../models/keep-manifest";
+import { TreeNode, setNode, createTree } from '../../models/tree';
+import { CollectionFilesTree, CollectionFile, CollectionDirectory, createCollectionDirectory, createCollectionFile } from '../../models/collection-file';
 
 export const mapManifestToCollectionFilesTree = (manifest: KeepManifest): CollectionFilesTree =>
     manifestToCollectionFiles(manifest)
@@ -67,7 +46,7 @@ const splitDirectory = (directory: CollectionDirectory): CollectionDirectory[] =
 };
 
 const mapPathComponentToDirectory = (component: string, index: number, components: string[]): CollectionDirectory =>
-    createDirectory({
+    createCollectionDirectory({
         parentId: index === 0 ? '' : joinPathComponents(components, index),
         id: joinPathComponents(components, index + 1),
         name: component,
@@ -77,7 +56,7 @@ const joinPathComponents = (components: string[], index: number) =>
     `/${components.slice(0, index).join('/')}`;
 
 const mapStreamDirectory = (stream: KeepManifestStream): CollectionDirectory =>
-    createDirectory({
+    createCollectionDirectory({
         parentId: '',
         id: stream.name,
         name: stream.name,
@@ -85,26 +64,10 @@ const mapStreamDirectory = (stream: KeepManifestStream): CollectionDirectory =>
 
 const mapStreamFile = (stream: KeepManifestStream) =>
     (file: KeepManifestStreamFile): CollectionFile =>
-        createFile({
+        createCollectionFile({
             parentId: stream.name,
             id: `${stream.name}/${file.name}`,
             name: file.name,
             size: file.size,
         });
 
-export const createDirectory = (data: Partial<CollectionDirectory>): CollectionDirectory => ({
-    id: '',
-    name: '',
-    parentId: '',
-    type: CollectionFileType.DIRECTORY,
-    ...data
-});
-
-export const createFile = (data: Partial<CollectionFile>): CollectionFile => ({
-    id: '',
-    name: '',
-    parentId: '',
-    size: 0,
-    type: CollectionFileType.FILE,
-    ...data
-});
\ No newline at end of file
diff --git a/src/models/keep-manifest.test.ts b/src/services/collection-files-service/collection-manifest-parser.test.ts
similarity index 97%
rename from src/models/keep-manifest.test.ts
rename to src/services/collection-files-service/collection-manifest-parser.test.ts
index d9c4967..eddc9c6 100644
--- a/src/models/keep-manifest.test.ts
+++ b/src/services/collection-files-service/collection-manifest-parser.test.ts
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { parseKeepManifestText, parseKeepManifestStream } from "./keep-manifest";
+import { parseKeepManifestText, parseKeepManifestStream } from "./collection-manifest-parser";
 
 describe('parseKeepManifestText', () => {
     it('should parse text into streams', () => {
diff --git a/src/models/keep-manifest.ts b/src/services/collection-files-service/collection-manifest-parser.ts
similarity index 83%
copy from src/models/keep-manifest.ts
copy to src/services/collection-files-service/collection-manifest-parser.ts
index 085d910..df334d4 100644
--- a/src/models/keep-manifest.ts
+++ b/src/services/collection-files-service/collection-manifest-parser.ts
@@ -2,19 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export type KeepManifest = KeepManifestStream[];
-
-export interface KeepManifestStream {
-    name: string;
-    locators: string[];
-    files: Array<KeepManifestStreamFile>;
-}
-
-export interface KeepManifestStreamFile {
-    name: string;
-    position: string;
-    size: number;
-}
+import { KeepManifestStream, KeepManifestStreamFile } from "../../models/keep-manifest";
 
 /**
  * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts
index e526c6a..e19bcb4 100644
--- a/src/store/collection-panel/collection-panel-action.ts
+++ b/src/store/collection-panel/collection-panel-action.ts
@@ -8,9 +8,9 @@ import { ResourceKind } from "../../models/resource";
 import { CollectionResource } from "../../models/collection";
 import { collectionService } from "../../services/services";
 import { collectionPanelFilesAction } from "./collection-panel-files/collection-panel-files-actions";
-import { parseKeepManifestText } from "../../models/keep-manifest";
-import { mapManifestToCollectionFilesTree } from "../../models/collection-file";
-import { getNodeChildren, createTree } from "../../models/tree";
+import { createTree } from "../../models/tree";
+import { mapManifestToCollectionFilesTree } from "../../services/collection-files-service/collection-manifest-mapper";
+import { parseKeepManifestText } from "../../services/collection-files-service/collection-manifest-parser";
 
 export const collectionPanelActions = unionize({
     LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-reducer.test.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-reducer.test.ts
index 88b7fd0..636b592 100644
--- a/src/store/collection-panel/collection-panel-files/collection-panel-files-reducer.test.ts
+++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-reducer.test.ts
@@ -4,22 +4,22 @@
 
 import { collectionPanelFilesReducer } from "./collections-panel-files-reducer";
 import { collectionPanelFilesAction } from "./collection-panel-files-actions";
-import { CollectionFile, CollectionDirectory, createFile, createDirectory } from "../../../models/collection-file";
+import { CollectionFile, CollectionDirectory, createCollectionFile, createCollectionDirectory } from "../../../models/collection-file";
 import { createTree, setNode, getNodeValue, mapTreeValues, Tree } from "../../../models/tree";
 import { CollectionPanelFile, CollectionPanelDirectory } from "./collection-panel-files-state";
 
 describe('CollectionPanelFilesReducer', () => {
 
     const files: Array<CollectionFile | CollectionDirectory> = [
-        createDirectory({ id: 'Directory 1', name: 'Directory 1', parentId: '' }),
-        createDirectory({ id: 'Directory 2', name: 'Directory 2', parentId: 'Directory 1' }),
-        createDirectory({ id: 'Directory 3', name: 'Directory 3', parentId: '' }),
-        createDirectory({ id: 'Directory 4', name: 'Directory 4', parentId: 'Directory 3' }),
-        createFile({ id: 'file1.txt', name: 'file1.txt', parentId: 'Directory 2' }),
-        createFile({ id: 'file2.txt', name: 'file2.txt', parentId: 'Directory 2' }),
-        createFile({ id: 'file3.txt', name: 'file3.txt', parentId: 'Directory 3' }),
-        createFile({ id: 'file4.txt', name: 'file4.txt', parentId: 'Directory 3' }),
-        createFile({ id: 'file5.txt', name: 'file5.txt', parentId: 'Directory 4' }),
+        createCollectionDirectory({ id: 'Directory 1', name: 'Directory 1', parentId: '' }),
+        createCollectionDirectory({ id: 'Directory 2', name: 'Directory 2', parentId: 'Directory 1' }),
+        createCollectionDirectory({ id: 'Directory 3', name: 'Directory 3', parentId: '' }),
+        createCollectionDirectory({ id: 'Directory 4', name: 'Directory 4', parentId: 'Directory 3' }),
+        createCollectionFile({ id: 'file1.txt', name: 'file1.txt', parentId: 'Directory 2' }),
+        createCollectionFile({ id: 'file2.txt', name: 'file2.txt', parentId: 'Directory 2' }),
+        createCollectionFile({ id: 'file3.txt', name: 'file3.txt', parentId: 'Directory 3' }),
+        createCollectionFile({ id: 'file4.txt', name: 'file4.txt', parentId: 'Directory 3' }),
+        createCollectionFile({ id: 'file5.txt', name: 'file5.txt', parentId: 'Directory 4' }),
     ];
 
     const collectionFilesTree = files.reduce((tree, file) => setNode({
@@ -35,7 +35,7 @@ describe('CollectionPanelFilesReducer', () => {
 
     it('SET_COLLECTION_FILES', () => {
         expect(getNodeValue('Directory 1')(collectionPanelFilesTree)).toEqual({
-            ...createDirectory({ id: 'Directory 1', name: 'Directory 1', parentId: '' }),
+            ...createCollectionDirectory({ id: 'Directory 1', name: 'Directory 1', parentId: '' }),
             collapsed: true,
             selected: false
         });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list