@Transactional(propagation = Propagation.REQUIRED) public WADOSupportDTO getWADOSupportDTO(String study, String series, String image, String user) { WADOSupportDTO returnValue = new WADOSupportDTO(); log.info("Study-" + study + " series-" + series + " image-" + image); try { List<Object[]> images = this.getHibernateTemplate() .getSessionFactory() .getCurrentSession() .createSQLQuery(WADO_QUERY) .setParameter("study", study) .setParameter("series", series) .setParameter("image", image) .list(); if (images.size() == 0) { log.info("image not found"); return null; // nothing to do } List<SiteData> authorizedSites; UserObject uo = userTable.get(user); if (uo != null) { authorizedSites = uo.getAuthorizedSites(); if (authorizedSites == null) { AuthorizationManager manager = new AuthorizationManager(user); authorizedSites = manager.getAuthorizedSites(); uo.setAuthorizedSites(authorizedSites); } } else { AuthorizationManager manager = new AuthorizationManager(user); authorizedSites = manager.getAuthorizedSites(); uo = new UserObject(); uo.setAuthorizedSites(authorizedSites); userTable.put(user, uo); } returnValue.setCollection((String) images.get(0)[0]); returnValue.setSite((String) images.get(0)[1]); boolean isAuthorized = false; for (SiteData siteData : authorizedSites) { if (siteData.getCollection().equals(returnValue.getCollection())) { if (siteData.getSiteName().equals(returnValue.getSite())) { isAuthorized = true; break; } } } if (!isAuthorized) { System.out.println("User: "******" not authorized"); return null; // not authorized } String filePath = (String) images.get(0)[2]; File imageFile = new File(filePath); if (!imageFile.exists()) { log.error("File " + filePath + " does not exist"); return null; } returnValue.setImage(FileUtils.readFileToByteArray(imageFile)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return returnValue; }
@Transactional(propagation = Propagation.REQUIRED) public WADOSupportDTO getWADOSupportDTO(WADOParameters params, String user) { WADOSupportDTO returnValue = new WADOSupportDTO(); log.info( "Study-" + params.getStudyUID() + " series-" + params.getSeriesUID() + " image-" + params.getObjectUID()); try { List<Object[]> images = this.getHibernateTemplate() .getSessionFactory() .getCurrentSession() .createSQLQuery(WADO_QUERY) .setParameter("study", params.getStudyUID()) .setParameter("series", params.getSeriesUID()) .setParameter("image", params.getObjectUID()) .list(); if (images.size() == 0) { log.error("image not found"); returnValue.setErrors("image not found"); return returnValue; } List<SiteData> authorizedSites; UserObject uo = userTable.get(user); if (uo != null) { authorizedSites = uo.getAuthorizedSites(); if (authorizedSites == null) { AuthorizationManager manager = new AuthorizationManager(user); authorizedSites = manager.getAuthorizedSites(); uo.setAuthorizedSites(authorizedSites); } } else { System.out.println("the user is " + user); AuthorizationManager manager = new AuthorizationManager(user); authorizedSites = manager.getAuthorizedSites(); uo = new UserObject(); uo.setAuthorizedSites(authorizedSites); userTable.put(user, uo); } returnValue.setCollection((String) images.get(0)[0]); returnValue.setSite((String) images.get(0)[1]); boolean isAuthorized = false; for (SiteData siteData : authorizedSites) { if (siteData.getCollection().equals(returnValue.getCollection())) { if (siteData.getSiteName().equals(returnValue.getSite())) { isAuthorized = true; break; } } } if (!isAuthorized) { System.out.println("User: "******" not authorized"); return null; // not authorized } String filePath = (String) images.get(0)[2]; File imageFile = new File(filePath); if (!imageFile.exists()) { log.error("File " + filePath + " does not exist"); returnValue.setErrors("File does not exist"); return returnValue; } if (params.getContentType().equals(("application/dicom"))) { returnValue.setImage(FileUtils.readFileToByteArray(imageFile)); } else { JPEGResult result = DCMUtils.getJPGFromFile(imageFile, params); if (result.getErrors() != null) { returnValue.setErrors(result.getErrors()); return returnValue; } returnValue.setImage(result.getImages()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); returnValue.setErrors("unable to process request"); return returnValue; } return returnValue; }