List of usage examples for java.util ArrayList clear
public void clear()
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private static void addSyncTaskListVer1(String pl, ArrayList<SyncTaskItem> sync) { //Extract ArrayList<String> field String list1 = "", list2 = "", list3 = "", npl = ""; if (pl.indexOf("[") >= 0) { // found first List list1 = pl.substring(pl.indexOf("[") + 1, pl.indexOf("]")); npl = pl.replace("[" + list1 + "]\t", ""); if (npl.indexOf("[") >= 0) { // found second List list2 = npl.substring(npl.indexOf("[") + 1, npl.indexOf("]")); npl = npl.replace("[" + list2 + "]\t", ""); }// w w w .j a v a2 s . c o m if (npl.indexOf("[") >= 0) { // found third List list3 = npl.substring(npl.indexOf("[") + 1, npl.indexOf("]")); npl = npl.replace("[" + list3 + "]\t", ""); } } else npl = pl; // Log.v("","pl="+pl); // Log.v("","npl="+npl); String[] tmp_pl = npl.split("\t");// {"type","name","active",options...}; String[] parm = new String[100]; for (int i = 0; i < 100; i++) parm[i] = ""; for (int i = 0; i < tmp_pl.length; i++) { if (tmp_pl[i] == null) parm[i] = ""; else { if (tmp_pl[i] == null) parm[i] = ""; else parm[i] = convertToSpecChar(tmp_pl[i].trim()); } // Log.v("","i="+i+", "+parm[i]); } if (parm[0].equals(SMBSYNC_PROF_TYPE_SETTINGS)) return; //ignore settings entry if (parm[0].equals(SMBSYNC_PROF_TYPE_SYNC)) {//Sync ArrayList<String> ff = new ArrayList<String>(); ArrayList<String> df = new ArrayList<String>(); ArrayList<String> wifi_wl = new ArrayList<String>(); if (list1.length() != 0) { String[] fp = list1.split("\t"); for (int i = 0; i < fp.length; i++) ff.add(convertToSpecChar(fp[i])); } else ff.clear(); if (list2.length() != 0) { String[] dp = list2.split("\t"); for (int i = 0; i < dp.length; i++) df.add(convertToSpecChar(dp[i])); } else df.clear(); if (list3.length() != 0) { String[] wl = list3.split("\t"); for (int i = 0; i < wl.length; i++) wifi_wl.add(convertToSpecChar(wl[i])); } else wifi_wl.clear(); SyncTaskItem stli = new SyncTaskItem(parm[1], parm[2].equals("0") ? false : true, false); stli.setSyncTaskType(parm[3]); stli.setMasterFolderType(parm[4]); stli.setMasterSmbUser(parm[5]); stli.setMasterSmbPassword(parm[6]); stli.setMasterSmbShareName(parm[7]); stli.setMasterDirectoryName(parm[8]); stli.setMasterRemoteAddr(parm[9]); stli.setMasterRemotePort(parm[10]); stli.setMasterRemoteHostname(parm[11]); stli.setMasterRemoteDomain(parm[12]); stli.setTargetFolderType(parm[13]); stli.setTargetSmbUser(parm[14]); stli.setTargetSmbPassword(parm[15]); stli.setTargetSmbShareName(parm[16]); stli.setTargetDirectoryName(parm[17]); stli.setTargetRemoteAddr(parm[18]); stli.setTargetRemotePort(parm[19]); stli.setTargetRemoteHostname(parm[20]); stli.setTargetRemoteDomain(parm[21]); stli.setFileFilter(ff); stli.setDirFilter(df); stli.setSyncWifiConnectionWhiteList(wifi_wl); stli.setSyncProcessRootDirFile(parm[22].equals("1") ? true : false); stli.setSyncProcessOverrideOrDelete(parm[23].equals("1") ? true : false); stli.setSyncConfirmOverrideOrDelete(parm[24].equals("1") ? true : false); stli.setSyncDetectLastModBySmbsync(parm[25].equals("1") ? true : false); stli.setSyncDoNotResetLastModSmbFile(parm[26].equals("1") ? true : false); stli.setSyncRetryCount(parm[27]); stli.setSyncEmptyDirectory(parm[28].equals("1") ? true : false); stli.setSyncHiddenFile(parm[29].equals("1") ? true : false); stli.setSyncHiddenDirectory(parm[30].equals("1") ? true : false); stli.setSyncSubDirectory(parm[31].equals("1") ? true : false); stli.setSyncUseSmallIoBuffer(parm[32].equals("1") ? true : false); stli.setSyncTestMode(parm[33].equals("1") ? true : false); stli.setSyncDifferentFileAllowableTime(Integer.parseInt(parm[34])); stli.setSyncDifferentFileByModTime(parm[35].equals("1") ? true : false); stli.setSyncUseFileCopyByTempName(parm[36].equals("1") ? true : false); stli.setSyncWifiStatusOption(parm[37]); stli.setLastSyncTime(parm[38]); stli.setLastSyncResult(Integer.parseInt(parm[39])); if (!parm[40].equals("") && !parm[40].equals("end")) stli.setSyncTaskPosition(Integer.parseInt(parm[40])); if (!parm[41].equals("") && !parm[41].equals("end")) stli.setMasterFolderUseInternalUsbFolder(parm[41].equals("1") ? true : false); if (!parm[41].equals("") && !parm[42].equals("end")) stli.setTargetFolderUseInternalUsbFolder(parm[42].equals("1") ? true : false); sync.add(stli); } }
From source file:op.care.reports.PnlReport.java
private JPanel createContentPanel4Day(LocalDate day) { // OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage("misc.msg.wait", progress, progressMax)); // progress++; final String key = DateFormat.getDateInstance().format(day.toDate()); synchronized (contentmap) { if (contentmap.containsKey(key)) { return contentmap.get(key); }//from w w w . j a v a 2 s.co m } final JPanel dayPanel = new JPanel(new VerticalLayout()); dayPanel.setOpaque(false); synchronized (valuecache) { if (!valuecache.containsKey(key)) { valuecache.put(key, NReportTools.getNReports4Day(resident, day)); } int i = 0; // for zebra pattern for (final NReport nreport : valuecache.get(key)) { if (tbShowReplaced.isSelected() || !nreport.isObsolete()) { String title = SYSTools.toHTMLForScreen(SYSConst.html_table(SYSConst .html_table_tr("<td width=\"800\" align=\"left\">" + "<b><p>" + (nreport.isObsolete() ? SYSConst.html_16x16_Eraser_internal : "") + (nreport.isReplacement() ? SYSConst.html_16x16_Edited_internal : "") + DateFormat.getTimeInstance(DateFormat.SHORT).format(nreport.getPit()) + " " + SYSTools.xx("misc.msg.Time.short") + ", " + nreport.getMinutes() + " " + SYSTools.xx("misc.msg.Minute(s)") + ", " + nreport.getUser().getFullname() + (nreport.getCommontags().isEmpty() ? "" : " " + CommontagsTools.getAsHTML(nreport.getCommontags(), SYSConst.html_16x16_tagPurple_internal)) + "</p></b></td>") + SYSConst.html_table_tr("<td width=\"800\" align=\"left\">" + SYSTools.replace(nreport.getText(), "\n", "<br/>", false) + "</td>"), "0")); final DefaultCPTitle pnlSingle = new DefaultCPTitle(SYSTools.toHTMLForScreen(title), null); pnlSingle.getButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { GUITools.showPopup(GUITools.getHTMLPopup(pnlSingle.getButton(), NReportTools.getInfoAsHTML(nreport)), SwingConstants.NORTH); } }); if (!nreport.getAttachedFilesConnections().isEmpty()) { /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = new JButton( Integer.toString(nreport.getAttachedFilesConnections().size()), SYSConst.icon22greenStar); btnFiles.setToolTipText(SYSTools.xx("misc.btnfiles.tooltip")); btnFiles.setForeground(Color.BLUE); btnFiles.setHorizontalTextPosition(SwingUtilities.CENTER); btnFiles.setFont(SYSConst.ARIAL18BOLD); btnFiles.setPressedIcon(SYSConst.icon22Pressed); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.setAlignmentY(Component.TOP_ALIGNMENT); btnFiles.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnFiles.setContentAreaFilled(false); btnFiles.setBorder(null); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Closure fileHandleClosure = OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? null : new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); final NReport myReport = em.find(NReport.class, nreport.getID()); em.close(); final String keyNewDay = DateFormat.getDateInstance() .format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); } synchronized (linemap) { linemap.remove(nreport); } synchronized (valuecache) { valuecache.get(keyNewDay).remove(nreport); valuecache.get(keyNewDay).add(myReport); Collections.sort(valuecache.get(keyNewDay)); } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2); } }; new DlgFiles(nreport, fileHandleClosure); } }); btnFiles.setEnabled(OPDE.isFTPworking()); pnlSingle.getRight().add(btnFiles); } if (!nreport.getAttachedQProcessConnections().isEmpty()) { /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = new JButton( Integer.toString(nreport.getAttachedQProcessConnections().size()), SYSConst.icon22redStar); btnProcess.setToolTipText(SYSTools.xx("misc.btnprocess.tooltip")); btnProcess.setForeground(Color.YELLOW); btnProcess.setHorizontalTextPosition(SwingUtilities.CENTER); btnProcess.setFont(SYSConst.ARIAL18BOLD); btnProcess.setPressedIcon(SYSConst.icon22Pressed); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); btnProcess.setAlignmentY(Component.TOP_ALIGNMENT); btnProcess.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnProcess.setContentAreaFilled(false); btnProcess.setBorder(null); btnProcess.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgProcessAssign(nreport, new Closure() { @Override public void execute(Object o) { if (o == null) { return; } Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o; ArrayList<QProcess> assigned = result.getFirst(); ArrayList<QProcess> unassigned = result.getSecond(); EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NReport myReport = em.merge(nreport); em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT); ArrayList<SYSNR2PROCESS> attached = new ArrayList<SYSNR2PROCESS>( myReport.getAttachedQProcessConnections()); for (SYSNR2PROCESS linkObject : attached) { if (unassigned.contains(linkObject.getQProcess())) { linkObject.getQProcess().getAttachedNReportConnections() .remove(linkObject); linkObject.getNReport().getAttachedQProcessConnections() .remove(linkObject); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": " + nreport.getTitle() + " ID: " + nreport.getID(), PReportTools.PREPORT_TYPE_REMOVE_ELEMENT, linkObject.getQProcess())); em.remove(linkObject); } } attached.clear(); for (QProcess qProcess : assigned) { java.util.List<QProcessElement> listElements = qProcess .getElements(); if (!listElements.contains(myReport)) { QProcess myQProcess = em.merge(qProcess); SYSNR2PROCESS myLinkObject = em .merge(new SYSNR2PROCESS(myQProcess, myReport)); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": " + nreport.getTitle() + " ID: " + nreport.getID(), PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess)); qProcess.getAttachedNReportConnections().add(myLinkObject); myReport.getAttachedQProcessConnections().add(myLinkObject); } } em.getTransaction().commit(); final String keyNewDay = DateFormat.getDateInstance() .format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); } synchronized (linemap) { linemap.remove(nreport); } synchronized (valuecache) { valuecache.get(keyNewDay).remove(nreport); valuecache.get(keyNewDay).add(myReport); Collections.sort(valuecache.get(keyNewDay)); } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } else { reloadDisplay(true); } } catch (RollbackException ole) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); } }); btnProcess.setEnabled( OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)); pnlSingle.getRight().add(btnProcess); } /*** * __ __ * | \/ | ___ _ __ _ _ * | |\/| |/ _ \ '_ \| | | | * | | | | __/ | | | |_| | * |_| |_|\___|_| |_|\__,_| * */ final JButton btnMenu = new JButton(SYSConst.icon22menu); btnMenu.setPressedIcon(SYSConst.icon22Pressed); btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMenu.setAlignmentY(Component.TOP_ALIGNMENT); btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMenu.setContentAreaFilled(false); btnMenu.setBorder(null); btnMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane() .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnMenu); popup.removeExcludedComponent(btnMenu); JPanel pnl = getMenu(nreport); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnMenu.setEnabled(!nreport.isObsolete()); pnlSingle.getRight().add(btnMenu); JPanel zebra = new JPanel(); zebra.setLayout(new BoxLayout(zebra, BoxLayout.LINE_AXIS)); zebra.setOpaque(true); if (i % 2 == 0) { zebra.setBackground(SYSConst.orange1[SYSConst.light2]); } else { zebra.setBackground(Color.WHITE); } zebra.add(pnlSingle.getMain()); i++; dayPanel.add(zebra); linemap.put(nreport, pnlSingle.getMain()); } } } synchronized (contentmap) { contentmap.put(key, dayPanel); } return dayPanel; }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Get the acls for a document library./*from w w w.ja v a 2s . co m*/ * @param site * @param guid is the list/library GUID * @return array of sids * @throws Exception */ public String[] getACLs(String site, String guid, boolean activeDirectoryAuthority) throws ManifoldCFException, ServiceInterruption { long currentTime; try { if (site.compareTo("/") == 0) site = ""; // root case UserGroupWS userService = new UserGroupWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall = userService .getUserGroupSoapHandler(); PermissionsWS aclService = new PermissionsWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.schemas.sharepoint.soap.directory.PermissionsSoap aclCall = aclService .getPermissionsSoapHandler(); com.microsoft.schemas.sharepoint.soap.directory.GetPermissionCollectionResponseGetPermissionCollectionResult aclResult = aclCall .getPermissionCollection(guid, "List"); org.apache.axis.message.MessageElement[] aclList = aclResult.get_any(); XMLDoc doc = new XMLDoc(aclList[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException( "Bad xml - missing outer 'ns1:GetPermissionCollection' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:GetPermissionCollection")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:GetPermissionCollection'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); if (nodeList.size() != 1) { throw new ManifoldCFException(" No results found."); } parent = nodeList.get(0); nodeList.clear(); doc.processPath(nodeList, "*", parent); Set<String> sids = new HashSet<String>(); int i = 0; for (; i < nodeList.size(); i++) { Object node = nodeList.get(i); String mask = doc.getValue(node, "Mask"); long maskValue = new Long(mask).longValue(); if ((maskValue & 1L) == 1L) { // Permission to view String isUser = doc.getValue(node, "MemberIsUser"); if (isUser.compareToIgnoreCase("True") == 0) { // Use AD user or group String userLogin = doc.getValue(node, "UserLogin"); String userSid = getSidForUser(userCall, userLogin, activeDirectoryAuthority); sids.add(userSid); } else { // Role List<String> roleSids; String roleName = doc.getValue(node, "RoleName"); if (roleName.length() == 0) { roleName = doc.getValue(node, "GroupName"); if (roleName != null && roleName.length() > 0) { roleSids = getSidsForGroup(userCall, roleName, activeDirectoryAuthority); } else { Logging.connectors.warn( "SharePoint: Unrecognized permission collection entry: no role, no group: " + doc.getXML()); roleSids = new ArrayList<String>(); } } else { roleSids = getSidsForRole(userCall, roleName, activeDirectoryAuthority); } for (String sid : roleSids) { sids.add(sid); } } } } return sids.toArray(new String[0]); } catch (java.net.MalformedURLException e) { throw new ManifoldCFException("Bad SharePoint url: " + e.getMessage(), e); } catch (javax.xml.rpc.ServiceException e) { if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got a service exception getting the acls for site " + site + " guid " + guid + " - retrying", e); currentTime = System.currentTimeMillis(); throw new ServiceInterruption("Service exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 12 * 60 * 60000L, -1, true); } catch (org.apache.axis.AxisFault e) { currentTime = System.currentTimeMillis(); if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) { org.w3c.dom.Element elem = e.lookupFaultDetail( new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode")); if (elem != null) { elem.normalize(); String httpErrorCode = elem.getFirstChild().getNodeValue().trim(); if (httpErrorCode.equals("404")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + site + " did not exist; assuming list/library deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to get the acls if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug( "SharePoint: The crawl user did not have access to the permissions service for " + baseUrl + site + "; skipping documents within"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + site + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + site + ": " + e.getMessage(), e); } throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The list " + guid + " in site " + site + " did not exist; assuming list/library deleted"); return null; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting permissions for the list " + guid + " in site " + site + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return null; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Unknown SharePoint server error getting the acls for site " + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) { String exceptionName = e.getFaultString(); if (exceptionName.equals("java.lang.InterruptedException")) throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unknown remote exception getting the acls for site " + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting the acls for site " + site + " guid " + guid, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Get the acls for a document.//ww w .ja v a2 s .co m * NOTE that this function only works for SharePoint 2007+ with the MCPermissions web service installed. * @param site is the encoded subsite path * @param file is the encoded file url (not including protocol or server or location, but including encoded subsite, library and folder/file path) * @return array of document SIDs * @throws ManifoldCFException * @throws ServiceInterruption */ public String[] getDocumentACLs(String site, String file, boolean activeDirectoryAuthority) throws ManifoldCFException, ServiceInterruption { long currentTime; try { if (site.compareTo("/") == 0) site = ""; // root case // Calculate the full server-relative path of the file String encodedRelativePath = serverLocation + file; if (encodedRelativePath.startsWith("/")) encodedRelativePath = encodedRelativePath.substring(1); if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Getting document acls for site '" + site + "' file '" + file + "': Encoded relative path is '" + encodedRelativePath + "'"); UserGroupWS userService = new UserGroupWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall = userService .getUserGroupSoapHandler(); MCPermissionsWS aclService = new MCPermissionsWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.sharepoint.webpartpages.PermissionsSoap aclCall = aclService.getPermissionsSoapHandler(); com.microsoft.sharepoint.webpartpages.GetPermissionCollectionResponseGetPermissionCollectionResult aclResult = aclCall .getPermissionCollection(encodedRelativePath, "Item"); if (aclResult == null) { Logging.connectors.debug("SharePoint: document acls were null"); return null; } org.apache.axis.message.MessageElement[] aclList = aclResult.get_any(); if (Logging.connectors.isDebugEnabled()) { Logging.connectors.debug("SharePoint: document acls xml: '" + aclList[0].toString() + "'"); } XMLDoc doc = new XMLDoc(aclList[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException( "Bad xml - missing outer 'ns1:GetPermissionCollection' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("GetPermissionCollection")) throw new ManifoldCFException("Bad xml - outer node is not 'GetPermissionCollection'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); if (nodeList.size() != 1) { throw new ManifoldCFException(" No results found."); } parent = nodeList.get(0); nodeList.clear(); doc.processPath(nodeList, "*", parent); Set<String> sids = new HashSet<String>(); int i = 0; for (; i < nodeList.size(); i++) { Object node = nodeList.get(i); String mask = doc.getValue(node, "Mask"); long maskValue = new Long(mask).longValue(); if ((maskValue & 1L) == 1L) { // Permission to view String isUser = doc.getValue(node, "MemberIsUser"); if (isUser.compareToIgnoreCase("True") == 0) { // Use AD user or group String userLogin = doc.getValue(node, "UserLogin"); String userSid = getSidForUser(userCall, userLogin, activeDirectoryAuthority); sids.add(userSid); } else { // Role List<String> roleSids; String roleName = doc.getValue(node, "RoleName"); if (roleName.length() == 0) { roleName = doc.getValue(node, "GroupName"); roleSids = getSidsForGroup(userCall, roleName, activeDirectoryAuthority); } else { roleSids = getSidsForRole(userCall, roleName, activeDirectoryAuthority); } for (String sid : roleSids) { sids.add(sid); } } } } return sids.toArray(new String[0]); } catch (java.net.MalformedURLException e) { throw new ManifoldCFException("Bad SharePoint url: " + e.getMessage(), e); } catch (javax.xml.rpc.ServiceException e) { if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got a service exception getting the acls for site " + site + " file " + file + " - retrying", e); currentTime = System.currentTimeMillis(); throw new ServiceInterruption("Service exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 12 * 60 * 60000L, -1, true); } catch (org.apache.axis.AxisFault e) { currentTime = System.currentTimeMillis(); if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) { org.w3c.dom.Element elem = e.lookupFaultDetail( new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode")); if (elem != null) { elem.normalize(); String httpErrorCode = elem.getFirstChild().getNodeValue().trim(); if (httpErrorCode.equals("404")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + site + " did not exist; assuming library deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to get the acls if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug( "SharePoint: The crawl user did not have access to the MCPermissions service for " + baseUrl + site + "; skipping documents within"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + site + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + site + ": " + e.getMessage(), e); } throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The file " + file + " in site " + site + " did not exist; assuming file deleted"); return null; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting permissions for the file " + file + " in site " + site + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return null; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Unknown SharePoint server error getting the acls for site " + site + " file " + file + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) { String exceptionName = e.getFaultString(); if (exceptionName.equals("java.lang.InterruptedException")) throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unknown remote exception getting the acls for site " + site + " file " + file + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting the acls for site " + site + " file " + file, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Gets a list of field values of the given document * @param fieldNames//w w w. j a va2 s . c o m * @param site * @param docId * @return set of the field values */ public Map<String, String> getFieldValues(String[] fieldNames, String site, String docLibrary, String docId, boolean dspStsWorks) throws ManifoldCFException, ServiceInterruption { long currentTime; try { HashMap<String, String> result = new HashMap<String, String>(); if (site.compareTo("/") == 0) site = ""; // root case if (dspStsWorks) { StsAdapterWS listService = new StsAdapterWS(baseUrl + site, userName, password, configuration, httpClient); StsAdapterSoapStub stub = (StsAdapterSoapStub) listService.getStsAdapterSoapHandler(); String[] vArray = new String[1]; vArray[0] = "1.0"; VersionsHeader myVersion = new VersionsHeader(); myVersion.setVersion(vArray); stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "versions", myVersion); RequestHeader reqHeader = new RequestHeader(); reqHeader.setDocument(DocumentType.content); reqHeader.setMethod(MethodType.query); stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "request", reqHeader); QueryRequest myRequest = new QueryRequest(); DSQuery sQuery = new DSQuery(); sQuery.setSelect("/list[@id='" + docLibrary + "']"); sQuery.setResultContent(ResultContentType.dataOnly); myRequest.setDsQuery(sQuery); DspQuery spQuery = new DspQuery(); spQuery.setRowLimit(1); // For the Requested Fields if (fieldNames.length > 0) { Fields spFields = new Fields(); Field[] fieldArray = new Field[0]; ArrayList fields = new ArrayList(); Field spField = new Field(); // spField.setName( "ID" ); // spField.setAlias( "ID" ); // fields.add( spField ); for (String fieldName : fieldNames) { spField = new Field(); spField.setName(fieldName); spField.setAlias(fieldName); fields.add(spField); } spFields.setField((Field[]) fields.toArray(fieldArray)); spQuery.setFields(spFields); } // Of this document DspQueryWhere spWhere = new DspQueryWhere(); org.apache.axis.message.MessageElement criterion = new org.apache.axis.message.MessageElement( (String) null, "Contains"); SOAPElement seFieldRef = criterion.addChildElement("FieldRef"); seFieldRef.addAttribute(SOAPFactory.newInstance().createName("Name"), "FileRef"); SOAPElement seValue = criterion.addChildElement("Value"); seValue.addAttribute(SOAPFactory.newInstance().createName("Type"), "String"); seValue.setValue(docId); org.apache.axis.message.MessageElement[] criteria = { criterion }; spWhere.set_any(criteria); spQuery.setWhere((DspQueryWhere) spWhere); // Set Criteria myRequest.getDsQuery().setQuery(spQuery); StsAdapterSoap call = stub; // Make Request QueryResponse resp = call.query(myRequest); org.apache.axis.message.MessageElement[] list = resp.get_any(); if (Logging.connectors.isDebugEnabled()) { Logging.connectors.debug("SharePoint: list xml: '" + list[0].toString() + "'"); } XMLDoc doc = new XMLDoc(list[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException("Bad xml - missing outer 'ns1:dsQueryResponse' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); //System.out.println( "Outer NodeName = " + doc.getNodeName(parent) ); if (!doc.getNodeName(parent).equals("ns1:dsQueryResponse")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:dsQueryResponse'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); parent = nodeList.get(0); // <Shared_X0020_Documents /> nodeList.clear(); doc.processPath(nodeList, "*", parent); // Process each result (Should only be one ) // Get each childs Value and add to return array for (int i = 0; i < nodeList.size(); i++) { Object documentNode = nodeList.get(i); ArrayList fieldList = new ArrayList(); doc.processPath(fieldList, "*", documentNode); for (int j = 0; j < fieldList.size(); j++) { Object field = fieldList.get(j); String fieldData = doc.getData(field); String fieldName = doc.getNodeName(field); // Right now this really only works right for single-valued fields. For multi-valued // fields, we'd need to know in advance that they were multivalued // so that we could interpret commas as value separators. result.put(fieldName, fieldData); } } } else { // SharePoint 2010: Get field values some other way // Sharepoint 2010; use Lists service instead ListsWS lservice = new ListsWS(baseUrl + site, userName, password, configuration, httpClient); ListsSoapStub stub1 = (ListsSoapStub) lservice.getListsSoapHandler(); String sitePlusDocId = serverLocation + site + docId; if (sitePlusDocId.startsWith("/")) sitePlusDocId = sitePlusDocId.substring(1); GetListItemsQuery q = buildMatchQuery("FileRef", "Text", sitePlusDocId); GetListItemsViewFields viewFields = buildViewFields(fieldNames); GetListItemsResponseGetListItemsResult items = stub1.getListItems(docLibrary, "", q, viewFields, "1", buildNonPagingQueryOptions(), null); if (items == null) return result; MessageElement[] list = items.get_any(); if (Logging.connectors.isDebugEnabled()) { Logging.connectors.debug("SharePoint: getListItems for '" + docId + "' using FileRef value '" + sitePlusDocId + "' xml response: '" + list[0].toString() + "'"); } ArrayList nodeList = new ArrayList(); XMLDoc doc = new XMLDoc(list[0].toString()); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) throw new ManifoldCFException("Bad xml - expecting one outer 'ns1:listitems' node - there are " + Integer.toString(nodeList.size()) + " nodes"); Object parent = nodeList.get(0); if (!"ns1:listitems".equals(doc.getNodeName(parent))) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:listitems'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); if (nodeList.size() != 1) throw new ManifoldCFException("Expected rsdata result but no results found."); Object rsData = nodeList.get(0); int itemCount = Integer.parseInt(doc.getValue(rsData, "ItemCount")); if (itemCount == 0) return result; // Now, extract the files from the response document ArrayList nodeDocs = new ArrayList(); doc.processPath(nodeDocs, "*", rsData); if (nodeDocs.size() != itemCount) throw new ManifoldCFException("itemCount does not match with nodeDocs.size()"); if (itemCount != 1) throw new ManifoldCFException("Expecting only one item, instead saw '" + itemCount + "'"); Object o = nodeDocs.get(0); // Look for all the specified attributes in the record for (Object attrName : fieldNames) { String attrValue = doc.getValue(o, "ows_" + (String) attrName); if (attrValue != null) { result.put(attrName.toString(), valueMunge(attrValue)); } } } return result; } catch (javax.xml.soap.SOAPException e) { throw new ManifoldCFException("Soap exception: " + e.getMessage(), e); } catch (java.net.MalformedURLException e) { throw new ManifoldCFException("Bad SharePoint url: " + e.getMessage(), e); } catch (javax.xml.rpc.ServiceException e) { if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got a service exception getting field values for site " + site + " library " + docLibrary + " document '" + docId + "' - retrying", e); currentTime = System.currentTimeMillis(); throw new ServiceInterruption("Service exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 12 * 60 * 60000L, -1, true); } catch (org.apache.axis.AxisFault e) { if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) { org.w3c.dom.Element elem = e.lookupFaultDetail( new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode")); if (elem != null) { elem.normalize(); String httpErrorCode = elem.getFirstChild().getNodeValue().trim(); if (httpErrorCode.equals("404")) return null; else if (httpErrorCode.equals("403")) throw new ManifoldCFException("Remote procedure exception: " + e.getMessage(), e); else if (httpErrorCode.equals("401")) { if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug( "SharePoint: Crawl user does not have sufficient privileges to get field values for site " + site + " library " + docLibrary + " - skipping", e); return null; } throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + site + ": " + e.getMessage(), e); } throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e); } if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) { String exceptionName = e.getFaultString(); if (exceptionName.equals("java.lang.InterruptedException")) throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED); } // I don't know if this is what you get when the library is missing, but here's hoping. if (e.getMessage().indexOf("List does not exist") != -1) return null; if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got a remote exception getting field values for site " + site + " library " + docLibrary + " document [" + docId + "] - retrying", e); currentTime = System.currentTimeMillis(); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { throw new ManifoldCFException("Unexpected remote exception occurred: " + e.getMessage(), e); } }
From source file:FormatStorage.Unit.java
public Record[] getRecordByValue(FieldValue[] values, int width, byte op) throws Exception { int sidx = segment.index(); byte[] buffer = segment.formatData.unitPool().getUnitBytes(sidx, index); if (buffer == null) { buffer = loadUnitBuffer(segment.formatData.in()); segment.formatData.unitPool().poolUnitBytes(sidx, index, buffer, segment); }// ww w . j a v a2 s . c o m boolean VAR = segment.formatData.isVar(); loadDataMeta(buffer, VAR); dataInputBuffer.reset(buffer, 0, buffer.length); ArrayList<Record> resultArrary = new ArrayList<Record>(100); for (int i = 0; i < recordNum; i++) { long dataChunkOffset = offsetArray[i]; long dataChunkLen = 0; if (i < recordNum - 1) { dataChunkLen = offsetArray[i + 1] - dataChunkOffset; } else { dataChunkLen = metaOffset - dataChunkOffset; } short fieldNum = fieldMap.fieldNum(); DataChunk chunk = new DataChunk(fieldNum); chunk.unpersistent(dataChunkOffset, dataChunkLen, dataInputBuffer); boolean optimize = false; Record record = chunk.toRecord(fieldMap, false, segment.formatData.fieldValueBytes); chunk = null; if (op == ConstVar.OP_GetSpecial) { boolean equal = true; for (int j = 0; j < values.length; j++) { short idx = record.tabIndex2recIndex(values[j].idx); if (idx == -1) { equal = false; break; } int cr = WritableComparator.compareBytes(values[j].value, 0, values[j].value.length, record.fieldValues.get(idx).value, 0, record.fieldValues.get(idx).len); if (cr != 0) { equal = false; break; } } if (equal) { resultArrary.add(record); } } else { resultArrary.add(record); } record = null; } Record[] records = null; int size = resultArrary.size(); if (size == 0) { return records; } records = new Record[size]; for (int i = 0; i < size; i++) { records[i] = resultArrary.get(i); } resultArrary.clear(); return records; }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.MetaThesaurusToSQL.java
private void loadConcepts(String codingSchemeName) throws SQLException { messages_.info("loading concepts - getting a total count"); PreparedStatement getCodingSchemeInfo = umlsConnection2_ .prepareStatement("SELECT COUNT(*) as cnt FROM MRCONSO"); ResultSet results = getCodingSchemeInfo.executeQuery(); results.next();/* w w w . j a va 2 s .c o m*/ int total = results.getInt("cnt"); results.close(); getCodingSchemeInfo.close(); int start = 0; String lastCui = null; ArrayList conceptPresentations = new ArrayList(); int codeCount = 0; int rowCount = 0; // collect them all into batches of concept codes. when the code // changes, load that code while (start < total) { // mysql still can't seem to stream results properly, so I'm going // to batch them. messages_.info("Fetching a batch of results"); getCodingSchemeInfo = umlsConnection2_.prepareStatement(umlsSqlModifier_.modifySQL( "SELECT LAT, CODE, AUI, CUI, TS, STT, ISPREF, STR, TTY, SAB FROM MRCONSO ORDER BY {BINARY} CUI {LIMIT}")); // mysql doesn't stream results - the {LIMIT above and this is for // getting limits on mysql code} if (umlsSqlModifier_.getDatabaseType().equals("MySQL")) { getCodingSchemeInfo.setInt(1, start); getCodingSchemeInfo.setInt(2, batchSize); start += batchSize; } else if (umlsSqlModifier_.getDatabaseType().equals("PostgreSQL")) { // postgres properly streams results, we can just set the fetch // size, and only loop once getCodingSchemeInfo.setFetchSize(batchSize); umlsConnection2_.setAutoCommit(false); start = total; } else { start = total; } results = getCodingSchemeInfo.executeQuery(); log.debug("query finished, processing results"); while (results.next()) { rowCount++; // store all the data from this row. ConceptPresentation temp = new ConceptPresentation(); temp.conceptCode = results.getString("CODE"); temp.cui = results.getString("CUI"); if (lastCui != null && !temp.cui.equals(lastCui)) { loadConcept(codingSchemeName, (ConceptPresentation[]) conceptPresentations .toArray(new ConceptPresentation[conceptPresentations.size()])); conceptPresentations.clear(); presentationCounter_ = 1; codeCounter_ = 1; definitionCounter_ = 1; cuiCounter_ = 1; semTypeCounter_ = 1; if (codeCount % 100 == 0) { messages_.busy(); } codeCount++; if (codeCount % 10000 == 0) { messages_.info("On row " + rowCount + " out of " + total + " rows - found " + codeCount + " concepts"); } } temp.language = results.getString("LAT"); // add for populating the supportedLanguages later supportedLanguages_.add(temp.language); temp.presentationFormat = null; temp.TTY = results.getString("TTY"); temp.representationForm = temp.TTY; temp.value = results.getString("STR"); temp.TS = results.getString("TS"); temp.STT = results.getString("STT"); temp.isPreferred = new Boolean(false); temp.source = results.getString("SAB"); temp.ISPREF = results.getString("ISPREF"); temp.AUI = results.getString("AUI"); // See if there is a "better" value for the representationalForm // mapping String repFormMap = (String) mrconsoRepresentationalMap_.get(temp.representationForm); if (repFormMap != null) { temp.representationForm = repFormMap; } lastCui = temp.cui; conceptPresentations.add(temp); } results.close(); getCodingSchemeInfo.close(); } // load the last one if (lastCui != null) { // need to add this, just once - assuming there were codes, so this // is a good place for it. supportedPropertyTypes_.add(SQLTableConstants.TBLCOLVAL_TEXTUALPRESENTATION); loadConcept(codingSchemeName, (ConceptPresentation[]) conceptPresentations .toArray(new ConceptPresentation[conceptPresentations.size()])); codeCount++; } // we are done with inserting entities, close the preparedStatement. insertIntoEntities.close(); insertIntoEntityType.close(); messages_.info("Loaded " + codeCount + " concepts from " + rowCount + " rows"); supportedPropertyQualifiers_.add("source-code"); supportedPropertyQualifiers_.add("AUI"); supportedPropertyQualifiers_.add("HCD"); updateApproxNumberOfConcepts(codeCount, codingSchemeName); loadSupportedProperties(codingSchemeName); loadSupportedPropertyQualifiers(codingSchemeName); loadSupportedLanguages(codingSchemeName); loadSupportedSources(codingSchemeName); }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSToSQL.java
private void loadConcepts(String UMLSCodingSchemeName, String codingSchemeName) throws SQLException { messages_.info("loading concepts - getting a total count"); PreparedStatement getCodingSchemeInfo = umlsConnection2_ .prepareStatement("SELECT COUNT(*) as cnt FROM MRCONSO WHERE SAB = ?"); getCodingSchemeInfo.setString(1, UMLSCodingSchemeName); ResultSet results = getCodingSchemeInfo.executeQuery(); results.next();// w w w .jav a2 s .c o m int total = results.getInt("cnt"); results.close(); getCodingSchemeInfo.close(); int start = 0; String lastCode = null; ArrayList conceptPresentations = new ArrayList(); int codeCount = 0; int rowCount = 0; // collect them all into batches of concept codes. when the code // changes, load that code while (start < total) { messages_.info("Fetching a batch of results"); getCodingSchemeInfo = umlsConnection2_.prepareStatement( umlsSqlModifier_.modifySQL("SELECT LAT, CODE, CUI, LUI, SUI, AUI, TS, STT, STR, TTY " + " FROM MRCONSO WHERE SAB = ? ORDER BY {BINARY} CODE {LIMIT}")); getCodingSchemeInfo.setString(1, UMLSCodingSchemeName); // mysql doesn't stream results - the {LIMIT above and this is for // getting limits on mysql code} if (umlsSqlModifier_.getDatabaseType().equals("MySQL")) { getCodingSchemeInfo.setInt(2, start); getCodingSchemeInfo.setInt(3, batchSize); start += batchSize; } else if (umlsSqlModifier_.getDatabaseType().equals("PostgreSQL")) { // postgres properly streams results, we can just set the fetch // size, and only loop once getCodingSchemeInfo.setFetchSize(batchSize); umlsConnection2_.setAutoCommit(false); start = total; } else { start = total; } results = getCodingSchemeInfo.executeQuery(); log.debug("query finished, processing results"); while (results.next()) { rowCount++; // store all the data from this row. ConceptPresentation temp = new ConceptPresentation(); temp.conceptCode = results.getString("CODE"); temp.cui = results.getString("CUI"); // there are some concepts that just have "NOCODE" as the // code... need to make them unique. if (temp.conceptCode.equals("NOCODE")) { temp.conceptCode = temp.conceptCode + "-" + temp.cui; } if (lastCode != null && !temp.conceptCode.equals(lastCode)) { loadConcept(UMLSCodingSchemeName, codingSchemeName, (ConceptPresentation[]) conceptPresentations .toArray(new ConceptPresentation[conceptPresentations.size()])); conceptPresentations.clear(); commentCounter_ = 1; presentationCounter_ = 1; instructionCounter_ = 1; definitionCounter_ = 1; propertyCounter_ = 1; cuiCounter_ = 1; semTypeCounter_ = 1; if (codeCount % 10 == 0) { messages_.busy(); } codeCount++; if (codeCount % 1000 == 0) { messages_.info("On row " + rowCount + " out of " + total + " rows - found " + codeCount + " concepts"); } } temp.language = results.getString("LAT"); if (UMLSCodingSchemeName.equals("SNOMEDCT")) { // snomed has a different way of recording the language of // the presentation... String snomedLanguage = getSnomedLanguageForPresentation(results.getString("CUI"), results.getString("LUI"), results.getString("SUI")); if (snomedLanguage != null && snomedLanguage.length() > 0) { temp.language = snomedLanguage; } } // add for populating the supportedLanguages later supportedLanguages_.add(temp.language); temp.presentationFormat = SQLTableConstants.TBLCOLVAL_FORMAT_TXT_PLAIN; temp.TTY = results.getString("TTY"); temp.representationForm = temp.TTY; temp.value = results.getString("STR"); temp.TS = results.getString("TS"); temp.STT = results.getString("STT"); temp.AUI = results.getString("AUI"); temp.isPreferred = new Boolean(false); temp.source = UMLSCodingSchemeName; // See if there is a "better" value for the representationalForm // mapping String repFormMap = (String) mrconsoRepresentationalMap_.get(temp.representationForm); if (repFormMap != null) { temp.representationForm = repFormMap; } lastCode = temp.conceptCode; conceptPresentations.add(temp); } results.close(); } // load the last one if (lastCode != null) { // need to add this, just once - assuming there were codes, so this // is a good place for it. supportedPropertyTypes_.add(SQLTableConstants.TBLCOLVAL_TEXTUALPRESENTATION); loadConcept(UMLSCodingSchemeName, codingSchemeName, (ConceptPresentation[]) conceptPresentations .toArray(new ConceptPresentation[conceptPresentations.size()])); codeCount++; } messages_.info("Loaded " + codeCount + " concepts from " + rowCount + " rows"); // we are done with inserting entities, close the preparedStatement. insertIntoEntities.close(); insertIntoEntityType.close(); updateApproxNumberOfConcepts(codeCount, codingSchemeName); loadSupportedProperties(codingSchemeName); loadSupportedLanguages(codingSchemeName); getCodingSchemeInfo.close(); }
From source file:gima.neo4j.testsuite.osmcheck.OSMImporter.java
public void importFile(OSMWriter<?> osmWriter, String dataset, boolean allPoints, Charset charset) throws IOException, XMLStreamException { System.out.println("Importing with osm-writer: " + osmWriter); osmWriter.getOrCreateOSMDataset(layerName); osm_dataset = osmWriter.getDatasetId(); long startTime = System.currentTimeMillis(); long[] times = new long[] { 0L, 0L, 0L, 0L }; javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance(); CountedFileReader reader = new CountedFileReader(dataset, charset); javax.xml.stream.XMLStreamReader parser = factory.createXMLStreamReader(reader); int countXMLTags = 0; beginProgressMonitor(100);//from w w w . j a va 2 s . c om setLogContext(dataset); boolean startedWays = false; boolean startedRelations = false; try { ArrayList<String> currentXMLTags = new ArrayList<String>(); int depth = 0; Map<String, Object> wayProperties = null; ArrayList<Long> wayNodes = new ArrayList<Long>(); Map<String, Object> relationProperties = null; ArrayList<Map<String, Object>> relationMembers = new ArrayList<Map<String, Object>>(); LinkedHashMap<String, Object> currentNodeTags = new LinkedHashMap<String, Object>(); while (true) { updateProgressMonitor(reader.getPercentRead()); incrLogContext(); int event = parser.next(); if (event == javax.xml.stream.XMLStreamConstants.END_DOCUMENT) { break; } switch (event) { case javax.xml.stream.XMLStreamConstants.START_ELEMENT: currentXMLTags.add(depth, parser.getLocalName()); String tagPath = currentXMLTags.toString(); if (tagPath.equals("[osm]")) { osmWriter.setDatasetProperties(extractProperties(parser)); } else if (tagPath.equals("[osm, bounds]")) { osmWriter.addOSMBBox(extractProperties("bbox", parser)); } else if (tagPath.equals("[osm, node]")) { // <node id="269682538" lat="56.0420950" lon="12.9693483" user="sanna" uid="31450" visible="true" version="1" changeset="133823" timestamp="2008-06-11T12:36:28Z"/> osmWriter.createOSMNode(extractProperties("node", parser)); } else if (tagPath.equals("[osm, way]")) { // <way id="27359054" user="spull" uid="61533" visible="true" version="8" changeset="4707351" timestamp="2010-05-15T15:39:57Z"> if (!startedWays) { startedWays = true; times[0] = System.currentTimeMillis(); osmWriter.optimize(); times[1] = System.currentTimeMillis(); } wayProperties = extractProperties("way", parser); wayNodes.clear(); } else if (tagPath.equals("[osm, way, nd]")) { Map<String, Object> properties = extractProperties(parser); wayNodes.add(Long.parseLong(properties.get("ref").toString())); } else if (tagPath.endsWith("tag]")) { Map<String, Object> properties = extractProperties(parser); currentNodeTags.put(properties.get("k").toString(), properties.get("v").toString()); } else if (tagPath.equals("[osm, relation]")) { // <relation id="77965" user="Grillo" uid="13957" visible="true" version="24" changeset="5465617" timestamp="2010-08-11T19:25:46Z"> if (!startedRelations) { startedRelations = true; times[2] = System.currentTimeMillis(); osmWriter.optimize(); times[3] = System.currentTimeMillis(); } relationProperties = extractProperties("relation", parser); relationMembers.clear(); } else if (tagPath.equals("[osm, relation, member]")) { relationMembers.add(extractProperties(parser)); } if (startedRelations) { if (countXMLTags < 10) { log("Starting tag at depth " + depth + ": " + currentXMLTags.get(depth) + " - " + currentXMLTags.toString()); for (int i = 0; i < parser.getAttributeCount(); i++) { log("\t" + currentXMLTags.toString() + ": " + parser.getAttributeLocalName(i) + "[" + parser.getAttributeNamespace(i) + "," + parser.getAttributePrefix(i) + "," + parser.getAttributeType(i) + "," + "] = " + parser.getAttributeValue(i)); } } countXMLTags++; } depth++; break; case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (currentXMLTags.toString().equals("[osm, node]")) { osmWriter.addOSMNodeTags(allPoints, currentNodeTags); } else if (currentXMLTags.toString().equals("[osm, way]")) { osmWriter.createOSMWay(wayProperties, wayNodes, currentNodeTags); } else if (currentXMLTags.toString().equals("[osm, relation]")) { osmWriter.createOSMRelation(relationProperties, relationMembers, currentNodeTags); } depth--; currentXMLTags.remove(depth); // log("Ending tag at depth "+depth+": "+currentTags.get(depth)); break; default: break; } } } finally { endProgressMonitor(); parser.close(); osmWriter.finish(); this.osm_dataset = osmWriter.getDatasetId(); } describeTimes(startTime, times); osmWriter.describeMissing(); osmWriter.describeLoaded(); long stopTime = System.currentTimeMillis(); log("info | Elapsed time in seconds: " + (1.0 * (stopTime - startTime) / 1000.0)); stats.dumpGeomStats(); stats.printTagStats(); }
From source file:com.chinamobile.bcbsp.bspstaff.BSPStaff.java
/** * Prepare for recovery , reset the parameters. * /*from w w w . ja v a2 s . c o m*/ * @param job * @param workerAgent * @param hostName */ private void prepareRecoverySchedule(BSPJob job, WorkerAgentProtocol workerAgent, String hostName) { this.ssc = sssc.secondStageSuperStepBarrierForRecovery(job.getInt("staff.fault.superstep", 0)); this.setPartitionToWorkerManagerNameAndPort(ssc.getPartitionToWorkerManagerNameAndPort()); this.localBarrierNum = getLocalBarrierNumber(hostName); ArrayList<String> tmp = new ArrayList<String>(); for (String str : this.getPartitionToWorkerManagerNameAndPort().values()) { if (!tmp.contains(str)) { tmp.add(str); } } workerAgent.setNumberWorkers(this.getJobId(), this.getSid(), tmp.size()); tmp.clear(); this.workerMangerNum = workerAgent.getNumberWorkers(this.getJobId(), this.getSid()); this.currentSuperStepCounter = ssc.getAbleCheckPoint(); }