List of usage examples for java.util ArrayList clear
public void clear()
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Gets a list of lists given a parent site * @param parentSite the site to search for lists, empty string for root * @return lists of NameValue objects, representing lists */// w w w . jav a 2s .com public List<NameValue> getLists(String parentSite, String parentSiteDecoded) throws ManifoldCFException, ServiceInterruption { long currentTime; try { ArrayList<NameValue> result = new ArrayList<NameValue>(); String parentSiteRequest = parentSite; if (parentSiteRequest.equals("/")) { parentSiteRequest = ""; // root case parentSiteDecoded = ""; } ListsWS listsService = new ListsWS(baseUrl + parentSiteRequest, userName, password, configuration, httpClient); ListsSoap listsCall = listsService.getListsSoapHandler(); GetListCollectionResponseGetListCollectionResult listResp = listsCall.getListCollection(); org.apache.axis.message.MessageElement[] lists = listResp.get_any(); //if ( parentSite.compareTo("/Sample2") == 0) System.out.println( lists[0].toString() ); XMLDoc doc = new XMLDoc(lists[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException("Bad xml - missing outer 'ns1:Lists' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:Lists")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:Lists'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); // <ns1:Lists> String prefixPath = decodedServerLocation + parentSiteDecoded + "/"; int i = 0; while (i < nodeList.size()) { Object o = nodeList.get(i++); String baseType = doc.getValue(o, "BaseType"); if (baseType.equals("0")) { // We think it's a list // This is how we display it, so this has the right path extension String urlPath = doc.getValue(o, "DefaultViewUrl"); // This is the pretty name String title = doc.getValue(o, "Title"); // Leave this in for the moment if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: List: '" + urlPath + "', '" + title + "'"); // If it has no view url, we don't have any idea what to do with it if (urlPath != null && urlPath.length() > 0) { // Normalize conditionally if (!urlPath.startsWith("/")) urlPath = prefixPath + urlPath; // Get rid of what we don't want, unconditionally if (urlPath.startsWith(prefixPath)) { urlPath = urlPath.substring(prefixPath.length()); // We're at the /Lists/listname part of the name. Figure out where the end of it is. int index = urlPath.indexOf("/"); if (index == -1) throw new ManifoldCFException("Bad list view url without site: '" + urlPath + "'"); String pathpart = urlPath.substring(0, index); if ("Lists".equals(pathpart)) { int k = urlPath.indexOf("/", index + 1); if (k == -1) throw new ManifoldCFException( "Bad list view url without 'Lists': '" + urlPath + "'"); pathpart = urlPath.substring(index + 1, k); } if (pathpart.length() != 0 && !pathpart.equals("_catalogs")) { if (title == null || title.length() == 0) title = pathpart; result.add(new NameValue(pathpart, title)); } } else { Logging.connectors.warn("SharePoint: List view url is not in the expected form: '" + urlPath + "'; expected something beginning with '" + prefixPath + "'; skipping"); } } } } return result; } 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 lists for site " + parentSite + " - 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 read lists for site " + parentSite + " - skipping", e); return null; } throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + parentSite + ": " + 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); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug( "SharePoint: Got a remote exception reading lists for site " + parentSite + " - 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:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Gets a list of field names of the given document library * @param site//w w w . j av a 2 s .c om * @param list/library name * @return list of the fields */ public Map<String, String> getFieldList(String site, String listName) throws ManifoldCFException, ServiceInterruption { long currentTime; try { Map<String, String> result = new HashMap<String, String>(); if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: In getFieldList; site='" + site + "', listName='" + listName + "'"); // The docLibrary must be a GUID, because we don't have title. if (site.compareTo("/") == 0) site = ""; ListsWS listService = new ListsWS(baseUrl + site, userName, password, configuration, httpClient); ListsSoap listCall = listService.getListsSoapHandler(); GetListResponseGetListResult listResponse = listCall.getList(listName); org.apache.axis.message.MessageElement[] List = listResponse.get_any(); 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 node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:List")) throw new ManifoldCFException( "Bad xml - outer node is '" + doc.getNodeName(parent) + "' not 'ns1:List'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); // <ns1:Fields> for (Object metaField : nodeList) { if (doc.getNodeName(metaField).equals("ns1:Fields")) { ArrayList fieldsList = new ArrayList(); doc.processPath(fieldsList, "*", metaField); for (Object o : fieldsList) { String name = doc.getValue(o, "DisplayName"); String fieldName = doc.getValue(o, "Name"); String hidden = doc.getValue(o, "Hidden"); // System.out.println( "Hidden :" + hidden ); if (name.length() != 0 && fieldName.length() != 0 && (!hidden.equalsIgnoreCase("true"))) { // make sure we don't include the same field more than once. // This may happen if the Library has more than one view. if (result.containsKey(fieldName) == false) result.put(fieldName, name); } } } } // System.out.println(result.size()); return result; } 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 list for site " + site + " listName " + listName + " - 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 list for site " + site + " listName " + listName + " - 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 list for site " + site + " listName " + listName + " - 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:op.care.reports.PnlReport.java
private JPanel getMenu(final NReport nreport) { JPanel pnlMenu = new JPanel(new VerticalLayout()); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { /***// w ww .j a v a2s.c o m * _____ _ _ _ * | ____|__| (_) |_ * | _| / _` | | __| * | |__| (_| | | |_ * |_____\__,_|_|\__| * */ final JButton btnEdit = GUITools.createHyperlinkButton("nursingrecords.reports.btnEdit.tooltip", SYSConst.icon22edit3, null); btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgReport(nreport.clone(), new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport newReport = em.merge((NReport) o); NReport oldReport = em.merge(nreport); em.lock(oldReport, LockModeType.OPTIMISTIC); newReport.setReplacementFor(oldReport); for (SYSNR2FILE oldAssignment : oldReport.getAttachedFilesConnections()) { em.remove(oldAssignment); } oldReport.getAttachedFilesConnections().clear(); for (SYSNR2PROCESS oldAssignment : oldReport.getAttachedQProcessConnections()) { em.remove(oldAssignment); } oldReport.getAttachedQProcessConnections().clear(); oldReport.setEditedBy(em.merge(OPDE.getLogin().getUser())); oldReport.setEditDate(new Date()); oldReport.setReplacedBy(newReport); em.getTransaction().commit(); final String keyNewDay = DateFormat.getDateInstance() .format(newReport.getPit()); final String keyOldDay = DateFormat.getDateInstance() .format(oldReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); contentmap.remove(keyOldDay); } synchronized (linemap) { linemap.remove(oldReport); } synchronized (valuecache) { valuecache.get(keyOldDay).remove(nreport); valuecache.get(keyOldDay).add(oldReport); Collections.sort(valuecache.get(keyOldDay)); if (valuecache.containsKey(keyNewDay)) { valuecache.get(keyNewDay).add(newReport); Collections.sort(valuecache.get(keyNewDay)); } } synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : newReport.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } if (minmax.isAfter(new DateTime(newReport.getPit()))) { minmax.setStart(new DateTime(newReport.getPit())); } if (minmax.isBefore(new DateTime(newReport.getPit()))) { minmax.setEnd(new DateTime(newReport.getPit())); } createCP4Day(new LocalDate(oldReport.getPit())); createCP4Day(new LocalDate(newReport.getPit())); buildPanel(); GUITools.scroll2show(jspReports, cpMap.get(keyNewDay), cpsReports, new Closure() { @Override public void execute(Object o) { GUITools.flashBackground(linemap.get(newReport), 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnEdit.setEnabled(NReportTools.isChangeable(nreport)); pnlMenu.add(btnEdit); /*** * ____ _ _ * | _ \ ___| | ___| |_ ___ * | | | |/ _ \ |/ _ \ __/ _ \ * | |_| | __/ | __/ || __/ * |____/ \___|_|\___|\__\___| * */ final JButton btnDelete = GUITools.createHyperlinkButton("nursingrecords.reports.btnDelete.tooltip", SYSConst.icon22delete, null); btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><i>" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT).format( nreport.getPit()) + "</i><br/>" + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport delReport = em.merge(nreport); em.lock(delReport, LockModeType.OPTIMISTIC); delReport.setDeletedBy(em.merge(OPDE.getLogin().getUser())); for (SYSNR2FILE oldAssignment : delReport .getAttachedFilesConnections()) { em.remove(oldAssignment); } delReport.getAttachedFilesConnections().clear(); for (SYSNR2PROCESS oldAssignment : delReport .getAttachedQProcessConnections()) { em.remove(oldAssignment); } delReport.getAttachedQProcessConnections().clear(); em.getTransaction().commit(); final String keyDay = DateFormat.getDateInstance() .format(delReport.getPit()); synchronized (contentmap) { contentmap.remove(keyDay); } synchronized (linemap) { linemap.remove(delReport); } synchronized (valuecache) { valuecache.get(keyDay).remove(nreport); valuecache.get(keyDay).add(delReport); Collections.sort(valuecache.get(keyDay)); } createCP4Day(new LocalDate(delReport.getPit())); buildPanel(); if (tbShowReplaced.isSelected()) { GUITools.flashBackground(linemap.get(delReport), 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnDelete.setEnabled(NReportTools.isChangeable(nreport)); pnlMenu.add(btnDelete); /*** * _ _ _____ _ ____ * | |__ | |_ _ _|_ _|/ \ / ___|___ * | '_ \| __| '_ \| | / _ \| | _/ __| * | |_) | |_| | | | |/ ___ \ |_| \__ \ * |_.__/ \__|_| |_|_/_/ \_\____|___/ * */ final JButton btnTAGs = GUITools.createHyperlinkButton("misc.msg.editTags", SYSConst.icon22tagPurple, null); btnTAGs.setAlignmentX(Component.RIGHT_ALIGNMENT); btnTAGs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); final JPanel pnl = new JPanel(new BorderLayout(5, 5)); final PnlCommonTags pnlCommonTags = new PnlCommonTags(nreport.getCommontags(), true, 3); pnl.add(new JScrollPane(pnlCommonTags), BorderLayout.CENTER); JButton btnApply = new JButton(SYSConst.icon22apply); pnl.add(btnApply, BorderLayout.SOUTH); btnApply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport myReport = em.merge(nreport); em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT); myReport.getCommontags().clear(); for (Commontags commontag : pnlCommonTags.getListSelectedTags()) { myReport.getCommontags().add(em.merge(commontag)); } 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)); } synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : myReport.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2); } catch (OptimisticLockException ole) { OPDE.warn(ole); OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnTAGs); popup.removeExcludedComponent(btnTAGs); pnl.setPreferredSize(new Dimension(350, 150)); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnTAGs.setEnabled(NReportTools.isChangeable(nreport) && NReportTools.isMine(nreport)); pnlMenu.add(btnTAGs); /*** * _ _ __ __ _ _ * | |__ | |_ _ __ | \/ (_)_ __ _ _| |_ ___ ___ * | '_ \| __| '_ \| |\/| | | '_ \| | | | __/ _ \/ __| * | |_) | |_| | | | | | | | | | | |_| | || __/\__ \ * |_.__/ \__|_| |_|_| |_|_|_| |_|\__,_|\__\___||___/ * */ final JButton btnMinutes = GUITools.createHyperlinkButton("nursingrecords.reports.btnminutes.tooltip", SYSConst.icon22clock, null); btnMinutes.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMinutes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JPopupMenu menu = SYSCalendar.getMinutesMenu( new int[] { 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60, 120, 240, 360 }, new Closure() { @Override public void execute(Object o) { 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); myReport.setMinutes((Integer) o); myReport.setEditDate(new Date()); 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); menu.show(btnMinutes, 0, btnMinutes.getHeight()); } }); btnMinutes.setEnabled(!nreport.isObsolete() && NReportTools.isMine(nreport)); pnlMenu.add(btnMinutes); pnlMenu.add(new JSeparator()); /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = GUITools.createHyperlinkButton("misc.btnfiles.tooltip", SYSConst.icon22attach, null); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Closure fileHandleClosure = nreport.isObsolete() ? 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()); pnlMenu.add(btnFiles); /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = GUITools.createHyperlinkButton("misc.btnprocess.tooltip", SYSConst.icon22link, null); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); 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(); } } }); } }); pnlMenu.add(btnProcess); } return pnlMenu; }
From source file:com.silverwrist.dynamo.unistore.MessageImpl.java
public synchronized void delete(DynamoUser caller) throws DatabaseException, DynamoSecurityException { testPermission(caller, Namespaces.UNISTORE_PERMISSIONS_NAMESPACE, "delete.message", "no.deleteMessage"); // We need to have lists of the text and binary parts on hand before we delete everything, so that we can // send out notifications. However, not every one of the parts will be in our cache, so we'll need to create // some temporary instances, but use the cached ones whereever feasible. Map pmap = m_ops.listTextParts(m_id); ArrayList text_parts = new ArrayList(pmap.size()); Iterator it = pmap.entrySet().iterator(); while (it.hasNext()) { // look for a matching TextPartImpl Map.Entry ntry = (Map.Entry) (it.next()); TextPartImpl p = (TextPartImpl) (m_part_to_text.get(ntry.getKey())); if (p == null) p = (TextPartImpl) (m_pk_to_text.get(ntry.getValue())); if (p == null) { // create a "scratch" instance PropertyKey pk = (PropertyKey) (ntry.getValue()); QualifiedNameKey qname = new QualifiedNameKey(m_nscache.namespaceIdToName(pk.getNamespaceID()), pk.getName());//from w ww .j av a 2 s.c o m p = new TextPartImpl(m_post, this, ((Integer) (ntry.getKey())).intValue(), qname); } // end if text_parts.add(p); } // end while pmap = m_ops.listBinaryParts(m_id); ArrayList binary_parts = new ArrayList(pmap.size()); it = pmap.entrySet().iterator(); while (it.hasNext()) { // look for a matching BinaryPartImpl Map.Entry ntry = (Map.Entry) (it.next()); BinaryPartImpl p = (BinaryPartImpl) (m_part_to_binary.get(ntry.getKey())); if (p == null) p = (BinaryPartImpl) (m_pk_to_binary.get(ntry.getValue())); if (p == null) { // create a "scratch" instance PropertyKey pk = (PropertyKey) (ntry.getValue()); QualifiedNameKey qname = new QualifiedNameKey(m_nscache.namespaceIdToName(pk.getNamespaceID()), pk.getName()); p = new BinaryPartImpl(m_post, this, ((Integer) (ntry.getKey())).intValue(), qname); } // end if binary_parts.add(p); } // end while // Delete the message from the database. m_ops.delete(m_id); // Cut loose most of our data before we start notifying. m_ops = null; m_nscache = null; m_srm = null; m_users = null; m_parentid = -1; m_seq = -1; m_creator = -1; m_posted = null; m_aclid = -1; m_properties.clear(); m_text_count = -1; m_binary_count = -1; m_part_to_text.clear(); m_pk_to_text.clear(); m_part_to_binary.clear(); m_pk_to_binary.clear(); // Send out the deletion notifications (and clear the data) for all parts. it = text_parts.iterator(); while (it.hasNext()) { // make sure all of these parts are BALEETED! TextPartImpl p = (TextPartImpl) (it.next()); p.baleeted(); } // end while text_parts.clear(); it = binary_parts.iterator(); while (it.hasNext()) { // make sure all of these parts are BALEETED! BinaryPartImpl p = (BinaryPartImpl) (it.next()); p.baleeted(); } // end while binary_parts.clear(); // Send our own "BALEETED!" notification. m_post.postUpdate(new MessageDeletedEvent(this)); // Now cut loose the rest of our data. m_post = null; m_id = -1; }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * * @param parentSite//from w ww . j ava2 s. c o m * @param docLibrary * @return document library ID * @throws ManifoldCFException * @throws ServiceInterruption */ public String getDocLibID(String parentSite, String parentSiteDecoded, String docLibrary) throws ServiceInterruption, ManifoldCFException { long currentTime; try { // The old code here used to call the lists service to find the guid, using the doc library url name as the title. // This did not work when the title differed from the url name. // On 5/8/2008 I modified the code to use the lists service to locate the correct record by matching the defaultViewUrl field, // so that we instead iterate through the children. It's more expensive but it works. String parentSiteRequest = parentSite; if (parentSiteRequest.equals("/")) { parentSiteRequest = ""; // root case parentSiteDecoded = ""; } ListsWS listsService = new ListsWS(baseUrl + parentSiteRequest, userName, password, configuration, httpClient); ListsSoap listsCall = listsService.getListsSoapHandler(); GetListCollectionResponseGetListCollectionResult listResp = listsCall.getListCollection(); org.apache.axis.message.MessageElement[] lists = listResp.get_any(); XMLDoc doc = new XMLDoc(lists[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException("Bad xml - missing outer 'ns1:Lists' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:Lists")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:Lists'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); // <ns1:Lists> String prefixPath = decodedServerLocation + parentSiteDecoded + "/"; int i = 0; while (i < nodeList.size()) { Object o = nodeList.get(i++); String baseType = doc.getValue(o, "BaseType"); if (baseType.equals("1")) { // We think it's a library // This is how we display it, so this has the right path extension String urlPath = doc.getValue(o, "DefaultViewUrl"); // If it has no view url, we don't have any idea what to do with it if (urlPath != null && urlPath.length() > 0) { // Normalize conditionally if (!urlPath.startsWith("/")) urlPath = prefixPath + urlPath; // Get rid of what we don't want, unconditionally if (urlPath.startsWith(prefixPath)) { urlPath = urlPath.substring(prefixPath.length()); // We're at the library name. Figure out where the end of it is. int index = urlPath.indexOf("/"); if (index == -1) throw new ManifoldCFException( "Bad library view url without site: '" + urlPath + "'"); String pathpart = urlPath.substring(0, index); if (pathpart.equals(docLibrary)) { // We found it! // Return its ID return doc.getValue(o, "ID"); } } else { Logging.connectors.warn("SharePoint: Library view url is not in the expected form: '" + urlPath + "'; it should start with '" + prefixPath + "'; skipping"); } } } } // Not found - return null return null; } 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 library ID for site " + parentSite + " library " + docLibrary + " - 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 + parentSite + " did not exist; assuming library deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to list libraries if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: The crawl user did not have access to list libraries for " + baseUrl + parentSite + "; skipping"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + parentSite + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + parentSite + ": " + 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 " + docLibrary + " in site " + parentSite + " did not exist; assuming 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 library ID for the list " + docLibrary + " in site " + parentSite + " 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 library ID for site " + parentSite + " library " + docLibrary + " - 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 library ID for site " + parentSite + " library " + docLibrary + " - 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 library ID for site " + parentSite + " library " + docLibrary, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * * @param parentSite//from w w w . j a va 2 s .c om * @param list name * @return document library ID * @throws ManifoldCFException * @throws ServiceInterruption */ public String getListID(String parentSite, String parentSiteDecoded, String listName) throws ServiceInterruption, ManifoldCFException { long currentTime; try { // The old code here used to call the lists service to find the guid, using the doc library url name as the title. // This did not work when the title differed from the url name. // On 5/8/2008 I modified the code to use the lists service to locate the correct record by matching the defaultViewUrl field, // so that we instead iterate through the children. It's more expensive but it works. String parentSiteRequest = parentSite; if (parentSiteRequest.equals("/")) { parentSiteRequest = ""; // root case parentSiteDecoded = ""; } ListsWS listsService = new ListsWS(baseUrl + parentSiteRequest, userName, password, configuration, httpClient); ListsSoap listsCall = listsService.getListsSoapHandler(); GetListCollectionResponseGetListCollectionResult listResp = listsCall.getListCollection(); org.apache.axis.message.MessageElement[] lists = listResp.get_any(); XMLDoc doc = new XMLDoc(lists[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException("Bad xml - missing outer 'ns1:Lists' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:Lists")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:Lists'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); // <ns1:Lists> String prefixPath = decodedServerLocation + parentSiteDecoded + "/"; int i = 0; while (i < nodeList.size()) { Object o = nodeList.get(i++); String baseType = doc.getValue(o, "BaseType"); if (baseType.equals("0")) { // We think it's a list // This is how we display it, so this has the right path extension String urlPath = doc.getValue(o, "DefaultViewUrl"); // If it has no view url, we don't have any idea what to do with it if (urlPath != null && urlPath.length() > 0) { // Normalize conditionally if (!urlPath.startsWith("/")) urlPath = prefixPath + urlPath; // Get rid of what we don't want, unconditionally if (urlPath.startsWith(prefixPath)) { urlPath = urlPath.substring(prefixPath.length()); // We're at the Lists/listname part of the name. Figure out where the end of it is. int index = urlPath.indexOf("/"); if (index == -1) throw new ManifoldCFException("Bad list view url without site: '" + urlPath + "'"); String pathpart = urlPath.substring(0, index); if ("Lists".equals(pathpart)) { int k = urlPath.indexOf("/", index + 1); if (k == -1) throw new ManifoldCFException( "Bad list view url without 'Lists': '" + urlPath + "'"); pathpart = urlPath.substring(index + 1, k); } if (pathpart.equals(listName)) { // We found it! // Return its ID return doc.getValue(o, "ID"); } } else { Logging.connectors.warn("SharePoint: List view url is not in the expected form: '" + urlPath + "'; expected something beginning with '" + prefixPath + "'; skipping"); } } } } // Not found - return null return null; } 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 list ID for site " + parentSite + " list " + listName + " - 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 + parentSite + " did not exist; assuming list deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to list libraries if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: The crawl user did not have access to list lists for " + baseUrl + parentSite + "; skipping"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + parentSite + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + parentSite + ": " + 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 " + listName + " in site " + parentSite + " did not exist; assuming list 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 list ID for the list " + listName + " in site " + parentSite + " 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 list ID for site " + parentSite + " list " + listName + " - 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 list ID for site " + parentSite + " list " + listName + " - 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 list ID for site " + parentSite + " list " + listName, 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 attachment URLs, given a site, list name, and list item ID. These will be returned * as name/value pairs; the "name" is the name of the attachment, and the "value" is the full URL. *///from w w w .j ava2s . c o m public List<NameValue> getAttachmentNames(String site, String listName, String itemID) throws ManifoldCFException, ServiceInterruption { long currentTime; try { ArrayList<NameValue> result = new ArrayList<NameValue>(); if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: In getAttachmentNames; site='" + site + "', listName='" + listName + "', itemID='" + itemID + "'"); // The docLibrary must be a GUID, because we don't have title. if (site.compareTo("/") == 0) site = ""; ListsWS listService = new ListsWS(baseUrl + site, userName, password, configuration, httpClient); ListsSoap listCall = listService.getListsSoapHandler(); GetAttachmentCollectionResponseGetAttachmentCollectionResult listResponse = listCall .getAttachmentCollection(listName, itemID); org.apache.axis.message.MessageElement[] List = listResponse.get_any(); 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 node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object attachments = nodeList.get(0); if (!doc.getNodeName(attachments).equals("ns1:Attachments")) throw new ManifoldCFException( "Bad xml - outer node '" + doc.getNodeName(attachments) + "' is not 'ns1:Attachments'"); nodeList.clear(); doc.processPath(nodeList, "*", attachments); int i = 0; while (i < nodeList.size()) { Object o = nodeList.get(i++); if (!doc.getNodeName(o).equals("ns1:Attachment")) throw new ManifoldCFException( "Bad xml - inner node '" + doc.getNodeName(o) + "' is not 'ns1:Attachment'"); String attachmentURL = doc.getData(o); if (attachmentURL != null) { int index = attachmentURL.lastIndexOf("/"); if (index == -1) throw new ManifoldCFException("Unexpected attachment URL form: '" + attachmentURL + "'"); result.add(new NameValue(attachmentURL.substring(index + 1), new java.net.URL(attachmentURL).getPath())); } } return result; } 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 attachments for site " + site + " listName " + listName + " itemID " + itemID + " - 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 attachment list for site " + site + " listName " + listName + " itemID " + itemID + " - 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 attachments for site " + site + " listName " + listName + " itemID " + itemID + " - 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:net.cellcloud.talk.TalkService.java
/** ? Session *///from w w w .java2 s . co m protected void processUnidentifiedSessions(long time) { if (null == this.unidentifiedSessions || this.unidentifiedSessions.isEmpty()) { return; } // Session ArrayList<Session> sessionList = null; Iterator<Map.Entry<Long, Certificate>> iter = this.unidentifiedSessions.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Long, Certificate> e = iter.next(); Certificate cert = e.getValue(); if (false == cert.checked) { cert.checked = true; deliverChecking(cert.session, cert.plaintext, cert.key); } else { // 20 if (time - cert.time > 20000) { if (null == sessionList) { sessionList = new ArrayList<Session>(); } sessionList.add(cert.session); } } } if (null != sessionList) { // Session Iterator<Session> siter = sessionList.iterator(); while (siter.hasNext()) { Session session = siter.next(); StringBuilder log = new StringBuilder(); log.append("Talk service session timeout: "); log.append(session.getAddress().getAddress().getHostAddress()); log.append(":"); log.append(session.getAddress().getPort()); Logger.i(TalkService.class, log.toString()); log = null; // this.unidentifiedSessions.remove(session.getId()); if (session instanceof HttpSession) { // HTTP Session this.httpSessionManager.unmanage((HttpSession) session); } else if (session instanceof WebSocketSession) { // WebSocket Session this.webSocketManager.close((WebSocketSession) session); } else { // ??? Session this.acceptor.close(session); } } sessionList.clear(); sessionList = null; } }
From source file:org.alfresco.solr.SolrInformationServer.java
@Override public void reindexNodeByQuery(String query) throws IOException, AuthenticationException, JSONException { SolrQueryRequest request = null;// w w w. ja va2s.c o m RefCounted<SolrIndexSearcher> refCounted = null; try { refCounted = core.getSearcher(false, true, null); SolrIndexSearcher solrIndexSearcher = refCounted.get(); request = getLocalSolrQueryRequest(); NumericDocValues dbidDocValues = solrIndexSearcher.getAtomicReader() .getNumericDocValues(QueryConstants.FIELD_DBID); ArrayList<Node> batch = new ArrayList<Node>(200); DocList docList = cloud.getDocList(nativeRequestHandler, request, query.startsWith("{") ? query : "{!afts}" + query); for (DocIterator it = docList.iterator(); it.hasNext(); /**/) { int docID = it.nextDoc(); // Obtain the ACL ID for this ACL doc. long dbid = dbidDocValues.get(docID); Node node = new Node(); node.setId(dbid); node.setStatus(SolrApiNodeStatus.UNKNOWN); node.setTxnId(Long.MAX_VALUE); batch.add(node); if (batch.size() >= 200) { indexNodes(batch, true); batch.clear(); } } if (batch.size() > 0) { indexNodes(batch, true); batch.clear(); } } finally { if (request != null) { request.close(); } if (refCounted != null) { refCounted.decref(); } } }
From source file:com.ikanow.aleph2.analytics.hadoop.assets.UpdatedCombineFileInputFormat.java
@VisibleForTesting void createSplits(Map<String, Set<OneBlockInfo>> nodeToBlocks, Map<OneBlockInfo, String[]> blockToNodes, Map<String, List<OneBlockInfo>> rackToBlocks, long totLength, long maxSize, long minSizeNode, long minSizeRack, List<InputSplit> splits) { ArrayList<OneBlockInfo> validBlocks = new ArrayList<OneBlockInfo>(); long curSplitSize = 0; int totalNodes = nodeToBlocks.size(); long totalLength = totLength; Multiset<String> splitsPerNode = HashMultiset.create(); Set<String> completedNodes = new HashSet<String>(); while (true) { // it is allowed for maxSize to be 0. Disable smoothing load for such cases // process all nodes and create splits that are local to a node. Generate // one split per node iteration, and walk over nodes multiple times to // distribute the splits across nodes. for (Iterator<Map.Entry<String, Set<OneBlockInfo>>> iter = nodeToBlocks.entrySet().iterator(); iter .hasNext();) {/*from w w w . j a v a2 s . c o m*/ Map.Entry<String, Set<OneBlockInfo>> one = iter.next(); String node = one.getKey(); // Skip the node if it has previously been marked as completed. if (completedNodes.contains(node)) { continue; } Set<OneBlockInfo> blocksInCurrentNode = one.getValue(); // for each block, copy it into validBlocks. Delete it from // blockToNodes so that the same block does not appear in // two different splits. Iterator<OneBlockInfo> oneBlockIter = blocksInCurrentNode.iterator(); while (oneBlockIter.hasNext()) { OneBlockInfo oneblock = oneBlockIter.next(); // Remove all blocks which may already have been assigned to other // splits. if (!blockToNodes.containsKey(oneblock)) { oneBlockIter.remove(); continue; } validBlocks.add(oneblock); blockToNodes.remove(oneblock); curSplitSize += oneblock.length; // if the accumulated split size exceeds the maximum, then // create this split. if (maxSize != 0 && curSplitSize >= maxSize) { // create an input split and add it to the splits array addCreatedSplit(splits, Collections.singleton(node), validBlocks); totalLength -= curSplitSize; curSplitSize = 0; splitsPerNode.add(node); // Remove entries from blocksInNode so that we don't walk these // again. blocksInCurrentNode.removeAll(validBlocks); validBlocks.clear(); // Done creating a single split for this node. Move on to the next // node so that splits are distributed across nodes. break; } } if (validBlocks.size() != 0) { // This implies that the last few blocks (or all in case maxSize=0) // were not part of a split. The node is complete. // if there were any blocks left over and their combined size is // larger than minSplitNode, then combine them into one split. // Otherwise add them back to the unprocessed pool. It is likely // that they will be combined with other blocks from the // same rack later on. // This condition also kicks in when max split size is not set. All // blocks on a node will be grouped together into a single split. if (minSizeNode != 0 && curSplitSize >= minSizeNode && splitsPerNode.count(node) == 0) { // haven't created any split on this machine. so its ok to add a // smaller one for parallelism. Otherwise group it in the rack for // balanced size create an input split and add it to the splits // array addCreatedSplit(splits, Collections.singleton(node), validBlocks); totalLength -= curSplitSize; splitsPerNode.add(node); // Remove entries from blocksInNode so that we don't walk this again. blocksInCurrentNode.removeAll(validBlocks); // The node is done. This was the last set of blocks for this node. } else { // Put the unplaced blocks back into the pool for later rack-allocation. for (OneBlockInfo oneblock : validBlocks) { blockToNodes.put(oneblock, oneblock.hosts); } } validBlocks.clear(); curSplitSize = 0; completedNodes.add(node); } else { // No in-flight blocks. if (blocksInCurrentNode.size() == 0) { // Node is done. All blocks were fit into node-local splits. completedNodes.add(node); } // else Run through the node again. } } // Check if node-local assignments are complete. if (completedNodes.size() == totalNodes || totalLength == 0) { // All nodes have been walked over and marked as completed or all blocks // have been assigned. The rest should be handled via rackLock assignment. LOG.info("DEBUG: Terminated node allocation with : CompletedNodes: " + completedNodes.size() + ", size left: " + totalLength); break; } } // if blocks in a rack are below the specified minimum size, then keep them // in 'overflow'. After the processing of all racks is complete, these // overflow blocks will be combined into splits. ArrayList<OneBlockInfo> overflowBlocks = new ArrayList<OneBlockInfo>(); Set<String> racks = new HashSet<String>(); // Process all racks over and over again until there is no more work to do. while (blockToNodes.size() > 0) { // Create one split for this rack before moving over to the next rack. // Come back to this rack after creating a single split for each of the // remaining racks. // Process one rack location at a time, Combine all possible blocks that // reside on this rack as one split. (constrained by minimum and maximum // split size). // iterate over all racks for (Iterator<Map.Entry<String, List<OneBlockInfo>>> iter = rackToBlocks.entrySet().iterator(); iter .hasNext();) { Map.Entry<String, List<OneBlockInfo>> one = iter.next(); racks.add(one.getKey()); List<OneBlockInfo> blocks = one.getValue(); // for each block, copy it into validBlocks. Delete it from // blockToNodes so that the same block does not appear in // two different splits. boolean createdSplit = false; for (OneBlockInfo oneblock : blocks) { if (blockToNodes.containsKey(oneblock)) { validBlocks.add(oneblock); blockToNodes.remove(oneblock); curSplitSize += oneblock.length; // if the accumulated split size exceeds the maximum, then // create this split. if (maxSize != 0 && curSplitSize >= maxSize) { // create an input split and add it to the splits array addCreatedSplit(splits, getHosts(racks), validBlocks); createdSplit = true; break; } } } // if we created a split, then just go to the next rack if (createdSplit) { curSplitSize = 0; validBlocks.clear(); racks.clear(); continue; } if (!validBlocks.isEmpty()) { if (minSizeRack != 0 && curSplitSize >= minSizeRack) { // if there is a minimum size specified, then create a single split // otherwise, store these blocks into overflow data structure addCreatedSplit(splits, getHosts(racks), validBlocks); } else { // There were a few blocks in this rack that // remained to be processed. Keep them in 'overflow' block list. // These will be combined later. overflowBlocks.addAll(validBlocks); } } curSplitSize = 0; validBlocks.clear(); racks.clear(); } } assert blockToNodes.isEmpty(); assert curSplitSize == 0; assert validBlocks.isEmpty(); assert racks.isEmpty(); // Process all overflow blocks for (OneBlockInfo oneblock : overflowBlocks) { validBlocks.add(oneblock); curSplitSize += oneblock.length; // This might cause an exiting rack location to be re-added, // but it should be ok. for (int i = 0; i < oneblock.racks.length; i++) { racks.add(oneblock.racks[i]); } // if the accumulated split size exceeds the maximum, then // create this split. if (maxSize != 0 && curSplitSize >= maxSize) { // create an input split and add it to the splits array addCreatedSplit(splits, getHosts(racks), validBlocks); curSplitSize = 0; validBlocks.clear(); racks.clear(); } } // Process any remaining blocks, if any. if (!validBlocks.isEmpty()) { addCreatedSplit(splits, getHosts(racks), validBlocks); } }