public Application() { @SuppressWarnings("resource") AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(FhirServiceConfig.class); ctx.refresh(); classes.add(CORSFilter.class); FhirService fhirService = ctx.getBean(FhirService.class); try { fhirService.initialize(ctx.getBean(FhirTerminologyProviderService.class)); } catch (BeansException | JAXBException e) { throw new ServerErrorException(Response.Status.SERVICE_UNAVAILABLE, e); } singletons.add(fhirService); }
private User _addUser( PersonCreatorForm personCreatorForm, Company company) { try { return _userLocalService.addUser( UserConstants.USER_ID_DEFAULT, company.getCompanyId(), false, personCreatorForm.getPassword1(), personCreatorForm.getPassword2(), personCreatorForm.hasAlternateName(), personCreatorForm.getAlternateName(), personCreatorForm.getEmail(), 0, StringPool.BLANK, LocaleUtil.getDefault(), personCreatorForm.getGivenName(), StringPool.BLANK, personCreatorForm.getFamilyName(), 0, 0, personCreatorForm.isMale(), personCreatorForm.getBirthdayMonth(), personCreatorForm.getBirthdayDay(), personCreatorForm.getBirthdayYear(), personCreatorForm.getJobTitle(), null, null, null, null, false, new ServiceContext()); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private PageItems<DLFileEntry> _getPageItems( Pagination pagination, Long dlFolderId) { try { DLFolder dlFolder = _dlFolderService.getFolder(dlFolderId); List<DLFileEntry> dlFileEntries = _dlFileEntryService.getFileEntries( dlFolder.getGroupId(), dlFolder.getFolderId(), pagination.getStartPosition(), pagination.getEndPosition(), null); int count = _dlFileEntryService.getFileEntriesCount( dlFolder.getGroupId(), dlFolder.getFolderId()); return new PageItems<>(dlFileEntries, count); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
/** * Auto-complete method to search for members * * @param member * A query string that will be matched against email and * signature * @param offset * If paging is required, the offset into the result set * @param limit * If paging is required, the number of rows to return * @return A list of members matching the query string * @throws ServerErrorException */ public Response getMembers(String member, Integer offset, Integer limit) throws ServerErrorException { try { // Get the DAO implementation MemberDAO memberDAO = DAOProvider.getDAO(MemberDAO.class); // Perform the search List<MemberDTO> memberDTOs = memberDAO.findByEmailOrSignature(member, offset, limit); // Convert the result List<Member> members = memberConverter.convertPublic(memberDTOs); // Return the result return Response.status(200).entity(members).build(); } catch (Exception e) { Response response = ResponseUtils.serverError(e); throw new ServerErrorException(response); } }
void refreshLocks() { try { TrpCollection col = collectionsSelector.getSelectedCollection(); int colId = (col == null || isShowAllLocks()) ? -1 : col.getColId(); int docId = parseDocId(); logger.debug("listing locks from server, colId = "+colId+" docId = "+docId); List<PageLock> locks = store.listPageLocks(colId, -1, -1); // filter docId locally: if (docId != -1) { for (ListIterator<PageLock> it = locks.listIterator(); it.hasNext(); ) { PageLock l = it.next(); if (l.getDocId() != docId) it.remove(); logger.debug("logged in at " + l.getLoginTime()); } } logger.debug("got "+locks.size()+" locks!"); refreshList(locks); } catch (SessionExpiredException | ServerErrorException | IllegalArgumentException | NoConnectionException e1) { onError("Error loading page locks", e1); } }
@Override protected void okPressed() { if(titleField.getText().length() < 1){ //print some error message MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR); messageBox.setMessage("Feature must have a title!"); int rc = messageBox.open(); return; } feat.setTitle(titleField.getText()); feat.setDescription(descField.getText()); try { Storage.getInstance().storeEdFeature(feat, colCheckbox.getSelection()); } catch (SessionExpiredException | ServerErrorException | IllegalArgumentException | NoConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } efd.updateFeatures(); efd.updateEditDecl(); super.okPressed(); }
public List<EdFeature> getAvailFeatures() throws NoConnectionException, SessionExpiredException, ServerErrorException, IllegalArgumentException { // checkConnection(true); List<EdFeature> features; if(isLoggedIn() && isRemoteDoc()){ features = conn.getEditDeclFeatures(getCurrentDocumentCollectionId()); } else { try { features = new TrpServerConn(TrpServerConn.PROD_SERVER_URI).getEditDeclFeatures(0); } catch (LoginException e) { //is only thrown if uriStr is null or empty e.printStackTrace(); features = new ArrayList<>(0); } } return features; }
/** * Retrieves tags. * @param offset If paging is required, the offset into the result set * @param limit If paging is required, the number of rows to return * @return A list of tags * @throws ServerErrorException If internal error occurs */ public Response getTags(Integer offset, Integer limit) throws ServerErrorException { try { // Get DAO implementation TagDAO tagDAO = DAOProvider.getDAO(TagDAO.class); // Get list of tags List<TagDTO> tagsDTOs = tagDAO.findAll(offset, limit); // Convert to beans List<Tag> tags = converter.convert(tagsDTOs); // Return result return Response.status(200).entity(tags).build(); } catch (Exception e) { Response response = ResponseUtils.serverError(e); throw new ServerErrorException(response); } }
public static Class<? extends WebApplicationException> getWebApplicationExceptionClass(Response response) { int status = response.getStatus(); final Class<? extends WebApplicationException> exceptionType = EXCEPTIONS_MAP.get(status); if (exceptionType == null) { final int family = status / 100; switch (family) { case 3: return RedirectionException.class; case 4: return ClientErrorException.class; case 5: return ServerErrorException.class; default: return WebApplicationException.class; } } return exceptionType; }
@Test public void testCreateException() { assertExceptionType(Response.Status.INTERNAL_SERVER_ERROR, InternalServerErrorException.class); assertExceptionType(Response.Status.NOT_FOUND, NotFoundException.class); assertExceptionType(Response.Status.FORBIDDEN, ForbiddenException.class); assertExceptionType(Response.Status.BAD_REQUEST, BadRequestException.class); assertExceptionType(Response.Status.METHOD_NOT_ALLOWED, NotAllowedException.class); assertExceptionType(Response.Status.UNAUTHORIZED, NotAuthorizedException.class); assertExceptionType(Response.Status.NOT_ACCEPTABLE, NotAcceptableException.class); assertExceptionType(Response.Status.UNSUPPORTED_MEDIA_TYPE, NotSupportedException.class); assertExceptionType(Response.Status.SERVICE_UNAVAILABLE, ServiceUnavailableException.class); assertExceptionType(Response.Status.TEMPORARY_REDIRECT, RedirectionException.class); assertExceptionType(Response.Status.LENGTH_REQUIRED, ClientErrorException.class); assertExceptionType(Response.Status.BAD_GATEWAY, ServerErrorException.class); assertExceptionType(Response.Status.NO_CONTENT, WebApplicationException.class); }
public List<String> getCountries(){ if(countries != null){ return countries; } URI uri = UriBuilder.fromUri(restServiceAddress + "/rest/v1/all").build(); Client client = ClientBuilder.newClient(); Response response = client.target(uri).request(MediaType.APPLICATION_JSON_TYPE).get(); try { String json = response.readEntity(String.class); countries = extractCountriesFromJSon(json); countries.sort(String::compareTo); } catch (JSONException e) { throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR); } return countries; }
private void changeVersionStatus(String text){ Storage storage = Storage.getInstance(); String pages = getPagesString(); String[] pageList = pages.split(","); if (!pages.equals("") && pageList.length >= 1){ for (String page : pageList){ int pageNr = Integer.valueOf(page); int colId = storage.getCurrentDocumentCollectionId(); int docId = storage.getDocId(); int transcriptId = storage.getPage().getCurrentTranscript().getTsId(); try { storage.getConnection().updatePageStatus(colId, docId, pageNr, transcriptId, EditStatus.fromString(text), "test"); } catch (SessionExpiredException | ServerErrorException | ClientErrorException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
@Override protected void okPressed() { if(titleField.getText().length() < 1){ //print some error message MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR); messageBox.setMessage("Feature must have a title!"); int rc = messageBox.open(); return; } feat.setTitle(titleField.getText()); feat.setDescription(descField.getText()); try { Storage.getInstance().storeEdFeature(feat, colCheckbox.getSelection()); } catch (SessionExpiredException | ServerErrorException | IllegalArgumentException | NoConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } efd.updateFeatures(); super.okPressed(); }
/** * Saves all transcripts in transcriptsMap. * @param transcriptsMap A map of the transcripts to save. The map's key is the page-id, its value is a pair of the collection-id and the * corresponding TrpPageType object to save as newest version. * @param monitor A progress monitor that can also be null is no GUI status update is needed. */ public void saveTranscriptsMap(Map<Integer, Pair<Integer, TrpPageType>> transcriptsMap, IProgressMonitor monitor) throws SessionExpiredException, ServerErrorException, IllegalArgumentException, Exception { if (monitor != null) monitor.beginTask("Saving affected transcripts", transcriptsMap.size()); int c = 0; for (Pair<Integer, TrpPageType> ptPair : transcriptsMap.values()) { if (monitor != null && monitor.isCanceled()) return; saveTranscript(ptPair.getLeft(), ptPair.getRight(), null, ptPair.getRight().getMd().getTsId(), "Tagged from text"); if (monitor != null) monitor.worked(c++); ++c; } }
/** * Wrapper method which takes a pages range string of the currently loaded document */ public List<String> analyzeLayoutOnLatestTranscriptOfPages(String pageStr, boolean doBlockSeg, boolean doLineSeg, boolean doWordSeg, boolean doPolygonToBaseline, boolean doBaselineToPolygon, String jobImpl, String pars) throws SessionExpiredException, ServerErrorException, ClientErrorException, IllegalArgumentException, NoConnectionException, IOException { checkConnection(true); if (!isRemoteDoc()) { throw new IOException("No remote doc loaded!"); } int colId = getCurrentDocumentCollectionId(); DocumentSelectionDescriptor dd = getDoc().getDocSelectionDescriptorForPagesString(pageStr); List<DocumentSelectionDescriptor> dsds = new ArrayList<>(); dsds.add(dd); List<String> jobids = new ArrayList<>(); List<TrpJobStatus> jobs = conn.analyzeLayout(colId, dsds, doBlockSeg, doLineSeg, doWordSeg, doPolygonToBaseline, doBaselineToPolygon, jobImpl, pars); for (TrpJobStatus j : jobs) { jobids.add(j.getJobId()); } return jobids; }
@Override public ShortestPathsResult getShortestPaths(ShortestPathsRequest request) throws ServerErrorException { log.debug("Got request for shortest paths."); IVRouterResponse response = getShortestPathsInternal(request); List<IVRouterResult> results = response.getResults(); // we can expect the response to contain exactly one element if (results != null && results.size() == 1) { return (ShortestPathsResult) results.get(0); } return null; }
@Override public Company createContext(HttpServletRequest httpServletRequest) { try { return _portal.getCompany(httpServletRequest); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private void _deleteJournalArticle(Long journalArticleId) { try { JournalArticle article = _journalArticleService.getArticle( journalArticleId); _journalArticleService.deleteArticle( article.getGroupId(), article.getArticleId(), article.getArticleResourceUuid(), new ServiceContext()); } catch (NoSuchArticleException nsae) { } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private JournalArticle _getJournalArticle(Long journalArticleId) { try { return _journalArticleService.getArticle(journalArticleId); } catch (NoSuchArticleException nsae) { throw new NotFoundException( "Unable to get article " + journalArticleId, nsae); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private Optional<User> _getUserOptional(JournalArticle journalArticle) { try { return Optional.ofNullable( _userService.getUserById(journalArticle.getUserId())); } catch (NoSuchUserException | PrincipalException e) { throw new NotFoundException( "Unable to get user " + journalArticle.getUserId(), e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private void _deleteDLFolder(Long dlFolderId) { try { _dlFolderService.deleteFolder(dlFolderId); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private DLFolder _getDLFolder(Long dlFolderId) { try { return _dlFolderService.getFolder(dlFolderId); } catch (NoSuchEntryException | PrincipalException e) { throw new NotFoundException( "Unable to get folder " + dlFolderId, e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private PageItems<DLFolder> _getPageItems( Pagination pagination, Long groupId) { try { List<DLFolder> dlFolders = _dlFolderService.getFolders( groupId, 0, pagination.getStartPosition(), pagination.getEndPosition(), null); int count = _dlFolderService.getFoldersCount(groupId, 0); return new PageItems<>(dlFolders, count); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private String _getPath(DLFolder dlFolder) { try { return dlFolder.getPath(); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private void _deleteUser(Long userId) { try { _userLocalService.deleteUser(userId); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private User _getUser(Long userId) { try { return _userLocalService.getUserById(userId); } catch (NoSuchUserException | PrincipalException e) { throw new NotFoundException("Unable to get user " + userId, e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private void _deleteBlogsEntry(Long blogsEntryId) { try { _blogsService.deleteEntry(blogsEntryId); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private BlogsEntry _getBlogsEntry(Long blogsEntryId) { try { return _blogsService.getEntry(blogsEntryId); } catch (NoSuchEntryException | PrincipalException e) { throw new NotFoundException( "Unable to get blogs entry " + blogsEntryId, e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private Optional<User> _getUserOptional(BlogsEntry blogsEntry) { try { return Optional.ofNullable( _userService.getUserById(blogsEntry.getUserId())); } catch (NoSuchUserException | PrincipalException e) { throw new NotFoundException( "Unable to get user " + blogsEntry.getUserId(), e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private void _deleteDLFileEntry(Long dlFileEntryId) { try { _dlFileEntryService.deleteFileEntry(dlFileEntryId); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private DLFileEntry _getDLFileEntry(Long dlFileEntryId) { try { return _dlFileEntryService.getFileEntry(dlFileEntryId); } catch (NoSuchEntryException | PrincipalException e) { throw new NotFoundException( "Unable to get file " + dlFileEntryId, e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private Optional<DLFolder> _getDLFolderOptional(DLFileEntry dlFileEntry) { try { return Optional.of( _dlFolderService.getFolder(dlFileEntry.getFolderId())); } catch (NoSuchFolderException nsfe) { throw new NotFoundException( "Unable to get group " + dlFileEntry.getFolderId(), nsfe); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private InputStream _getInputStream(DLFileEntry dlFileEntry) { try { return dlFileEntry.getContentStream(); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private Optional<User> _getUserOptional(DLFileEntry dlFileEntry) { try { return Optional.ofNullable( _userService.getUserById(dlFileEntry.getUserId())); } catch (NoSuchUserException | PrincipalException e) { throw new NotFoundException( "Unable to get user " + dlFileEntry.getUserId(), e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private void _deleteComment(Long commentId) { try { _commentManager.deleteComment(commentId); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
private Optional<User> _getUserOptional(Comment comment) { try { return Optional.ofNullable( _userService.getUserById(comment.getUserId())); } catch (NoSuchUserException | PrincipalException e) { throw new NotFoundException( "Unable to get user " + comment.getUserId(), e); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
@Override public Optional<WebSite> getWebSite(long groupId) { try { Group group = _groupLocalService.getGroup(groupId); return Optional.ofNullable(new WebSiteImpl(group)); } catch (NoSuchGroupException nsge) { return Optional.empty(); } catch (PortalException pe) { throw new ServerErrorException(500, pe); } }
@Test(expected = ServerErrorException.class) public void shouldThrowExceptionOnHttpServerError() { // given final Response response = someResponse(500, "Some Server Error"); final ServiceClient mockClient = someHttpClient(response, "/test"); // when final ContentProvider contentProvider = contentFrom(mockClient, "/test", TEXT_PLAIN); final BlockingObservable<Content> content = contentProvider.getContent(X, noOpTracer(), emptyParameters()).toBlocking(); // then verify(mockClient).get("/test", TEXT_PLAIN_TYPE); content.single(); }
private static void handleException(final Throwable ex, final boolean faultTolerant) { final Throwable cause = ex.getCause(); if (ex instanceof NotAllowedException || ex instanceof ServerErrorException || cause instanceof SocketException || cause instanceof UnknownHostException) { AppRuntimeExceptionHandler.handleZonkyMaintenanceError(ex, faultTolerant); } else { AppRuntimeExceptionHandler.handleUnexpectedException(ex); } }
private void movePage(int fromPageNr, int toPageNr) { try { Storage.getInstance().movePage(tw.getDoc().getCollection().getColId(), tw.getDoc().getId(), fromPageNr, toPageNr); } catch (SessionExpiredException | ServerErrorException | ClientErrorException | NoConnectionException e) { logger.error(e.toString()); } }