Search in sources :

Example 1 with Gist

use of org.eclipse.egit.github.core.Gist in project jbpm-work-items by kiegroup.

the class CreateGistWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        Document content = (Document) workItem.getParameter("Content");
        String description = (String) workItem.getParameter("Description");
        String isPublicStr = (String) workItem.getParameter("IsPublic");
        if (content != null) {
            Map<String, Object> results = new HashMap<String, Object>();
            GistService gistService = auth.getGistService(this.userName, this.password);
            Gist gist = new Gist();
            gist.setPublic(Boolean.parseBoolean(isPublicStr));
            gist.setDescription(description);
            GistFile file = new GistFile();
            file.setContent(new String(content.getContent(), StandardCharsets.UTF_8));
            file.setFilename(content.getName());
            gist.setFiles(Collections.singletonMap(file.getFilename(), file));
            gist = gistService.createGist(gist);
            results.put(RESULTS_VALUE, gist.getHtmlUrl());
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing gist content information.");
            throw new IllegalArgumentException("Missing gist content information.");
        }
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : Gist(org.eclipse.egit.github.core.Gist) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) GistFile(org.eclipse.egit.github.core.GistFile) GistService(org.eclipse.egit.github.core.service.GistService)

Aggregations

HashMap (java.util.HashMap)1 Gist (org.eclipse.egit.github.core.Gist)1 GistFile (org.eclipse.egit.github.core.GistFile)1 GistService (org.eclipse.egit.github.core.service.GistService)1 Document (org.jbpm.document.Document)1