|
1 | 1 | package au.org.ala.ecodata
|
2 | 2 |
|
| 3 | +import au.org.ala.ecodata.paratoo.ParatooCollection |
| 4 | +import au.org.ala.ecodata.paratoo.ParatooProject |
| 5 | +import au.org.ala.ecodata.paratoo.ParatooProtocolConfig |
3 | 6 | import au.org.ala.web.AlaSecured
|
4 | 7 | import grails.converters.JSON
|
5 | 8 | import grails.util.Environment
|
@@ -725,4 +728,58 @@ class AdminController {
|
725 | 728 | render errors as JSON
|
726 | 729 | }
|
727 | 730 |
|
| 731 | + /** |
| 732 | + * Re-fetch data from Paratoo. Helpful when data could not be parsed correctly the first time. |
| 733 | + * |
| 734 | + * @return |
| 735 | + */ |
| 736 | + @AlaSecured(["ROLE_ADMIN"]) |
| 737 | + def reSubmitDataSet() { |
| 738 | + String projectId = params.id |
| 739 | + String dataSetId = params.dataSetId |
| 740 | + String userId = params.userId ?: userService.getCurrentUser().userId |
| 741 | + if (!projectId || !dataSetId || !userId) { |
| 742 | + render text: [message: "Bad request"] as JSON, status: HttpStatus.SC_BAD_REQUEST |
| 743 | + return |
| 744 | + } |
| 745 | + |
| 746 | + ParatooCollection collection = new ParatooCollection(orgMintedUUID: dataSetId, coreProvenance: [:]) |
| 747 | + List<ParatooProject> projects = paratooService.userProjects(userId) |
| 748 | + ParatooProject project = projects.find {it.project.projectId == projectId } |
| 749 | + if (project) { |
| 750 | + paratooService.submitCollection(collection, project, userId) |
| 751 | + render text: [message: "Submitted request to fetch data for dataSet $dataSetId in project $projectId by user $userId"] as JSON, status: HttpStatus.SC_OK, contentType: 'application/json' |
| 752 | + } |
| 753 | + else { |
| 754 | + render text: [message: "Project not found"] as JSON, status: HttpStatus.SC_NOT_FOUND |
| 755 | + } |
| 756 | + } |
| 757 | + |
| 758 | + |
| 759 | + /** |
| 760 | + * Helper function to check the form generated for a protocol during the sync operation. |
| 761 | + * Usual step is to update Paratoo config in DB. Use this function to check the form generated. |
| 762 | + * @return |
| 763 | + */ |
| 764 | + @AlaSecured(["ROLE_ADMIN"]) |
| 765 | + def checkActivityFormForProtocol() { |
| 766 | + String protocolId = params.id |
| 767 | + List protocols = paratooService.getProtocolsFromParatoo() |
| 768 | + Map protocol = protocols.find { it.attributes.identifier == protocolId } |
| 769 | + if (!protocol) { |
| 770 | + render text: [message: "Protocol not found"] as JSON, status: HttpStatus.SC_NOT_FOUND, contentType: 'application/json' |
| 771 | + return |
| 772 | + } |
| 773 | + |
| 774 | + Map documentation = paratooService.getParatooSwaggerDocumentation() |
| 775 | + ParatooProtocolConfig config = paratooService.getProtocolConfig(protocolId) |
| 776 | + if (!config) { |
| 777 | + render text: [message: "Protocol config not found"] as JSON, status: HttpStatus.SC_NOT_FOUND, contentType: 'application/json' |
| 778 | + return |
| 779 | + } |
| 780 | + |
| 781 | + Map template = paratooService.buildTemplateForProtocol(protocol, documentation, config) |
| 782 | + render text: template as JSON, status: HttpStatus.SC_OK, contentType: 'application/json' |
| 783 | + } |
| 784 | + |
728 | 785 | }
|
0 commit comments