@Override @PlusTransactional public ResponseEvent<List<AuthDomainSummary>> getDomains( RequestEvent<ListAuthDomainCriteria> req) { List<AuthDomain> authDomains = daoFactory.getAuthDao().getAuthDomains(req.getPayload().maxResults()); return ResponseEvent.response(AuthDomainSummary.from(authDomains)); }
@Override @PlusTransactional public ResponseEvent<AuthDomainDetail> registerDomain(RequestEvent<AuthDomainDetail> req) { try { AuthDomainDetail detail = req.getPayload(); AuthDomain authDomain = domainRegFactory.createDomain(detail); ensureUniqueDomainName(authDomain.getName()); daoFactory.getAuthDao().saveOrUpdate(authDomain); return ResponseEvent.response(AuthDomainDetail.from(authDomain)); } catch (OpenSpecimenException ose) { return ResponseEvent.error(ose); } catch (Exception e) { return ResponseEvent.serverError(e); } }
@PlusTransactional public ResponseEvent<AuthDomainDetail> updateDomain(RequestEvent<AuthDomainDetail> req) { try { AuthDomainDetail detail = req.getPayload(); AuthDomain existingDomain = daoFactory.getAuthDao().getAuthDomainByName(detail.getName()); if (existingDomain == null) { throw OpenSpecimenException.userError(AuthProviderErrorCode.DOMAIN_NOT_FOUND); } AuthDomain authDomain = domainRegFactory.createDomain(detail); existingDomain.update(authDomain); return ResponseEvent.response(AuthDomainDetail.from(existingDomain)); } catch (OpenSpecimenException ose) { return ResponseEvent.error(ose); } catch (Exception e) { return ResponseEvent.serverError(e); } }
private void ensureUniqueDomainName(String domainName) { if (!daoFactory.getAuthDao().isUniqueAuthDomainName(domainName)) { throw OpenSpecimenException.userError(AuthProviderErrorCode.DUP_DOMAIN_NAME); } }