Example usage for org.apache.commons.lang3 StringUtils abbreviate

List of usage examples for org.apache.commons.lang3 StringUtils abbreviate

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils abbreviate.

Prototype

public static String abbreviate(final String str, final int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

private Map<Long, String> getFactorNames(ExpressionExperiment ee, int maxWidth) {
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();

    Map<Long, String> efs = new HashMap<>();
    for (ExperimentalFactor ef : factors) {
        efs.put(ef.getId(), StringUtils.abbreviate(StringUtils.capitalize(ef.getName()), maxWidth));
    }//ww w  .j a va2s .com
    return efs;
}

From source file:ubic.gemma.web.taglib.expression.experiment.AssayViewTag.java

@Override
public int doStartTag() throws JspException {

    StringBuilder buf = new StringBuilder();

    buf.append("<div>");

    // create table
    Map<BioMaterialValueObject, Map<ArrayDesignValueObject, Collection<BioAssayValueObject>>> bioAssayMap = new HashMap<>();
    Set<ArrayDesignValueObject> designs = new HashSet<>();
    Map<ArrayDesignValueObject, Long> arrayMaterialCount = new HashMap<>();

    // package all of this information into JSON for javascript dynamic retrieval
    Map<String, String> assayToMaterial = new HashMap<>();
    for (BioAssayValueObject assay : bioAssays) {
        // map for bioassays linked to a specific arraydesign
        // map for the bioassays linked to a specific biomaterial
        BioMaterialValueObject material = assay.getSample();
        ArrayDesignValueObject design = assay.getArrayDesign();
        designs.add(design);// ww  w. ja v  a 2s.  c o m

        // check if the assay list is initialized yet
        Map<ArrayDesignValueObject, Collection<BioAssayValueObject>> assayMap;
        if (bioAssayMap.containsKey(material)) {
            assayMap = bioAssayMap.get(material);
        } else {
            assayMap = new HashMap<>();
            bioAssayMap.put(material, assayMap);
        }

        if (assayMap.containsKey(design)) {
            assayMap.get(design).add(assay);
        } else {
            Collection<BioAssayValueObject> assayList = new ArrayList<>();
            assayList.add(assay);
            assayMap.put(design, assayList);
        }

        if (arrayMaterialCount.containsKey(design)) {
            Long count = arrayMaterialCount.get(design);
            count++;
            arrayMaterialCount.put(design, count);
        } else {
            Long count = new Long(1);
            arrayMaterialCount.put(design, count);
        }

    }
    int materialCount = bioAssayMap.keySet().size();
    buf.append("<table class='detail row-separated odd-gray'><tr>");
    buf.append("<th>" + materialCount + " BioMaterials</th>");
    // display arraydesigns
    for (ArrayDesignValueObject design : designs) {
        Long count = arrayMaterialCount.get(design);
        buf.append("<th>" + count + " BioAssays on<br /><a target='_blank' href=\"" + Settings.getRootContext()
                + "/arrays/showArrayDesign.html?id=" + design.getId() + "\" title=\"" + design.getName()
                + "\" >" + (design.getShortName() == null ? design.getName() : design.getShortName())
                + "</a></th>");
    }
    buf.append("</tr>");

    // display bioMaterials and the corresponding bioAssays
    int count = 1;

    Iterator<BioMaterialValueObject> iter = bioAssayMap.keySet().iterator();
    List<BioMaterialValueObject> materials = new ArrayList<>();
    while (iter.hasNext()) {
        materials.add(iter.next());
    }
    Comparator<BioMaterialValueObject> comparator = new BioMaterialComparator();
    Collections.sort(materials, comparator);
    int elementCount = 1;
    int emptyCount = 0;
    for (BioMaterialValueObject material : materials) {
        if (count % 2 == 0) {
            buf.append("<tr class='even' align=justify>");
        } else {
            buf.append("<tr class='odd' align=justify>");
        }

        String bmLink = "<a href='" + Settings.getRootContext() + "/bioMaterial/showBioMaterial.html?id="
                + material.getId() + "'> " + material.getName() + "</a>";
        buf.append("<td>" + bmLink + "</td>");

        Map<ArrayDesignValueObject, Collection<BioAssayValueObject>> assayMap = bioAssayMap.get(material);

        String image = "&nbsp;&nbsp;&nbsp;<img height=16 width=16 src='" + Settings.getRootContext()
                + "/images/icons/arrow_switch.png' />&nbsp;&nbsp;&nbsp;";
        for (ArrayDesignValueObject design : designs) {
            if (assayMap.containsKey(design)) {
                Collection<BioAssayValueObject> assays = assayMap.get(design);
                Collection<Long> ids = new ArrayList<>();
                Collection<String> tooltips = new ArrayList<>();
                for (BioAssayValueObject assay : assays) {
                    ids.add(assay.getId());
                    tooltips.add(StringUtils.abbreviate(assay.getName() + assay.getDescription(), 120));
                    this.addMaterial(assayToMaterial, assay.getId(), material.getId());
                }

                if (assayMap.get(design).size() > 1) {
                    String link = "<a title='" + StringUtils.join(tooltips.toArray(), "\n") + "' href='"
                            + Settings.getRootContext() + "/bioAssay/showAllBioAssays.html?id="
                            + StringUtils.join(ids.toArray(), ",") + "'> (list) </a>";
                    buf.append(
                            "<td>" + assayMap.get(design).size() + link + "&nbsp;" + elementCount + "</td>\n");

                } else {

                    /*
                     * Each bioassay has a unique id; the div it sits in is identified by the class 'dragitem'. See
                     * expressionExperiment.edit.jsp.
                     */

                    BioAssayValueObject assay = ((List<BioAssayValueObject>) assayMap.get(design)).get(0);
                    String shortDesc = StringUtils.abbreviate(assay.getDescription(), 60);
                    String link = "<a target=\"_blank\" title='" + shortDesc + "' href='"
                            + Settings.getRootContext() + "/bioAssay/showBioAssay.html?id=" + assay.getId()
                            + "'>" + assay.getName() + "</a>";
                    String editAttributes = " align='left' class='dragItem' id='bioassay." + assay.getId()
                            + "' material='" + material.getId() + "' assay='" + assay.getId()
                            + "' arrayDesign='" + design.getId() + "'";
                    if (edit && designs.size() > 1) {
                        buf.append("\n<td><span " + editAttributes + ">" + image + link);
                    } else {
                        buf.append("\n<td ><span>" + link + "&nbsp;");
                    }
                    buf.append("</span></td>\n");
                }

            } else {
                emptyCount = addEmpty(buf, assayToMaterial, emptyCount, material, image, design);
            }
        }

        buf.append("</tr>");
        count++;
        elementCount++;
    }

    // add a few blanks, but only if we are editing.
    if (edit) {
        addNovelBiomaterialSlots(buf, designs, assayToMaterial, count, emptyCount);
    }

    buf.append("</table>");

    if (edit) {
        // append JSON serialization
        try {
            String jsonSerialization = JSONMapper.toJSON(assayToMaterial).render(false);
            buf.append("<input type='hidden' id='assayToMaterialMap' name='assayToMaterialMap' value='"
                    + jsonSerialization + "'/>");
        } catch (MapperException e) {
            // cannot serialize
        }

    }

    buf.append("</div>");

    try {
        pageContext.getOut().print(buf.toString());
    } catch (Exception ex) {
        throw new JspException("assayViewTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:ubicrypt.ui.ctrl.HomeController.java

@PostConstruct
public void init() {
    gProgress = new GeneralProgress(inProgress, inProgressMessage);
    treeView.setCellFactory(treeView1 -> new TreeCellFactory(treeView1, fileUntracker, appEvents, gProgress));
    addProvider.setOnMouseClicked(event -> ctx.browse("selectProvider"));
    addFile.setOnMouseClicked(event -> {
        if (!localConfig.getProviders().stream().findAny().isPresent()) {
            ctx.browse("selectProvider");
            return;
        }//from   ww  w  . ja  v a  2s . c  o m
        fileAdder.accept(emptyPath);
    });
    settings.setOnMouseClicked(event -> ctx.browse("settings"));
    filesRoot = new TreeItem<>(new RootFilesItem(event -> fileAdder.accept(emptyPath)));
    TreeItem<ITreeItem> root = new TreeItem<>();
    treeView.setRoot(root);

    root.getChildren().add(filesRoot);
    treeView.setShowRoot(false);
    localConfig.getLocalFiles().stream().filter(Utils.ignoredFiles)
            .forEach(localFile -> addFiles(localFile.getPath().iterator(), basePath, filesRoot, localFile));

    //providers
    providersRoot = new TreeItem<>(new RootProvidersItem());
    root.getChildren().add(providersRoot);
    localConfig.getProviders().stream().forEach(providerAdder);

    //provider status events
    providerEvent.subscribe(pevent -> {
        switch (pevent.getEvent()) {
        case added:
            log.info("new provider added:{}", pevent.getHook().getProvider());
            final Optional<TreeItem<ITreeItem>> optItem = providersRoot.getChildren().stream()
                    .filter(item -> ((ProviderItem) item.getValue()).getProvider()
                            .equals(pevent.getHook().getProvider()))
                    .findFirst();
            if (!optItem.isPresent()) {
                providerAdder.accept(pevent.getHook().getProvider());
            }
            pevent.getHook().getStatusEvents().subscribe(event -> {
                Function<String, String> classLabel;
                log.info("provider status {}:{}", event, pevent.getHook().getProvider());
                switch (event) {
                case error:
                    classLabel = code -> format("tree-provider-%s-error", code);
                    break;
                default:
                    //TODO:labels for other statuses
                    classLabel = code -> format("tree-provider-%s", code);
                }
                optItem.ifPresent(item -> {
                    final ProviderItem providerItem = (ProviderItem) item.getValue();
                    final Node graphics = providerItem.getGraphics();
                    graphics.getStyleClass().clear();
                    providerDescriptors.stream()
                            .filter(pd -> pd.getType().equals(providerItem.getProvider().getClass()))
                            .map(ProviderDescriptor::getCode).findFirst()
                            .ifPresent(code -> graphics.getStyleClass().add(classLabel.apply(code)));
                });
            });
            break;
        case removed:
            //TODO: remove provider
            break;
        default:
            log.warn("unmanaged event:{}", pevent.getEvent());
        }
    });

    //remote file events
    fileEvents.filter(fileEvent -> fileEvent.getLocation() == FileEvent.Location.remote)
            .subscribe(fileEvent -> {
                log.debug("file remote event:{}", fileEvent);
                //update file icon
                final UbiFile<UbiFile> file = fileEvent.getFile();
                Observable.create(fileInSync.call(file)).subscribe(res -> {
                    searchFile(filesRoot, file).ifPresent(treeView -> {
                        final Node graphics = treeView.getValue().getGraphics();
                        graphics.getStyleClass().clear();
                        graphics.getStyleClass().add(format("tree-file-saved-%s", res));
                    });
                });
            });
    //local file events
    fileEvents.filter(fileEvent -> fileEvent.getLocation() == FileEvent.Location.local
            && fileEvent.getType() == FileEvent.Type.created).subscribe(fileEvent -> {
                log.debug("file local event:{}", fileEvent);
                localConfig.getLocalFiles().stream().filter(fileEvent.getFile()::equals).findFirst().ifPresent(
                        fe -> addFiles(fileEvent.getFile().getPath().iterator(), basePath, filesRoot, fe));
                searchFile(filesRoot, fileEvent.getFile()).ifPresent(treeView -> {
                    final Node graphics = treeView.getValue().getGraphics();
                    graphics.getStyleClass().clear();
                    graphics.getStyleClass().add(format("tree-file-saved-%s", true));
                });
            });

    //file progress monitor
    progressEvents.subscribe(progress -> {
        Platform.runLater(() -> {
            if (progress.isCompleted()) {
                log.debug("progress completed");
                if (!filesInProgress.remove(progress)) {
                    log.warn("progress not tracked. progress file:{}, element:{}",
                            progress.getProvenience().getFile());
                }
                Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), ae -> {
                    progressFile.setText("");
                    progressProvider.setText("");
                    progressBar.setProgress(0D);
                }));
                timeline.play();
            } else {
                filesInProgress.add(progress);
            }
            if (filesInProgress.isEmpty()) {
                //                    footer.setVisible(false);
                return;
            }
            footer.setVisible(true);
            filesInProgress.stream().findFirst().ifPresent(pr -> {
                progressFile.setText(StringUtils
                        .abbreviate(pr.getProvenience().getFile().getPath().getFileName().toString(), 30));
                progressProvider.setText(StringUtils.abbreviate(pr.getTarget().toString(), 30));
                progressBar.setProgress((double) progress.getChunk() / pr.getProvenience().getFile().getSize());
            });
        });
    });

    //sync-done events
    appEvents.subscribe(ClassMatcher.newMatcher().on(SyncBeginEvent.class, event -> {
        log.info("sync begin received");
        Platform.runLater(() -> {
            gProgress.startProgress("Synchronizing providers");
            addFile.setDisable(true);
            addProvider.setDisable(true);
        });
    }).on(SynchDoneEvent.class, event -> {
        log.debug("sync done");
        refreshItems(filesRoot);
        Platform.runLater(() -> {
            gProgress.stopProgress();
            addFile.setDisable(false);
            addProvider.setDisable(false);
        });
    }));
}

From source file:webserver.WebResource.java

public List<HTMLSearchResult> generateHTMLSearchresults(List<Pair<String, String>> searchResults)
        throws IOException, PebbleException {
    List<HTMLSearchResult> results = new ArrayList<>();
    for (Pair<String, String> result : searchResults) {
        String name = result.getA();
        String websitecontent = result.getB();
        Document htmlDoc = Jsoup.parse(websitecontent);
        String title = selectTitleOpt(htmlDoc);
        title = title == null ? "" : title;
        String description = selectDescriptionOpt(htmlDoc);
        description = description == null ? "" : description;
        description = StringUtils.abbreviate(description, 150);
        results.add(new HTMLSearchResult(title, description, name, "/" + name, "/" + name,
                "/namestorage:" + name, null));

    }//from   www.j ava 2s.  c o m
    return results;
}

From source file:won.bot.framework.component.needproducer.impl.MailFileNeedProducer.java

@Override
public synchronized Model readNeedFromFile(final File file) throws IOException {
    logger.debug("processing as mail file: {} ", file);
    FileInputStream fis = new FileInputStream(file);
    NeedModelBuilder needModelBuilder = new NeedModelBuilder();
    try {/*from w ww  .  ja  v a 2s  . co m*/
        MimeMessage emailMessage = new MimeMessage(null, fis);
        MimeMessageParser parser = new MimeMessageParser(emailMessage);
        parser.parse();
        needModelBuilder.setTitle(parser.getSubject());
        String content = null;
        if (parser.hasPlainContent()) {
            content = parser.getPlainContent();
        } else if (parser.hasHtmlContent()) {
            Document doc = Jsoup.parse(parser.getHtmlContent());
            content = doc.text();
        }
        if (content != null) {
            needModelBuilder.setDescription(content);
        }
        logger.debug("mail subject          : {}", parser.getSubject());
        logger.debug("mail has plain content: {}", parser.hasPlainContent());
        logger.debug("mail has html content : {}", parser.hasHtmlContent());
        logger.debug("mail has attachments  : {}", parser.hasAttachments());
        logger.debug("mail plain content    : {}", StringUtils.abbreviate(parser.getPlainContent(), 200));
        logger.debug("mail html content     : {}", StringUtils.abbreviate(parser.getHtmlContent(), 200));
        needModelBuilder.setUri("no:uri");
        return needModelBuilder.build();
    } catch (Exception e) {
        logger.debug("could not parse email from file {} ", file, e);
    } finally {
        if (fis != null)
            fis.close();
    }
    return null;
}

From source file:won.bot.framework.eventbot.action.impl.debugbot.CreateDebugNeedWithFacetsAction.java

@Override
protected void doRun(Event event) throws Exception {
    String replyText = "";
    URI reactingToNeedUriTmp = null;
    Dataset needDataset = null;/*  w w w  . ja v  a 2 s.c o  m*/
    if (event instanceof NeedSpecificEvent) {
        reactingToNeedUriTmp = ((NeedSpecificEvent) event).getNeedURI();
    } else {
        logger.warn("could not process non-need specific event {}", event);
        return;
    }
    if (event instanceof NeedCreatedEventForMatcher) {
        needDataset = ((NeedCreatedEventForMatcher) event).getNeedData();
    } else if (event instanceof HintDebugCommandEvent) {
        reactingToNeedUriTmp = ((HintDebugCommandEvent) event).getRemoteNeedURI();
    } else if (event instanceof ConnectDebugCommandEvent) {
        reactingToNeedUriTmp = ((ConnectDebugCommandEvent) event).getRemoteNeedURI();
    } else {
        logger.error("CreateEchoNeedWithFacetsAction cannot handle " + event.getClass().getName());
        return;
    }
    final URI reactingToNeedUri = reactingToNeedUriTmp;
    Path titlePath = PathParser.parse("won:hasContent/dc:title", DefaultPrefixUtils.getDefaultPrefixes());

    String titleString = null;
    if (needDataset != null) {
        titleString = RdfUtils.getStringPropertyForPropertyPath(needDataset, reactingToNeedUri, titlePath);
    }
    if (titleString != null) {
        if (isInitialForConnect) {
            replyText = "Debugging with initial connect: " + titleString;
        } else if (isInitialForHint) {
            replyText = "Debugging with initial hint: " + titleString;
        } else {
            replyText = "Debugging: " + titleString;
        }
    } else {
        replyText = "Debug Need No. " + counter.increment();
    }

    WonNodeInformationService wonNodeInformationService = getEventListenerContext()
            .getWonNodeInformationService();

    final URI wonNodeUri = getEventListenerContext().getNodeURISource().getNodeURI();
    final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
    final Model needModel = new NeedModelBuilder().setTitle(replyText)
            .setBasicNeedType(BasicNeedType.DO_TOGETHER)
            .setDescription("This is a need automatically created by the DebugBot.").setUri(needURI)
            .setFacetTypes(facets).build();

    final Event origEvent = event;

    logger.debug("creating need on won node {} with content {} ", wonNodeUri,
            StringUtils.abbreviate(RdfUtils.toString(needModel), 150));

    WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, needModel);
    //remember the need URI so we can react to success/failure responses
    EventBotActionUtils.rememberInListIfNamePresent(getEventListenerContext(), needURI, uriListName);

    EventListener successCallback = new EventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            logger.debug("need creation successful, new need URI is {}", needURI);
            if ((origEvent instanceof HintDebugCommandEvent) || isInitialForHint) {
                getEventListenerContext().getEventBus()
                        .publish(new NeedCreatedEventForDebugHint(needURI, wonNodeUri, needModel, null));
            } else if ((origEvent instanceof ConnectDebugCommandEvent) || isInitialForConnect) {
                getEventListenerContext().getEventBus()
                        .publish(new NeedCreatedEventForDebugConnect(needURI, wonNodeUri, needModel, null));
            } else {
                getEventListenerContext().getEventBus()
                        .publish(new NeedCreatedEvent(needURI, wonNodeUri, needModel, null));
            }
            //put the mapping between the original and the reaction in to the context.
            getEventListenerContext().getBotContext().put(reactingToNeedUri, needURI);
            getEventListenerContext().getBotContext().put(needURI, reactingToNeedUri);
        }
    };

    EventListener failureCallback = new EventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            String textMessage = WonRdfUtils.MessageUtils
                    .getTextMessage(((FailureResponseEvent) event).getFailureMessage());
            logger.debug("need creation failed for need URI {}, original message URI {}: {}", new Object[] {
                    needURI, ((FailureResponseEvent) event).getOriginalMessageURI(), textMessage });
            EventBotActionUtils.removeFromListIfNamePresent(getEventListenerContext(), needURI, uriListName);
            getEventListenerContext().getEventBus().publish(new NeedCreationFailedEvent(wonNodeUri));
        }
    };
    EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback,
            getEventListenerContext());

    logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
    getEventListenerContext().getWonMessageSender().sendWonMessage(createNeedMessage);
    logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
}

