public RuleBaseElementId generateId() { return new RuleBaseElementId(type, packageName, name); }
private String getUniqueRuleName(String name) { Collection<RuleBaseElementId> list = ruleManager.list(RuleBaseElementType.Rule); while (list.contains(new RuleBaseElementId(RuleBaseElementType.Rule, name))) { name = name + "_"; } return name; }
private RuleBaseElementId getIdforFile(File artifact) throws RuleBaseException, SAXException, IOException, ParserConfigurationException { RuleBaseElementType type = getTypeFromFile(artifact); String name = FilenameUtils.removeExtension(artifact.getName()); RuleBaseElementId id = new RuleBaseElementId(type, name); if (artifact.exists() && type.equals(RuleBaseElementType.Process)) { id.setPackageName(readPackageNameFromProcessFile(artifact)); } return id; }
@Override public void registerFlowTriggerEvent(Event event, String... flowIds) throws WorkflowException { String eventName = event.getName(); String ruleName = String.format("_generated_ trigger %s on %s", Arrays.asList(flowIds), eventName); StringBuffer ruleCode = generateFlowTriggerRule(event, flowIds); LOGGER.info("adding new rule with id: {}", ruleName); try { rulemanager.add(new RuleBaseElementId(RuleBaseElementType.Rule, ruleName), ruleCode.toString()); } catch (RuleBaseException e) { throw new WorkflowException(e); } }
@Override public synchronized void registerEvent(RemoteEvent event, String portId, String returnAddress, String serviceId) { String name = String.format("Notify %s via %s when %s occurs", returnAddress.toString(), portId, event.getClassName()); name = getUniqueRuleName(name); RuleBaseElementId id = new RuleBaseElementId(RuleBaseElementType.Rule, name); String eventMatcher = makeEventMatcher(event); try { String osgiHelperStatement; if (serviceId == null) { osgiHelperStatement = String.format(OSGI_HELPER_TEMPLATE1, portId, returnAddress); } else { osgiHelperStatement = String.format(OSGI_HELPER_TEMPLATE2, portId, returnAddress, serviceId); } ruleManager.add(id, String.format(EVENT_REGISTRATION_RULE_TEMPLATE, eventMatcher, osgiHelperStatement)); } catch (RuleBaseException e) { throw new IllegalArgumentException(e); } LOGGER.info("registering Event: {}", event); }
@Override public Collection<RuleBaseElementId> list(RuleBaseElementType type) { RuleBaseElementId example = new RuleBaseElementId(); example.setPackageName(null); example.setType(type); return listByExample(example); }
@Override public Collection<RuleBaseElementId> list(RuleBaseElementType type, String packageName) { RuleBaseElementId example = new RuleBaseElementId(); example.setType(type); example.setPackageName(packageName); return listByExample(example); }