List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:org.etudes.component.app.melete.ModuleDB.java
private String getAllSectionIds(Map deletedSections) { StringBuffer allIds = null; String a = null;//from w ww . j a va 2s. c o m if (deletedSections != null) { allIds = new StringBuffer("("); for (Iterator i = deletedSections.keySet().iterator(); i.hasNext();) { Object obj = i.next(); allIds.append(obj + ","); } } if (allIds != null && allIds.lastIndexOf(",") != -1) a = allIds.substring(0, allIds.lastIndexOf(",")) + " )"; return a; }
From source file:lcmc.cluster.ui.ClusterBrowser.java
public void parseClusterOutput(final String output, final StringBuffer clusterStatusOutput, final Host host, final CountDownLatch firstTime, final Application.RunMode runMode) { final ClusterStatus clusterStatus0 = this.clusterStatus; clStatusLock();/* w w w .j a va 2s . co m*/ if (crmStatusCanceledByUser || clusterStatus0 == null) { clStatusUnlock(); firstTime.countDown(); return; } if (output == null || "".equals(output)) { clusterStatus0.setOnlineNode(host.getName(), "no"); setCrmStatus(host, false); firstTime.countDown(); } else { // TODO: if we get ERROR:... show it somewhere clusterStatusOutput.append(output); /* removes the string from the output. */ int s = clusterStatusOutput.indexOf(RESET_STRING); while (s >= 0) { clusterStatusOutput.delete(s, s + RESET_STRING_LEN); s = clusterStatusOutput.indexOf(RESET_STRING); } if (clusterStatusOutput.length() > 12) { final String e = clusterStatusOutput.substring(clusterStatusOutput.length() - 12); if (e.trim().equals("---done---")) { final int i = clusterStatusOutput.lastIndexOf("---start---"); if (i >= 0) { if (clusterStatusOutput.indexOf("is stopped") >= 0) { /* TODO: heartbeat's not running. */ } else { final String status = clusterStatusOutput.substring(i); clusterStatusOutput.delete(0, clusterStatusOutput.length()); if (CLUSTER_STATUS_ERROR.equals(status)) { final boolean oldStatus = host.isCrmStatusOk(); clusterStatus0.setOnlineNode(host.getName(), "no"); setCrmStatus(host, false); if (oldStatus) { crmGraph.repaint(); } } else { if (clusterStatus0.parseStatus(status)) { LOG.debug1("processClusterOutput: host: " + host.getName()); final ServicesInfo ssi = servicesInfo; rscDefaultsInfo.setParameters(clusterStatus0.getRscDefaultsValuePairs()); ssi.setGlobalConfig(clusterStatus0); resourceUpdaterProvider.get().updateAllResources(ssi, ssi.getBrowser(), clusterStatus0, runMode); if (firstTime.getCount() == 1) { /* one more time so that id-refs work.*/ resourceUpdaterProvider.get().updateAllResources(ssi, ssi.getBrowser(), clusterStatus0, runMode); } treeMenuController.repaintMenuTree(); clusterHostsInfo.updateTable(ClusterHostsInfo.MAIN_TABLE); } final String online = clusterStatus0.isOnlineNode(host.getName()); if ("yes".equals(online)) { setCrmStatus(host, true); setCrmStatus(); } else { setCrmStatus(host, false); } } } firstTime.countDown(); } } } Tools.chomp(clusterStatusOutput); } clStatusUnlock(); }
From source file:org.medici.bia.common.search.AdvancedSearchDocument.java
/** * {@inheritDoc}/*from w w w. j a va 2 s . c om*/ */ @Override public void initFromAdvancedSearchCommand(AdvancedSearchCommand command) { //Words if ((command.getWord() != null) && (command.getWord().size() > 0)) { wordsTypes = new ArrayList<WordType>(command.getWord().size()); words = new ArrayList<String>(command.getWord().size()); for (String singleWord : command.getWord()) { //MD: This is for refine search when the URLencoder change the space in "+" singleWord = singleWord.replace("+", "%20"); singleWord = singleWord.replace("\"", "%22"); singleWord = singleWord.replace("'", "%27"); //RR: And this is for replacing special characters with unicode values singleWord = URLTransformer.decode(singleWord); StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 2) { wordsTypes.add(WordType.valueOf(stringTokenizer.nextToken())); StringBuffer tempString = new StringBuffer( URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); if (StringUtils.countMatches(tempString.toString(), "\"") % 2 != 0) { tempString.setCharAt(tempString.lastIndexOf("\""), ' '); } words.add(tempString.toString()); } else { continue; } } catch (URIException uriException) { logger.debug(uriException); wordsTypes.remove(wordsTypes.size() - 1); } } } else { wordsTypes = new ArrayList<WordType>(0); words = new ArrayList<String>(0); } // Person if ((command.getPerson() != null) && (command.getPerson().size() > 0)) { personId = new ArrayList<Integer>(command.getPerson().size()); person = new ArrayList<String>(command.getPerson().size()); for (String singleWord : command.getPerson()) { //MD: This is for refine search when the URLencoder change the space in "+" singleWord = singleWord.replace("+", "%20"); //RR: And this is for replacing special characters with unicode values singleWord = URLTransformer.decode(singleWord); StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text personId.add(new Integer(0)); try { person.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); } catch (URIException uriException) { logger.debug(uriException); } } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { personId.add(NumberUtils.createInteger(singleId)); } else { //Empty personId is equal to 0 personId.add(new Integer(0)); } try { person.add(URIUtil.decode(singleText, "UTF-8")); } catch (URIException uriException) { logger.debug(uriException); personId.remove(personId.size() - 1); } } } catch (NumberFormatException nex) { logger.error(nex); } } } else { personId = new ArrayList<Integer>(0); person = new ArrayList<String>(0); } // Place if ((command.getPlace() != null) && (command.getPlace().size() > 0)) { placeId = new ArrayList<Integer>(command.getPlace().size()); place = new ArrayList<String>(command.getPlace().size()); for (String singleWord : command.getPlace()) { //MD: This is for refine search when the URLencoder change the space in "+" singleWord = singleWord.replace("+", "%20"); //RR: And this is for replacing special characters with unicode values singleWord = URLTransformer.decode(singleWord); StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text placeId.add(new Integer(0)); place.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { placeId.add(NumberUtils.createInteger(singleId)); } else { //Empty placeId is equal to 0 placeId.add(new Integer(0)); } place.add(URIUtil.decode(singleText, "UTF-8")); } } catch (NumberFormatException nex) { logger.debug(nex); } catch (URIException uriException) { logger.debug(uriException); placeId.remove(placeId.size() - 1); } } } else { placeId = new ArrayList<Integer>(0); place = new ArrayList<String>(0); } // Sender if ((command.getSender() != null) && (command.getSender().size() > 0)) { senderId = new ArrayList<Integer>(command.getSender().size()); sender = new ArrayList<String>(command.getSender().size()); for (String singleWord : command.getSender()) { StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text senderId.add(new Integer(0)); sender.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { senderId.add(NumberUtils.createInteger(singleId)); } else { //Empty senderId is equal to 0 senderId.add(new Integer(0)); } sender.add(URIUtil.decode(singleText, "UTF-8")); } } catch (NumberFormatException nex) { logger.debug(nex); } catch (URIException uriException) { logger.debug(uriException); senderId.remove(senderId.size() - 1); } } } else { senderId = new ArrayList<Integer>(0); sender = new ArrayList<String>(0); } // From if ((command.getFrom() != null) && (command.getFrom().size() > 0)) { fromId = new ArrayList<Integer>(command.getFrom().size()); from = new ArrayList<String>(command.getFrom().size()); for (String singleWord : command.getFrom()) { //MD: This is for refine search when the URLencoder change the space in "+" singleWord = singleWord.replace("+", "%20"); //RR: And this is for replacing special characters with unicode values singleWord = URLTransformer.decode(singleWord); StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text fromId.add(new Integer(0)); from.add(stringTokenizer.nextToken()); } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { fromId.add(NumberUtils.createInteger(singleId)); } else { //Empty fromId is equal to 0 fromId.add(new Integer(0)); } from.add(URIUtil.decode(singleText, "UTF-8")); } } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); fromId.remove(fromId.size() - 1); } } } else { fromId = new ArrayList<Integer>(0); from = new ArrayList<String>(0); } // Recipient if ((command.getRecipient() != null) && (command.getRecipient().size() > 0)) { recipientId = new ArrayList<Integer>(command.getRecipient().size()); recipient = new ArrayList<String>(command.getRecipient().size()); for (String singleWord : command.getRecipient()) { StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text recipientId.add(new Integer(0)); recipient.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { recipientId.add(NumberUtils.createInteger(singleId)); } else { //Empty recipientId is equal to 0 recipientId.add(new Integer(0)); } recipient.add(URIUtil.decode(singleText, "UTF-8")); } } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); recipientId.remove(recipientId.size() - 1); } } } else { recipientId = new ArrayList<Integer>(0); recipient = new ArrayList<String>(0); } // To if ((command.getTo() != null) && (command.getTo().size() > 0)) { toId = new ArrayList<Integer>(command.getTo().size()); to = new ArrayList<String>(command.getTo().size()); for (String singleWord : command.getTo()) { //MD: This is for refine search when the URLencoder change the space in "+" singleWord = singleWord.replace("+", "%20"); //RR: And this is for replacing special characters with unicode values singleWord = URLTransformer.decode(singleWord); StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text toId.add(new Integer(0)); to.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { toId.add(NumberUtils.createInteger(singleId)); } else { //Empty toId is equal to 0 toId.add(new Integer(0)); } to.add(URIUtil.decode(singleText, "UTF-8")); } } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); toId.remove(toId.size() - 1); } } } else { toId = new ArrayList<Integer>(0); to = new ArrayList<String>(0); } // ResTo; if ((command.getRefersTo() != null) && (command.getRefersTo().size() > 0)) { refersToId = new ArrayList<Integer>(command.getRefersTo().size()); refersTo = new ArrayList<String>(command.getRefersTo().size()); for (String singleWord : command.getRefersTo()) { StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); // string format is number|text try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is |text refersToId.add(new Integer(0)); refersTo.add(stringTokenizer.nextToken()); } else if (stringTokenizer.countTokens() == 2) { String singleId = stringTokenizer.nextToken(); String singleText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(singleId)) { refersToId.add(NumberUtils.createInteger(singleId)); } else { //Empty refersToId is equal to 0 refersToId.add(new Integer(0)); } refersTo.add(URIUtil.decode(singleText, "UTF-8")); } } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); refersToId.remove(refersToId.size() - 1); } } } else { refersToId = new ArrayList<Integer>(0); refersTo = new ArrayList<String>(0); } // Extract if ((command.getExtract() != null) && (command.getExtract().size() > 0)) { extract = new ArrayList<String>(command.getExtract().size()); for (String singleWord : command.getExtract()) { //MD: This is for refine search when the URLencoder change the space in "+" singleWord = singleWord.replace("+", "%20"); singleWord = singleWord.replace("\"", "%22"); singleWord = singleWord.replace("'", "%27"); //RR: And this is for replacing special characters with unicode values singleWord = URLTransformer.decode(singleWord); try { extract.add(URIUtil.decode(singleWord, "UTF-8")); } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); } } } else { extract = new ArrayList<String>(0); } // Synopsis if ((command.getSynopsis() != null) && (command.getSynopsis().size() > 0)) { synopsis = new ArrayList<String>(command.getSynopsis().size()); for (String singleWord : command.getSynopsis()) { singleWord = singleWord.replace("+", "%20"); singleWord = singleWord.replace("\"", "%22"); singleWord = singleWord.replace("'", "%27"); singleWord = URLTransformer.decode(singleWord); try { synopsis.add(URIUtil.decode(singleWord, "UTF-8")); } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); } } } else { synopsis = new ArrayList<String>(0); } // Topics if ((command.getTopic() != null) && (command.getTopic().size() > 0)) { topicsId = new ArrayList<Integer>(command.getTopic().size()); topics = new ArrayList<String>(command.getTopic().size()); topicsPlaceId = new ArrayList<Integer>(command.getTopic().size()); topicsPlace = new ArrayList<String>(command.getTopic().size()); for (String singleWord : command.getTopic()) { singleWord = singleWord.replace("+", "%20"); StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); try { if (stringTokenizer.countTokens() == 0) { continue; } else if (stringTokenizer.countTokens() == 1) { // string format is number String topicId = stringTokenizer.nextToken(); if (NumberUtils.isNumber(topicId)) { topicsId.add(NumberUtils.createInteger(topicId)); } else { //Empty topicsId is equal to 0 topicsId.add(new Integer(0)); } // topics.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); } else if (stringTokenizer.countTokens() == 2) { // string format is number|text String topicId = stringTokenizer.nextToken(); String topicText = stringTokenizer.nextToken(); // Check if field is correct if (NumberUtils.isNumber(topicId)) { topicsId.add(NumberUtils.createInteger(topicId)); } else { //Empty topicsId is equal to 0 topicsId.add(new Integer(0)); } topics.add(URIUtil.decode(topicText, "UTF-8")); } else if (stringTokenizer.countTokens() == 3) { //string format is number|text|number String singleId = stringTokenizer.nextToken(); String topicText = stringTokenizer.nextToken(); String placeId = stringTokenizer.nextToken(); if (NumberUtils.isNumber(singleId)) { topicsId.add(NumberUtils.createInteger(singleId)); } else { topicsId.add(new Integer(0)); } topics.add(URIUtil.decode(topicText, "UTF-8")); if (NumberUtils.isNumber(placeId)) { topicsPlaceId.add(NumberUtils.createInteger(placeId)); } else { topicsPlaceId.add(new Integer(0)); } } else if (stringTokenizer.countTokens() == 4) { //string format is number|text|number|text String singleId = stringTokenizer.nextToken(); String topicText = stringTokenizer.nextToken(); String placeId = stringTokenizer.nextToken(); String placeText = stringTokenizer.nextToken(); if (NumberUtils.isNumber(singleId)) { topicsId.add(NumberUtils.createInteger(singleId)); } else { topicsId.add(new Integer(0)); } topics.add(URIUtil.decode(topicText, "UTF-8")); if (NumberUtils.isNumber(placeId)) { topicsPlaceId.add(NumberUtils.createInteger(placeId)); } else { topicsPlaceId.add(new Integer(0)); } topicsPlace.add(URIUtil.decode(placeText, "UTF-8")); } } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); topicsId.remove(topicsId.size() - 1); topicsPlaceId.remove(topicsPlaceId.size() - 1); } } } else { topicsId = new ArrayList<Integer>(0); topics = new ArrayList<String>(0); } //Topics Place // Place // if ((command.getTopicPlace() != null) && (command.getTopicPlace().size() >0)) { // topicsPlaceId = new ArrayList<Integer>(command.getTopicPlace().size()); // topicsPlace = new ArrayList<String>(command.getTopicPlace().size()); // // for (String singleWord : command.getTopicPlace()) { // //MD: This is for refine search when the URLencoder change the space in "+" and the special character "\u00E7" in "%E7" // singleWord = singleWord.replace("+", "%20"); // singleWord = singleWord.replace("%E7", "\u00E7"); // // StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); // try { // if (stringTokenizer.countTokens() == 0) { // continue; // } else if (stringTokenizer.countTokens() == 1) { // // string format is |text // topicsPlaceId.add(new Integer(0)); // topicsPlace.add(URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); // } else if (stringTokenizer.countTokens() == 2) { // // string format is number|text // String singleId = stringTokenizer.nextToken(); // String singleText = stringTokenizer.nextToken(); // // Check if field is correct // if (NumberUtils.isNumber(singleId)) { // topicsPlaceId.add(NumberUtils.createInteger(singleId)); // } else { // //Empty placeId is equal to 0 // topicsPlaceId.add(new Integer(0)); // } // topicsPlace.add(URIUtil.decode(singleText, "UTF-8")); // } // } catch (NumberFormatException numberFormatException) { // logger.debug(numberFormatException); // } catch (URIException uriException) { // logger.debug(uriException); // topicsPlaceId.remove(topicsPlaceId.size()-1); // } // } // } else { // topicsPlaceId = new ArrayList<Integer>(0); // topicsPlace = new ArrayList<String>(0); // } //Date if ((command.getDate() != null) && (command.getDate().size() > 0)) { datesTypes = new ArrayList<DateType>(command.getDate().size()); datesYear = new ArrayList<Integer>(command.getDate().size()); datesMonth = new ArrayList<Integer>(command.getDate().size()); datesDay = new ArrayList<Integer>(command.getDate().size()); datesYearBetween = new ArrayList<Integer>(command.getDate().size()); datesMonthBetween = new ArrayList<Integer>(command.getDate().size()); datesDayBetween = new ArrayList<Integer>(command.getDate().size()); for (String singleWord : command.getDate()) { //e.g. After|1222|01|12|1223|12|12 String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|"); datesTypes.add(DateType.valueOf(fields[0])); datesYear.add(DateUtils.getDateYearFromString(fields[1])); datesMonth.add(DateUtils.getDateMonthFromString(fields[2])); datesDay.add(DateUtils.getDateDayFromString(fields[3])); datesYearBetween.add(DateUtils.getDateYearFromString(fields[4])); datesMonthBetween.add(DateUtils.getDateMonthFromString(fields[5])); datesDayBetween.add(DateUtils.getDateDayFromString(fields[6])); } } else { datesTypes = new ArrayList<DateType>(0); datesYear = new ArrayList<Integer>(0); datesMonth = new ArrayList<Integer>(0); datesDay = new ArrayList<Integer>(0); datesYearBetween = new ArrayList<Integer>(0); datesMonthBetween = new ArrayList<Integer>(0); datesDayBetween = new ArrayList<Integer>(0); } //Date Created if ((command.getDateCreated() != null) && (command.getDateCreated().size() > 0)) { datesCreatedTypes = new ArrayList<DateType>(command.getDateCreated().size()); datesCreated = new ArrayList<Date>(command.getDateCreated().size()); datesCreatedBetween = new ArrayList<Date>(command.getDateCreated().size()); for (String singleWord : command.getDateCreated()) { //e.g. After|20120112|20120112 String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|"); datesCreatedTypes.add(DateType.valueOf(fields[0])); datesCreated.add(DateUtils.getDateFromString(fields[1])); datesCreatedBetween.add(DateUtils.getDateFromString(fields[2])); } } else { datesCreatedTypes = new ArrayList<DateType>(0); datesCreated = new ArrayList<Date>(0); datesCreatedBetween = new ArrayList<Date>(0); } //Date lastUpdate if ((command.getDateLastUpdate() != null) && (command.getDateLastUpdate().size() > 0)) { datesLastUpdateTypes = new ArrayList<DateType>(command.getDateLastUpdate().size()); datesLastUpdate = new ArrayList<Date>(command.getDateLastUpdate().size()); datesLastUpdateBetween = new ArrayList<Date>(command.getDateLastUpdate().size()); for (String singleWord : command.getDateLastUpdate()) { //e.g. After|20120112|20120112 String[] fields = StringUtils.splitPreserveAllTokens(singleWord, "|"); datesLastUpdateTypes.add(DateType.valueOf(fields[0])); datesLastUpdate.add(DateUtils.getDateFromString(fields[1])); datesLastUpdateBetween.add(DateUtils.getDateFromString(fields[2])); } } else { datesLastUpdateTypes = new ArrayList<DateType>(0); datesLastUpdate = new ArrayList<Date>(0); datesLastUpdateBetween = new ArrayList<Date>(0); } //Volume if ((command.getVolume() != null) && (command.getVolume().size() > 0)) { volumesTypes = new ArrayList<VolumeType>(command.getVolume().size()); volumes = new ArrayList<String>(command.getVolume().size()); volumesBetween = new ArrayList<String>(command.getVolume().size()); for (String singleWord : command.getVolume()) { StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); if ((stringTokenizer.countTokens() == 0) || (stringTokenizer.countTokens() == 1)) { continue; } else if (stringTokenizer.countTokens() == 2) { // string format is Exactly|12 volumesTypes.add(VolumeType.valueOf(stringTokenizer.nextToken())); volumes.add(stringTokenizer.nextToken()); volumesBetween.add("0"); } else if (stringTokenizer.countTokens() == 3) { // string format is Exactly|12|16 volumesTypes.add(VolumeType.valueOf(stringTokenizer.nextToken())); volumes.add(stringTokenizer.nextToken()); volumesBetween.add(stringTokenizer.nextToken()); } } } else { volumesTypes = new ArrayList<VolumeType>(0); volumes = new ArrayList<String>(0); volumesBetween = new ArrayList<String>(0); } // Insert if ((command.getInsert() != null && command.getInsert().size() > 0)) { insertNums = new ArrayList<String>(command.getInsert().size()); for (String insert : command.getInsert()) { insertNums.add(insert); } } else { insertNums = new ArrayList<String>(0); } //Folio if ((command.getFolio() != null) && (command.getFolio().size() > 0)) { foliosTypes = new ArrayList<AdvancedSearchAbstract.FolioType>(command.getFolio().size()); folios = new ArrayList<String>(command.getFolio().size()); foliosBetween = new ArrayList<String>(command.getFolio().size()); for (String singleWord : command.getFolio()) { StringTokenizer stringTokenizer = new StringTokenizer(singleWord, "|"); if ((stringTokenizer.countTokens() == 0) || (stringTokenizer.countTokens() == 1)) { continue; } else if (stringTokenizer.countTokens() == 2) { foliosTypes.add(FolioType.valueOf(stringTokenizer.nextToken())); folios.add(stringTokenizer.nextToken()); foliosBetween.add("0"); } else if (stringTokenizer.countTokens() == 3) { foliosTypes.add(FolioType.valueOf(stringTokenizer.nextToken())); folios.add(stringTokenizer.nextToken()); foliosBetween.add(stringTokenizer.nextToken()); } } } else { foliosTypes = new ArrayList<AdvancedSearchAbstract.FolioType>(0); folios = new ArrayList<String>(0); foliosBetween = new ArrayList<String>(0); } //FolioMod if (command.getFolioMod() != null && command.getFolioMod().size() > 0) { folioMods = new ArrayList<String>(command.getFolioMod().size()); folioMods.addAll(command.getFolioMod()); } else { folioMods = new ArrayList<String>(0); } //EntryId if ((command.getDocId() != null) && (command.getDocId().size() > 0)) { docIds = new ArrayList<String>(command.getDocId().size()); for (String singleWord : command.getDocId()) { try { docIds.add(URIUtil.decode(singleWord, "UTF-8")); } catch (NumberFormatException numberFormatException) { logger.debug(numberFormatException); } catch (URIException uriException) { logger.debug(uriException); } } } else { docIds = new ArrayList<String>(0); } //LogicalDelete if (command.getLogicalDelete() != null) { if (command.getLogicalDelete().equals("true")) { logicalDelete = Boolean.TRUE; } else { logicalDelete = Boolean.FALSE; } } //Users if (command.getUser() != null) { userActionTypes = new ArrayList<UserActionType>(command.getUser().size()); users = new ArrayList<String>(command.getUser().size()); for (String singleUser : command.getUser()) { //MD: This is for refine search when the URLencoder change the space in "+" singleUser = singleUser.replace("+", "%20"); singleUser = singleUser.replace("\"", "%22"); singleUser = singleUser.replace("'", "%27"); //RR: And this is for replacing special characters with unicode values singleUser = URLTransformer.decode(singleUser); StringTokenizer stringTokenizer = new StringTokenizer(singleUser, "|"); try { if (stringTokenizer.countTokens() == 2) { userActionTypes.add(UserActionType.valueOf(stringTokenizer.nextToken())); StringBuffer tempString = new StringBuffer( URIUtil.decode(stringTokenizer.nextToken(), "UTF-8")); if (StringUtils.countMatches(tempString.toString(), "\"") % 2 != 0) { tempString.setCharAt(tempString.lastIndexOf("\""), ' '); } users.add(tempString.toString()); } else { continue; } } catch (URIException uriException) { logger.debug(uriException); wordsTypes.remove(wordsTypes.size() - 1); } } } else { userActionTypes = new ArrayList<UserActionType>(0); users = new ArrayList<String>(0); } }
From source file:org.kuali.ole.service.impl.OLEEResourceSearchServiceImpl.java
public void getNewInstance(OLEEResourceRecordDocument oleERSDoc, String documentNumber) throws Exception { if (OleDocstoreResponse.getInstance().getEditorResponse() != null) { HashMap<String, OLEEditorResponse> oleEditorResponses = OleDocstoreResponse.getInstance() .getEditorResponse();/*from w w w. j a va2 s.co m*/ OLEEditorResponse oleEditorResponse = oleEditorResponses.get(documentNumber); String separator = getParameter(OLEConstants.OLEEResourceRecord.COMMA_SEPARATOR); String isbnAndissn = ""; List<String> instanceId = new ArrayList<String>(); List<OLEEResourceInstance> oleeResourceInstances = oleERSDoc.getOleERSInstances(); if (oleeResourceInstances.size() == 0) { oleeResourceInstances = new ArrayList<OLEEResourceInstance>(); } // List<OleCopy> copyList = new ArrayList<>(); //getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(oleEditorResponse.getBib().getId()); if (oleEditorResponse != null && StringUtils.isNotEmpty(oleEditorResponse.getLinkedInstanceId())) { instanceId.add(oleEditorResponse.getLinkedInstanceId()); } Holdings holdings = null; if (oleEditorResponse != null && oleERSDoc.getSelectInstance() != null && (oleERSDoc.getSelectInstance().equals(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE)) || oleERSDoc.getSelectInstance().equals(OLEConstants.OLEEResourceRecord.CREATE_NEW_INSTANCE)) { holdings = getDocstoreClientLocator().getDocstoreClient() .retrieveHoldings(oleEditorResponse.getLinkedInstanceId()); } int index = -1; if (holdings != null && holdings.getId() != null) { HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor(); OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent()); if (holdings instanceof org.kuali.ole.docstore.common.document.EHoldings) { if (oleEditorResponse != null && oleEditorResponse.getLinkedInstanceId().equalsIgnoreCase(holdings.getId())) { OLEEResourceInstance oleeResourceInstance = new OLEEResourceInstance(); if (oleERSDoc.getOleERSInstances() != null && oleERSDoc.getOleERSInstances().size() > 0) { for (OLEEResourceInstance eResourceInstance : oleeResourceInstances) { if (eResourceInstance.getInstanceId() .equals(oleEditorResponse.getLinkedInstanceId())) { index = oleeResourceInstances.indexOf(eResourceInstance); oleeResourceInstance = eResourceInstance; } } } oleeResourceInstance.setInstanceTitle(holdings.getBib().getTitle()); getHoldingsField(oleeResourceInstance, oleHoldings); oleeResourceInstance.setInstancePublisher(oleHoldings.getPublisher()); oleeResourceInstance.setPlatForm(oleHoldings.getPlatform().getPlatformName()); // oleeResourceInstance.setPublicDisplayNote(workEInstanceDocument.getPublicDisplayNote()); StringBuffer urls = new StringBuffer(); for (Link link : oleHoldings.getLink()) { urls.append(link.getUrl()); urls.append(","); } if (urls.toString().contains(",")) { String url = urls.substring(0, urls.lastIndexOf(",")); oleeResourceInstance.setUrl(url); } SearchParams searchParams = new SearchParams(); searchParams.getSearchConditions() .add(searchParams.buildSearchCondition(null, searchParams.buildSearchField(OLEConstants.BIB_DOC_TYPE, OLEConstants.BIB_SEARCH, holdings.getBib().getId()), null)); searchParams.getSearchResultFields().add(searchParams.buildSearchResultField( OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISBN)); searchParams.getSearchResultFields().add(searchParams.buildSearchResultField( OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISSN)); SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient() .search(searchParams); SearchResult searchResult; if (searchResponse.getSearchResults().size() > 0) { searchResult = searchResponse.getSearchResults().get(0); searchResult.getSearchResultFields(); for (SearchResultField searchResultField : searchResult.getSearchResultFields()) { isbnAndissn += searchResultField.getFieldValue(); isbnAndissn += separator; } } if (StringUtils.isNotEmpty(isbnAndissn)) { isbnAndissn = isbnAndissn.substring(0, isbnAndissn.lastIndexOf(separator)); } oleeResourceInstance.setIsbn(isbnAndissn); oleeResourceInstance.setStatus(oleHoldings.getAccessStatus()); oleeResourceInstance.setSubscriptionStatus(oleHoldings.getSubscriptionStatus()); oleeResourceInstance.setBibId(holdings.getBib().getId()); oleeResourceInstance.setInstanceId(holdings.getId()); oleeResourceInstance.setInstanceFlag("false"); if (index >= 0) { oleeResourceInstances.add(index, oleeResourceInstance); } else { oleeResourceInstances.add(oleeResourceInstance); } updateEResInOleCopy(holdings, oleERSDoc); } } if (holdings instanceof org.kuali.ole.docstore.common.document.PHoldings) { if (oleEditorResponse != null && oleEditorResponse.getLinkedInstanceId().equalsIgnoreCase(holdings.getId())) { OLEEResourceInstance oleeResourceInstance = new OLEEResourceInstance(); if (oleERSDoc.getOleERSInstances() != null && oleERSDoc.getOleERSInstances().size() > 0) { for (OLEEResourceInstance eResourceInstance : oleeResourceInstances) { if (eResourceInstance.getInstanceId() .equals(oleEditorResponse.getLinkedInstanceId())) { index = oleeResourceInstances.indexOf(eResourceInstance); oleeResourceInstance = eResourceInstance; } } } oleeResourceInstance.setInstanceTitle(holdings.getBib().getTitle()); oleeResourceInstance.setInstancePublisher(holdings.getBib().getPublisher()); SearchParams searchParams = new SearchParams(); searchParams.getSearchConditions() .add(searchParams.buildSearchCondition(null, searchParams.buildSearchField(OLEConstants.BIB_DOC_TYPE, OLEConstants.BIB_SEARCH, holdings.getBib().getId()), null)); searchParams.getSearchResultFields().add(searchParams.buildSearchResultField( OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISBN)); searchParams.getSearchResultFields().add(searchParams.buildSearchResultField( OLEConstants.BIB_DOC_TYPE, OLEConstants.OLEEResourceRecord.ERESOURCE_ISSN)); SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient() .search(searchParams); SearchResult searchResult; if (searchResponse.getSearchResults().size() > 0) { searchResult = searchResponse.getSearchResults().get(0); searchResult.getSearchResultFields(); for (SearchResultField searchResultField : searchResult.getSearchResultFields()) { isbnAndissn += searchResultField.getFieldValue(); isbnAndissn += separator; } } if (StringUtils.isNotEmpty(isbnAndissn)) { isbnAndissn = isbnAndissn.substring(0, isbnAndissn.lastIndexOf(separator)); } oleeResourceInstance.setIsbn(isbnAndissn); oleeResourceInstance.setBibId(holdings.getBib().getId()); oleeResourceInstance.setInstanceId(holdings.getId()); oleeResourceInstance.setHoldingsId(oleHoldings.getHoldingsIdentifier()); oleeResourceInstance.setInstanceFlag("true"); if (index >= 0) { oleeResourceInstances.add(index, oleeResourceInstance); } else { oleeResourceInstances.add(oleeResourceInstance); } updateEResInOleCopy(holdings, oleERSDoc); } } } oleERSDoc.setOleERSInstances(oleeResourceInstances); OleDocstoreResponse.getInstance().setEditorResponse(null); } }
From source file:lcmc.gui.ClusterBrowser.java
/** Process output from cluster. */ void processClusterOutput(final String output, final StringBuffer clusterStatusOutput, final Host host, final CountDownLatch firstTime, final boolean testOnly) { final ClusterStatus clStatus = clusterStatus; clStatusLock();// w ww . ja v a 2 s. co m if (clStatusCanceled || clStatus == null) { clStatusUnlock(); firstTime.countDown(); return; } if (output == null || "".equals(output)) { clStatus.setOnlineNode(host.getName(), "no"); setClStatus(host, false); firstTime.countDown(); } else { // TODO: if we get ERROR:... show it somewhere clusterStatusOutput.append(output); /* removes the string from the output. */ int s = clusterStatusOutput.indexOf(RESET_STRING); while (s >= 0) { clusterStatusOutput.delete(s, s + RESET_STRING_LEN); s = clusterStatusOutput.indexOf(RESET_STRING); } if (clusterStatusOutput.length() > 12) { final String e = clusterStatusOutput.substring(clusterStatusOutput.length() - 12); if (e.trim().equals("---done---")) { final int i = clusterStatusOutput.lastIndexOf("---start---"); if (i >= 0) { if (clusterStatusOutput.indexOf("is stopped") >= 0) { /* TODO: heartbeat's not running. */ } else { final String status = clusterStatusOutput.substring(i); clusterStatusOutput.delete(0, clusterStatusOutput.length()); if (CLUSTER_STATUS_ERROR.equals(status)) { final boolean oldStatus = host.isClStatus(); clStatus.setOnlineNode(host.getName(), "no"); setClStatus(host, false); if (oldStatus) { crmGraph.repaint(); } } else { if (clStatus.parseStatus(status)) { Tools.debug(this, "update cluster status: " + host.getName(), 1); final ServicesInfo ssi = servicesInfo; rscDefaultsInfo.setParameters(clStatus.getRscDefaultsValuePairs()); ssi.setGlobalConfig(clStatus); ssi.setAllResources(clStatus, testOnly); if (firstTime.getCount() == 1) { /* one more time so that id-refs work.*/ ssi.setAllResources(clStatus, testOnly); } repaintTree(); clusterHostsInfo.updateTable(ClusterHostsInfo.MAIN_TABLE); } final String online = clStatus.isOnlineNode(host.getName()); if ("yes".equals(online)) { setClStatus(host, true); setClStatus(); } else { setClStatus(host, false); } } } firstTime.countDown(); } } } Tools.chomp(clusterStatusOutput); } clStatusUnlock(); }
From source file:org.etudes.component.app.melete.ModuleDB.java
private String getDelSectionIds(Session session, int moduleId) { StringBuffer delIds = null; String a = null;/*from w w w.ja va 2s . com*/ String selectDelsecStr = "select sec.sectionId from Section sec where sec.deleteFlag=1 and sec.moduleId=:moduleId"; List<String> deletedSections = session.createQuery(selectDelsecStr).setInteger("moduleId", moduleId).list(); if (deletedSections != null) { delIds = new StringBuffer("("); for (Iterator i = deletedSections.iterator(); i.hasNext();) { Object obj = i.next(); delIds.append(obj + ","); } } if (delIds != null && delIds.lastIndexOf(",") != -1) a = delIds.substring(0, delIds.lastIndexOf(",")) + " )"; return a; }
From source file:com.orientechnologies.orient.jdbc.H2.java
public static Collection<String> translate(String sql) throws SQLException { List<String> sections = new ArrayList<String>(); if (StringUtils.isNotEmpty(sql)) { boolean quoted = false; int bracesOpen = 0; boolean create = false; boolean type = false; boolean typeLen = false; boolean not = false; int max = 0; String lastWord = null;/*from w w w . ja v a 2 s . c o m*/ String className = null; String fieldName = null; boolean classNameAppended = false; StringBuffer section = new StringBuffer(); for (final StringTokenizer splitter = new StringTokenizer(sql, " ();,'`\r\n\t", true); splitter .hasMoreTokens();) { String w = splitter.nextToken(); if (w.length() == 0) continue; if (!quoted) { w = w.toUpperCase(); if (stripWords.contains(w) || (SPACE.equals(w))) section.append(SPACE_CHAR); else if (QUOTE.equals(w) || QUOTE_ALT.equals(w)) { section.append(w); if (QUOTE_ALT.equals(w) && !quoted) w = QUOTE; if (QUOTE.equals(w) && !QUOTE.equals(lastWord)) quoted = !quoted; } else if (BRACE_OPEN.equals(w)) { bracesOpen++; if (create) { trim(section); if (!type) { sections.add(section.toString()); section = new StringBuffer("CREATE PROPERTY "); section.append(className).append('.'); } else { sections.add(section.toString()); section = new StringBuffer("ALTER PROPERTY "); section.append(className).append('.'); section.append(fieldName).append(" MAX "); typeLen = true; } } else section.append(w); } else if (BRACE_CLOSED.equals(w)) { bracesOpen--; if (create) { if (typeLen) { trim(section); section.append(SPACE_CHAR).append(max); typeLen = false; max = 0; section.append(SPACE_CHAR); continue; } else if (type) { type = false; classNameAppended = false; } else create = false; } section.append(w); } else if (COMMA.equals(w)) { if (create) { if (type) { if (!typeLen) { trim(section); sections.add(section.toString()); section = new StringBuffer("CREATE PROPERTY "); section.append(className).append('.'); type = false; classNameAppended = true; fieldName = null; } else max++; } else section.append(w); } } else if (create) { if (type) { boolean suppw = supportedWords.contains(w); if (typeLen || suppw) { if (suppw) { if (NOT.equals(w)) { not = true; continue; } else { trim(section); sections.add(section.toString()); section = new StringBuffer("ALTER PROPERTY "); section.append(className).append('.'); section.append(fieldName); if (not) { section.append(" NOT"); not = false; } if (NULL.equals(w)) { if (section.lastIndexOf(NOT) == section.length() - 3) section.append(w).append("=TRUE"); else section.append(SPACE_CHAR).append(NOT).append(w).append("=FALSE"); } else section.append(w); } } else max += Integer.parseInt(w); } else { final String mtype = typeMap.get(w); if (StringUtils.isEmpty(mtype)) throw new SQLException(String .format("Sorry, type %s is not supported by Orient at the moment.", w)); section.append(mtype); } } else if (!classNameAppended) { className = w; section.append(className); classNameAppended = true; } else { if (section.charAt(section.length() - 1) == SPACE_CHAR) section.deleteCharAt(section.length() - 1); section.append(w); fieldName = w; type = true; } } else if (supportedWords.contains(w)) section.append(w); else if (SEMICOLON.equals(w)) { trim(section); sections.add(section.toString()); section = new StringBuffer(); } else if (TABLE.equals(w)) { section.append(CLASS); create = true; } else section.append(w); } else section.append(w); } } return sections; }
From source file:org.safs.selenium.util.JavaScriptFunctions.java
/** * Compare 2 javascript objects.<br> * /* ww w . j a v a 2 s .c o m*/ * <pre> * StringBuffer jsScript = new StringBuffer(); * List<String> properties = new List<String>(); * properties.add("value"); * properties.add("id"); * properties.add("name"); * jsScript.append(JavaScriptFunctions.compareObject(properties)); * //object1 and object2 are javascript objects. * jsScript.append("return compareObject(object1, object2);"); * boolean equaled = WDLibrary.executeScript(jsScript.toString()); * </pre> * * <br><b>depending on: nothing.</b><br> * <br><b>depending level: 0</b><br> * * @param properties List, the property names to get value to compare between 2 objects. * @param object1 (<b>Javascript</b>) Object, the javascript object to compare * @param object2 (<b>Javascript</b>) Object, the javascript object to compare */ public static String compareObject(List<String> properties) { StringBuffer scriptCommand = new StringBuffer(); scriptCommand.append("function compareObject(obj1, obj2){\n"); scriptCommand.append(" equaled = false;\n"); scriptCommand.append(" try{\n"); scriptCommand.append(" if(obj1==obj2) equaled=true;\n"); scriptCommand.append(" if(!equaled){\n"); //compare each property of the 2 objects. if (!properties.isEmpty()) { scriptCommand.append(" equaled=("); for (String property : properties) { scriptCommand.append("obj1." + property + "==obj2." + property + " &&"); } int lastAndSignIndex = scriptCommand.lastIndexOf("&&"); scriptCommand.replace(lastAndSignIndex, scriptCommand.length(), ");\n"); } scriptCommand.append(" }\n"); scriptCommand.append(" }catch(error){}\n"); scriptCommand.append(" return equaled;\n"); scriptCommand.append("}\n"); return scriptCommand.toString(); }
From source file:com.xn.interfacetest.service.impl.TestCaseServiceImpl.java
private String formatParams(TestCaseDto caseDto, String contentType, TestInterfaceDto interfaceDto) { //?,???,???/*from w w w . j ava2 s . c o m*/ StringBuffer paramsStr = new StringBuffer(""); if (null != caseDto.getParamsType() && ParamsGroupTypeEnum.KEY.getId() == caseDto.getParamsType()) { //?? List<ParamDto> testParamsDtoList = testParamsService.listByCaseIdFromRelation(caseDto.getId()); if (contentType.equals("application/json")) { logger.info("??json" + testParamsDtoList.size() + "?"); //?json if (null != testParamsDtoList && testParamsDtoList.size() > 0) { JSONObject jsonObject = new JSONObject(); Iterator iterator = testParamsDtoList.iterator(); //---??? Date date = new Date(); while (iterator.hasNext()) { ParamDto param = (ParamDto) iterator.next(); logger.info("?" + param.toString()); String value = param.getValue(); //?? if (param.getFormatType() == ParamFormatTypeEnum.ENCRYPT.getId()) { //?,??? value = encrypt(interfaceDto.getJarPath(), interfaceDto, caseDto.getId(), param.getMethodName(), date); logger.info("????" + param.getName() + "," + value); } else if (value.equals("timestamp")) { // value = (date.getTime()) + ""; } jsonObject.put(param.getName(), value); } paramsStr = paramsStr.append(jsonObject.toString()); logger.info("??" + paramsStr); } } else { logger.info("??&?" + testParamsDtoList.size() + "?"); //? if (null != testParamsDtoList && testParamsDtoList.size() > 0) { Iterator iterator = testParamsDtoList.iterator(); //---??? Date date = new Date(); while (iterator.hasNext()) { ParamDto param = (ParamDto) iterator.next(); String value = param.getValue(); //?? if (param.getFormatType() == ParamFormatTypeEnum.ENCRYPT.getId()) { //?,??? value = encrypt(interfaceDto.getJarPath(), interfaceDto, caseDto.getId(), param.getMethodName(), date); logger.info("????" + param.getName() + "," + value); } else if (value.equals("timestamp")) { // value = (date.getTime()) + ""; } paramsStr.append(param.getName() + "=" + param.getValue()); paramsStr.append("&"); } paramsStr = new StringBuffer(paramsStr.substring(0, paramsStr.lastIndexOf("&"))); } } } else if (null != caseDto.getParamsType() && ParamsGroupTypeEnum.CUSTOM.getId() == caseDto.getParamsType()) { //?? logger.info("?" + caseDto.getCustomParams()); paramsStr = new StringBuffer(caseDto.getCustomParams()); } return paramsStr.toString(); }
From source file:org.etudes.component.app.melete.ModuleDB.java
public void deleteModules(List delModules, List allModules, String courseId, String userId) throws Exception { long starttime = System.currentTimeMillis(); Transaction tx = null;/*from w ww. j a va2 s . com*/ //If not all modules of the course need to be deleted if (delModules.size() != allModules.size()) { logger.debug("delete some Modules begin"); ArrayList<DelModuleInfo> DelModuleInfoList = new ArrayList<DelModuleInfo>(0); List delResourcesList; try { // Get resources for modules that need to be deleted delResourcesList = getActiveResourcesFromList(delModules); allModules.removeAll(delModules); if ((delResourcesList != null) && (delResourcesList.size() > 0)) { List<String> allActiveResources = getActiveResourcesFromList(allModules); if (allActiveResources != null && delResourcesList != null) { logger.debug("active list and all" + delResourcesList.size() + " ; " + allActiveResources.size()); delResourcesList.removeAll(allActiveResources); } } // get all module-ids and section_ids // update seq_no for each deleted_module StringBuffer allModuleIds = new StringBuffer("("); StringBuffer allSectionIds = new StringBuffer("("); ArrayList<StringBuffer> allSectionIdsArray = new ArrayList<StringBuffer>(); String delModuleIds = null; //String delSectionIds = null; int count = 1; for (Iterator dmIter = delModules.iterator(); dmIter.hasNext();) { Module dm = (Module) dmIter.next(); allModuleIds.append(dm.getModuleId().toString() + ","); Map delSections = dm.getSections(); if (delSections != null && !delSections.isEmpty()) { for (Iterator i = delSections.keySet().iterator(); i.hasNext();) { if (count % MAX_IN_CLAUSES == 0) { allSectionIds.append(i.next() + ")"); allSectionIdsArray.add(allSectionIds); allSectionIds = new StringBuffer("("); } else { allSectionIds.append(i.next() + ","); } count++; } } Map delDeletedSections = dm.getDeletedSections(); if (delDeletedSections != null && !delDeletedSections.isEmpty()) { for (Iterator i1 = delDeletedSections.keySet().iterator(); i1.hasNext();) { if (count % MAX_IN_CLAUSES == 0) { allSectionIds.append(i1.next() + ")"); allSectionIdsArray.add(allSectionIds); allSectionIds = new StringBuffer("("); } else { allSectionIds.append(i1.next() + ","); } count++; } } // record seq_no and id DelModuleInfoList .add(new DelModuleInfo(dm.getModuleId().toString(), dm.getCoursemodule().getSeqNo())); } if (allModuleIds.lastIndexOf(",") != -1) delModuleIds = allModuleIds.substring(0, allModuleIds.lastIndexOf(",")) + " )"; //if (allSectionIds.lastIndexOf(",") != -1) delSectionIds = allSectionIds.substring(0, allSectionIds.lastIndexOf(",")) + " )"; if (allSectionIds.lastIndexOf(",") != -1) { if (count % MAX_IN_CLAUSES != 0) { allSectionIds.replace(allSectionIds.lastIndexOf(","), allSectionIds.lastIndexOf(",") + 1, ")"); allSectionIdsArray.add(allSectionIds); } } Session session = hibernateUtil.currentSession(); tx = session.beginTransaction(); String delMeleteResourceStr; int deletedEntities; // delete modules and sections String updSectionResourceStr = "update SectionResource sr set sr.resource = null where sr.section in "; String delSectionResourceStr = "delete SectionResource sr where sr.section in "; String delBookmarksStr = "delete Bookmark bm where bm.sectionId in "; String delSectionStr = "delete Section s where s.moduleId in " + delModuleIds; String delCourseModuleStr = "delete CourseModule cm where cm.moduleId in " + delModuleIds; String delModuleshDatesStr = "delete ModuleShdates msh where msh.moduleId in " + delModuleIds; String delSpecialAccStr = "delete SpecialAccess sa where sa.moduleId in " + delModuleIds; String delModuleStr = "delete Module m where m.moduleId in " + delModuleIds; if (allSectionIdsArray != null) { for (int i = 0; i < allSectionIdsArray.size(); i++) { allSectionIds = allSectionIdsArray.get(i); deletedEntities = session.createQuery(updSectionResourceStr + allSectionIds.toString()) .executeUpdate(); deletedEntities = session.createQuery(delSectionResourceStr + allSectionIds.toString()) .executeUpdate(); logger.debug("section resource deleted" + deletedEntities); deletedEntities = session.createQuery(delBookmarksStr + allSectionIds.toString()) .executeUpdate(); logger.debug("Boomkarks deleted " + deletedEntities); } } if (delModuleIds != null) { deletedEntities = session.createQuery(delSectionStr).executeUpdate(); logger.debug("section deleted" + deletedEntities); deletedEntities = session.createQuery(delCourseModuleStr).executeUpdate(); logger.debug("course module deleted" + deletedEntities); deletedEntities = session.createQuery(delModuleshDatesStr).executeUpdate(); deletedEntities = session.createQuery(delSpecialAccStr).executeUpdate(); logger.debug("special access deleted" + deletedEntities); deletedEntities = session.createQuery(delModuleStr).executeUpdate(); logger.debug("module deleted" + deletedEntities); } // delete module collection logger.debug("updating seq_number now"); List<CourseModule> courseModules = new ArrayList<CourseModule>(0); for (ListIterator i = allModules.listIterator(); i.hasNext();) { Module mdbean = (Module) i.next(); courseModules.add((CourseModule) mdbean.getCoursemodule()); } assignSeqs(session, courseModules); // delete resources if ((delResourcesList != null) && (delResourcesList.size() > 0)) { StringBuffer delResourceIds = new StringBuffer("("); // delete melete resource and from content resource for (Iterator delIter = delResourcesList.listIterator(); delIter.hasNext();) { String delResourceId = (String) delIter.next(); if ((delResourceId == null) || (delResourceId.trim().length() == 0)) { logger.warn("NULL or empty resource id found in delete process "); continue; } delResourceIds.append("'" + delResourceId + "',"); } //Ensuring that there are no empty resource ids if ((delResourceIds.length() > 4) && (delResourceIds.lastIndexOf(",") != -1)) { delResourceIds = new StringBuffer( delResourceIds.substring(0, delResourceIds.lastIndexOf(",")) + " )"); delMeleteResourceStr = "delete MeleteResource mr where mr.resourceId in " + delResourceIds; deletedEntities = session.createQuery(delMeleteResourceStr).executeUpdate(); logger.debug("melete resource deleted" + deletedEntities); } } tx.commit(); } catch (HibernateException he) { if (tx != null) tx.rollback(); logger.error(he.toString()); throw he; } catch (Exception e) { if (tx != null) tx.rollback(); logger.error(e.toString()); e.printStackTrace(); throw e; } finally { try { hibernateUtil.closeSession(); } catch (HibernateException he) { logger.error(he.toString()); throw he; } } logger.debug("Successfully cleared Melete tables"); logger.debug("Removing module collections now"); Collections.reverse(DelModuleInfoList); for (DelModuleInfo dmi : DelModuleInfoList) { meleteCHService.removeCollection(courseId, "module_" + dmi.getId()); } logger.debug("Removing upload collection resources"); for (Iterator delIter = delResourcesList.listIterator(); delIter.hasNext();) { String delResourceId = (String) delIter.next(); if ((delResourceId == null) || (delResourceId.trim().length() == 0)) { logger.warn("NULL or empty resource id found in delete process "); continue; } //TypeEditor sections will have been removed already if (delResourceId.startsWith("/private/meleteDocs/" + courseId + "/uploads/")) { meleteCHService.removeResource(delResourceId); } } long endtime = System.currentTimeMillis(); logger.debug("delete some modules ends " + (endtime - starttime)); } else { logger.debug("delete all Modules begin"); try { Session session = hibernateUtil.currentSession(); tx = session.beginTransaction(); StringBuffer allModuleIds = new StringBuffer("("); String delModuleIds = null; for (Iterator dmIter = delModules.iterator(); dmIter.hasNext();) { Module dm = (Module) dmIter.next(); allModuleIds.append(dm.getModuleId().toString() + ","); } if (allModuleIds.lastIndexOf(",") != -1) delModuleIds = allModuleIds.substring(0, allModuleIds.lastIndexOf(",")) + " )"; deleteEverything(courseId, session, delModuleIds); //remove entire collection try { meleteCHService.removeCollection(courseId, null); } catch (Exception removeColl) { //do nothing } tx.commit(); } catch (HibernateException he) { if (tx != null) tx.rollback(); logger.error(he.toString()); throw he; } catch (Exception e) { if (tx != null) tx.rollback(); logger.error(e.toString()); e.printStackTrace(); throw e; } finally { try { hibernateUtil.closeSession(); } catch (HibernateException he) { logger.error(he.toString()); throw he; } } long endtime = System.currentTimeMillis(); logger.debug("delete all modules ends " + (endtime - starttime)); } }