From source file:won.bot.framework.eventbot.action.impl.needlifecycle.CreateEchoNeedWithFacetsAction.java

@Override
protected void doRun(Event event) throws Exception {
    String replyText = "";
    if (!(event instanceof NeedCreatedEventForMatcher)) {
        logger.error("CreateEchoNeedWithFacetsAction can only handle NeedCreatedEventForMatcher");
        return;// w  ww . j  av a  2 s.c o m
    }
    final URI reactingToNeedUri = ((NeedCreatedEventForMatcher) event).getNeedURI();
    final Dataset needDataset = ((NeedCreatedEventForMatcher) event).getNeedData();
    String titleString = WonRdfUtils.NeedUtils.getNeedTitle(needDataset, reactingToNeedUri);
    if (titleString != null) {
        replyText = titleString;
    } else {
        replyText = "Your Posting (" + reactingToNeedUri.toString() + ")";
    }

    WonNodeInformationService wonNodeInformationService = getEventListenerContext()
            .getWonNodeInformationService();

    final URI wonNodeUri = getEventListenerContext().getNodeURISource().getNodeURI();
    final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
    final Model needModel = new NeedModelBuilder().setTitle("RE: " + replyText)
            .setBasicNeedType(BasicNeedType.SUPPLY)
            .setDescription("This is a need automatically created by the EchoBot.").setUri(needURI)
            .setFacetTypes(facets).build();

    logger.debug("creating need on won node {} with content {} ", wonNodeUri,
            StringUtils.abbreviate(RdfUtils.toString(needModel), 150));

    WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, needModel);
    //remember the need URI so we can react to success/failure responses
    EventBotActionUtils.rememberInListIfNamePresent(getEventListenerContext(), needURI, uriListName);

    EventListener successCallback = new EventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            logger.debug("need creation successful, new need URI is {}", needURI);
            getEventListenerContext().getEventBus()
                    .publish(new NeedCreatedEvent(needURI, wonNodeUri, needModel, null));
            //put the mapping between the original and the reaction in to the context.
            getEventListenerContext().getBotContext().put(reactingToNeedUri, needURI);
            getEventListenerContext().getBotContext().put(needURI, reactingToNeedUri);
        }
    };

    EventListener failureCallback = new EventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            String textMessage = WonRdfUtils.MessageUtils
                    .getTextMessage(((FailureResponseEvent) event).getFailureMessage());
            logger.debug("need creation failed for need URI {}, original message URI {}: {}", new Object[] {
                    needURI, ((FailureResponseEvent) event).getOriginalMessageURI(), textMessage });
            EventBotActionUtils.removeFromListIfNamePresent(getEventListenerContext(), needURI, uriListName);
            getEventListenerContext().getEventBus().publish(new NeedCreationFailedEvent(wonNodeUri));
        }
    };
    EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback,
            getEventListenerContext());

    logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
    getEventListenerContext().getWonMessageSender().sendWonMessage(createNeedMessage);
    logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
}

