Skip to content

Commit

Permalink
Updated implementation
Browse files Browse the repository at this point in the history
- Updated implementation of fileObj value
- Review pipeline fully functional with tree view
  • Loading branch information
shayanaijaz committed Oct 24, 2024
1 parent 81723ef commit 2742ce4
Show file tree
Hide file tree
Showing 19 changed files with 489 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const DataFilesProjectFileListing = ({ system, path }) => {
type: 'PROJECTS_GET_METADATA',
payload: system,
});

dispatch({
type: 'PROJECTS_GET_PUBLICATION_REQUESTS',
payload: system,
})

}, [system]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ReviewProjectStructure = ({ projectTree }) => {

useEffect(() => {
if (projectTree && projectTree.length > 0) {
setExpandedNodes([projectTree[0].uuid]);
setExpandedNodes([projectTree[0].id]);
}
}, [projectTree]);

Expand Down Expand Up @@ -65,7 +65,7 @@ const ReviewProjectStructure = ({ projectTree }) => {
const dataType = node.metadata.data_type;
// reconstruct editFile to mimic SelectedFile object
const editFile = {
id: node.uuid,
id: node.id,
uuid: node.uuid,
metadata: node.metadata,
name: node.metadata.name,
Expand Down Expand Up @@ -122,8 +122,8 @@ const ReviewProjectStructure = ({ projectTree }) => {
>
<div>
<TreeItem
key={node.uuid}
nodeId={node.uuid}
key={node.id}
nodeId={node.id}
label={
<div className={styles['node-name-div']}>
{node.label ?? node.name}
Expand All @@ -139,7 +139,7 @@ const ReviewProjectStructure = ({ projectTree }) => {
}}
onLabelClick={() => handleNodeToggle}
>
{expandedNodes.includes(node.uuid) && node.id !== 'NODE_ROOT' && (
{expandedNodes.includes(node.id) && node.id !== 'NODE_ROOT' && (
<div className={styles['metadata-description-div']}>
{(canEdit || node.metadata.data_type === 'file') && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ const DataFilesProjectReview = ({ system }) => {
const { metadata } = useSelector((state) => state.projects);

const fetchTree = useCallback(async () => {
if (projectId) {
try {
const response = await fetchUtil({
url: `api/${portalName.toLowerCase()}/tree`,
params: {
project_id: projectId,
},
});
setTree(response);
const response = await fetchUtil({
url: `api/${portalName.toLowerCase()}/tree`,
params: {
project_id: projectId,
},
});
setTree(response);
} catch (error) {
console.error('Error fetching tree data:', error);
setTree([]);
console.error('Error fetching tree data:', error);
setTree([]);
}
}
}, [portalName, projectId]);

useEffect(() => {
Expand Down
35 changes: 35 additions & 0 deletions client/src/redux/reducers/projects.reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function projects(state = initialState, action) {
return {
...state,
metadata: {
...state.metadata,
...action.payload,
loading: false,
error: null,
Expand Down Expand Up @@ -249,6 +250,40 @@ export default function projects(state = initialState, action) {
result: null,
},
};
case 'PROJECTS_GET_PUBLICATION_REQUESTS_STARTED':
return {
...state,
operation: {
name: 'getPublicationRequests',
loading: true,
error: null,
result: null,
},
};
case 'PROJECTS_GET_PUBLICATION_REQUESTS_SUCCESS':
return {
...state,
metadata: {
...state.metadata,
publication_requests: action.payload,
},
operation: {
name: 'getPublicationRequests',
loading: false,
error: null,
result: action.payload,
},
}
case 'PROJECTS_GET_PUBLICATION_REQUESTS_FAILED':
return {
...state,
operation: {
name: 'getPublicationRequests',
loading: false,
error: action.payload,
result: null,
},
};
default:
return state;
}
Expand Down
27 changes: 27 additions & 0 deletions client/src/redux/sagas/projects.sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,32 @@ export function* createPublicationRequest(action) {
}
}

export async function fetchPublicationRequestsUtil(system) {
const result = await fetchUtil({
url: `/api/publications/publication-request/${system}`,
});
return result.response;
}

export function* getPublicationRequests(action) {

yield put({
type: 'PROJECTS_GET_PUBLICATION_REQUESTS_STARTED',
});
try {
const publicationRequests = yield call(fetchPublicationRequestsUtil, action.payload);
yield put({
type: 'PROJECTS_GET_PUBLICATION_REQUESTS_SUCCESS',
payload: publicationRequests,
});
} catch (error) {
yield put({
type: 'PROJECTS_GET_PUBLICATION_REQUESTS_FAILED',
payload: error,
});
}
}

export async function createEntityUtil(entityType, projectId, path, data) {
const result = await fetchUtil({
url: `/api/projects/${projectId}/entities/create`,
Expand Down Expand Up @@ -259,4 +285,5 @@ export function* watchProjects() {
yield takeLatest('PROJECTS_SET_MEMBER', setMember);
yield takeLatest('PROJECTS_SET_TITLE_DESCRIPTION', setTitleDescription);
yield takeLatest('PROJECTS_CREATE_PUBLICATION_REQUEST', createPublicationRequest);
yield takeLatest('PROJECTS_GET_PUBLICATION_REQUESTS', getPublicationRequests);
}
46 changes: 23 additions & 23 deletions server/portal/apps/_custom/drp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ def model_dump(self, *args, **kwargs):
return partial(super().model_dump, by_alias=True, exclude_none=True)(
*args, **kwargs
)

class DrpFileMetadata(DrpMetadataModel):
"""Model for DRP File Metadata"""

model_config = ConfigDict(
extra="forbid",
)

data_type: Literal['file']
name: Optional[str] = None
image_type: Optional[Literal[
'8_bit', '16_bit_signed', '16_bit_unsigned', '32_bit_signed', '32_bit_unsigned', '32_bit_real', '64_bit_real',
'24_bit_rgb', '24_bit_rgb_planar', '24_bit_bgr', '24_bit_integer', '32_bit_argb', '32_bit_abgr', '1_bit_bitmap',
]] = None
height: Optional[int] = None
width: Optional[int] = None
number_of_images: Optional[int] = None
offset_to_first_image: Optional[int] = None
gap_between_images: Optional[int] = None
byte_order: Optional[Literal['big_endian', 'little_endian']] = None

class FileObj(DrpMetadataModel):
"""Model for associated files"""
Expand All @@ -32,6 +52,7 @@ class FileObj(DrpMetadataModel):
length: Optional[int] = None
last_modified: Optional[str] = None
uuid: Optional[str] = None
value: Optional[DrpFileMetadata] = None

class PartialEntityWithFiles(DrpMetadataModel):
"""Model for representing an entity with associated files."""
Expand All @@ -40,7 +61,6 @@ class PartialEntityWithFiles(DrpMetadataModel):

# file_tags: list[FileTag] = []
file_objs: list[FileObj] = []

class DrpProjectRelatedDatasets(DrpMetadataModel):
"""Model for DRP Project Related Datasets"""

Expand Down Expand Up @@ -77,7 +97,6 @@ class DrpProjectRelatedPublications(DrpMetadataModel):
publication_description: Optional[str] = None
publication_link: Optional[str] = None


class DrpProjectMetadata(DrpMetadataModel):
"""Model for DRP Project Metadata"""

Expand All @@ -95,8 +114,9 @@ class DrpProjectMetadata(DrpMetadataModel):
related_software: list[DrpProjectRelatedSoftware] = []
related_publications: list[DrpProjectRelatedPublications] = []
publication_date: Optional[str] = None
authors: list[str] = []
authors: list[dict] = []
file_objs: list[FileObj] = []
is_review_project : Optional[bool] = None

class DrpDatasetMetadata(DrpMetadataModel):
"""Model for Base DRP Dataset Metadata"""
Expand Down Expand Up @@ -192,23 +212,3 @@ class DrpAnalysisDatasetMetadata(DrpDatasetMetadata):
external_uri: Optional[str] = None
sample: str
base_origin_data: Optional[str] = None

class DrpFileMetadata(DrpMetadataModel):
"""Model for DRP File Metadata"""

model_config = ConfigDict(
extra="forbid",
)

data_type: Literal['file']
name: Optional[str] = None
image_type: Optional[Literal[
'8_bit', '16_bit_signed', '16_bit_unsigned', '32_bit_signed', '32_bit_unsigned', '32_bit_real', '64_bit_real',
'24_bit_rgb', '24_bit_rgb_planar', '24_bit_bgr', '24_bit_integer', '32_bit_argb', '32_bit_abgr', '1_bit_bitmap',
]] = None
height: Optional[int] = None
width: Optional[int] = None
number_of_images: Optional[int] = None
offset_to_first_image: Optional[int] = None
gap_between_images: Optional[int] = None
byte_order: Optional[Literal['big_endian', 'little_endian']] = None
31 changes: 17 additions & 14 deletions server/portal/apps/_custom/drp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from portal.apps.projects.models.project_metadata import ProjectMetadata
from portal.apps._custom.drp import constants
import networkx as nx
from portal.apps.projects.workspace_operations.project_meta_operations import get_ordered_value
class DigitalRocksSampleView(BaseApiView):

def get(self, request):
Expand Down Expand Up @@ -55,8 +56,6 @@ def _get_entity(uuid):

def get(self, request):

metadata_data_types = ['sample', 'origin_data', 'analysis_data', 'file']

project_id = request.GET.get('project_id')
full_project_id = f'{settings.PORTAL_PROJECTS_SYSTEM_PREFIX}.{project_id}'

Expand All @@ -66,27 +65,31 @@ def get(self, request):

graph = nx.node_link_graph(graph_model.value)

for node in graph.nodes:
node_uuid = graph.nodes[node].get("uuid")
for node_id in graph.nodes:

entity = self._get_entity(node_uuid)
metadata = entity.ordered_value
node = graph.nodes[node_id]

file_objs = entity.value.get('fileObjs', [])
if node.get('value'):
metadata = get_ordered_value(node['name'], node['value'])
file_objs = node['value'].get('fileObjs', [])
else:
node_uuid = node.get("uuid")
entity = self._get_entity(node_uuid)
metadata = get_ordered_value(entity.name, entity.value)
file_objs = entity.value.get('fileObjs', [])

file_objs_dict = []

for file_obj in file_objs:
file_obj_entity = self._get_entity(file_obj.get('uuid'))
file_obj_metadata = file_obj_entity.ordered_value

file_objs_dict.append({
**file_obj,
'metadata': file_obj_metadata
})

graph.nodes[node]['metadata'] = metadata
graph.nodes[node]['fileObjs'] = file_objs_dict
'id': file_obj.get('uuid'),
'metadata': get_ordered_value(constants.FILE, file_obj.get('value'))
})

node['metadata'] = metadata
node['fileObjs'] = file_objs_dict

tree = nx.tree_data(graph, "NODE_ROOT")

Expand Down
Loading

0 comments on commit 2742ce4

Please sign in to comment.