Skip to content

Commit

Permalink
Fix #41: Fix delete provider type
Browse files Browse the repository at this point in the history
Issue #41: Fix or remove provider type creation/deletion
  • Loading branch information
Frank Duncan committed Jul 23, 2018
1 parent bb798f9 commit 04e41bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<AgreementDocument> getAgreementDocuments(long[] agreementIds) {
if (agreementIds.length == 0) {
return new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public ModelAndView view() throws PortalServiceException {
criteria.setSortColumn("description");

SearchResult<ProviderType> 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);
Expand All @@ -143,6 +144,7 @@ public ModelAndView view() throws PortalServiceException {
public ModelAndView search(@ModelAttribute("criteria") ProviderTypeSearchCriteria criteria)
throws PortalServiceException {
SearchResult<ProviderType> 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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,4 +130,11 @@ void updateProviderTypeLicenseSettings(
ProviderType providerType,
String[] licenseIds
);

/**
* Updates the ProviderType can delete setting.
*
* @param providerType providerType
*/
void updateProviderTypeCanDelete(ProviderType prviderType);
}

0 comments on commit 04e41bf

Please sign in to comment.