Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #208 from biocompute-objects/22.07
Browse files Browse the repository at this point in the history
22.07
  • Loading branch information
HadleyKing authored Jul 14, 2022
2 parents d66910c + 24d0d79 commit e8597e2
Show file tree
Hide file tree
Showing 31 changed files with 652 additions and 374 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"clsx": "^1.1.1",
"crypto-js": "^4.1.1",
"depcheck": "^1.4.2",
"file-saver": "^2.0.5",
"formik": "^2.1.5",
"moment": "^2.27.0",
"object-hash": "^2.2.0",
Expand Down
15 changes: 9 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function App() {
anon_api_info: [
{
token: '627626823549f787c3ec763ff687169206626149',
public_hostname: 'http://127.0.0.1:8000'
public_hostname: 'http://127.0.0.1:8000',
human_readable_hostname: 'BCO Server (Not Logged In)'
}
]
},
Expand All @@ -64,7 +65,8 @@ function App() {
anon_api_info: [
{
token: '627626823549f787c3ec763ff687169206626149',
public_hostname: 'https://test.portal.biochemistry.gwu.edu'
public_hostname: 'https://test.portal.biochemistry.gwu.edu',
human_readable_hostname: 'BCO Server (Not Logged In)'
}
]
},
Expand All @@ -86,15 +88,16 @@ function App() {
anon_api_info: [
{
token: 'b196023f46cdc919d064b0d9f210154d9a7a5b2e',
public_hostname: 'https://biocomputeobject.org'
public_hostname: 'https://biocomputeobject.org',
human_readable_hostname: 'BCO Server (Not Logged In)'
}
]
}
};
const versions = {
portal: '22.05.2',
bcodb: '22.05.1',
userdb: '22.05'
portal: '22.07',
bcodb: '22.07',
userdb: '22.07'
};

/**
Expand Down
58 changes: 58 additions & 0 deletions src/components/API/ApiValidateSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// /src/components/Api/ApiValidateSchema.js

/* Validated a BCO using the API */

import PropTypes from 'prop-types';
import { saveAs } from 'file-saver';

export default function ApiValidateSchema(objectInformation, contents, setPublish, viewResult) {
fetch(`${objectInformation.hostname}/api/objects/validate/`, {
method: 'POST',
body: JSON.stringify({
POST_validate_bco: [
contents
]

}),
headers: {
'Content-type': 'application/json; charset=UTF-8'
}
})
.then((response) => {
if (!response.ok) {
throw new Error(response.status);
} else {
return response.json()
.then((data) => {
if (response.status === 200) {
console.log('POST_validate_bco: Success!', data);
setPublish(true);
} else {
setPublish(false);
}
if (viewResult === 'download') {
const blob = new Blob([JSON.stringify(data)], { type: 'text/json' });
saveAs(blob, `${objectInformation.object_id}.json`);
}
if (viewResult === 'display') {
const link = document.createElement('a');
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'text/json' });
// alert(`Result display: ${blob}`);
link.href = URL.createObjectURL(blob);
window.open(link);
}
});
}
})
.catch((error) => {
console.log(`error: ${error}`);
alert(`Validate Draft FAILED! ${error}`);
});
}

ApiValidateSchema.PropTypes = {
objectInformation: PropTypes.object.isRequired,
contents: PropTypes.object.isRequired,
setPublish: PropTypes.func,
viewResult: PropTypes.string,
};
8 changes: 4 additions & 4 deletions src/components/API/CreateDraftObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ draft id */

