| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  | import { faker } from 'ember-cli-mirage'; | 
					
						
							| 
									
										
										
										
											2018-02-14 16:00:32 -08:00
										 |  |  | import { IFunctionRouteHandler, IMirageServer } from 'wherehows-web/typings/ember-cli-mirage'; | 
					
						
							|  |  |  | import { ApiStatus } from 'wherehows-web/utils/api/shared'; | 
					
						
							| 
									
										
										
										
											2018-02-21 09:46:04 -08:00
										 |  |  | import { getDatasetColumns, getDatasetSchema } from 'wherehows-web/mirage/helpers/columns'; | 
					
						
							| 
									
										
										
										
											2018-02-09 00:04:22 -08:00
										 |  |  | import { getDatasetCompliance } from 'wherehows-web/mirage/helpers/compliance'; | 
					
						
							|  |  |  | import { getComplianceDataTypes } from 'wherehows-web/mirage/helpers/compliance-data-types'; | 
					
						
							|  |  |  | import { getDatasetComplianceSuggestion } from 'wherehows-web/mirage/helpers/compliance-suggestions'; | 
					
						
							|  |  |  | import { getDataset } from 'wherehows-web/mirage/helpers/dataset'; | 
					
						
							|  |  |  | import { getDatasetAccess } from 'wherehows-web/mirage/helpers/dataset-access'; | 
					
						
							|  |  |  | import { getDatasetComments } from 'wherehows-web/mirage/helpers/dataset-comments'; | 
					
						
							|  |  |  | import { getDatasetDbVersions } from 'wherehows-web/mirage/helpers/dataset-db-versions'; | 
					
						
							|  |  |  | import { getDatasetDepends } from 'wherehows-web/mirage/helpers/dataset-depends'; | 
					
						
							|  |  |  | import { getDatasetImpact } from 'wherehows-web/mirage/helpers/dataset-impact'; | 
					
						
							|  |  |  | import { getDatasetInstances } from 'wherehows-web/mirage/helpers/dataset-instances'; | 
					
						
							|  |  |  | import { getDatasetOwners } from 'wherehows-web/mirage/helpers/dataset-owners'; | 
					
						
							|  |  |  | import { getDatasetPlatforms } from 'wherehows-web/mirage/helpers/dataset-platforms'; | 
					
						
							|  |  |  | import { getDatasetProperties } from 'wherehows-web/mirage/helpers/dataset-properties'; | 
					
						
							|  |  |  | import { getDatasetReferences } from 'wherehows-web/mirage/helpers/dataset-references'; | 
					
						
							|  |  |  | import { getDatasetSample } from 'wherehows-web/mirage/helpers/dataset-sample'; | 
					
						
							|  |  |  | import { getDatasetView } from 'wherehows-web/mirage/helpers/dataset-view'; | 
					
						
							|  |  |  | import { getOwnerTypes } from 'wherehows-web/mirage/helpers/owner-types'; | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  | import { getConfig } from 'wherehows-web/mirage/helpers/config'; | 
					
						
							|  |  |  | import { getAuth } from 'wherehows-web/mirage/helpers/authenticate'; | 
					
						
							| 
									
										
										
										
											2018-02-07 12:32:03 -08:00
										 |  |  | import { aclAuth } from 'wherehows-web/mirage/helpers/aclauth'; | 
					
						
							| 
									
										
										
										
											2017-08-15 23:16:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default function(this: IMirageServer) { | 
					
						
							| 
									
										
										
										
											2017-10-02 15:27:38 -07:00
										 |  |  |   this.get('/config', getConfig); | 
					
						
							| 
									
										
										
										
											2017-08-15 23:16:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |   this.post('/authenticate', getAuth); | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 10:18:23 -08:00
										 |  |  |   this.passthrough('/write-coverage'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 00:04:22 -08:00
										 |  |  |   this.namespace = '/api/v2'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 09:46:04 -08:00
										 |  |  |   this.get('/datasets/:identifier/', getDatasetView); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:identifier/owners', getDatasetOwners); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/schema', getDatasetSchema); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/compliance/suggestions', getDatasetComplianceSuggestion); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/owners', getDatasetOwners); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 17:33:42 -08:00
										 |  |  |   this.get('/list/compliance-data-types', getComplianceDataTypes); | 
					
						
							| 
									
										
										
										
											2018-02-09 00:04:22 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   this.get('/list/platforms', getDatasetPlatforms); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 03:42:40 -07:00
										 |  |  |   this.namespace = '/api/v1'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 00:04:22 -08:00
										 |  |  |   this.get('/datasets/:dataset_id', getDataset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/view', getDatasetView); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/columns', getDatasetColumns); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/compliance', getDatasetCompliance); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/compliance/suggestions', getDatasetComplianceSuggestion); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/comments', getDatasetComments); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/owners', getDatasetOwners); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/instances', getDatasetInstances); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/owner/types', getOwnerTypes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/sample', getDatasetSample); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/impacts', getDatasetImpact); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/depends', getDatasetDepends); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/access', getDatasetAccess); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/references', getDatasetReferences); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/properties', getDatasetProperties); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/datasets/:dataset_id/versions/db/:db_id', getDatasetDbVersions); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:20:19 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |   interface IFlowsObject { | 
					
						
							|  |  |  |     flows: any; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   this.get('/flows', function(this: IFunctionRouteHandler, { flows }: IFlowsObject, request: any) { | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |     const { page } = request.queryParams; | 
					
						
							|  |  |  |     const flowsArr = this.serialize(flows.all()); | 
					
						
							|  |  |  |     const count = faker.random.number({ min: 20000, max: 40000 }); | 
					
						
							|  |  |  |     const itemsPerPage = 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2017-10-11 17:44:18 -07:00
										 |  |  |       status: ApiStatus.OK, | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |       data: { | 
					
						
							|  |  |  |         count: count, | 
					
						
							|  |  |  |         flows: flowsArr, | 
					
						
							|  |  |  |         itemsPerPage: itemsPerPage, | 
					
						
							|  |  |  |         page: page, | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |         totalPages: Math.round(count / itemsPerPage) | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/list/datasets', (server: any) => { | 
					
						
							|  |  |  |     const { datasetNodes } = server.db; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       status: 'ok', | 
					
						
							|  |  |  |       nodes: datasetNodes | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   interface IOwnersObject { | 
					
						
							|  |  |  |     owners: any; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   interface IDatasetsObject { | 
					
						
							|  |  |  |     datasets: any; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   this.get('/datasets', function( | 
					
						
							|  |  |  |     this: IFunctionRouteHandler, | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |     { datasets }: IDatasetsObject, | 
					
						
							|  |  |  |     { owners }: IOwnersObject, | 
					
						
							|  |  |  |     request: any | 
					
						
							|  |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |     const { page } = request.queryParams; | 
					
						
							|  |  |  |     const datasetsArr = this.serialize(datasets.all()); | 
					
						
							|  |  |  |     const ownersArr = this.serialize(owners.all()); | 
					
						
							|  |  |  |     const newDatasetsArr = datasetsArr.map(function(dataset: any) { | 
					
						
							|  |  |  |       dataset.owners = ownersArr; | 
					
						
							|  |  |  |       return dataset; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const count = faker.random.number({ min: 20000, max: 40000 }); | 
					
						
							|  |  |  |     const itemsPerPage = 10; | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2017-10-11 17:44:18 -07:00
										 |  |  |       status: ApiStatus.OK, | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |       data: { | 
					
						
							|  |  |  |         count: count, | 
					
						
							|  |  |  |         page: page, | 
					
						
							|  |  |  |         itemsPerPage: itemsPerPage, | 
					
						
							|  |  |  |         totalPages: Math.round(count / itemsPerPage), | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |         datasets: newDatasetsArr | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/metrics', (server: any, request: any) => { | 
					
						
							|  |  |  |     const { page } = request.queryParams; | 
					
						
							|  |  |  |     const { metricMetrics } = server.db; | 
					
						
							|  |  |  |     const count = faker.random.number({ min: 10000, max: 20000 }); | 
					
						
							|  |  |  |     const itemsPerPage = 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2017-10-11 17:44:18 -07:00
										 |  |  |       status: ApiStatus.OK, | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |       data: { | 
					
						
							|  |  |  |         count: count, | 
					
						
							|  |  |  |         page: page, | 
					
						
							|  |  |  |         itemsPerPage: itemsPerPage, | 
					
						
							|  |  |  |         totalPages: Math.round(count / itemsPerPage), | 
					
						
							|  |  |  |         metrics: metricMetrics | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/party/entities', (server: any) => { | 
					
						
							|  |  |  |     const { userEntities } = server.db; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2017-10-11 17:44:18 -07:00
										 |  |  |       status: ApiStatus.OK, | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |       userEntities: userEntities | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   this.get('/user/me', () => { | 
					
						
							|  |  |  |     const testUser = 'testUser'; | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       user: { | 
					
						
							|  |  |  |         id: faker.random.number({ min: 1000, max: 5000 }), | 
					
						
							|  |  |  |         userName: testUser, | 
					
						
							|  |  |  |         departmentNum: 0, | 
					
						
							|  |  |  |         email: testUser + '@linkedin.com', | 
					
						
							|  |  |  |         name: testUser, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:46:47 -08:00
										 |  |  |         userSetting: <{ [prop: string]: null }>{ | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |           detailDefaultView: null, | 
					
						
							|  |  |  |           defaultWatch: null | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2017-10-11 17:44:18 -07:00
										 |  |  |       status: ApiStatus.OK | 
					
						
							| 
									
										
										
										
											2017-10-09 14:44:19 -07:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:20:19 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 12:32:03 -08:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Add GET request to check the current user ACL permission | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   this.get('/acl', (server: any, request: any) => { | 
					
						
							|  |  |  |     if (request.queryParams.hasOwnProperty('LDAP')) { | 
					
						
							|  |  |  |       const { LDAP } = request.queryParams; | 
					
						
							|  |  |  |       const principal = `urn:li:userPrincipal:${LDAP}`; | 
					
						
							|  |  |  |       let accessUserslist = server.db.datasetAclUsers.where({ principal }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (accessUserslist.length > 0) { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           status: ApiStatus.OK, | 
					
						
							|  |  |  |           isAccess: true, | 
					
						
							|  |  |  |           body: server.db.datasetAclUsers | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         status: ApiStatus.FAILED, | 
					
						
							|  |  |  |         isAccess: false, | 
					
						
							|  |  |  |         body: server.db.datasetAclUsers | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         users: server.db.datasetAclUsers, | 
					
						
							|  |  |  |         status: ApiStatus.OK | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Add POST request to support to the current user get ACL permission. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   this.post('/acl', aclAuth); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 17:44:18 -07:00
										 |  |  |   this.passthrough(); | 
					
						
							| 
									
										
										
										
											2017-08-15 23:16:38 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-02 15:27:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  | export function testConfig(this: IMirageServer) {} |