Skip to content

Commit

Permalink
fix(TestNotificationConfigMenu): left-over controllers + TestRenameEn…
Browse files Browse the repository at this point in the history
…try(page DONE)[POST requests]
  • Loading branch information
adityadeshlahre committed Aug 10, 2024
1 parent c4953e8 commit ec2bd2b
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 45 deletions.

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion frontend/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1279,5 +1279,10 @@
"instructions.test.activation": "Active Tests: a checked box indicates an already active test. To activate a test, check the box; to deactivate, uncheck the box. Any sample types without an existing active test are deactivated and appear at the bottom, under 'Inactive Sample Types'. If one of the tests is activated, the sample type will be activated.",
"label.button.finished": "Finished",
"panel.panelName": "Panel Name",
"label.testName": "Test names"
"label.testName": "Test names",
"reporting.label.testName": "Reporting Test Name",
"french.current": "FRENCH current",
"english.current": "ENGLISH current",
"required.invalidtext": "This field is required",
"confirmation.rename": "Confirm Changes above you made."
}
7 changes: 6 additions & 1 deletion frontend/src/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1183,5 +1183,10 @@
"instructions.test.activation": "Tests actifs: une case cochée indique un test déjà actif. Pour activer un test, cochez la case; pour désactiver, décochez la case. Tous les types d'échantillons sans test actif existant sont désactivés et apparaissent en bas, sous 'Types d'échantillons inactifs'. Si l'un des tests est activé, le type d'échantillon sera activé.",
"label.button.finished": "Terminé",
"panel.panelName": "Nom du panel",
"label.testName": "Noms des tests"
"label.testName": "Noms des tests",
"reporting.label.testName": "Nom du test dans les rapports",
"french.current": "FRANÇAIS actuel",
"english.current": "ANGLAIS actuel",
"required.invalidtext": "Ce champ est requis",
"confirmation.rename": "Confirmez les modifications ci-dessus que vous avez apportées."
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class MethodManagementRestController extends BaseController {
@RequestMapping(value = "/MethodManagement", produces = MediaType.APPLICATION_JSON_VALUE)

@RequestMapping(value = "/MethodManagement", produces = MediaType.APPLICATION_JSON_VALUE, method = {
RequestMethod.GET, RequestMethod.POST })
public ResponseEntity<MethodManagementForm> showMethodManagement(HttpServletRequest request) {
MethodManagementForm form = new MethodManagementForm();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.openelisglobal.common.management.controller.rest;

import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.controller.BaseController;
import org.openelisglobal.common.management.form.PanelManagementForm;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class PanelManagementRestController extends BaseController {

@RequestMapping(value = "/PanelManagement", method = { RequestMethod.GET, RequestMethod.POST })
public PanelManagementForm showPanelManagement(HttpServletRequest request) {
PanelManagementForm form = new PanelManagementForm();

// return findForward(FWD_SUCCESS, form);
return form;
}

@Override
protected String findLocalForward(String forward) {
if (FWD_SUCCESS.equals(forward)) {
return "panelManagementDefinition";
} else {
return "PageNotFound";
}
}

@Override
protected String getPageTitleKey() {
return null;
}

@Override
protected String getPageSubtitleKey() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.openelisglobal.common.management.controller.rest;

import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.controller.BaseController;
import org.openelisglobal.common.management.form.SampleTypeManagementForm;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class SampleTypeManagementRestController extends BaseController {

@RequestMapping(value = "/SampleTypeManagement", method = { RequestMethod.GET, RequestMethod.POST })
public SampleTypeManagementForm showSampleTypeManagement(HttpServletRequest request) {
SampleTypeManagementForm form = new SampleTypeManagementForm();
// return findForward(FWD_SUCCESS, form);
return form;
}

@Override
protected String findLocalForward(String forward) {
if (FWD_SUCCESS.equals(forward)) {
return "sampleTypeManagementDefinition";
} else {
return "PageNotFound";
}
}

@Override
protected String getPageTitleKey() {
return null;
}

@Override
protected String getPageSubtitleKey() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.openelisglobal.common.management.controller.rest;

import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.controller.BaseController;
import org.openelisglobal.common.management.form.TestSectionManagementForm;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class TestSectionManagementRestController extends BaseController {

@RequestMapping(value = "/TestSectionManagement", method = { RequestMethod.GET, RequestMethod.POST })
public TestSectionManagementForm showTestSectionManagement(HttpServletRequest request) {
TestSectionManagementForm form = new TestSectionManagementForm();

// return findForward(FWD_SUCCESS, form);
return form;
}

@Override
protected String findLocalForward(String forward) {
if (FWD_SUCCESS.equals(forward)) {
return "testSectionManagementDefinition";
} else {
return "PageNotFound";
}
}

@Override
protected String getPageTitleKey() {
return null;
}

@Override
protected String getPageSubtitleKey() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.openelisglobal.common.management.controller.rest;

import javax.servlet.http.HttpServletRequest;
import org.openelisglobal.common.controller.BaseController;
import org.openelisglobal.common.management.form.UomManagementForm;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class UomManagementRestController extends BaseController {

private static final String[] ALLOWED_FIELDS = new String[] {};

@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAllowedFields(ALLOWED_FIELDS);
}

@RequestMapping(value = "/UomManagement", method = { RequestMethod.GET, RequestMethod.POST })
public UomManagementForm showUomManagement(HttpServletRequest request) {
UomManagementForm form = new UomManagementForm();

// return findForward(FWD_SUCCESS, form);
return form;
}

@Override
protected String findLocalForward(String forward) {
if (FWD_SUCCESS.equals(forward)) {
return "uomManagementDefinition";
} else {
return "PageNotFound";
}
}

@Override
protected String getPageTitleKey() {
return null;
}

@Override
protected String getPageSubtitleKey() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is OpenELIS code.
*
* Copyright (C) ITECH, University of Washington, Seattle WA. All Rights Reserved.
*/
package org.openelisglobal.common.provider.query.rest;

import java.util.Locale;
import org.apache.commons.validator.GenericValidator;
import org.json.simple.JSONObject;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.localization.valueholder.Localization;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.test.service.TestService;
import org.openelisglobal.test.valueholder.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class TestNamesProviderRestController {

private final TestService testService;

public TestNamesProviderRestController(TestService testService) {
this.testService = testService;
}

@GetMapping("/TestNamesProvider")
public ResponseEntity<JSONObject> processRequest(@RequestParam("testId") String testId) {

String jResult;
JSONObject jsonResult = new JSONObject();
String jString;

if (GenericValidator.isBlankOrNull(testId)) {
jResult = "INVALID";
jString = "Internal error, please contact Admin and file bug report";
return ResponseEntity.badRequest().body(createErrorResponse(jString));
} else {
try {
jResult = createJsonTestNames(testId, jsonResult);
jString = jsonResult.toJSONString();
} catch (IllegalStateException e) {
LogEvent.logDebug(e);
jResult = "INVALID";
jString = "Internal error, please contact Admin and file bug report";
return ResponseEntity.status(500).body(createErrorResponse(jString));
}
}
return ResponseEntity.ok(jsonResult);
}

@SuppressWarnings("unchecked")
private String createJsonTestNames(String testId, JSONObject jsonResult) throws IllegalStateException {

String INVALID = "invalid";
String VALID = "valid";

if (GenericValidator.isBlankOrNull(testId)) {
throw new IllegalStateException("TestNamesProvider testId was blank. It must have a value");
}

Test test = SpringContext.getBean(TestService.class).get(testId);
if (test != null) {
Localization nameLocalization = test.getLocalizedTestName();
Localization reportNameLocalization = test.getLocalizedReportingName();

JSONObject nameObject = new JSONObject();
addAllLocalizations(nameObject, nameLocalization);
// nameObject.put("english", nameLocalization.getEnglish());
// nameObject.put("french", nameLocalization.getFrench());
jsonResult.put("name", nameObject);

JSONObject reportingNameObject = new JSONObject();
addAllLocalizations(reportingNameObject, reportNameLocalization);
// reportingNameObject.put("english", reportNameLocalization.getEnglish());
// reportingNameObject.put("french", reportNameLocalization.getFrench());
jsonResult.put("reportingName", reportingNameObject);

return VALID;
}

return INVALID;
}

@SuppressWarnings("unchecked")
private void addAllLocalizations(JSONObject jsonObject, Localization localization) {
for (Locale locale : localization.getLocalesWithValue()) {
jsonObject.put(locale.getDisplayLanguage(Locale.ENGLISH).toLowerCase(),
localization.getLocalizedValue(locale));
}
}

@SuppressWarnings("unchecked")
private JSONObject createErrorResponse(String message) {
JSONObject errorResponse = new JSONObject();
errorResponse.put("status", "error");
errorResponse.put("message", message);
return errorResponse;
}
}

0 comments on commit ec2bd2b

Please sign in to comment.