@Override @PlusTransactional public ResponseEvent<DistributionProtocolDetail> deleteDistributionProtocol( RequestEvent<Long> req) { try { AccessCtrlMgr.getInstance().ensureUserIsAdmin(); DistributionProtocol existing = daoFactory.getDistributionProtocolDao().getById(req.getPayload()); if (existing == null) { return ResponseEvent.userError(DistributionProtocolErrorCode.NOT_FOUND); } existing.delete(); daoFactory.getDistributionProtocolDao().saveOrUpdate(existing); return ResponseEvent.response(DistributionProtocolDetail.from(existing)); } catch (OpenSpecimenException ose) { return ResponseEvent.error(ose); } catch (Exception e) { return ResponseEvent.serverError(e); } }
@Override @PlusTransactional public ResponseEvent<DistributionProtocolDetail> updateActivityStatus( RequestEvent<DistributionProtocolDetail> req) { try { AccessCtrlMgr.getInstance().ensureUserIsAdmin(); Long dpId = req.getPayload().getId(); String status = req.getPayload().getActivityStatus(); if (StringUtils.isBlank(status) || !Status.isValidActivityStatus(status)) { return ResponseEvent.userError(ActivityStatusErrorCode.INVALID); } DistributionProtocol existing = daoFactory.getDistributionProtocolDao().getById(dpId); if (existing == null) { return ResponseEvent.userError(DistributionProtocolErrorCode.NOT_FOUND); } if (existing.getActivityStatus().equals(status)) { return ResponseEvent.response(DistributionProtocolDetail.from(existing)); } if (status.equals(Status.ACTIVITY_STATUS_DISABLED.getStatus())) { existing.delete(); } else { existing.setActivityStatus(status); } daoFactory.getDistributionProtocolDao().saveOrUpdate(existing); return ResponseEvent.response(DistributionProtocolDetail.from(existing)); } catch (OpenSpecimenException ose) { return ResponseEvent.error(ose); } catch (Exception e) { return ResponseEvent.serverError(e); } }