List of usage examples for java.lang String compareToIgnoreCase
public int compareToIgnoreCase(String str)
From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java
public ResolvedConceptReferencesIteratorWrapper searchByAssociations(String scheme, String version, String matchText, String[] associationsToNavigate, String[] association_qualifier_names, String[] association_qualifier_values, int search_direction, String source, String matchAlgorithm, boolean designationOnly, boolean ranking, int maxToReturn) { /*/*from w w w. j av a2s .c om*/ * _logger.debug("searchByAssociations scheme: " + scheme); * _logger.debug("searchByAssociations matchText: " + matchText); * _logger.debug("searchByAssociations resolve_direction: " + * search_direction); _logger.debug("searchByAssociations source: " + * source); _logger.debug("searchByAssociations search_direction: " + * search_direction); * _logger.debug("searchByAssociations matchAlgorithm: " + * matchAlgorithm); * * if (associationsToNavigate != null) { for (int lcv=0; * lcv<associationsToNavigate.length; lcv++) { String str = (String) * associationsToNavigate[lcv]; * _logger.debug("searchByAssociations associationsToNavigate: " + str); * } } * * if (association_qualifier_names != null) { for (int lcv=0; * lcv<association_qualifier_names.length; lcv++) { String str = * (String) association_qualifier_names[lcv]; * _logger.debug("searchByAssociations association_qualifier_names: " + * str); } } * * if (association_qualifier_values != null) { for (int lcv=0; * lcv<association_qualifier_values.length; lcv++) { String str = * (String) association_qualifier_values[lcv]; * _logger.debug("searchByAssociations association_qualifier_values: " + * str); } } */ if (matchText == null) return null; NameAndValueList associationList = null; if (associationsToNavigate != null) { associationList = createNameAndValueList(associationsToNavigate, null); } NameAndValueList qualifiers = null; if (association_qualifier_names != null) { qualifiers = createNameAndValueList(association_qualifier_names, association_qualifier_values); } //String matchText0 = matchText; String matchAlgorithm0 = matchAlgorithm; //matchText0 = matchText0.trim(); String message = null; long ms = System.currentTimeMillis(); long dt = 0; long total_delay = 0; boolean timeout = false; boolean preprocess = true; //if (matchText == null || matchText.length() == 0) { if (matchText.length() == 0) { return null; } matchText = matchText.trim(); if (matchAlgorithm.compareToIgnoreCase("contains") == 0) { matchAlgorithm = findBestContainsAlgorithm(matchText); } CodedNodeSet cns = null; ResolvedConceptReferencesIterator iterator = null; try { LexBIGService lbSvc = new RemoteServerUtil().createLexBIGService(); if (lbSvc == null) { _logger.warn("lbSvc = null"); return null; } Vector cns_vec = new Vector(); cns = null; iterator = null; _logger.debug("\tsearching " + scheme); ms = System.currentTimeMillis(); CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag(); if (version != null) versionOrTag.setVersion(version); try { // KLO, 022410 change failed //cns = lbSvc.getNodeSet(scheme, versionOrTag, null); cns = getNodeSet(lbSvc, scheme, versionOrTag); // cns = getNodeSetByEntityType(scheme, versionOrTag, // "concept"); if (cns != null) { try { // find cns if (designationOnly) { cns = cns.restrictToMatchingDesignations(matchText, null, matchAlgorithm, null); } cns = restrictToSource(cns, source); int resolveAssociationDepth = 1; // int maxToReturn = -1; // ConceptReference graphFocus = null; // CodedNodeSet cns2 = cng.toNodeList(graphFocus, // resolveForward, resolveBackward, // resolveAssociationDepth, maxToReturn); // CodedNodeSet difference(CodedNodeSet codesToRemove) // cns = cns2.difference(cns); // if (cns != null) { // cns = filterOutAnonymousClasses(lbSvc, scheme, cns); if (cns != null) { cns_vec.add(cns); } // } } catch (Exception ex) { // return null; } } } catch (Exception e) { e.printStackTrace(); // return null; } dt = System.currentTimeMillis() - ms; ms = System.currentTimeMillis(); total_delay = total_delay + dt; //if (total_delay > (long) (NCItBrowserProperties.getPaginationTimeOut() * 60 * 1000)) { if (total_delay > Constants.MILLISECONDS_PER_MINUTE * NCItBrowserProperties.getPaginationTimeOut()) { message = "WARNING: Search is incomplete -- please enter more specific search criteria."; } iterator = null; if (cns_vec.size() == 0) { return null; } LocalNameList restrictToProperties = null;// new LocalNameList(); // boolean resolveConcepts = true; // if (!ranking) resolveConcepts = false; boolean resolveConcepts = false; SortOptionList sortCriteria = null; if (ranking) { sortCriteria = Constructors.createSortOptionList(new String[] { "matchToQuery" }); } else { sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code // resolveConcepts = false; } resolveConcepts = false; try { try { boolean resolveForward = true; boolean resolveBackward = true; if (search_direction == Constants.SEARCH_SOURCE) { resolveForward = false; resolveBackward = true; } else if (search_direction == Constants.SEARCH_TARGET) { resolveForward = true; resolveBackward = false; } int resolveAssociationDepth = 1; // iterator = cns.resolve(sortCriteria, null, // restrictToProperties, null, resolveConcepts); ResolvedConceptReferencesIterator quickUnionIterator = new QuickUnionIterator(cns_vec, sortCriteria, null, restrictToProperties, null, resolveConcepts); if (associationsToNavigate == null && qualifiers == null) { /* iterator = new SearchByAssociationIteratorDecorator( quickUnionIterator, resolveForward, resolveBackward, resolveAssociationDepth, maxToReturn); */ iterator = createSearchByAssociationIteratorDecorator(quickUnionIterator, resolveForward, resolveBackward, resolveAssociationDepth, maxToReturn); } else { /* iterator = new SearchByAssociationIteratorDecorator( quickUnionIterator, resolveForward, resolveBackward, associationList, qualifiers, resolveAssociationDepth, maxToReturn); */ iterator = createSearchByAssociationIteratorDecorator(quickUnionIterator, resolveForward, resolveBackward, associationList, qualifiers, resolveAssociationDepth, maxToReturn); } } catch (Exception e) { _logger.error("Method: SearchUtil.searchByAssociations"); _logger.error("* ERROR: cns.resolve throws exceptions."); _logger.error("* " + e.getClass().getSimpleName() + ": " + e.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); return null; } } catch (Exception e) { e.printStackTrace(); return null; } finally { _logger.debug("Run time (ms): " + (System.currentTimeMillis() - ms)); } // Pending LexEVS fix: // if (iterator != null) iterator.setMessage(message); if (iterator == null) { _logger.warn("=================== searchByAssociations returns iterator == null???"); } return new ResolvedConceptReferencesIteratorWrapper(iterator, message); }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
protected static final int zstrcmpi(String string1, String string2) { // KJS 10/31/13 - When I do a "IF "aaaa" <= "bbbb"", this should return > 0 but it's returning -1 so I am // switching the strings. //return string1.compareToIgnoreCase( string2 ); return string2.compareToIgnoreCase(string1); }
From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java
/** * Performs a search and fills the model (useful when a page needs to remind * search parameters/results)/* w ww. ja v a 2s. com*/ * * @param request the request * @param conf the configuration * @return the model * @throws SiteMessageException if an error occurs */ public static Map<String, Object> getSearchResultModel(HttpServletRequest request, SolrSearchAppConf conf) throws SiteMessageException { String strQuery = request.getParameter(PARAMETER_QUERY); String[] facetQuery = request.getParameterValues(PARAMETER_FACET_QUERY); String sort = request.getParameter(PARAMETER_SORT_NAME); String order = request.getParameter(PARAMETER_SORT_ORDER); String strCurrentPageIndex = request.getParameter(PARAMETER_PAGE_INDEX); String fname = StringUtils.isBlank(request.getParameter(PARAMETER_FACET_NAME)) ? null : request.getParameter(PARAMETER_FACET_LABEL).trim(); String flabel = StringUtils.isBlank(request.getParameter(PARAMETER_FACET_LABEL)) ? null : request.getParameter(PARAMETER_FACET_LABEL).trim(); String strConfCode = request.getParameter(PARAMETER_CONF); Locale locale = request.getLocale(); if (conf == null) { //Use default conf if not provided conf = SolrSearchAppConfService.loadConfiguration(null); } StringBuilder sbFacetQueryUrl = new StringBuilder(); SolrFieldManager sfm = new SolrFieldManager(); List<String> lstSingleFacetQueries = new ArrayList<String>(); Hashtable<String, Boolean> switchType = getSwitched(); ArrayList<String> facetQueryTmp = new ArrayList<String>(); if (facetQuery != null) { for (String fq : facetQuery) { if (sbFacetQueryUrl.indexOf(fq) == -1) { String strFqNameIHM = getFacetNameFromIHM(fq); String strFqValueIHM = getFacetValueFromIHM(fq); if (fname == null || !switchType.containsKey(fname) || (strFqNameIHM != null && strFqValueIHM != null && strFqValueIHM.equalsIgnoreCase(flabel) && strFqNameIHM.equalsIgnoreCase(fname))) { sbFacetQueryUrl.append("&fq=" + fq); sfm.addFacet(fq); facetQueryTmp.add(fq); lstSingleFacetQueries.add(fq); } } } // for (String fq : facetQuery) // { // if (sbFacetQueryUrl.indexOf(fq) == -1) // { // // sbFacetQueryUrl.append("&fq=" + fq); // sfm.addFacet(fq); // lstSingleFacetQueries.add(fq); // } // } } facetQuery = new String[facetQueryTmp.size()]; facetQuery = facetQueryTmp.toArray(facetQuery); if (StringUtils.isNotBlank(conf.getFilterQuery())) { int nNewLength = (facetQuery == null) ? 1 : (facetQuery.length + 1); String[] newFacetQuery = new String[nNewLength]; for (int i = 0; i < (nNewLength - 1); i++) { newFacetQuery[i] = facetQuery[i]; } newFacetQuery[newFacetQuery.length - 1] = conf.getFilterQuery(); facetQuery = newFacetQuery; } boolean bEncodeUri = Boolean.parseBoolean( AppPropertiesService.getProperty(PROPERTY_ENCODE_URI, Boolean.toString(DEFAULT_ENCODE_URI))); String strSearchPageUrl = AppPropertiesService.getProperty(PROPERTY_SEARCH_PAGE_URL); String strError = SolrConstants.CONSTANT_EMPTY_STRING; int nLimit = SOLR_RESPONSE_MAX; // Check XSS characters if ((strQuery != null) && (StringUtil.containsXssCharacters(strQuery))) { strError = I18nService.getLocalizedString(MESSAGE_INVALID_SEARCH_TERMS, locale); } if (StringUtils.isNotBlank(strError) || StringUtils.isBlank(strQuery)) { strQuery = ALL_SEARCH_QUERY; String strOnlyFacets = AppPropertiesService.getProperty(PROPERTY_ONLY_FACTES); if (StringUtils.isNotBlank(strError) || (((facetQuery == null) || (facetQuery.length <= 0)) && StringUtils.isNotBlank(strOnlyFacets) && SolrConstants.CONSTANT_TRUE.equals(strOnlyFacets))) { //no request and no facet selected : we show the facets but no result nLimit = 0; } } // paginator & session related elements int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt(PROPERTY_RESULTS_PER_PAGE, DEFAULT_RESULTS_PER_PAGE); String strCurrentItemsPerPage = request.getParameter(PARAMETER_NB_ITEMS_PER_PAGE); int nCurrentItemsPerPage = strCurrentItemsPerPage != null ? Integer.parseInt(strCurrentItemsPerPage) : 0; int nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, nCurrentItemsPerPage, nDefaultItemsPerPage); strCurrentPageIndex = (strCurrentPageIndex != null) ? strCurrentPageIndex : DEFAULT_PAGE_INDEX; SolrSearchEngine engine = SolrSearchEngine.getInstance(); SolrFacetedResult facetedResult = engine.getFacetedSearchResults(strQuery, facetQuery, sort, order, nLimit, Integer.parseInt(strCurrentPageIndex), nItemsPerPage, SOLR_SPELLCHECK); List<SolrSearchResult> listResults = facetedResult.getSolrSearchResults(); List<HashMap<String, Object>> points = null; if (conf.getExtraMappingQuery()) { List<SolrSearchResult> listResultsGeoloc = engine.getGeolocSearchResults(strQuery, facetQuery, nLimit); points = getGeolocModel(listResultsGeoloc); } // The page should not be added to the cache // Notify results infos to QueryEventListeners notifyQueryListeners(strQuery, listResults.size(), request); UrlItem url = new UrlItem(strSearchPageUrl); String strQueryForPaginator = strQuery; if (bEncodeUri) { strQueryForPaginator = SolrUtil.encodeUrl(request, strQuery); } url.addParameter(PARAMETER_QUERY, strQueryForPaginator); url.addParameter(PARAMETER_NB_ITEMS_PER_PAGE, nItemsPerPage); if (strConfCode != null) { url.addParameter(PARAMETER_CONF, strConfCode); } for (String strFacetName : lstSingleFacetQueries) { url.addParameter(PARAMETER_FACET_QUERY, SolrUtil.encodeUrl(strFacetName)); } // nb items per page IPaginator<SolrSearchResult> paginator = new DelegatePaginator<SolrSearchResult>(listResults, nItemsPerPage, url.getUrl(), PARAMETER_PAGE_INDEX, strCurrentPageIndex, facetedResult.getCount()); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_RESULTS_LIST, paginator.getPageItems()); // put the query only if it's not *.* model.put(MARK_QUERY, ALL_SEARCH_QUERY.equals(strQuery) ? SolrConstants.CONSTANT_EMPTY_STRING : strQuery); model.put(MARK_FACET_QUERY, sbFacetQueryUrl.toString()); model.put(MARK_PAGINATOR, paginator); model.put(MARK_NB_ITEMS_PER_PAGE, nItemsPerPage); model.put(MARK_ERROR, strError); model.put(MARK_FACETS, facetedResult.getFacetFields()); model.put(MARK_SOLR_FIELDS, SolrFieldManager.getFacetList()); model.put(MARK_FACETS_DATE, facetedResult.getFacetDateList()); model.put(MARK_HISTORIQUE, sfm.getCurrentFacet()); model.put(MARK_FACETS_LIST, lstSingleFacetQueries); model.put(MARK_CONF_QUERY, strConfCode); model.put(MARK_CONF, conf); model.put(MARK_POINTS, points); if (SOLR_SPELLCHECK && (strQuery != null) && (strQuery.compareToIgnoreCase(ALL_SEARCH_QUERY) != 0)) { SpellCheckResponse checkResponse = engine.getSpellChecker(strQuery); if (checkResponse != null) { model.put(MARK_SUGGESTION, checkResponse.getCollatedResults()); //model.put(MARK_SUGGESTION, facetedResult.getSolrSpellCheckResponse().getCollatedResults()); } } model.put(MARK_SORT_NAME, sort); model.put(MARK_SORT_ORDER, order); model.put(MARK_SORT_LIST, SolrFieldManager.getSortList()); model.put(MARK_FACET_TREE, facetedResult.getFacetIntersection()); model.put(MARK_ENCODING, SolrUtil.getEncoding()); String strRequestUrl = request.getRequestURL().toString(); model.put(FULL_URL, strRequestUrl); model.put(SOLR_FACET_DATE_GAP, SolrSearchEngine.SOLR_FACET_DATE_GAP); return model; }
From source file:onl.netfishers.netshot.RestService.java
@GET @Path("reports/export") @RolesAllowed("readonly") @Produces({ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }) public Response getDataXLSX(@Context HttpServletRequest request, @DefaultValue("-1") @QueryParam("group") long group, @DefaultValue("false") @QueryParam("interfaces") boolean exportInterfaces, @DefaultValue("false") @QueryParam("inventory") boolean exportInventory, @DefaultValue("xlsx") @QueryParam("format") String fileFormat) throws WebApplicationException { logger.debug("REST request, export data."); User user = (User) request.getSession().getAttribute("user"); if (fileFormat.compareToIgnoreCase("xlsx") == 0) { String fileName = String.format("netshot-export_%s.xlsx", (new SimpleDateFormat("yyyyMMdd-HHmmss")).format(new Date())); Session session = Database.getSession(); try {/*w ww .j a va 2 s . com*/ Workbook workBook = new XSSFWorkbook(); Row row; Cell cell; CreationHelper createHelper = workBook.getCreationHelper(); CellStyle datetimeCellStyle = workBook.createCellStyle(); datetimeCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-mm-dd hh:mm")); CellStyle dateCellStyle = workBook.createCellStyle(); dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-mm-dd")); Sheet summarySheet = workBook.createSheet("Summary"); row = summarySheet.createRow(0); row.createCell(0).setCellValue("Netshot version"); row.createCell(1).setCellValue(Netshot.VERSION); row = summarySheet.createRow(1); row.createCell(0).setCellValue("Exported by"); row.createCell(1).setCellValue(user.getName()); row = summarySheet.createRow(2); row.createCell(0).setCellValue("Date and time"); cell = row.createCell(1); cell.setCellValue(new Date()); cell.setCellStyle(datetimeCellStyle); row = summarySheet.createRow(4); row.createCell(0).setCellValue("Selected Group"); Query query; if (group == -1) { query = session.createQuery("select d from Device d"); row.createCell(1).setCellValue("None"); } else { query = session.createQuery("select d from Device d join d.ownerGroups g where g.id = :id") .setLong("id", group); DeviceGroup deviceGroup = (DeviceGroup) session.get(DeviceGroup.class, group); row.createCell(1).setCellValue(deviceGroup.getName()); } Sheet deviceSheet = workBook.createSheet("Devices"); row = deviceSheet.createRow(0); row.createCell(0).setCellValue("ID"); row.createCell(1).setCellValue("Name"); row.createCell(2).setCellValue("Management IP"); row.createCell(3).setCellValue("Domain"); row.createCell(4).setCellValue("Network Class"); row.createCell(5).setCellValue("Family"); row.createCell(6).setCellValue("Creation"); row.createCell(7).setCellValue("Last Change"); row.createCell(8).setCellValue("Software"); row.createCell(9).setCellValue("End of Sale Date"); row.createCell(10).setCellValue("End Of Life Date"); int yDevice = 1; @SuppressWarnings("unchecked") List<Device> devices = query.list(); for (Device device : devices) { row = deviceSheet.createRow(yDevice++); row.createCell(0).setCellValue(device.getId()); row.createCell(1).setCellValue(device.getName()); row.createCell(2).setCellValue(device.getMgmtAddress().getIp()); row.createCell(3).setCellValue(device.getMgmtDomain().getName()); row.createCell(4).setCellValue(device.getNetworkClass().toString()); row.createCell(5).setCellValue(device.getFamily()); cell = row.createCell(6); cell.setCellValue(device.getCreatedDate()); cell.setCellStyle(datetimeCellStyle); cell = row.createCell(7); cell.setCellValue(device.getChangeDate()); cell.setCellStyle(datetimeCellStyle); row.createCell(8).setCellValue(device.getSoftwareVersion()); if (device.getEosDate() != null) { cell = row.createCell(9); cell.setCellValue(device.getEosDate()); cell.setCellStyle(dateCellStyle); } if (device.getEolDate() != null) { cell = row.createCell(10); cell.setCellValue(device.getEolDate()); cell.setCellStyle(dateCellStyle); } } if (exportInterfaces) { Sheet interfaceSheet = workBook.createSheet("Interfaces"); row = interfaceSheet.createRow(0); row.createCell(0).setCellValue("Device ID"); row.createCell(1).setCellValue("Virtual Device"); row.createCell(2).setCellValue("Name"); row.createCell(3).setCellValue("Description"); row.createCell(4).setCellValue("VRF"); row.createCell(5).setCellValue("MAC Address"); row.createCell(6).setCellValue("Enabled"); row.createCell(7).setCellValue("Level 3"); row.createCell(8).setCellValue("IP Address"); row.createCell(9).setCellValue("Mask Length"); row.createCell(10).setCellValue("Usage"); int yInterface = 1; for (Device device : devices) { for (NetworkInterface networkInterface : device.getNetworkInterfaces()) { if (networkInterface.getIpAddresses().size() == 0) { row = interfaceSheet.createRow(yInterface++); row.createCell(0).setCellValue(device.getId()); row.createCell(1).setCellValue(networkInterface.getVirtualDevice()); row.createCell(2).setCellValue(networkInterface.getInterfaceName()); row.createCell(3).setCellValue(networkInterface.getDescription()); row.createCell(4).setCellValue(networkInterface.getVrfInstance()); row.createCell(5).setCellValue(networkInterface.getMacAddress()); row.createCell(6).setCellValue(networkInterface.isEnabled()); row.createCell(7).setCellValue(networkInterface.isLevel3()); row.createCell(8).setCellValue(""); row.createCell(9).setCellValue(""); row.createCell(10).setCellValue(""); } for (NetworkAddress address : networkInterface.getIpAddresses()) { row = interfaceSheet.createRow(yInterface++); row.createCell(0).setCellValue(device.getId()); row.createCell(1).setCellValue(networkInterface.getVirtualDevice()); row.createCell(2).setCellValue(networkInterface.getInterfaceName()); row.createCell(3).setCellValue(networkInterface.getDescription()); row.createCell(4).setCellValue(networkInterface.getVrfInstance()); row.createCell(5).setCellValue(networkInterface.getMacAddress()); row.createCell(6).setCellValue(networkInterface.isEnabled()); row.createCell(7).setCellValue(networkInterface.isLevel3()); row.createCell(8).setCellValue(address.getIp()); row.createCell(9).setCellValue(address.getPrefixLength()); row.createCell(10).setCellValue(address.getAddressUsage() == null ? "" : address.getAddressUsage().toString()); } } } } if (exportInventory) { Sheet inventorySheet = workBook.createSheet("Inventory"); row = inventorySheet.createRow(0); row.createCell(0).setCellValue("Device ID"); row.createCell(1).setCellValue("Slot"); row.createCell(2).setCellValue("Part Number"); row.createCell(3).setCellValue("Serial Number"); int yInventory = 1; for (Device device : devices) { for (Module module : device.getModules()) { row = inventorySheet.createRow(yInventory++); row.createCell(0).setCellValue(device.getId()); row.createCell(1).setCellValue(module.getSlot()); row.createCell(2).setCellValue(module.getPartNumber()); row.createCell(3).setCellValue(module.getSerialNumber()); } } } ByteArrayOutputStream output = new ByteArrayOutputStream(); workBook.write(output); workBook.close(); return Response.ok(output.toByteArray()) .header("Content-Disposition", "attachment; filename=" + fileName).build(); } catch (IOException e) { logger.error("Unable to write the resulting file.", e); throw new WebApplicationException("Unable to write the resulting file.", javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR); } catch (Exception e) { logger.error("Unable to generate the report.", e); throw new WebApplicationException("Unable to generate the report.", javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR); } finally { session.close(); } } logger.warn("Invalid requested file format."); throw new WebApplicationException("The requested file format is invalid or not supported.", javax.ws.rs.core.Response.Status.BAD_REQUEST); }
From source file:bfile.util.StringUtils.java
/** * <p>Compare two Strings lexicographically, ignoring case differences, * as per {@link String#compareToIgnoreCase(String)}, returning :</p> * <ul>/* w ww .j a v a 2 s . c om*/ * <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code null})</li> * <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li> * <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li> * </ul> * * <p>This is a {@code null} safe version of :</p> * <blockquote><pre>str1.compareToIgnoreCase(str2)</pre></blockquote> * * <p>{@code null} inputs are handled according to the {@code nullIsLess} parameter. * Two {@code null} references are considered equal. * Comparison is case insensitive.</p> * * <pre> * StringUtils.compareIgnoreCase(null, null, *) = 0 * StringUtils.compareIgnoreCase(null , "a", true) < 0 * StringUtils.compareIgnoreCase(null , "a", false) > 0 * StringUtils.compareIgnoreCase("a", null, true) > 0 * StringUtils.compareIgnoreCase("a", null, false) < 0 * StringUtils.compareIgnoreCase("abc", "abc", *) = 0 * StringUtils.compareIgnoreCase("abc", "ABC", *) = 0 * StringUtils.compareIgnoreCase("a", "b", *) < 0 * StringUtils.compareIgnoreCase("b", "a", *) > 0 * StringUtils.compareIgnoreCase("a", "B", *) < 0 * StringUtils.compareIgnoreCase("A", "b", *) < 0 * StringUtils.compareIgnoreCase("ab", "abc", *) < 0 * </pre> * * @see String#compareToIgnoreCase(String) * @param str1 the String to compare from * @param str2 the String to compare to * @param nullIsLess whether consider {@code null} value less than non-{@code null} value * @return < 0, 0, > 0, if {@code str1} is respectively less, equal ou greater than {@code str2}, * ignoring case differences. * @since 3.5 */ public static int compareIgnoreCase(final String str1, final String str2, final boolean nullIsLess) { if (str1 == str2) { return 0; } if (str1 == null) { return nullIsLess ? -1 : 1; } if (str2 == null) { return nullIsLess ? 1 : -1; } return str1.compareToIgnoreCase(str2); }
From source file:org.pentaho.di.ui.spoon.Spoon.java
/** * Refresh the object selection tree (on the left of the screen) *///from w w w.j a va2 s.c om public void refreshTree() { if (shell.isDisposed()) { return; } if (!viewSelected) { return; // Nothing to see here, move along... } if (selectionTree == null || selectionTree.isDisposed()) { // ////////////////////////////////////////////////////////////////////////////////////////////////// // // Now set up the transformation/job tree // selectionTree = new Tree(variableComposite, SWT.SINGLE); props.setLook(selectionTree); selectionTree.setLayout(new FillLayout()); addDefaultKeyListeners(selectionTree); /* * ExpandItem treeItem = new ExpandItem(mainExpandBar, SWT.NONE); treeItem.setControl(selectionTree); * treeItem.setHeight(shell.getBounds().height); setHeaderImage(treeItem, * GUIResource.getInstance().getImageLogoSmall(), STRING_SPOON_MAIN_TREE, 0, true); */ // Add a tree memory as well... TreeMemory.addTreeListener(selectionTree, STRING_SPOON_MAIN_TREE); selectionTree.addMenuDetectListener(new MenuDetectListener() { public void menuDetected(MenuDetectEvent e) { setMenu(selectionTree); } }); selectionTree.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { showSelection(); } }); selectionTree.addSelectionListener(new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { doubleClickedInTree(selectionTree); } }); // Set a listener on the tree addDragSourceToTree(selectionTree); } GUIResource guiResource = GUIResource.getInstance(); TransMeta activeTransMeta = getActiveTransformation(); JobMeta activeJobMeta = getActiveJob(); boolean showAll = activeTransMeta == null && activeJobMeta == null; // get a list of transformations from the transformation map // /* * List<TransMeta> transformations = delegates.trans.getTransformationList(); Collections.sort(transformations); * TransMeta[] transMetas = transformations.toArray(new TransMeta[transformations.size()]); * * // get a list of jobs from the job map List<JobMeta> jobs = delegates.jobs.getJobList(); Collections.sort(jobs); * JobMeta[] jobMetas = jobs.toArray(new JobMeta[jobs.size()]); */ // Refresh the content of the tree for those transformations // // First remove the old ones. selectionTree.removeAll(); // Now add the data back // if (!props.isOnlyActiveFileShownInTree() || showAll || activeTransMeta != null) { TreeItem tiTrans = new TreeItem(selectionTree, SWT.NONE); tiTrans.setText(STRING_TRANSFORMATIONS); tiTrans.setImage(GUIResource.getInstance().getImageBol()); // Set expanded if this is the only transformation shown. if (props.isOnlyActiveFileShownInTree()) { TreeMemory.getInstance().storeExpanded(STRING_SPOON_MAIN_TREE, tiTrans, true); } for (TabMapEntry entry : delegates.tabs.getTabs()) { Object managedObject = entry.getObject().getManagedObject(); if (managedObject instanceof TransMeta) { TransMeta transMeta = (TransMeta) managedObject; if (!props.isOnlyActiveFileShownInTree() || showAll || (activeTransMeta != null && activeTransMeta.equals(transMeta))) { // Add a tree item with the name of transformation // String name = delegates.tabs.makeTabName(transMeta, entry.isShowingLocation()); if (Const.isEmpty(name)) { name = STRING_TRANS_NO_NAME; } TreeItem tiTransName = new TreeItem(tiTrans, SWT.NONE); tiTransName.setText(name); tiTransName.setImage(guiResource.getImageTransGraph()); // Set expanded if this is the only transformation // shown. if (props.isOnlyActiveFileShownInTree()) { TreeMemory.getInstance().storeExpanded(STRING_SPOON_MAIN_TREE, tiTransName, true); } // ///////////////////////////////////////////////////// // // Now add the database connections // TreeItem tiDbTitle = new TreeItem(tiTransName, SWT.NONE); tiDbTitle.setText(STRING_CONNECTIONS); tiDbTitle.setImage(guiResource.getImageBol()); String[] dbNames = new String[transMeta.nrDatabases()]; for (int i = 0; i < dbNames.length; i++) { dbNames[i] = transMeta.getDatabase(i).getName(); } Arrays.sort(dbNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); // Draw the connections themselves below it. for (String dbName : dbNames) { DatabaseMeta databaseMeta = transMeta.findDatabase(dbName); if (!filterMatch(dbName)) { continue; } TreeItem tiDb = new TreeItem(tiDbTitle, SWT.NONE); tiDb.setText(databaseMeta.getDisplayName()); if (databaseMeta.isShared()) { tiDb.setFont(guiResource.getFontBold()); } tiDb.setImage(guiResource.getImageConnection()); } // ///////////////////////////////////////////////////// // // The steps // TreeItem tiStepTitle = new TreeItem(tiTransName, SWT.NONE); tiStepTitle.setText(STRING_STEPS); tiStepTitle.setImage(guiResource.getImageBol()); // Put the steps below it. for (int i = 0; i < transMeta.nrSteps(); i++) { StepMeta stepMeta = transMeta.getStep(i); PluginInterface stepPlugin = PluginRegistry.getInstance() .findPluginWithId(StepPluginType.class, stepMeta.getStepID()); if (!filterMatch(stepMeta.getName()) && !filterMatch(stepMeta.getName())) { continue; } TreeItem tiStep = new TreeItem(tiStepTitle, SWT.NONE); tiStep.setText(stepMeta.getName()); if (stepMeta.isShared()) { tiStep.setFont(guiResource.getFontBold()); } if (!stepMeta.isDrawn()) { tiStep.setForeground(guiResource.getColorDarkGray()); } Image stepIcon = guiResource.getImagesStepsSmall().get(stepPlugin.getIds()[0]); if (stepIcon == null) { stepIcon = guiResource.getImageBol(); } tiStep.setImage(stepIcon); } // ///////////////////////////////////////////////////// // // The hops // TreeItem tiHopTitle = new TreeItem(tiTransName, SWT.NONE); tiHopTitle.setText(STRING_HOPS); tiHopTitle.setImage(guiResource.getImageBol()); // Put the steps below it. for (int i = 0; i < transMeta.nrTransHops(); i++) { TransHopMeta hopMeta = transMeta.getTransHop(i); if (!filterMatch(hopMeta.toString())) { continue; } TreeItem tiHop = new TreeItem(tiHopTitle, SWT.NONE); tiHop.setText(hopMeta.toString()); if (hopMeta.isEnabled()) { tiHop.setImage(guiResource.getImageHop()); } else { tiHop.setImage(guiResource.getImageDisabledHop()); } } // ///////////////////////////////////////////////////// // // The partitions // TreeItem tiPartitionTitle = new TreeItem(tiTransName, SWT.NONE); tiPartitionTitle.setText(STRING_PARTITIONS); tiPartitionTitle.setImage(guiResource.getImageBol()); // Put the steps below it. for (int i = 0; i < transMeta.getPartitionSchemas().size(); i++) { PartitionSchema partitionSchema = transMeta.getPartitionSchemas().get(i); if (!filterMatch(partitionSchema.getName())) { continue; } TreeItem tiPartition = new TreeItem(tiPartitionTitle, SWT.NONE); tiPartition.setText(partitionSchema.getName()); tiPartition.setImage(guiResource.getImageFolderConnections()); if (partitionSchema.isShared()) { tiPartition.setFont(guiResource.getFontBold()); } } // ///////////////////////////////////////////////////// // // The slaves // TreeItem tiSlaveTitle = new TreeItem(tiTransName, SWT.NONE); tiSlaveTitle.setText(STRING_SLAVES); tiSlaveTitle.setImage(guiResource.getImageBol()); // Put the slaves below it. // String[] slaveNames = transMeta.getSlaveServerNames(); Arrays.sort(slaveNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); for (String slaveName : slaveNames) { SlaveServer slaveServer = transMeta.findSlaveServer(slaveName); if (!filterMatch(slaveServer.getName())) { continue; } TreeItem tiSlave = new TreeItem(tiSlaveTitle, SWT.NONE); tiSlave.setText(slaveServer.getName()); tiSlave.setImage(guiResource.getImageSlave()); if (slaveServer.isShared()) { tiSlave.setFont(guiResource.getFontBold()); } } // ///////////////////////////////////////////////////// // // The clusters // TreeItem tiClusterTitle = new TreeItem(tiTransName, SWT.NONE); tiClusterTitle.setText(STRING_CLUSTERS); tiClusterTitle.setImage(guiResource.getImageBol()); // Put the steps below it. for (int i = 0; i < transMeta.getClusterSchemas().size(); i++) { ClusterSchema clusterSchema = transMeta.getClusterSchemas().get(i); if (!filterMatch(clusterSchema.getName())) { continue; } TreeItem tiCluster = new TreeItem(tiClusterTitle, SWT.NONE); tiCluster.setText(clusterSchema.toString()); tiCluster.setImage(guiResource.getImageCluster()); if (clusterSchema.isShared()) { tiCluster.setFont(guiResource.getFontBold()); } } } } } } if (!props.isOnlyActiveFileShownInTree() || showAll || activeJobMeta != null) { TreeItem tiJobs = new TreeItem(selectionTree, SWT.NONE); tiJobs.setText(STRING_JOBS); tiJobs.setImage(GUIResource.getInstance().getImageBol()); // Set expanded if this is the only job shown. if (props.isOnlyActiveFileShownInTree()) { tiJobs.setExpanded(true); TreeMemory.getInstance().storeExpanded(STRING_SPOON_MAIN_TREE, tiJobs, true); } // Now add the jobs // for (TabMapEntry entry : delegates.tabs.getTabs()) { Object managedObject = entry.getObject().getManagedObject(); if (managedObject instanceof JobMeta) { JobMeta jobMeta = (JobMeta) managedObject; if (!props.isOnlyActiveFileShownInTree() || showAll || (activeJobMeta != null && activeJobMeta.equals(jobMeta))) { // Add a tree item with the name of job // String name = delegates.tabs.makeTabName(jobMeta, entry.isShowingLocation()); if (Const.isEmpty(name)) { name = STRING_JOB_NO_NAME; } if (!filterMatch(name)) { continue; } TreeItem tiJobName = new TreeItem(tiJobs, SWT.NONE); tiJobName.setText(name); tiJobName.setImage(guiResource.getImageJobGraph()); // Set expanded if this is the only job shown. if (props.isOnlyActiveFileShownInTree()) { TreeMemory.getInstance().storeExpanded(STRING_SPOON_MAIN_TREE, tiJobName, true); } // ///////////////////////////////////////////////////// // // Now add the database connections // TreeItem tiDbTitle = new TreeItem(tiJobName, SWT.NONE); tiDbTitle.setText(STRING_CONNECTIONS); tiDbTitle.setImage(guiResource.getImageBol()); String[] dbNames = new String[jobMeta.nrDatabases()]; for (int i = 0; i < dbNames.length; i++) { dbNames[i] = jobMeta.getDatabase(i).getName(); } Arrays.sort(dbNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); // Draw the connections themselves below it. for (String dbName : dbNames) { DatabaseMeta databaseMeta = jobMeta.findDatabase(dbName); if (!filterMatch(databaseMeta.getName())) { continue; } TreeItem tiDb = new TreeItem(tiDbTitle, SWT.NONE); tiDb.setText(databaseMeta.getDisplayName()); if (databaseMeta.isShared()) { tiDb.setFont(guiResource.getFontBold()); } tiDb.setImage(guiResource.getImageConnection()); } // ///////////////////////////////////////////////////// // // The job entries // TreeItem tiJobEntriesTitle = new TreeItem(tiJobName, SWT.NONE); tiJobEntriesTitle.setText(STRING_JOB_ENTRIES); tiJobEntriesTitle.setImage(guiResource.getImageBol()); // Put the job entries below it. // for (int i = 0; i < jobMeta.nrJobEntries(); i++) { JobEntryCopy jobEntry = jobMeta.getJobEntry(i); if (!filterMatch(jobEntry.getName()) && !filterMatch(jobEntry.getDescription())) { continue; } TreeItem tiJobEntry = ConstUI.findTreeItem(tiJobEntriesTitle, jobEntry.getName()); if (tiJobEntry != null) { continue; // only show it once } tiJobEntry = new TreeItem(tiJobEntriesTitle, SWT.NONE); tiJobEntry.setText(jobEntry.getName()); // if (jobEntry.isShared()) // tiStep.setFont(guiResource.getFontBold()); TODO: // allow job entries to be shared as well... if (jobEntry.isStart()) { tiJobEntry.setImage(GUIResource.getInstance().getImageStart()); } else if (jobEntry.isDummy()) { tiJobEntry.setImage(GUIResource.getInstance().getImageDummy()); } else { String key = jobEntry.getEntry().getPluginId(); Image image = GUIResource.getInstance().getImagesJobentriesSmall().get(key); tiJobEntry.setImage(image); } } // ///////////////////////////////////////////////////// // // The slaves // TreeItem tiSlaveTitle = new TreeItem(tiJobName, SWT.NONE); tiSlaveTitle.setText(STRING_SLAVES); tiSlaveTitle.setImage(guiResource.getImageBol()); // Put the slaves below it. // String[] slaveNames = jobMeta.getSlaveServerNames(); Arrays.sort(slaveNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); for (String slaveName : slaveNames) { SlaveServer slaveServer = jobMeta.findSlaveServer(slaveName); if (!filterMatch(slaveServer.getName())) { continue; } TreeItem tiSlave = new TreeItem(tiSlaveTitle, SWT.NONE); tiSlave.setText(slaveServer.getName()); tiSlave.setImage(guiResource.getImageSlave()); if (slaveServer.isShared()) { tiSlave.setFont(guiResource.getFontBold()); } } } } } } // Set the expanded state of the complete tree. TreeMemory.setExpandedFromMemory(selectionTree, STRING_SPOON_MAIN_TREE); // refreshCoreObjectsHistory(); selectionTree.setFocus(); selectionTree.layout(); variableComposite.layout(true, true); setShellText(); }
From source file:org.apache.solr.handler.component.SemanticSearchHandler.java
private void ParseRequestParams(SolrQueryRequest req, SemanticSearchConfigParams params, ModifiableSolrParams qparams) throws SyntaxError { qparams.set(CommonParams.Q, req.getParams().get(CommonParams.Q).toLowerCase().replace(" not ", " \\not ") .replace(" or ", " \\or ").replace(" and ", " \\and ")); // get method of semantic concepts retrievals String tmp = req.getParams().get("conceptsmethod"); if (tmp != null) { params.e_Method = Enums.getSemanticMethod(tmp); if (params.e_Method == Enums.ENUM_SEMANTIC_METHOD.e_UNKNOWN) { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (conceptsmethod)"); }//from w w w .j a v a 2 s . c o m } // get measure relatedness flag tmp = req.getParams().get("measure_relatedness"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.measure_relatedness = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (measure_relatedness)"); } } // get semantic relatedness experiment flag tmp = req.getParams().get("hrelatednessexpr"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relatedness_experiment = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelatednessexpr)"); } } else params.hidden_relatedness_experiment = false; // get quote concepts flag tmp = req.getParams().get("hunquoteconcepts"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_unquote_concepts = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hunquoteconcepts)"); } } else params.hidden_unquote_concepts = false; // get pagerank weighting flag tmp = req.getParams().get("hpagerankweight"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_pagerank_weighting = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hpagerankweight)"); } } else params.hidden_pagerank_weighting = false; // get enable title search flag tmp = req.getParams().get("titlesearch"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_title_search = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (titlesearch)"); } } // get force see also flag tmp = req.getParams().get("hrelaxseealso"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_see_also = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxseealso)"); } } else params.hidden_relax_see_also = false; // get ignored concepts if any String[] ignsem = req.getParams().getFieldParams(null, "ignsem"); if (ignsem != null) { params.ignored_concepts = new HashSet<String>(); for (String s : ignsem) params.ignored_concepts.add(java.net.URLDecoder.decode(s)); } // get fqs if any //params.fqs = req.getParams().getFieldParams(null, "fqs"); String[] fqs = req.getParams().getFieldParams(null, "fqs"); if (fqs != null) { params.fqs = new HashMap<String, ArrayList<String>>(); for (String fq : fqs) { String[] fqToken = fq.split(":"); ArrayList<String> values = params.fqs.get(fqToken[0]); if (values == null) values = new ArrayList<String>(); values.add(fqToken[1]); params.fqs.put(fqToken[0], values); } } // get relax NER flag tmp = req.getParams().get("hrelaxner"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_ner = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxner)"); } } else params.hidden_relax_ner = false; // get relax categories flag tmp = req.getParams().get("hrelaxcategories"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_categories = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxcategories)"); } } else params.hidden_relax_categories = false; // get relax search flag tmp = req.getParams().get("hrelaxsearch"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_search = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxsearch)"); } } else params.hidden_relax_search = false; // get CI freetext flag tmp = req.getParams().get("hfreetext"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.ci_freetext = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hfreetext)"); } } else params.ci_freetext = false; // get absolute explicit concepts flag tmp = req.getParams().get("habsexplicit"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.abs_explicit = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (habsexplicit)"); } } else params.abs_explicit = false; // get include q flag tmp = req.getParams().get("hincludeq"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_include_q = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hincludeq)"); } } else params.hidden_include_q = false; // get boolean flag tmp = req.getParams().get("hboolean"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_boolean = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hboolean)"); } } else params.hidden_boolean = false; // get show records flag tmp = req.getParams().get("showrecords"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_show_records = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (showrecords)"); } } else params.enable_show_records = false; // get search all flag tmp = req.getParams().get("searchall"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_search_all = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (searchall)"); } } else params.enable_search_all = false; // get search title flag tmp = req.getParams().get("searchtitle"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_search_title = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (searchtitle)"); } } else params.enable_search_title = false; // get search abstract flag tmp = req.getParams().get("searchabstract"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_search_abstract = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (searchabstract)"); } } else params.enable_search_abstract = false; // get search description flag tmp = req.getParams().get("searchdescription"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_search_description = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (searchdescription)"); } } else params.enable_search_description = false; // get search claims flag tmp = req.getParams().get("searchclaims"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_search_claims = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (searchclaims)"); } } else params.enable_search_claims = false; // get extract all flag tmp = req.getParams().get("extractall"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_extract_all = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (extractall)"); } } else params.enable_extract_all = false; // get extract title flag tmp = req.getParams().get("extracttitle"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_extract_title = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (extracttitle)"); } } else params.enable_extract_title = false; // get extract abstract flag tmp = req.getParams().get("extractabstract"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_extract_abstract = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (extractabstract)"); } } else params.enable_extract_abstract = false; // get extract description flag tmp = req.getParams().get("extractdescription"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_extract_description = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (extractdescription)"); } } else params.enable_extract_description = false; // get extract claims flag tmp = req.getParams().get("extractclaims"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.enable_extract_claims = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (extractclaims)"); } } else params.enable_extract_claims = false; // get relax caching flag tmp = req.getParams().get("hrelaxcache"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_cache = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxcache)"); } } else params.hidden_relax_cache = false; // get relax list of filter flag tmp = req.getParams().get("hrelaxlistof"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_listof = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxlistof)"); } } else params.hidden_relax_listof = false; // get relax same title flag tmp = req.getParams().get("hrelaxsametitle"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_same_title = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxsametitle)"); } } else params.hidden_relax_same_title = false; // get relax filtering flag tmp = req.getParams().get("hrelaxfilters"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_filters = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxfilters)"); } } else params.hidden_relax_filters = false; // get relax disambiguation filter flag tmp = req.getParams().get("hrelaxdisambig"); if (tmp != null && tmp.length() > 0) { if (tmp.compareTo("on") == 0) params.hidden_relax_disambig = true; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hrelaxdisambig)"); } } else params.hidden_relax_disambig = false; // get method of experiment input file tmp = req.getParams().get("hexperin"); if (tmp != null && tmp.length() > 0) { params.in_path = StringEscapeUtils.escapeHtml(tmp); qparams.set("hexperin", params.in_path); } // get method of experiment input file tmp = req.getParams().get("hexperout"); if (tmp != null && tmp.length() > 0) { params.out_path = StringEscapeUtils.escapeHtml(tmp); qparams.set("hexperout", params.out_path); } // get distance metric method tmp = req.getParams().get("hsim"); if (tmp != null && tmp.length() > 0) { params.e_Distance = Enums.getDistanceMethod(tmp); if (params.e_Distance == Enums.ENUM_DISTANCE_METRIC.e_UNKNOWN) { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hsim)"); } } // get analytic type tmp = req.getParams().get("analytic"); if (tmp != null && tmp.length() > 0) { if (tmp.compareToIgnoreCase("explore") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_TECH_EXPLORE; else if (tmp.compareToIgnoreCase("landscape") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_TECH_LANDSCAPE; else if (tmp.compareToIgnoreCase("competitive") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_CI; else if (tmp.compareToIgnoreCase("prior") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_PRIOR; else if (tmp.compareToIgnoreCase("relatedness") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_RELATEDNESS; else if (tmp.compareToIgnoreCase("search") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_SEARCH; else if (tmp.compareToIgnoreCase("relevancy") == 0) params.e_analytic_type = Enums.ENUM_ANALYTIC_TYPE.e_RELEVANCY; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (analytic)"); } } if (params.e_analytic_type == Enums.ENUM_ANALYTIC_TYPE.e_RELEVANCY) { // get ipc filter tmp = req.getParams().get("ipcfilter"); if (tmp != null && tmp.length() > 0) { if (tmp.compareToIgnoreCase("none") == 0) params.e_ipc_filter = Enums.ENUM_IPC_FILTER.e_NONE; else if (tmp.compareToIgnoreCase("section") == 0) params.e_ipc_filter = Enums.ENUM_IPC_FILTER.e_IPC_SECTION; else if (tmp.compareToIgnoreCase("class") == 0) params.e_ipc_filter = Enums.ENUM_IPC_FILTER.e_IPC_CLASS; else if (tmp.compareToIgnoreCase("subclass") == 0) params.e_ipc_filter = Enums.ENUM_IPC_FILTER.e_IPC_SUBCLASS; else if (tmp.compareToIgnoreCase("group") == 0) params.e_ipc_filter = Enums.ENUM_IPC_FILTER.e_IPC_GROUP; else if (tmp.compareToIgnoreCase("subgroup") == 0) params.e_ipc_filter = Enums.ENUM_IPC_FILTER.e_IPC_SUBGROUP; else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (ipc filter)"); } } // get priors, should be comma separated tmp = req.getParams().get("priors"); if (tmp != null) { params.relevancy_priors = tmp.split(","); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (priors)"); } // get priors, should be comma separated tmp = req.getParams().get("priorshits"); if (tmp != null) { if (tmp.matches("\\d+")) { params.priors_hits = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (priors)"); } } } // get maximum hits in initial wiki search tmp = req.getParams().get("hmaxhits"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_max_hits = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hmaxhits)"); } } else params.hidden_max_hits = Integer.MAX_VALUE; // get maximum levels in concept graph tmp = req.getParams().get("hmaxlevels"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_max_levels = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hmaxlevels)"); } } else params.hidden_max_levels = 2; // get maximum hits in initial wiki search tmp = req.getParams().get("hminassocnt"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_min_asso_cnt = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hminassocnt)"); } } // else // params.hidden_min_asso_cnt = 1; // get minimum wiki article length to search tmp = req.getParams().get("hminwikilen"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_min_wiki_length = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hminwikilen)"); } } // else // params.hidden_min_wiki_length = 0; // get minimum seealso article length to search tmp = req.getParams().get("hminseealsolen"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_min_seealso_length = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hminseealsolen)"); } } // else // params.hidden_min_seealso_length = 0; // get maximum ngrams of wiki titles tmp = req.getParams().get("hmaxngrams"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_max_title_ngrams = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hmaxngrams)"); } } // get maximum seealso ngrams of wiki titles tmp = req.getParams().get("hseealsomaxngrams"); if (tmp != null) { if (tmp.matches("\\d+")) { params.hidden_max_seealso_ngrams = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (hseealsomaxngrams)"); } } // get wiki search field tmp = req.getParams().get("hwikifield"); if (tmp != null) params.hidden_wiki_search_field = tmp; // get wiki extra query tmp = req.getParams().get("hwikiextraq"); if (tmp != null) params.hidden_wiki_extra_query = tmp; // get number of CI patents to retrieve tmp = req.getParams().get("patentsno"); if (tmp != null) { if (tmp.matches("\\d+")) { params.ci_patents_num = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (ci_patents_num)"); } } // get number of semantic concepts to retrieve tmp = req.getParams().get("conceptsno"); if (tmp != null) { if (tmp.matches("\\d+")) { params.concepts_num = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (conceptsno)"); } } // get number of results to retrieve tmp = req.getParams().get("resultsno"); if (tmp != null && tmp.length() > 0) { if (tmp.matches("\\d+")) { params.results_num = Integer.parseInt(tmp); } else { // clear request and send back bad request syntax req.setParams(new ModifiableSolrParams()); throw new SyntaxError("Invalid value for request parameter (resultsno)"); } } }
From source file:org.commoncrawl.service.crawler.CrawlList.java
/** fetch succeeded **/ void fetchSucceeded(final CrawlTarget target, int downloadTime, final NIOHttpHeaders httpHeaders, final Buffer contentBuffer) { _lastRequestWasIOException = false;/*from w w w . ja va2 s.c om*/ _lastRequestDownloadTime = downloadTime; _lastRequestRedirectCount = target.getRedirectCount(); _fetchEndTime = System.currentTimeMillis(); _activeConnection = null; getHost().incrementCounter(CrawlListHost.CounterId.SuccessfullGetCount, 1); // reset host's io error count _host.resetCounter(CrawlListHost.CounterId.ConsecutiveIOErrorCount); if (getActiveDomain() != null) getActiveDomain()._domainRetryCounter = 0; Disposition oldDisposition = _disposition; final String originalHost = URLUtils.fastGetHostFromURL(target.getOriginalURL()); final String activeHost = URLUtils.fastGetHostFromURL(target.getActiveURL()); if (originalHost != null && activeHost != null) { // update our server ip information from information contained within crawl target ... cacheDNSEntry(activeHost, target.getServerIP(), target.getServerIPTTL()); // if the target was redirected ... cache the original ip address and ttl as well ... if (target.isRedirected()) { if (target.getOriginalRequestData() != null) { cacheDNSEntry(originalHost, target.getOriginalRequestData()._serverIP, target.getOriginalRequestData()._serverIPTTL); } } } final int resultCode = NIOHttpConnection.getHttpResponseCode(httpHeaders); if (resultCode == 200) { getHost().incrementCounter(CrawlListHost.CounterId.Http200Count, 1); if (getActiveDomain() != null) { getActiveDomain()._HTTP200Count++; getActiveDomain()._SequentialHTTPFailuresCount = 0; } // validate www rewrite rule if not set and target was redirected ... if (target.isRedirected()) { /* this is broken for the new list design if (!originalHost.equalsIgnoreCase(activeHost)) { // if redirect strips the www then ... if ((originalHost.startsWith("www.") || originalHost.startsWith("WWW.")) && activeHost.equalsIgnoreCase(originalHost.substring(4))) { addWWWReWriteItem(originalHost,WWWRULE_Remove); } // else if redirect adds the www then ... else if ((activeHost.startsWith("www.") || activeHost.startsWith("WWW.")) && originalHost.equalsIgnoreCase(activeHost.substring(4))) { addWWWReWriteItem(originalHost,WWWRULE_Add); } } */ } } else if (resultCode >= 400 && resultCode < 500) { if (resultCode == 403) { // inform host for stats tracking purposes _host.incrementCounter(CrawlListHost.CounterId.Http403Count, 1); } if (getActiveDomain() != null) getActiveDomain()._SequentialHTTPFailuresCount++; } else if (resultCode >= 500 && resultCode < 600) { if (getActiveDomain() != null) { getActiveDomain()._SequentialHTTPFailuresCount++; } } if (_scheduled != target) { if (_scheduled == null) LOG.error("List:" + getHost().getIPAddressAsString() + " List:" + getListName() + " fetchSucceed Target is:" + target.getOriginalURL() + " ActiveTarget is NULL!"); else LOG.error("List:" + getHost().getIPAddressAsString() + " List:" + getListName() + " fetchSucceed Target is:" + target.getOriginalURL() + " " + target.toString() + " ActiveTarget is:" + _scheduled.getOriginalURL() + " " + _scheduled.toString()); } else { // clear active ... _scheduled = null; // if this is the robots target ... if ((target.getFlags() & CrawlURL.Flags.IsRobotsURL) == 1) { final CrawlerStats crawlerStats = CrawlerServer.getEngine().getCrawlerStats(); // process the robots data if any ... // check for null queue (in case of unit test); if (resultCode == 200) { _robotsRetrieved = true; synchronized (crawlerStats) { crawlerStats.setRobotsRequestsSucceeded(crawlerStats.getRobotsRequestsSucceeded() + 1); crawlerStats.setRobotsRequestsQueuedForParse( crawlerStats.getRobotsRequestsQueuedForParse() + 1); } LOG.info("### Scheduling Robots Parse for:" + target.getActiveURL()); // transition to a waiting on completion disposition ... _disposition = Disposition.WaitingOnCompletion; if (getServerSingleton() != null) { // schedule a robots parser parse attempt ... getServerSingleton().registerThreadPool("robots", 5) .execute(new ConcurrentTask<RobotRuleResult>(getServerSingleton().getEventLoop(), new Callable<RobotRuleResult>() { public RobotRuleResult call() throws Exception { try { TextBytes contentData = new TextBytes(contentBuffer.get()); String contentEncoding = httpHeaders .findValue("Content-Encoding"); if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { if (Environment.detailLogEnabled()) LOG.info("GZIP Encoding Detected for Robots File For:" + activeHost); UnzipResult result = GZIPUtils.unzipBestEffort( contentData.getBytes(), CrawlEnvironment.CONTENT_SIZE_LIMIT); if (result == null) { contentData = null; if (Environment.detailLogEnabled()) LOG.info( "GZIP Decoder returned NULL for Robots File For:" + activeHost); } else { contentData.set(result.data.get(), result.data.getOffset(), result.data.getCount()); } } try { if (contentData != null) { String robotsTxt = contentData.toString().trim() .toLowerCase(); if (robotsTxt.startsWith("<html") || robotsTxt.startsWith("<!doctype html")) { contentData = null; CrawlerServer.getEngine().logRobots( System.currentTimeMillis(), _robotsHostName, resultCode, null, CrawlerEngine.RobotsLogEventType.HTTP_GET_Complete, CrawlerEngine.RobotsParseFlag_ContentWasHTML); } else { CrawlerServer.getEngine().logRobots( System.currentTimeMillis(), _robotsHostName, resultCode, robotsTxt, CrawlerEngine.RobotsLogEventType.HTTP_GET_Complete, 0); synchronized (this) { _lastFetchedRobotsData = robotsTxt; _lastFetchedRobotsHostName = _robotsHostName; } } } else { CrawlerServer.getEngine().logRobots( System.currentTimeMillis(), _robotsHostName, resultCode, null, CrawlerEngine.RobotsLogEventType.HTTP_GET_Complete, CrawlerEngine.RobotsParseFlag_ContentDecodeFailed); } } catch (Exception e) { LOG.error(CCStringUtils.stringifyException(e)); CrawlerServer.getEngine().logRobots( System.currentTimeMillis(), _robotsHostName, resultCode, null, CrawlerEngine.RobotsLogEventType.HTTP_GET_Complete, CrawlerEngine.RobotsParseFlag_ContentDecodeFailed); } if (Environment.detailLogEnabled()) LOG.info("Parsing Robots File for Host:" + activeHost); RobotRuleResult result = new RobotRuleResult(); if (contentData != null) { synchronized (_crc32) { _crc32.reset(); _crc32.update(contentData.getBytes(), contentData.getOffset(), contentData.getLength()); result.crcValue = _crc32.getValue(); } RobotRulesParser parser = new RobotRulesParser( getServerSingleton().getConfig()); result.ruleSet = parser.parseRules(contentData.getBytes(), contentData.getOffset(), contentData.getLength()); } else { result.ruleSet = RobotRulesParser.getEmptyRules(); result.crcValue = 0; } return result; } catch (Exception e) { LOG.error(CCStringUtils.stringifyException(e)); throw e; } } }, new ConcurrentTask.CompletionCallback<RobotRuleResult>() { public void taskComplete(RobotRuleResult loadResult) { synchronized (crawlerStats) { crawlerStats.setRobotsRequestsQueuedForParse( crawlerStats.getRobotsRequestsQueuedForParse() - 1); } if (loadResult != null) { boolean disallowsAll = !_ruleSet.isAllowed("/"); boolean robotsHadCrawlDelay = _ruleSet.getCrawlDelay() != -1; boolean explicitMention = _ruleSet.explicitMention; int logFlags = 0; if (disallowsAll) logFlags |= CrawlerEngine.RobotsParseFlag_ExcludesAll; if (explicitMention) logFlags |= CrawlerEngine.RobotsParseFlag_ExplicitMention; if (robotsHadCrawlDelay) logFlags |= CrawlerEngine.RobotsParseFlag_HasCrawlDelay; synchronized (crawlerStats) { crawlerStats.setRobotsRequestsSuccessfullParse( crawlerStats.getRobotsRequestsSuccessfullParse() + 1); if (disallowsAll) { crawlerStats.setRobotsFileExcludesAllContent( crawlerStats.getRobotsFileExcludesAllContent() + 1); if (explicitMention) crawlerStats.setRobotsFileExplicitlyExcludesAll( crawlerStats .getRobotsFileExplicitlyExcludesAll() + 1); } if (explicitMention) { crawlerStats.setRobotsFileHasExplicitMention( crawlerStats.getRobotsFileHasExplicitMention() + 1); } if (robotsHadCrawlDelay) { crawlerStats.setRobotsFileHadCrawlDelay( crawlerStats.getRobotsFileHadCrawlDelay() + 1); } } CrawlerServer.getEngine().logRobots(System.currentTimeMillis(), _robotsHostName, 0, null, CrawlerEngine.RobotsLogEventType.Parse_Succeeded, logFlags); _ruleSet = loadResult.ruleSet; _robotsCRC = loadResult.crcValue; _host.cacheRobotsFile(_ruleSet, _robotsCRC); } else { CrawlerServer.getEngine().logRobots(System.currentTimeMillis(), _robotsHostName, 0, null, CrawlerEngine.RobotsLogEventType.Parse_Failed, 0); synchronized (crawlerStats) { crawlerStats.setRobotsRequestsFailedParse( crawlerStats.getRobotsRequestsFailedParse() + 1); } // LOG.error("####Robots parsing for host:" + activeHost + " failed."); _ruleSet = RobotRulesParser.getEmptyRules(); _robotsCRC = 0; } //if (Environment.detailLogEnabled()) LOG.info("####Robots RETRIEVED for Host:" + activeHost + " CrawlDelay IS:" + getCrawlDelay(false)); if (originalHost != null && activeHost != null) { updateRobotsCRCForDomain(_robotsCRC, originalHost, _robotsReturned400, _robotsReturned403); if (activeHost.compareToIgnoreCase(originalHost) != 0) { updateRobotsCRCForDomain(_robotsCRC, activeHost, _robotsReturned400, _robotsReturned403); } } Disposition oldDisposition = _disposition; if (getNextPending(false) != null) { _disposition = Disposition.ItemAvailable; } else { _disposition = Disposition.WaitingOnTime; } if (oldDisposition != _disposition) { // notify queue getHost().listDispositionChanged(CrawlList.this, oldDisposition, _disposition); } } public void taskFailed(Exception e) { if (Environment.detailLogEnabled()) LOG.error("####Robots parsing for host:" + _robotsHostName + " failed with exception" + e); _ruleSet = RobotRulesParser.getEmptyRules(); Disposition oldDisposition = _disposition; if (getNextPending(false) != null) { _disposition = Disposition.ItemAvailable; } else { _disposition = Disposition.WaitingOnTime; } if (oldDisposition != _disposition) { // notify queue getHost().listDispositionChanged(CrawlList.this, oldDisposition, _disposition); } } })); } // explitly return here ( inorder to wait for the async completion event) return; } //otherwise ... else { synchronized (crawlerStats) { crawlerStats.setRobotsRequestsFailed(crawlerStats.getRobotsRequestsFailed() + 1); } CrawlerServer.getEngine().logRobots(System.currentTimeMillis(), _robotsHostName, resultCode, null, CrawlerEngine.RobotsLogEventType.HTTP_GET_Failed, 0); _robotsCRC = 0; if (Environment.detailLogEnabled()) LOG.info("####Robots GET for Host:" + activeHost + "FAILED With Result Code:" + resultCode); //TODO: MAKE THIS MORE ROBUST ... // clear robots flag ... _robotsRetrieved = true; // see if result code was a 403 if (resultCode >= 400 && resultCode <= 499) { _robotsReturned400 = true; if (resultCode == 403) _robotsReturned403 = true; } // for now, assume no robots rules for any error conditions ... _ruleSet = RobotRulesParser.getEmptyRules(); if (originalHost != null && activeHost != null) { updateRobotsCRCForDomain(_robotsCRC, originalHost, _robotsReturned400, _robotsReturned403); if (activeHost.compareToIgnoreCase(originalHost) != 0) { updateRobotsCRCForDomain(_robotsCRC, activeHost, _robotsReturned400, _robotsReturned403); } } } } if (getServerSingleton() != null && getServerSingleton().failHostsOnStats()) { // update active host stats and check for failure ... checkActiveHostStatsForFailure(); } // if there are no more items in the queue if (getNextPending(false) == null) { // if offline count is zero then mark this domain's queue as empty if (_offlineTargetCount == 0) { _disposition = Disposition.QueueEmpty; } // otherwise put us in a wait state and potentially queue up a disk load else { _disposition = Disposition.WaitingOnTime; // potentially queue up a disk load potentiallyQueueDiskLoad(); } } else { // if we are ready to fetch the next item ... if (calculateNextWaitTime() < System.currentTimeMillis()) { _disposition = Disposition.ItemAvailable; } else { // transition to a new wait state ... _disposition = Disposition.WaitingOnTime; } } if (oldDisposition != _disposition) { // either way ... notify queue getHost().listDispositionChanged(this, oldDisposition, _disposition); } } }
From source file:com.krawler.esp.servlets.deskeramob_V1.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request/* w ww . j a v a2s .c o m*/ * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SessionExpiredException { response.setContentType("text/html;charset=UTF-8"); ResultSet rs = null; ResultSet rsForSubQ = null; PreparedStatement pstmt = null; String result = ""; boolean android = false; Connection conn = null; try { conn = DbPool.getConnection(); int action = Integer.parseInt(request.getParameter("action")); int mode = Integer.parseInt(request.getParameter("mode")); if (!StringUtil.isNullOrEmpty(request.getParameter("android"))) { android = Boolean.parseBoolean(request.getParameter("android")); } switch (action) { case 0: // generate application id String u = request.getParameter("u"); String p = request.getParameter("p"); String d = request.getParameter("d"); result = authUser(conn, u, p, d); break; case 1: // dashboard request int limit = 15, offset = 0; String userid = request.getParameter("userid").toString(); String projectlist = DashboardHandler.getProjectList(conn, userid, 1000, 0, ""); JSONArray projList = null; try { JSONObject projListObj = new JSONObject(projectlist); projList = projListObj.getJSONArray("data"); } catch (JSONException ex) { result = "{\"data\":[{\"success\":false,\"data\":" + ex.getMessage() + "}]}"; } switch (mode) { case 1: // due tasks try { boolean projMod = false; for (int c = 0; c < projList.length(); c++) { JSONObject te = projList.getJSONObject(c); if (DashboardHandler.isModerator(conn, userid, te.getString("id"))) { projMod = true; break; } } PreparedStatement pstmt1 = null; JSONObject jobj = new JSONObject(); String query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt1 = conn.prepareStatement(query); pstmt1.setString(1, "0"); pstmt1.setString(2, userid); ResultSet rs1 = pstmt1.executeQuery(); int count = 0; if (rs1.next()) { count = rs1.getInt("count"); } if (projList == null) { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } else { for (int i = 0; i < projList.length(); i++) { JSONObject temp = projList.getJSONObject(i); String projid = temp.getString("id"); String qry = ""; String projName = ""; boolean moderator = DashboardHandler.isModerator(conn, userid, projid); if (!moderator) { qry = "(SELECT taskid FROM proj_task WHERE projectid=? AND taskid NOT IN " + "(SELECT taskid FROM proj_taskresourcemapping)) " + "UNION " + "(SELECT taskid FROM proj_taskresourcemapping WHERE resourceid = ? " + "AND taskid IN (SELECT taskid FROM proj_task WHERE projectid = ?))"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); pstmt1.setString(2, userid); pstmt1.setString(3, projid); } else { qry = "SELECT taskid FROM proj_task WHERE projectid = ?"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); } rs1 = pstmt1.executeQuery(); String tids = ""; while (rs1.next()) { tids += "'" + rs1.getString("taskid") + "',"; } if (tids.length() > 0) { tids = tids.substring(0, (tids.length() - 1)); pstmt1 = conn.prepareStatement( "SELECT projectname FROM project WHERE projectid = ?"); pstmt1.setString(1, projid); rs1 = pstmt1.executeQuery(); if (rs1.next()) { projName = rs1.getString("projectname"); } qry = "SELECT priority,taskname,percentcomplete,DATE_FORMAT(startdate,'%D %b %y') AS startdate,DATE_FORMAT(enddate,'%D %b %y') AS enddate, taskid " + "FROM proj_task " + "WHERE percentcomplete < 100 AND taskid IN (" + tids + ") AND (date(enddate)>=date(now())) AND (date(startdate) <= date(now()))"; // pstmt.setInt(1, limit); pstmt1 = conn.prepareStatement(qry); rs1 = pstmt1.executeQuery(); while (rs1.next()) { JSONObject j = new JSONObject(); j.put("projectname", projName); j.put("taskname", rs1.getString("taskname")); j.put("taskid", rs1.getString("taskid")); j.put("complete", rs1.getString("percentcomplete")); j.put("startdate", rs1.getString("startdate")); j.put("enddate", rs1.getString("enddate")); int ptr = rs1.getInt("priority"); String pStr = "medium"; if (ptr == 0) { pStr = "high"; } else if (ptr == 2) { pStr = "low"; } j.put("priority", pStr); if (moderator) { String res = DashboardHandler.getTaskResources(conn, rs1.getString("taskid"), projid, userid); if (!StringUtil.equal(res, "{}")) { JSONObject jobj1 = new JSONObject(res); JSONArray jarr = jobj1.getJSONArray("data"); String resr = ""; for (int cnt = 0; cnt < jarr.length(); cnt++) { resr += jarr.getJSONObject(cnt).getString("resourcename") + ", "; } resr = resr.substring(0, (resr.length() - 2)); if (!StringUtil.isNullOrEmpty(resr)) { j.put("assignedto", resr); } } } jobj.append("data", j); } } } } if (jobj.has("data")) { JSONObject fin = new JSONObject(); fin.put("count", String.valueOf(count)); jobj.append("msgcount", fin); jobj.put("moderator", projMod); result = jobj.toString(); } else { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[],\"moderator\":" + Boolean.toString(projMod) + "}"; } } catch (JSONException ex) { } break; case 0: // overdue tasks try { JSONObject jobj = new JSONObject(); PreparedStatement pstmt1 = null; String query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt1 = conn.prepareStatement(query); pstmt1.setString(1, "0"); pstmt1.setString(2, userid); ResultSet rs1 = pstmt1.executeQuery(); int count = 0; if (rs1.next()) { count = rs1.getInt("count"); } if (projList == null) { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } else { for (int i = 0; i < projList.length(); i++) { JSONObject temp = projList.getJSONObject(i); String projid = temp.getString("id"); String qry = ""; String projName = ""; boolean moderator = DashboardHandler.isModerator(conn, userid, projid); if (!moderator) { qry = "(SELECT taskid FROM proj_task WHERE projectid=? AND taskid NOT IN " + "(SELECT taskid FROM proj_taskresourcemapping)) " + "UNION " + "(SELECT taskid FROM proj_taskresourcemapping WHERE resourceid = ?)"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); pstmt1.setString(2, userid); } else { qry = "SELECT taskid FROM proj_task WHERE projectid = ?"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); } rs1 = pstmt1.executeQuery(); String tids = ""; while (rs1.next()) { tids += "'" + rs1.getString("taskid") + "',"; } if (tids.length() > 0) { tids = tids.substring(0, (tids.length() - 1)); pstmt1 = conn.prepareStatement( "SELECT projectname FROM project WHERE projectid = ?"); pstmt1.setString(1, projid); rs1 = pstmt1.executeQuery(); if (rs1.next()) { projName = rs1.getString("projectname"); } qry = "SELECT priority,taskname,percentcomplete, datediff(CURRENT_DATE,date(enddate)) as overdueby,DATE_FORMAT(enddate,'%D %b %y') AS enddate, taskid " + "FROM proj_task " + "WHERE percentcomplete < 100 AND taskid IN (" + tids + ") AND date(proj_task.enddate) < date(now()) LIMIT ? OFFSET ?"; pstmt1 = conn.prepareStatement(qry); pstmt1.setInt(1, limit); pstmt1.setInt(2, offset); rs1 = pstmt1.executeQuery(); while (rs1.next()) { JSONObject j = new JSONObject(); j.put("projectname", projName); j.put("taskid", rs1.getString("taskid")); j.put("taskname", rs1.getString("taskname")); j.put("complete", rs1.getString("percentcomplete")); j.put("overdueby", rs1.getString("overdueby")); j.put("enddate", rs1.getString("enddate")); int ptr = rs1.getInt("priority"); String pStr = "medium"; if (ptr == 0) { pStr = "high"; } else if (ptr == 2) { pStr = "low"; } j.put("priority", pStr); if (moderator) { String res = DashboardHandler.getTaskResources(conn, rs1.getString("taskid"), projid, userid); if (!StringUtil.equal(res, "{}")) { JSONObject jobj1 = new JSONObject(res); JSONArray jarr = jobj1.getJSONArray("data"); String resr = ""; for (int cnt = 0; cnt < jarr.length(); cnt++) { resr += jarr.getJSONObject(cnt).getString("resourcename") + ", "; } resr = resr.substring(0, (resr.length() - 2)); if (!StringUtil.isNullOrEmpty(resr)) { j.put("assignedto", resr); } } } jobj.append("data", j); } } } } if (jobj.has("data")) { JSONObject fin = new JSONObject(); fin.put("count", count); jobj.append("msgcount", fin); result = jobj.toString(); } else { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } } catch (JSONException ex) { } break; case 2: // calendar events PreparedStatement pstmt1 = null; String query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt1 = conn.prepareStatement(query); pstmt1.setString(1, "0"); pstmt1.setString(2, userid); ResultSet rs1 = pstmt1.executeQuery(); int count = 0; if (rs1.next()) { count = rs1.getInt("count"); } String timezone = "+00:00"; timezone = Timezone.getTimeZone(conn, userid); String sqlquery = "SELECT calendarevents.subject,project.projectname, startts, endts, DATE_FORMAT(calendarevents.startts,'%D %b %y') AS 'startdate' ," + "DATE_FORMAT(calendarevents.startts,'%h:%i %p') AS 'starttime'," + "CASE calendarevents.priority WHEN 'm' THEN 'Medium' WHEN 'l' THEN 'Low' WHEN 'h' THEN 'High' END AS priority" + " FROM calendarevents INNER JOIN calendars ON calendars.cid =calendarevents.cid INNER JOIN project ON project.projectid = calendars.userid " + " WHERE project.projectid IN (SELECT project.projectid FROM project INNER JOIN projectmembers ON " + " projectmembers.projectid = project.projectid WHERE userid = ?) AND calendars.timestamp> ? " + " AND date(startts)>=CURRENT_DATE AND date(startts)<=(ADDDATE(CURRENT_DATE, 7)) ORDER BY startts LIMIT ? OFFSET ?"; pstmt = conn.prepareStatement(sqlquery); pstmt.setString(1, userid); pstmt.setString(2, "1970-01-01 00:00:00"); pstmt.setInt(3, limit); pstmt.setInt(4, offset); rsForSubQ = pstmt.executeQuery(); try { JSONObject jobj = new JSONObject(); while (rsForSubQ.next()) { timezone = timezone.substring(0, 4) + "00"; String startts = rsForSubQ.getString("startts"); startts = Timezone.toUserDefTimezone(conn, startts, timezone); Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startts); int date = Integer.parseInt(new SimpleDateFormat("d").format(startDate)); String ordinal = getDateOrdinal(date); JSONObject j = new JSONObject(); j.put("subject", rsForSubQ.getString("subject")); j.put("projectname", rsForSubQ.getString("projectname")); j.put("startdate", new SimpleDateFormat("d'".concat(ordinal).concat("' MMM yy")) .format(startDate)); j.put("starttime", new SimpleDateFormat("hh:mm a").format(startDate)); j.put("priority", rsForSubQ.getString("priority")); jobj.append("data", j); } if (jobj.has("data")) { JSONObject fin = new JSONObject(); fin.put("count", String.valueOf(count)); jobj.append("msgcount", fin); result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (ParseException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } //result = kwljson.GetJsonForGrid(rsForSubQ); break; case 3: // unread personal msgs query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt = conn.prepareStatement(query); pstmt.setString(1, "0"); pstmt.setString(2, userid); rsForSubQ = pstmt.executeQuery(); count = 0; if (rsForSubQ.next()) { count = rsForSubQ.getInt("count"); } query = "Select post_id ,concat(fname,' ',lname) as post_fullname,userlogin.username as poster_id , post_text , post_subject ," + " post_time from mailmessages inner join users " + "on users.userid = mailmessages.poster_id inner join userlogin on users.userid=userlogin.userid where folder = ? and to_id = ? and readflag = false ORDER BY post_time DESC"; pstmt = conn.prepareStatement(query); pstmt.setString(1, "0"); pstmt.setString(2, userid); // pstmt.setInt(3, limit); // pstmt.setInt(4, offset); rsForSubQ = pstmt.executeQuery(); //result = kwljson.GetJsonForGrid(rsForSubQ); try { JSONObject jobj = new JSONObject(); String companyid = getCompanyID(conn, userid); String subdomain = CompanyHandler.getCompanySubdomainByCompanyID(conn, companyid); while (rsForSubQ.next()) { JSONObject j = new JSONObject(); String postTime = Timezone.toCompanyTimezone(conn, rsForSubQ.getString("post_time"), companyid); Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(postTime); int date = Integer.parseInt(new SimpleDateFormat("d").format(startDate)); String ordinal = getDateOrdinal(date); j.put("post_id", rsForSubQ.getString("post_id")); j.put("post_fullname", rsForSubQ.getString("post_fullname")); j.put("poster_id", rsForSubQ.getString("poster_id")); j.put("post_text", insertSmiley(rsForSubQ.getString("post_text"), URLUtil.getPageURL(request, com.krawler.esp.web.resource.Links.loginpageFull, subdomain))); j.put("post_subject", rsForSubQ.getString("post_subject")); j.put("post_time", new SimpleDateFormat( "dd'".concat(ordinal).concat("' MMM yy").concat(" hh:mm a")) .format(startDate)); jobj.append("data", j); } if (jobj.has("data")) { JSONObject temp = new JSONObject(); temp.put("count", String.valueOf(count)); jobj.append("msgcount", temp); result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (ParseException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } break; case 4: // list of users's projects String companyid = getCompanyID(conn, userid); // boolean isSuperUser = DashboardHandler.isSuperUser(conn, companyid, userid); try { JSONObject jobj = getUserProjectList(conn, userid); // JSONObject projectList = new JSONObject(DashboardHandler.getProjectListMember(conn, userid, 10, 0)); // JSONArray projArray = projectList.getJSONArray("data"); // int prc = projArray.length(); // JSONObject jobj = new JSONObject(); // if (prc > 0) { // for (int i = 0; i < projArray.length(); i++) { // JSONObject tempProj = projArray.getJSONObject(i); // if(tempProj.getInt("status") > 3){ // JSONObject j = new JSONObject(); // j.put("name", tempProj.getString("name")); // j.put("id", tempProj.getString("id")); // jobj.append("data", j); // } // } // } if (jobj.has("data")) { result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } break; case 5: // list of project resources try { JSONObject jobj = new JSONObject(); jobj = getProjectResourceList(conn, request); // String responseText = projdb.getProjectResources(conn, request.getParameter("id")); // try { // JSONObject jobj = new JSONObject(); // if (responseText.compareTo("{data:{}}") != 0) { // JSONObject resJOBJ = new JSONObject(responseText); // JSONArray jArray = resJOBJ.getJSONArray("data"); // int prec = jArray.length(); // if (prec > 0) { // for (int i = 0; i < prec; i++) { // JSONObject j = new JSONObject(); // j.put("name", jArray.getJSONObject(i).getString("resourcename")); // j.put("id", jArray.getJSONObject(i).getString("resourceid")); // jobj.append("data", j); // } // } // } if (jobj.has("data")) { result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } break; case 6:// display project list if (!AdminServlet.isCreator(conn, userid) || android) { result = projectlist; } else { companyid = getCompanyID(conn, userid); result = AdminServlet.getProjData(conn, request, companyid, ""); } break; case 7:// fetch assigned/unassigned members result = getAssiUnAssiProjctMembers(conn, request.getParameter("projectid")); break; case 8:// isSuperUser int projectcount = 0; companyid = getCompanyID(conn, userid); boolean isSuper = DashboardHandler.isSuperUser(conn, companyid, userid); JSONObject temp = new JSONObject(); JSONObject jobj = new JSONObject(); temp.put("superuser", isSuper); jobj.append("data", temp); try { JSONObject projectList = getUserProjectList(conn, userid); JSONArray projectArray = projectList.getJSONArray("data"); for (int c = 0; c < projectArray.length(); c++) { JSONObject te = projectArray.getJSONObject(c); request.setAttribute("id", te.getString("id")); JSONArray member = getProjectResourceList(conn, request).getJSONArray("data"); for (int i = 0; i < member.length(); i++) { JSONObject j = member.getJSONObject(i); jobj.append("projectmember", j); } jobj.append("data", te); projectcount++; } } catch (Exception e) { result = e.toString(); } jobj.put("projectcount", projectcount); jobj.put("userid", userid); result = jobj.toString(); break; case 9:// manage members String userids = request.getParameter("userid"); if (StringUtil.isNullOrEmpty(userids)) { result = "{\"result\":[{\"success\":false}], \"msg\":[{\"msgText\": \"Can not remove all project members.\"}]}"; } else { userids = userids.substring(0, (userids.length() - 1)); String[] uids = userids.split(","); String pid = request.getParameter("projectid"); result = manageMembers(conn, pid, uids, userid); } break; case 10: // company user list companyid = getCompanyID(conn, userid); String companyMembers = AdminServlet.getAdminUserData(conn, request, companyid, "", false); // result = "{\"result\":[{\"success\":false}], \"msg\":[{\"msgText\": \"Could not complete your request.\"}]}"; result = "{\"result\":[{\"success\":true}],\"data\":" + companyMembers + "}"; break; } break; case 2: // Update Records userid = request.getParameter("userid").toString(); switch (mode) { case 1:// set read flag String post_id = request.getParameter("post_id"); String query = "update mailmessages set readflag=true where post_id = ?"; pstmt = conn.prepareStatement(query); pstmt.setString(1, post_id); int rows = pstmt.executeUpdate(); if (rows > 0) { conn.commit(); result = "{\"success\":true}"; } else { result = "{\"success\":false}"; } break; case 2:// update percent value for record String taskid = request.getParameter("taskid"); String pcomplete = request.getParameter("complete"); query = "update proj_task set percentcomplete = ? where taskid = ?"; pstmt = conn.prepareStatement(query); pstmt.setString(1, pcomplete); pstmt.setString(2, taskid); rows = pstmt.executeUpdate(); if (rows > 0) { conn.commit(); result = "{\"success\":true}"; } else { result = "{\"success\":false}"; } break; case 3:// insert tasks try { String projId = request.getParameter("projectid"); pstmt = conn.prepareStatement( "select max(taskindex) as maxindex from proj_task where projectid=?"); pstmt.setString(1, projId); rs = pstmt.executeQuery(); int rowindex = 1; if (rs.next()) { rowindex = rs.getInt(1) + 1; } java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy/MM/dd"); taskid = UUID.randomUUID().toString(); String taskname = request.getParameter("name"); String stdate = request.getParameter("start"); String enddate = request.getParameter("end"); int priority = 1; if (!StringUtil.isNullOrEmpty(request.getParameter("priority"))) { priority = Integer.parseInt(request.getParameter("priority")); } pstmt = conn.prepareStatement( "INSERT INTO proj_task(taskid, taskname, duration, startdate, enddate, projectid, " + "taskindex, level, parent, actualstartdate, actualduration, percentcomplete, notes, priority, " + "isparent) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); pstmt.setString(1, taskid); pstmt.setString(2, taskname); java.util.Date DateVal = sdf.parse(stdate); java.util.Date sDate = sdf.parse(stdate); Timestamp ts = new Timestamp(DateVal.getTime()); pstmt.setTimestamp(4, ts); DateVal = sdf.parse(enddate); int duration = SchedulingUtilities.calculateWorkingDays(conn, projId, sDate, DateVal); pstmt.setString(3, String.valueOf(duration)); ts = new Timestamp(DateVal.getTime()); pstmt.setTimestamp(5, ts); pstmt.setString(6, projId); pstmt.setString(7, String.valueOf(rowindex)); pstmt.setString(8, "0"); pstmt.setString(9, "0"); DateVal = sdf.parse(stdate); ts = new Timestamp(DateVal.getTime()); pstmt.setTimestamp(10, ts); pstmt.setString(11, String.valueOf(duration)); //if(request.getParameter("completed").equals(null)) pstmt.setString(12, "0"); // else // pstmt.setString(12, request.getParameter("completed")); pstmt.setString(13, ""); pstmt.setInt(14, priority); pstmt.setBoolean(15, false); boolean flag = pstmt.execute(); if (!request.getParameter("assignto").equals("")) { String[] resArray = request.getParameter("assignto").split(","); for (int i = 0; i < resArray.length; i++) { int dur = 0; String rid = resArray[i]; pstmt = conn.prepareStatement( "insert into proj_taskresourcemapping (taskid,resourceid,resduration) values(?,?,?)"); pstmt.setString(1, taskid); pstmt.setString(2, rid); pstmt.setInt(3, dur); pstmt.execute(); } } conn.commit(); result = "{\"success\":[{\"result\":true}]}"; } catch (ParseException ex) { Logger.getLogger(deskeramob.class.getName()).log(Level.SEVERE, null, ex); result = "{\"success\":[{\"result\":false}],\"data\":" + ex.getMessage() + "}"; } break; case 4: // create user // String companyid = getCompanyID(conn, userid); // result = createUser(conn, request, companyid, userid); // if (!StringUtil.isNullOrEmpty(result) && result.contains("failure")) { // result = "{\"success\":[{\"result\":false,\"error\":\"Could not complete your request. Please try again later.\"}]}"; // } else { // conn.commit(); // result = "{\"success\":[{\"result\":true,\"error\":\"User created successfully.\"}]}"; // } break; case 5: // import contacts result = importContacts(conn, request); break; case 6: // export contacts result = exportContacts(conn, request); if (!StringUtil.isNullOrEmpty(result)) { result = "{\"import\":[{\"result\":true}]," + result.substring(1, (result.length() - 1)) + "}"; } else { result = "{\"import\":[{\"result\":true,\"error\":\"There seem to be some problem with server. Could not import contacts.\"}]}"; } break; } break; case 3: // company updates switch (mode) { case 1:// create new company // result = createNewCompany(conn, request, response); // JSONObject j = new JSONObject(result); // if (j.getJSONArray("data").getJSONObject(0).has("success") && j.getJSONArray("data").getJSONObject(0).getString("success").equals("true")) { // result = authUser(conn, request.getParameter("u"), request.getParameter("p"), request.getParameter("cdomain")); // } break; case 2: //create project userid = request.getParameter("userid").toString(); String subdomain = CompanyHandler.getCompanySubdomainByUser(conn, userid); String companyid = getCompanyID(conn, userid); result = createProject(conn, request, companyid, subdomain, userid); if (StringUtil.equal("success", result)) { result = "{\"success\":[{\"result\":true}]}"; } else { result = "{\"success\":[{\"result\":false,\"error\":\"" + result + "\"}]}"; } break; case 3: //delete project userid = request.getParameter("userid").toString(); companyid = getCompanyID(conn, userid); result = AdminServlet.deleteProject(conn, request, companyid, userid, "iPhone"); if (StringUtil.equal("failure", result)) { result = "{\"success\":[{\"result\":false}]}"; DbPool.quietRollback(conn); } else { result = "{\"success\":[{\"result\":true}]}"; conn.commit(); } break; } break; case 4: //Project Reports switch (mode) { case 0://Project chart(type="milestones") if (!StringUtil.isNullOrEmpty(request.getParameter("projid")) && !StringUtil.isNullOrEmpty(request.getParameter("uid"))) { result = DashboardHandler.getChartURL(conn, request.getParameter("projid"), request.getParameter("uid"), "progress"); } break; case 1: //milestone(rtype="milestone"), overdue(rtype="overdue"), task in progress(rtype="taskinprogress", percent=-99), un-started task(rtype="taskinprogress", percent=0) if (!StringUtil.isNullOrEmpty(request.getParameter("projid")) && !StringUtil.isNullOrEmpty(request.getParameter("userid"))) { result = projectReport.getProjectReportJson(request, false, false); if (result.compareToIgnoreCase("{data:{}}") == 0) { result = "{\"data\":[]}"; } } break; } break; } } catch (JSONException ex) { Logger.getLogger(deskeramob.class.getName()).log(Level.SEVERE, null, ex); result = "{\"success\":[{\"result\":\"1\"}],\"data\":" + ex.getMessage() + "}"; } catch (ServiceException ex) { result = "{\"success\":[{\"result\":\"0\"}],\"data\":" + ex.getMessage() + "}"; } catch (SQLException ex) { result = "{\"success\":[{\"result\":\"0\"}],\"data\":" + ex.getMessage() + "}"; } finally { DbPool.quietClose(conn); response.getWriter().println(result); } response.getWriter().close(); }