public static String determineFileType(FileMetadata fm) throws IOException { // TODO: networkDataFile StudyFile sf = fm.getStudyFile(); if (sf instanceof TabularDataFile) { return determineTabularDataFileType((TabularDataFile) sf); } else { if (sf.isRemote()) { return FileUtil.determineFileType(fm.getLabel()); } else { return FileUtil.determineFileType(new File(sf.getFileSystemLocation()), fm.getLabel()); } } }
public void remove(Long id) { VDCUser user = (VDCUser) em.find(VDCUser.class, id); if (user != null) { // Need to remove this user from other collections it may belong to. for (Iterator it = user.getUserGroups().iterator(); it.hasNext(); ) { UserGroup group = (UserGroup) it.next(); group.getUsers().remove(user); } for (Iterator it2 = user.getStudies().iterator(); it2.hasNext(); ) { Study study = (Study) it2.next(); study.getAllowedUsers().remove(user); } for (Iterator it2 = user.getStudyFiles().iterator(); it2.hasNext(); ) { StudyFile studyFile = (StudyFile) it2.next(); studyFile.getAllowedUsers().remove(user); } for (Iterator it = user.getAllowedFileVdcs().iterator(); it.hasNext(); ) { VDC elem = (VDC) it.next(); elem.getAllowedFileUsers().remove(user); } em.remove(user); } }
public static String getUserFriendlyOriginalType(StudyFile sf) { String originalType = sf.getOriginalFileType(); if (!StringUtil.isEmpty(originalType)) { if (originalType.indexOf(";") != -1) { originalType = originalType.substring(0, originalType.indexOf(";")); } try { return ResourceBundle.getBundle("FileTypeBundle").getString(originalType); } catch (MissingResourceException e) { return originalType; } } return originalType; }
public static String getUserFriendlyFileType(StudyFile sf) { String tempFileType = sf.getFileType(); if (tempFileType != null) { if (tempFileType.indexOf(";") != -1) { tempFileType = tempFileType.substring(0, tempFileType.indexOf(";")); } try { return ResourceBundle.getBundle("FileTypeBundle").getString(tempFileType); } catch (MissingResourceException e) { return tempFileType; } } return tempFileType; }
private boolean isUserAuthorizedForNonRolePage( PageDef pageDef, HttpServletRequest request, LoginBean loginBean, UserGroup ipUserGroup) { VDCUser user = null; if (loginBean != null) { user = loginBean.getUser(); } if (user != null && user.getNetworkRole() != null && user.getNetworkRole().getName().equals(NetworkRoleServiceLocal.ADMIN)) { // If you are network admin, you can do anything! return true; } VDC currentVDC = vdcService.getVDCFromRequest(request); if (currentVDC != null && !isTermsOfUsePage(pageDef) && isVdcRestricted(pageDef, request)) { if (currentVDC.isVDCRestrictedForUser(user, ipUserGroup)) { return false; } } else if (pageDef != null && (pageDef.getName().equals(PageDefServiceLocal.DV_OPTIONS_PAGE) || pageDef.getName().equals(PageDefServiceLocal.ACCOUNT_OPTIONS_PAGE) || pageDef.getName().equals(PageDefServiceLocal.ACCOUNT_PAGE) || pageDef.getName().equals(PageDefServiceLocal.MANAGE_STUDIES_PAGE))) { // For these pages, the only requirement is // to be logged in. if (user == null) { return false; } String userParam = request.getParameter("userId"); if (userParam != null && !userParam.equals(user.getId().toString())) { // To view other users, logged in user must be an admin or curator if (!(user.isAdmin(currentVDC) || user.isCurator(currentVDC))) { return false; } } } else if (isViewStudyPage(pageDef)) { Study study = null; StudyVersion studyVersion = null; String studyId = VDCBaseBean.getParamFromRequestOrComponent("studyId", request); String versionNumber = VDCBaseBean.getParamFromRequestOrComponent("versionNumber", request); if (studyId != null) { study = studyService.getStudy(Long.parseLong(studyId)); if (versionNumber != null) { studyVersion = studyService.getStudyVersion(Long.parseLong(studyId), new Long(versionNumber)); } } else { study = studyService.getStudyByGlobalId( VDCBaseBean.getParamFromRequestOrComponent("globalId", request)); } if (study.isStudyRestrictedForUser(user, ipUserGroup)) { return false; } if (studyVersion != null) { // If study has been deaccessioned, // only show the page if the user is authorized to edit if (study.isDeaccessioned() && (user == null || !study.isUserAuthorizedToEdit(user))) { return false; } // If this is a draft version, only show the version if the user is authorized to edit if (studyVersion.isWorkingCopy() && (user == null || !study.isUserAuthorizedToEdit(user))) { return false; } } } else if (isVersionDiffPage(pageDef)) { Study study = null; StudyVersion studyVersion1 = null; StudyVersion studyVersion2 = null; String studyId = VDCBaseBean.getParamFromRequestOrComponent("studyId", request); Long[] versionList = VDCRequestBean.parseVersionNumberList(request); studyVersion1 = studyService.getStudyVersion(Long.parseLong(studyId), versionList[0]); studyVersion2 = studyService.getStudyVersion(Long.parseLong(studyId), versionList[1]); if (studyId != null) { study = studyService.getStudy(Long.parseLong(studyId)); } else { study = studyService.getStudyByGlobalId( VDCBaseBean.getParamFromRequestOrComponent("globalId", request)); } if (study.isStudyRestrictedForUser(user, ipUserGroup)) { return false; } // If study has been deaccessioned, // only show the page if the user is authorized to edit if (study.isDeaccessioned() && (user == null || !study.isUserAuthorizedToEdit(user))) { return false; } // If this is a draft version, only show the version if the user is authorized to edit if ((studyVersion1.isWorkingCopy() || studyVersion2.isWorkingCopy()) && (user == null || !study.isUserAuthorizedToEdit(user))) { return false; } if ("confirmRelease".equals(request.getParameter("actionMode")) && !study.isUserAuthorizedToRelease(user)) { return false; } } else if (isSubsettingPage(pageDef)) { String dtId = VDCBaseBean.getParamFromRequestOrComponent("dtId", request); DataTable dataTable = variableService.getDataTable(Long.parseLong(dtId)); Study study = dataTable.getStudyFile().getStudy(); if (study.isStudyRestrictedForUser(user, ipUserGroup)) { return false; } } else if (isExploreDataPage(pageDef)) { String fileId = VDCBaseBean.getParamFromRequestOrComponent("fileId", request); StudyFile sf = studyFileService.getStudyFile(Long.parseLong(fileId)); if (sf.isFileRestrictedForUser(user, currentVDC, ipUserGroup)) { return false; } } else if (isEditAccountPage(pageDef)) { String userId = VDCBaseBean.getParamFromRequestOrComponent("userId", request); if (user == null || user.getId() != Long.parseLong(userId)) { return false; } } else if (isManifestPage(pageDef)) { LockssConfig chkLockssConfig = getLockssConfig(currentVDC); if (chkLockssConfig == null) { return false; } else if (chkLockssConfig.getserverAccess().equals(ServerAccess.GROUP)) { VDCRole userRole = null; String userVDCRoleName = null; if (user != null && currentVDC != null) { userRole = loginBean.getVDCRole(currentVDC); } if (user != null && userRole != null && user.isAdmin(currentVDC)) { return true; } if (user != null && user.getNetworkRole() != null && user.getNetworkRole().getName().equals(NetworkRoleServiceLocal.ADMIN)) { // If you are network admin, you can do anything! return true; } if (!lockssAuth.isAuthorizedLockssServer(currentVDC, request)) { return false; } } } return true; }