Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

986 reference papers #1011

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion database/009-create-mention-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ CREATE TABLE mention (
page VARCHAR(50),
image_url VARCHAR(500) CHECK (image_url ~ '^https?://'),
mention_type mention_type NOT NULL,
external_id VARCHAR(500),
source VARCHAR(50) NOT NULL,
version VARCHAR(100),
note VARCHAR(500),
scraped_at TIMESTAMPTZ,
citations_scraped_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL
updated_at TIMESTAMPTZ NOT NULL,
UNIQUE(external_id, source)
);

CREATE FUNCTION sanitise_insert_mention() RETURNS TRIGGER LANGUAGE plpgsql AS
Expand Down Expand Up @@ -81,6 +84,20 @@ CREATE TABLE mention_for_software (
);


CREATE TABLE reference_paper_for_software (
mention UUID REFERENCES mention (id),
software UUID REFERENCES software (id),
PRIMARY KEY (mention, software)
);


CREATE TABLE citation_for_mention (
mention UUID REFERENCES mention (id),
citation UUID REFERENCES mention (id),
PRIMARY KEY (mention, citation)
);


CREATE FUNCTION search_mentions_for_software(software_id UUID, search_text VARCHAR) RETURNS SETOF mention STABLE LANGUAGE plpgsql AS
$$
BEGIN
Expand Down
32 changes: 24 additions & 8 deletions database/020-row-level-security.sql
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,9 @@ CREATE POLICY admin_all_rights ON research_domain_for_project TO rsd_admin


-- mentions
-- TODO: not sure what to do here,
-- should a mention only be visible if you can see at least one software or project for which it relates?
ALTER TABLE mention ENABLE ROW LEVEL SECURITY;

CREATE POLICY anyone_can_read ON mention FOR SELECT TO rsd_web_anon, rsd_user
USING (id IN (SELECT mention FROM mention_for_software)
OR id IN (SELECT mention FROM output_for_project)
OR id IN (SELECT mention FROM impact_for_project)
OR id IN (SELECT mention_id FROM release_version));

CREATE POLICY maintainer_can_read ON mention FOR SELECT TO rsd_user
USING (TRUE);

CREATE POLICY maintainer_can_delete ON mention FOR DELETE TO rsd_user
Expand Down Expand Up @@ -484,6 +476,30 @@ CREATE POLICY admin_all_rights ON mention_for_software TO rsd_admin
WITH CHECK (TRUE);


ALTER TABLE reference_paper_for_software ENABLE ROW LEVEL SECURITY;

CREATE POLICY anyone_can_read ON reference_paper_for_software FOR SELECT TO rsd_web_anon, rsd_user
USING (software IN (SELECT id FROM software));

CREATE POLICY maintainer_all_rights ON reference_paper_for_software TO rsd_user
USING (software IN (SELECT * FROM software_of_current_maintainer()))
WITH CHECK (software IN (SELECT * FROM software_of_current_maintainer()));

CREATE POLICY admin_all_rights ON reference_paper_for_software TO rsd_admin
USING (TRUE)
WITH CHECK (TRUE);


ALTER TABLE citation_for_mention ENABLE ROW LEVEL SECURITY;

CREATE POLICY anyone_can_read ON citation_for_mention FOR SELECT TO rsd_web_anon, rsd_user
USING (mention IN (SELECT id FROM mention));

CREATE POLICY admin_all_rights ON citation_for_mention TO rsd_admin
USING (TRUE)
WITH CHECK (TRUE);


ALTER TABLE output_for_project ENABLE ROW LEVEL SECURITY;

CREATE POLICY anyone_can_read ON output_for_project FOR SELECT TO rsd_web_anon, rsd_user
Expand Down
82 changes: 82 additions & 0 deletions database/109-mention-views.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
-- SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
-- SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]>
-- SPDX-FileCopyrightText: 2023 Netherlands eScience Center
--
-- SPDX-License-Identifier: Apache-2.0