From source file:won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction.java

@Override
protected void doRun(Event event) throws Exception {
    if (getEventListenerContext().getNeedProducer().isExhausted()) {
        logger.info("the bot's need producer is exhausted.");
        getEventListenerContext().getEventBus().publish(new NeedProducerExhaustedEvent());
        return;/*w  w w .j  ava 2 s.c o m*/
    }
    final Model needModel = getEventListenerContext().getNeedProducer().create();
    if (needModel == null) {
        logger.warn("needproducer failed to produce a need model, aborting need creation");
        return;
    }
    for (URI facetURI : facets) {
        WonRdfUtils.FacetUtils.addFacet(needModel, facetURI);
    }
    final URI wonNodeUri = getEventListenerContext().getNodeURISource().getNodeURI();
    logger.debug("creating need on won node {} with content {} ", wonNodeUri,
            StringUtils.abbreviate(RdfUtils.toString(needModel), 150));
    WonNodeInformationService wonNodeInformationService = getEventListenerContext()
            .getWonNodeInformationService();
    final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
    WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, needModel);
    //remember the need URI so we can react to success/failure responses
    EventBotActionUtils.rememberInListIfNamePresent(getEventListenerContext(), needURI, uriListName);

    EventListener successCallback = new EventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            logger.debug("need creation successful, new need URI is {}", needURI);
            getEventListenerContext().getEventBus()
                    .publish(new NeedCreatedEvent(needURI, wonNodeUri, needModel, null));
        }
    };

    EventListener failureCallback = new EventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            String textMessage = WonRdfUtils.MessageUtils
                    .getTextMessage(((FailureResponseEvent) event).getFailureMessage());
            logger.debug("need creation failed for need URI {}, original message URI {}: {}", new Object[] {
                    needURI, ((FailureResponseEvent) event).getOriginalMessageURI(), textMessage });
            EventBotActionUtils.removeFromListIfNamePresent(getEventListenerContext(), needURI, uriListName);
            getEventListenerContext().getEventBus().publish(new NeedCreationFailedEvent(wonNodeUri));
        }
    };
    EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback,
            getEventListenerContext());

    logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
    getEventListenerContext().getWonMessageSender().sendWonMessage(createNeedMessage);
    logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
}