From 04e41bfd2fd9c964c60783569527366323b4728e Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Sun, 22 Jul 2018 21:52:35 -0500 Subject: [PATCH] Fix #41: Fix delete provider type Issue #41: Fix or remove provider type creation/deletion --- .../services/impl/ProviderTypeServiceBean.java | 17 ++++++++++++++++- .../admin/ProviderTypeController.java | 7 +++++-- .../medicaid/services/ProviderTypeService.java | 9 ++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/psm-app/cms-business-process/src/main/java/gov/medicaid/services/impl/ProviderTypeServiceBean.java b/psm-app/cms-business-process/src/main/java/gov/medicaid/services/impl/ProviderTypeServiceBean.java index e5f15eb24..b5ee1d883 100644 --- a/psm-app/cms-business-process/src/main/java/gov/medicaid/services/impl/ProviderTypeServiceBean.java +++ b/psm-app/cms-business-process/src/main/java/gov/medicaid/services/impl/ProviderTypeServiceBean.java @@ -195,7 +195,8 @@ public ProviderType getByDescription(String description) { * @throws PortalServiceException - If there are any errors during the execution of this method */ @TransactionAttribute(TransactionAttributeType.REQUIRED) - public void delete(long id) throws PortalServiceException { + @Override + public void delete(String id) throws PortalServiceException { try { ProviderType obj = getEm().find(ProviderType.class, id); if (obj == null) { @@ -301,6 +302,20 @@ public void updateProviderTypeLicenseSettings( getEm().merge(providerType); } + @Override + public void updateProviderTypeCanDelete(ProviderType providerType) { + providerType.setCanDelete( + 0 == ((Number) (getEm().createQuery("SELECT count(*) FROM Entity WHERE providerType = :providerType") + .setParameter("providerType", providerType) + .getSingleResult())) + .intValue() && + 0 == ((Number) (getEm().createQuery("SELECT count(*) FROM ProviderTypeSetting WHERE providerTypeCode = :providerTypeCode") + .setParameter("providerTypeCode", providerType.getCode()) + .getSingleResult())) + .intValue() + ); + } + private List getAgreementDocuments(long[] agreementIds) { if (agreementIds.length == 0) { return new ArrayList<>(); diff --git a/psm-app/cms-web/src/main/java/gov/medicaid/controllers/admin/ProviderTypeController.java b/psm-app/cms-web/src/main/java/gov/medicaid/controllers/admin/ProviderTypeController.java index a952692e1..85a4a31ce 100644 --- a/psm-app/cms-web/src/main/java/gov/medicaid/controllers/admin/ProviderTypeController.java +++ b/psm-app/cms-web/src/main/java/gov/medicaid/controllers/admin/ProviderTypeController.java @@ -123,6 +123,7 @@ public ModelAndView view() throws PortalServiceException { criteria.setSortColumn("description"); SearchResult result = providerTypeService.search(criteria); + result.getItems().forEach(providerTypeService::updateProviderTypeCanDelete); ModelAndView model = new ModelAndView("admin/service_admin_provider_types"); model.addObject("providerTypesSearchResult", result); model.addObject("searchCriteria", criteria); @@ -143,6 +144,7 @@ public ModelAndView view() throws PortalServiceException { public ModelAndView search(@ModelAttribute("criteria") ProviderTypeSearchCriteria criteria) throws PortalServiceException { SearchResult result = providerTypeService.search(criteria); + result.getItems().forEach(providerTypeService::updateProviderTypeCanDelete); ModelAndView model = new ModelAndView("admin/service_admin_provider_types"); model.addObject("providerTypesSearchResult", result); model.addObject("searchCriteria", criteria); @@ -162,6 +164,7 @@ public ModelAndView search(@ModelAttribute("criteria") ProviderTypeSearchCriteri @RequestMapping(value = "/admin/getProviderType", method = RequestMethod.GET) public ModelAndView get(@RequestParam("providerTypeId") String providerTypeId) throws PortalServiceException { ProviderType providerType = providerTypeService.get(providerTypeId); + providerTypeService.updateProviderTypeCanDelete(providerType); return view(providerType); } @@ -308,9 +311,9 @@ public ModelAndView edit(@ModelAttribute("providerType") ProviderType providerTy */ @RequestMapping(value = "/admin/deleteProviderTypes", method = RequestMethod.GET) @ResponseBody - public String delete(@RequestParam("providerTypeIds") long[] providerTypeIds, HttpServletRequest request) + public String delete(@RequestParam("providerTypeIds") String[] providerTypeIds, HttpServletRequest request) throws PortalServiceException { - for (long providerTypeId : providerTypeIds) { + for (String providerTypeId : providerTypeIds) { providerTypeService.delete(providerTypeId); } return "success"; diff --git a/psm-app/services/src/main/java/gov/medicaid/services/ProviderTypeService.java b/psm-app/services/src/main/java/gov/medicaid/services/ProviderTypeService.java index 5bcc30a92..12535d6f5 100644 --- a/psm-app/services/src/main/java/gov/medicaid/services/ProviderTypeService.java +++ b/psm-app/services/src/main/java/gov/medicaid/services/ProviderTypeService.java @@ -81,7 +81,7 @@ public interface ProviderTypeService { * @param id - the ID of the provider type to delete * @throws PortalServiceException - If there are any errors during the execution of this method */ - void delete(long id) throws PortalServiceException; + void delete(String id) throws PortalServiceException; /** * This method gets all the provider types that meet the search criteria. If none available, the search result will @@ -130,4 +130,11 @@ void updateProviderTypeLicenseSettings( ProviderType providerType, String[] licenseIds ); + + /** + * Updates the ProviderType can delete setting. + * + * @param providerType providerType + */ + void updateProviderTypeCanDelete(ProviderType prviderType); }