/** * Find documents based on filter. * * @param {String} collection Collection name * @param {Object} filter Key, value Object * @param {Object} options options.limit, options.offset * @return {Promise<any>} Promise for list of found documents. */ async find(collectionName: string, filter: any, options: any): Promise<any> { if (_.isNil(collectionName) || !_.isString(collectionName) || _.isEmpty(collectionName)) { throw new Error('invalid or missing collection argument'); } let filterQuery: any = filter || {}; const opts = options || {}; let filterResult: any; let bindVars: any; let customFilter = ''; // checking if a custom query should be used if (!_.isEmpty(opts.customQueries)) { for (let queryName of opts.customQueries) { if (!this.customQueries.has(queryName)) { throw new Error(`custom query ${query} not found`); } const customQuery = this.customQueries.get(queryName); if (customQuery.type == 'query') { // standalone query const result: ArrayCursor = await query(this.db, collectionName, customQuery.code, opts.customArguments || {}); // Cursor object return result.all(); // TODO: paginate } else { // filter customFilter += ` ${customQuery.code} `; } } } if (!_.isArray(filterQuery)) { filterQuery = [filterQuery]; } if (_.isEmpty(filterQuery[0])) { filterQuery = true; } else { filterResult = buildFilter(filterQuery); filterQuery = filterResult.q; } let sortQuery = buildSorter(opts); let limitQuery = buildLimiter(opts); let returnResult = buildReturn(opts); let returnQuery = returnResult.q; // return complete node in case no specific fields are specified if (_.isEmpty(returnQuery)) { returnQuery = 'RETURN node'; } let queryString = `FOR node in @@collection FILTER ${filterQuery}`; if (!_.isEmpty(customFilter)) { queryString += customFilter; } queryString += ` ${sortQuery} ${limitQuery} ${returnQuery}`; let varArgs = {}; if (filterResult && filterResult.bindVarsMap) { varArgs = filterResult.bindVarsMap; } let returnArgs = {}; if (returnResult && returnResult.bindVarsMap) { returnArgs = returnResult.bindVarsMap; } let limitArgs; if (_.isEmpty(limitQuery)) { limitArgs = {}; } else { if (!_.isNil(opts.limit)) { limitArgs = { limit: opts.limit }; if (!_.isNil(opts.offset)) { limitArgs = { offset: opts.offset, limit: opts.limit }; } } } varArgs = _.assign(varArgs, limitArgs); varArgs = _.assign(varArgs, returnArgs); bindVars = _.assign({ '@collection': collectionName }, varArgs); if (!_.isEmpty(customFilter) && opts.customArguments) { bindVars = _.assign(bindVars, opts.customArguments); } const res = await query(this.db, collectionName, queryString, bindVars); const docs = await res.all(); // TODO: paginate return _.map(docs, sanitizeOutputFields); }
update.extend('$assign', (spec, object) => _.assign({}, object, spec));
return this.getLedgerVersion().then(ledgerVersion => _.assign({}, options, {ledgerVersion}))
todo => todo.id === action.id ? assign({}, todo, { completed: !todo.completed }) : todo,
M: MALE_COLOR, POSITIVE: YES_COLOR, NEGATIVE: NO_COLOR, MISSENSE: MUT_COLOR_MISSENSE, INFRAME: MUT_COLOR_INFRAME, TRUNCATING: MUT_COLOR_TRUNC, FUSION: MUT_COLOR_FUSION, PROMOTER: MUT_COLOR_PROMOTER, OTHER: MUT_COLOR_OTHER, "WILD TYPE": DEFAULT_GREY, AMPLIFICATION: CNA_COLOR_AMP, GAIN: CNA_COLOR_GAIN, DIPLOID: DEFAULT_GREY, "SHALLOW DELETION": CNA_COLOR_HETLOSS, "DEEP DELETION": CNA_COLOR_HOMDEL }, na: "#CCCCCC", mutatedGene: '#008000', deletion: '#0000FF', amplification: '#FF0000', } }; _.forEach(studyViewFrontEnd.colors.reservedValue, (color, key)=>{ // expand reservedValue entries to handle other case possibilities. eg expand TRUE to True and true (studyViewFrontEnd.colors.reservedValue as any)[key.toLowerCase()] = color; (studyViewFrontEnd.colors.reservedValue as any)[key[0] + key.slice(1).toLowerCase()] = color; }); export const STUDY_VIEW_CONFIG: StudyViewConfig = _.assign(studyViewFrontEnd, AppConfig.serverConfig.study_view);
return super.getNewInstance().then((newInstance) => _.assign(newInstance, {id: uuid.v4()}));
export function put(obj?: any): RequestInit { return assign({}, { method: "PUT" }, convert(obj)); }
.add<UpdatePeripheral>("UPDATE_PERIPHERAL", function (s, a) { let target = s.all[a.payload.index]; _.assign(target, a.payload.peripheral, { dirty: true }); return s; });
/** * This is the worker function that *optimizes* an existing variation (or original) * * Note that we assume that original files always stay in the protected * folder and aren't moved on activation. If that changes, the optimization * queue must also work with a copy of the original file to avoid file * access conflicts. * * @param {Job} job * @return {Promise<any>} */ public static async optimize(job: Job): Promise<any> { let file: FileDocument; // retrieve data from deserialized job const data = job.data as JobData; const srcPath = data.srcPath; const destPath = data.destPath; // {filename}.{processor}._processing.{ext} const requestState = data.requestState; file = await state.models.File.findOne({ id: data.fileId }).exec(); if (!file) { logger.warn(requestState, '[ProcessorWorker.optimize] [%s | #%s] skip: File "%s" has been removed from DB, ignoring.', data.processor, job.id, data.fileId); return null; } const processor = processorManager.getOptimizationProcessor(data.processor); const variation = file.getVariation(data.destVariation); try { // create directory if (!(await FileUtil.exists(dirname(destPath)))) { await FileUtil.mkdirp(dirname(destPath)); } logger.debug(requestState, '[ProcessorWorker.optimize] [%s | #%s] start: %s from %s to %s', data.processor, job.id, file.toDetailedString(variation), FileUtil.log(srcPath), FileUtil.log(destPath)); // run processor const createdFile = await processor.process(requestState, file, srcPath, destPath, variation); if (isUndefined(createdFile)) { throw new ApiError('Processor %s returned undefined but is supposed to return null or path to processed file.', processor.name); } // if a new file was created, update metadata and delete if necessary. if (createdFile) { // update metadata if some processing took place const metadataReader = Metadata.getReader(file, variation); const metadata = await metadataReader.getMetadata(requestState, file, createdFile, variation); const fileData: any = {}; if (variation) { fileData['variations.' + variation.name] = assign(metadataReader.serializeVariation(metadata), { bytes: (await statAsync(destPath)).size, mime_type: variation.mimeType, }); } else { fileData.metadata = await Metadata.readFrom(requestState, file, destPath); fileData.bytes = (await statAsync(destPath)).size; } await state.models.File.findOneAndUpdate({ _id: file._id }, { $set: fileData }).exec(); // abort if deleted if (await ProcessorWorker.isFileDeleted(file)) { logger.debug(requestState, '[ProcessorWorker.optimize] Removing created file due to deletion %s', FileUtil.log(destPath)); await unlinkAsync(createdFile); return null; } } // rename const newPath = await ProcessorWorker.isFileRenamed(requestState, file.getPath(requestState, variation), 'optimize'); const finalPath = newPath || file.getPath(requestState, variation); if (createdFile) { await renameAsync(createdFile, finalPath); // overwrites destination } logger.debug(requestState, '[ProcessorWorker.optimize] [%s | #%s] done: %s at %s', data.processor, job.id, file.toDetailedString(variation), FileUtil.log(finalPath)); return finalPath; } catch (err) { // nothing to return here because it's in the background. if (err.isApiError) { logger.error(requestState, err.print()); } else { logger.error(requestState, '[ProcessorWorker.optimize] Error while processing %s with %s:\n\n%s\n\n', file ? file.toDetailedString(variation) : 'null', job.data.processor, ApiError.colorStackTrace(err)); } // TODO log to raygun } }
function makeWholeSpec(initFn) { const initResult = initFn(browser); memberName = initResult.member; usersBrowser = _.assign(browser, pagesFor(browser)); memberIsAdmin = initResult.memberIsAdmin; forum = buildSite().addLargeForum({ title: forumTitle, members: ['alice', 'maria', 'michael'], }); const who = (memberIsAdmin ? "admin " : (memberName ? "member " : "a stranger")) + (memberName || ''); describe(`Navigation as ${who}:`, () => { it("import a site", () => { idAddress = server.importSiteData(forum.siteData); }); it("go to forum", () => { usersBrowser.go(idAddress.origin); usersBrowser.disableRateLimits(); }); if (memberName) { it("login", () => { member = forum.members[memberName]; usersBrowser.complex.loginWithPasswordViaTopbar(member); }); } it("Prepare tests: Add Maria's page to watchbar", () => { // This makes all different 'describe...' below work, also if the first one is skipped. usersBrowser.go('/' + forum.topics.byMariaCategoryA.slug); }); // ------- Test the forum // This tests navigation from all kinds of pages — user profile, search, topics — to the forum. describe("Test navigation to forum", () => { it("start at forum, to test forum", () => { usersBrowser.go(idAddress.origin); }); addForumTests("1: "); it("start at topic, go to forum, test forum", () => { usersBrowser.go('/' + forum.topics.byMariaCategoryA.slug); usersBrowser.topbar.clickHome(); }); addForumTests("2: "); it("remember / as last page", () => { usersBrowser.go('/'); }); it("start at user profile, go back to last page = to the forum, test forum", () => { usersBrowser.go('/-/users/maria'); usersBrowser.topbar.clickBack(); // goes back to the forum }); addForumTests("3: "); it("start at search page, go to forum, test forum", () => { usersBrowser.goToSearchPage(); usersBrowser.topbar.clickHome(); }); addForumTests("4: "); if (memberIsAdmin) { it("start in admin area, go to forum via watchbar, test forum", () => { usersBrowser.adminArea.goToLoginSettings(); usersBrowser.adminArea.waitAssertVisible(); usersBrowser.watchbar.openIfNeeded(); usersBrowser.watchbar.goToTopic(forumTitle, { isHome: true }); }); addForumTests("5: "); } }); // ------- Test a topic describe("Test navigation to topic", () => { it("start at forum, to test Maria's topic", () => { usersBrowser.go(idAddress.origin); }); it("... go to Maria's topic", () => { usersBrowser.forumTopicList.goToTopic(forum.topics.byMariaCategoryA.title); }); addMariasTopicTests(); it("start at another topic", () => { usersBrowser.go('/' + forum.topics.byMariaCategoryANr2.slug); }); it("... it looks ok", () => { usersBrowser.topic.waitForPostNrVisible(c.BodyNr); usersBrowser.topic.assertPostTextMatches(c.BodyNr, forum.topics.byMariaCategoryANr2.body); }); it("go to Maria's topic, test it (topic to topic)", () => { usersBrowser.watchbar.goToTopic(forum.topics.byMariaCategoryA.title); }); addMariasTopicTests(); it("start at user profile, go back to last page = to Maria's topic, test it", () => { usersBrowser.go('/-/users/maria'); usersBrowser.topbar.clickBack(); // goes back to the topic because it's the last page }); addMariasTopicTests(); it("start at search page, go back to topic, test it", () => { usersBrowser.goToSearchPage(); usersBrowser.topbar.clickBack(); }); addMariasTopicTests(); if (memberIsAdmin) { it("start in admin area, users list, go to topic", () => { usersBrowser.adminArea.goToUsersEnabled(); usersBrowser.adminArea.users.waitForLoaded(); usersBrowser.watchbar.goToTopic(forum.topics.byMariaCategoryA.title); }); addMariasTopicTests(); } }); // ------- Test user profile describe("Test navigation to user profile", () => { it("start at forum, to test Maria's profile page", () => { usersBrowser.go(idAddress.origin); }); it("... go to Maria's profile page", () => { usersBrowser.forumTopicList.openAboutUserDialogForUsername('maria'); usersBrowser.aboutUserDialog.clickViewProfile(); }); addMariasProfileTets("1: "); it("start at a topic", () => { usersBrowser.go('/' + forum.topics.byMariaCategoryANr2.slug); }); it("... go to Maria's profile page", () => { usersBrowser.pageTitle.openAboutAuthorDialog(); usersBrowser.aboutUserDialog.clickViewProfile(); }); addMariasProfileTets("2: "); it("start at another user's profile", () => { usersBrowser.go('/-/users/michael'); }); it("... it looks ok", () => { usersBrowser.userProfilePage.waitForName(); usersBrowser.userProfilePage.assertUsernameIs('michael'); }); it("... go to Maria's profile page", () => { usersBrowser.topbar.clickBack(); // goes back to Maria's topic nr 2 usersBrowser.pageTitle.openAboutAuthorDialog(); // about Maria usersBrowser.aboutUserDialog.clickViewProfile(); // goes to Maria's profile }); addMariasProfileTets("3: "); it("start at search page, go to Maria's profile, test profile page", () => { usersBrowser.goToSearchPage(); usersBrowser.watchbar.openIfNeeded(); usersBrowser.watchbar.goToTopic(forum.topics.byMariaCategoryA.title); usersBrowser.pageTitle.openAboutAuthorDialog(); // about Maria usersBrowser.aboutUserDialog.clickViewProfile(); // goes to Maria's profile }); addMariasProfileTets("4: "); if (memberIsAdmin) { it("start in admin area, about user page, go to user", () => { usersBrowser.adminArea.goToUser(forum.members.maria); usersBrowser.adminArea.user.waitForLoaded(); usersBrowser.adminArea.user.viewPublProfile(); }); addMariasProfileTets("5: "); } }); // ------- Create topic, then test everything if (memberName) describe("Test new topic, and navigation from it to everything", () => { it("go to forum, create a topic", () => { usersBrowser.go(idAddress.origin); usersBrowser.complex.createAndSaveTopic({ title: newTopicTitle, body: newTopicText }); }); it("... now test all types of pages: go back to the forum, test it", () => { usersBrowser.topbar.clickHome(); }); addForumTests("NT: "); it("... another topic", () => { usersBrowser.forumTopicList.goToTopic(forum.topics.byMariaCategoryA.title); }); addMariasTopicTests(); it("... a user profile page", () => { usersBrowser.pageTitle.openAboutAuthorDialog(); usersBrowser.aboutUserDialog.clickViewProfile(); }); addMariasProfileTets("New-topic: "); it("... the search page", () => { usersBrowser.topbar.searchFor(forum.topics.byMariaCategoryA.title); }); addSearchPageTests(forum.topics.byMariaCategoryA.title); }); // ------- Test search page profile describe("Test navigation to search page", () => { it("start at forum, to test search page", () => { usersBrowser.go(idAddress.origin); }); it("... go to search page, by searching for a title by Maria", () => { usersBrowser.topbar.searchFor(forum.topics.byMariaCategoryA.title); }); addSearchPageTests(forum.topics.byMariaCategoryA.title); it("start at a topic, search for sth", () => { usersBrowser.go('/' + forum.topics.byMichaelCategoryA.slug); usersBrowser.topbar.searchFor(forum.topics.byMariaCategoryANr2.title); }); addSearchPageTests(forum.topics.byMariaCategoryANr2.title); it("start at a user's profile, search for sth", () => { usersBrowser.go('/-/users/michael'); usersBrowser.topbar.searchFor(forum.topics.byMariaCategoryB.title); }); addSearchPageTests(forum.topics.byMariaCategoryB.title); it("start at search page, with q=CategoryB", () => { usersBrowser.goToSearchPage('CategoryB'); }); addSearchPageTests('CategoryB'); if (memberIsAdmin) { it("start in admin area, review section, search for staff-only page TyT85WABR0", () => { usersBrowser.adminArea.goToReview(); usersBrowser.topbar.searchFor(forum.topics.byMariaStaffOnlyCat.title); }); addSearchPageTests(forum.topics.byMariaStaffOnlyCat.title); } }); }); }