public <T extends ProcessInstanceAttribute> T findOrCreateAttribute(Class<T> attrClass) { T attribute = findAttributeByClass(attrClass); if(attribute == null) { try { attribute = attrClass.newInstance(); addAttribute(attribute); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } return attribute; }
@Override public void loadData(BpmTask task) { ProcessInstance pi = task.getProcessInstance().getRootProcessInstance(); if (mode.equalsIgnoreCase(MODE_SMART)) { if (!"true".equalsIgnoreCase(pi.getSimpleAttributeValue("commentAdded", "false"))) { showContent = false; } } bic.removeAllItems(); ProcessComments comments = pi.findAttributeByClass(ProcessComments.class); if (comments != null) { List<ProcessComment> lst = new ArrayList<ProcessComment>(comments.getComments()); Collections.sort(lst, new Comparator<ProcessComment>() { @Override public int compare(ProcessComment o1, ProcessComment o2) { return o2.getCreateTime().compareTo(o1.getCreateTime()); } }); for (int i = 0; i < displayedComments && i < lst.size(); ++i) { bic.addBean(lst.get(i)); } } }
@Override public void loadData(BpmTask task) { ProcessInstance pi = task.getProcessInstance().getRootProcessInstance(); ProcessComments comments = pi.findAttributeByClass(ProcessComments.class); if (comments != null) { List<ProcessComment> lst = new ArrayList<ProcessComment>(comments.getComments()); Collections.sort(lst, new Comparator<ProcessComment>() { @Override public int compare(ProcessComment o1, ProcessComment o2) { return -o1.getCreateTime().compareTo(o2.getCreateTime()); } }); for (ProcessComment cmt : lst) { bic.addBean(cmt); } } processState = task.getTaskName(); }
@Override public void saveData(BpmTask task) { ProcessInstance pi = task.getProcessInstance().getRootProcessInstance(); ProcessComments comments = pi.findAttributeByClass(ProcessComments.class); if (comments == null) { comments = new ProcessComments(); comments.setProcessInstance(pi); comments.setKey(ProcessComments.class.getName()); pi.getProcessAttributes().add(comments); } comments.setComments(new HashSet()); for (ProcessComment pc : bic.getItemIds()) { comments.getComments().add(pc); pc.setComments(comments); } }
private void saveComment() { if (skipAddingComment) { return; } ProcessToolContext ctx = getCurrentContext(); ProcessComment pc = dialog.getProcessComment(); pc.setAuthor(ctx.getUserDataDAO().loadOrCreateUserByLogin(loggedUser)); pc.setAuthorSubstitute(substitutingUser != null ? ctx.getUserDataDAO().loadOrCreateUserByLogin(substitutingUser) : null); pc.setCreateTime(new Date()); pc.setProcessState(task.getTaskName()); ProcessInstance pi = task.getProcessInstance().getRootProcessInstance(); ProcessComments comments = pi.findAttributeByClass(ProcessComments.class); if (comments == null) { comments = new ProcessComments(); comments.setProcessInstance(pi); comments.setKey(ProcessComments.class.getName()); pi.getProcessAttributes().add(comments); } comments.getComments().add(pc); pc.setComments(comments); pi.setSimpleAttribute("commentAdded", "true"); } }