CREATE FUNCTION reference_papers_to_scrape()
RETURNS TABLE (
id UUID,
doi CITEXT,
citations_scraped_at TIMESTAMPTZ,
known_dois CITEXT[]
)
LANGUAGE sql STABLE AS
$$
SELECT mention.id, mention.doi, mention.citations_scraped_at, ARRAY_REMOVE(ARRAY_AGG(citation.doi), NULL)
FROM mention
LEFT JOIN citation_for_mention ON mention.id = citation_for_mention.mention
LEFT JOIN mention AS citation ON citation_for_mention.citation = citation.id
WHERE mention.id IN (
SELECT mention FROM reference_paper_for_software
)
GROUP BY mention.id
$$;

-- UNIQUE CITATIONS BY SOFTWARE ID
CREATE FUNCTION citation_by_software() RETURNS TABLE (
software UUID,
id UUID,
doi CITEXT,
url VARCHAR,
title VARCHAR,
authors VARCHAR,
publisher VARCHAR,
publication_year SMALLINT,
journal VARCHAR,
page VARCHAR,
image_url VARCHAR,
mention_type mention_type,
source VARCHAR,
reference_papers UUID[]
)LANGUAGE sql STABLE AS
$$
SELECT
reference_paper_for_software.software,
mention.id,
mention.doi,
mention.url,
mention.title,
mention.authors,
mention.publisher,
mention.publication_year,
mention.journal,
mention.page,
mention.image_url,
mention.mention_type,
mention.source,
ARRAY_AGG(
reference_paper_for_software.mention
) AS reference_paper
FROM
reference_paper_for_software
INNER JOIN
citation_for_mention ON citation_for_mention.mention = reference_paper_for_software.mention
INNER JOIN
mention ON mention.id = citation_for_mention.citation
GROUP BY
reference_paper_for_software.software,
mention.id,
mention.doi,
mention.url,
mention.title,
mention.authors,
mention.publisher,
mention.publication_year,
mention.journal,
mention.page,
mention.image_url,
mention.mention_type,
mention.source
;
$$;
2 changes: 1 addition & 1 deletion frontend/components/mention/MentionItemBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function MentionItemBase({item,pos,nav,type,role='find'}:MentionI
className="text-sm"
role={role}
/>
<MentionNote note={item.note} />
<MentionNote note={item.note ?? null} />
</article>
)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/mention/MentionViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function MentionViewItem({item, pos}: {item: MentionItemProps, po
doi={item?.doi}
className="text-sm"
/>
<MentionNote note={item.note} />
<MentionNote note={item.note ?? null} />
</div>
<div className="flex justify-center items-center">
{item?.url ? <LinkIcon /> : null}
Expand Down
44 changes: 24 additions & 20 deletions frontend/components/mention/useEditMentionReducer.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 dv4all
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

import {useContext} from 'react'
import {useCallback, useContext} from 'react'
import {EditMentionActionType} from './editMentionReducer'
import EditMentionContext from './editMentionContext'
import {MentionItemProps} from '~/types/Mention'

export default function useEditMentionReducer() {
const {state, dispatch} = useContext(EditMentionContext)

function setLoading(loading: boolean) {
const setLoading = useCallback((loading:boolean)=>{
dispatch({
type: EditMentionActionType.SET_LOADING,
payload: loading
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[])

function setMentions(mentions: MentionItemProps[]) {
const setMentions = useCallback((mentions: MentionItemProps[])=>{
dispatch({
type: EditMentionActionType.SET_MENTIONS,
payload: mentions
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[])

function onAdd(item: MentionItemProps) {
const onAdd = useCallback((item: MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_ADD,
payload: item
})
}
},[dispatch])

function onNewItem() {
const onNewItem = useCallback(()=>{
dispatch({
type: EditMentionActionType.SET_EDIT_MODAL,
payload: {
open:true
}
})
}
},[dispatch])

function onSubmit(item:MentionItemProps) {
const onSubmit = useCallback((item:MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_SUBMIT,
payload: item
})
}
},[dispatch])

function onUpdate(item:MentionItemProps) {
const onUpdate = useCallback((item:MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_UPDATE,
payload: item
})
}
},[dispatch])

function onDelete(item:MentionItemProps) {
const onDelete = useCallback((item:MentionItemProps)=>{
dispatch({
type: EditMentionActionType.ON_DELETE,
payload: item
})
}
},[dispatch])

function confirmDelete(item?: MentionItemProps) {
const confirmDelete = useCallback((item?: MentionItemProps)=>{
if (item) {
// open modal
dispatch({
Expand All @@ -81,9 +85,9 @@ export default function useEditMentionReducer() {
}
})
}
}
},[dispatch])

function setEditModal(item?: MentionItemProps) {
const setEditModal = useCallback((item?: MentionItemProps)=>{
if (item) {
// show modal when item provided
dispatch({
Expand All @@ -102,9 +106,9 @@ export default function useEditMentionReducer() {
}
})
}
}
},[dispatch])

// console.group('useOutputContext')
// console.group('useEditMentionReducer')
// console.log('state...', state)
// console.groupEnd()

Expand Down
23 changes: 17 additions & 6 deletions frontend/components/software/edit/editSoftwarePages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PersonAddIcon from '@mui/icons-material/PersonAdd'
import ContentLoader from '~/components/layout/ContentLoader'
import HomeRepairServiceIcon from '@mui/icons-material/HomeRepairService'
import PendingActionsIcon from '@mui/icons-material/PendingActions'
import PostAddIcon from '@mui/icons-material/PostAdd'

// import SoftwareInformation from './information'
// import SoftwareContributors from './contributors'
Expand All @@ -28,22 +29,25 @@ import PendingActionsIcon from '@mui/icons-material/PendingActions'
// import SoftwareMaintainers from './maintainers'

// use dynamic imports instead
const SoftwareContributors = dynamic(() => import('./contributors'),{
loading: ()=><ContentLoader />
})
const SoftwareInformation = dynamic(() => import('./information'),{
loading: ()=><ContentLoader />
})
const SoftwareContributors = dynamic(() => import('./contributors'),{
const SoftwareMaintainers = dynamic(() => import('./maintainers'),{
loading: ()=><ContentLoader />
})
const SoftwareOgranisations = dynamic(() => import('./organisations'),{
const SoftwareMentions = dynamic(() => import('./mentions'),{
loading: ()=><ContentLoader />
})
const PackageManagers = dynamic(() => import('./package-managers'),{
const SoftwareOgranisations = dynamic(() => import('./organisations'),{
loading: ()=><ContentLoader />
})
const SoftwareMentions = dynamic(() => import('./mentions'),{
const PackageManagers = dynamic(() => import('./package-managers'),{
loading: ()=><ContentLoader />
})
const SoftwareTestimonials = dynamic(() => import('./testimonials'),{
const ReferencePapers = dynamic(() => import('./reference-papers'),{
loading: ()=><ContentLoader />
})
const RelatedSoftware = dynamic(() => import('./related-software'),{
Expand All @@ -52,10 +56,11 @@ const RelatedSoftware = dynamic(() => import('./related-software'),{
const RelatedProjects = dynamic(() => import('./related-projects'),{
loading: ()=><ContentLoader />
})
const SoftwareMaintainers = dynamic(() => import('./maintainers'),{
const SoftwareTestimonials = dynamic(() => import('./testimonials'),{
loading: ()=><ContentLoader />
})


export type EditSoftwarePageProps = {
id: string
status: string,
Expand All @@ -82,6 +87,12 @@ export const editSoftwarePage:EditSoftwarePageProps[] = [{
icon: <FactoryIcon />,
render: () => <SoftwareOgranisations />,
status: 'Optional information'
},{
id: 'reference-paper',
label: 'Reference papers',
icon: <PostAddIcon />,
render: () => <ReferencePapers />,
status: 'Optional information'
},{
id: 'mentions',
label: 'Mentions',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2022 dv4all
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -112,7 +114,7 @@ export default function EditMentionsProvider(props: any) {
}
}
if (item.id) {
// existing RSD mention item to be added to project
// existing RSD mention item to be added to software
const resp = await addToMentionForSoftware({
software,
mention: item.id,
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/software/edit/mentions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]>
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
Expand All @@ -11,8 +12,8 @@ export type SearchTermInfo = {
term: string,
type: 'doi' | 'title'
}

export function extractSearchTerm(query: string): SearchTermInfo{

const doiRegexMatch = query.match(doiRegex)
if (doiRegexMatch != null) {
return {term: doiRegexMatch[0], type: 'doi'}
Expand Down
Loading