export default function CreateDraftObject(saveDraftTo, contents, prefix) {
const objectContents = contents;
console.log('objectContents', contents);
const ownerGroup = `${prefix}_drafter`.toLocaleLowerCase();

fetch(`${saveDraftTo[0]}/api/objects/drafts/create/`, {
method: 'POST',
Expand All @@ -15,7 +15,7 @@ export default function CreateDraftObject(saveDraftTo, contents, prefix) {
contents: objectContents,
prefix,
schema: 'IEEE',
owner_group: 'bco_drafter'
owner_group: ownerGroup
}
]
}),
Expand All @@ -32,10 +32,10 @@ export default function CreateDraftObject(saveDraftTo, contents, prefix) {
const data = await response.json();
throw new Error(data[0].message);
}
if (response.status === 200) {
if (response.status === 201) {
const data = await response.json();
console.log('data', data);
const objectId = data[0].object_id;
const objectId = data.object_id;
alert(`Create Draft Success! Save the following object ID to access later ${objectId}`);
const processed = objectId.replace('://', '/');
window.location.href = `${window.location}/${processed}`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/API/DeleteDraftObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ draft id */

export default function DeleteDraftObject(objectInformation, contents) {
const objectContents = contents;
const deleteDraft = window.confirm(`Are you sure you wnat to delete ${objectInformation.object_id}`);
const deleteDraft = window.confirm(`Are you sure you wnat to delete ${objectInformation.object_id}?`);
if (deleteDraft === true) {
fetch(`${objectInformation.hostname}/api/objects/drafts/modify/`, {
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions src/components/API/DeriveDraftObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export default function DeriveDraftObject(saveDraftTo, prefix) {
.then((data) => {
console.log('data', data[0].object_id);
const objectId = data[0].object_id;
alert(`Derrive Draft Success! Save the following object ID to access later ${data[0].object_id}`);
alert(`Derive Draft Success! Save the following object ID to access later ${data[0].object_id}`);
const processed = objectId.replace('://', '/');
console.log('derrive 42', `${window.location.origin}/builder/${processed}`);
console.log('derive 42', `${window.location.origin}/builder/${processed}`);
window.location.href = `${window.location.origin}/builder/${processed}`;
});
}
})
.catch((error) => {
console.log(`error: ${error}`);
alert(`Derrive Draft FAILED! ${error}`);
alert(`Derive Draft FAILED! ${error}`);
});
}

Expand Down
76 changes: 48 additions & 28 deletions src/components/API/PublishDraftObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ export default function PublishDraftObject(objectInformation, contents) {
const obectContents = contents;
const { version } = obectContents.provenance_domain;
const publishedId = obectContents.object_id.replace('DRAFT', version);
const prefix = obectContents.object_id.split('/')[3].split('_')[0];
const deleteDraft = window.confirm('Would you like to delete this draft object after publishing?');
fetch(`${objectInformation.hostname}/api/objects/drafts/publish/`, {
const prefix = obectContents.object_id.split('_')[0].split('/').pop();

fetch(`${objectInformation.hostname}/api/objects/drafts/modify/`, {
method: 'POST',
body: JSON.stringify({
POST_api_objects_drafts_publish: [
POST_api_objects_drafts_modify: [
{
prefix,
draft_id: obectContents.object_id,
object_id: publishedId,
delete_draft: deleteDraft
contents,
object_id: objectInformation.object_id
}
]
}),
Expand All @@ -26,28 +24,50 @@ export default function PublishDraftObject(objectInformation, contents) {
'Content-type': 'application/json; charset=UTF-8'
}
})
.then((response) => {
if (!response.ok) {
throw new Error(response.status);
} else if (response.status === 200) {
console.log('POST_api_objects_drafts_publish: Success!', response);
return response.json()
.then((data) => {
const returnedId = data[0].published_id;
const publishedObject = returnedId.replace('://', '/');
const viewer = `${window.location.origin}/objects/view/`;
window.location.href = `${viewer}${publishedObject}`;
alert('Object published successfully! Redirecting to the Object page for you to view');
});
} else if (response.status === 207) {
console.log('POST_api_objects_drafts_publish: Failed!');
return response.json()
.then((data) => {
const { message } = data[0];
alert(`Object publishing Failed! ${message}`);
});
.then((saveResponse) => {
if (!saveResponse.ok) {
throw new Error(saveResponse.status);
}
})
.then(fetch(`${objectInformation.hostname}/api/objects/drafts/publish/`, {
method: 'POST',
body: JSON.stringify({
POST_api_objects_drafts_publish: [
{
prefix,
draft_id: obectContents.object_id,
object_id: publishedId,
delete_draft: false
}
]
}),
headers: {
Authorization: `Token ${objectInformation.token}`,
'Content-type': 'application/json; charset=UTF-8'
}
})
.then((response) => {
if (!response.ok) {
throw new Error(response.status);
} else if (response.status === 200) {
console.log('POST_api_objects_drafts_publish: Success!', response);
return response.json()
.then((data) => {
const returnedId = data[0].published_id;
const publishedObject = returnedId.replace('://', '/');
const viewer = `${window.location.origin}/objects/view/`;
window.location.href = `${viewer}${publishedObject}`;
alert('Object published successfully! Redirecting to the Object page for you to view');
});
} else if (response.status === 207) {
console.log('POST_api_objects_drafts_publish: Failed!');
return response.json()
.then((data) => {
const { message } = data[0];
alert(`Object publishing Failed! ${message}`);
});
}
}))
.catch((error) => {
console.log(`error: ${error}`);
alert(`POST_api_objects_drafts_publish: FAILED! ${error}`);
Expand Down
6 changes: 3 additions & 3 deletions src/components/API/RetrieveDraftObject.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// /src/components/Api/RetrieveDraftObject.js
// /src/components/Api/RetrieveDraftObject.js

/* Retrievs a draft object using the current user's token and an object's
/* Retrievs a draft object using the current user's token and an object's
draft id */

export default function RetrieveDraftObject(objectId, setObjectContents) {
let objectContents = '';
const objectContents = '';
let userToken = '';

JSON.parse(localStorage.getItem('user')).apiinfo.forEach((item) => {
Expand Down
48 changes: 48 additions & 0 deletions src/components/API/UserdbSearchPrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// /src/components/Api/SearchPrefix.js

/* Retrievs a draft object using the current user's token and an object's
draft id */

import PropTypes from 'prop-types';

export default function SearchPrefix(action, search, ApiInfo, setRows) {
console.log('stuff', action, search, typeof setRows, `${ApiInfo}prefixes/`);
fetch(`${ApiInfo}prefixes/`, {
method: 'POST',
body: JSON.stringify({
post_userdb_prefix_search: [
{
search_type: action,
search_term: search,
}
]
}),
headers: {
'Content-type': 'application/json; charset=UTF-8'
}
})
.then((response) => {
if (response.ok) {
return response.json()
.then((data) => {
console.log('data', data);
setRows(data);
});
}
return response.json()
.then((data) => {
console.log('data', data);
alert(`${data}`);
});
}).catch((error) => {
console.log(`error: ${error}`);
alert(`Retrieve object FAILED! ${error}`);
});
}

SearchPrefix.PropTypes = {
action: PropTypes.string.isRequired,
search: PropTypes.string,
ApiInfo: PropTypes.object,
setRows: PropTypes.func
};
Loading

0 comments on commit e8597e2

Please sign in to comment.