org.drools.core.util.StringUtils Java Examples
The following examples show how to use
org.drools.core.util.StringUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UrlResource.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public boolean isDirectory() { try { URL url = getURL(); if ("file".equals(url.getProtocol())) { File file = new File(StringUtils.toURI(url.toString()).getSchemeSpecificPart()); return file.isDirectory(); } } catch (Exception e) { // swallow as returned false } return false; }
Example #2
Source File: MessageProducerGenerator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public MessageProducerGenerator( WorkflowProcess process, String modelfqcn, String processfqcn, String messageDataEventClassName, TriggerMetaData trigger) { this.process = process; this.trigger = trigger; this.packageName = process.getPackageName(); this.processId = process.getId(); this.processName = processId.substring(processId.lastIndexOf('.') + 1); String classPrefix = StringUtils.capitalize(processName); this.resourceClazzName = classPrefix + "MessageProducer_" + trigger.getOwnerId(); this.relativePath = packageName.replace(".", "/") + "/" + resourceClazzName + ".java"; this.messageDataEventClassName = messageDataEventClassName; }
Example #3
Source File: InsertObjectCommand.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public FactHandle execute(Context context) { KieSession ksession = ((RegistryContext)context).lookup( KieSession.class ); FactHandle factHandle; if ( StringUtils.isEmpty( this.entryPoint ) ) { factHandle = ksession.insert( object ); } else { factHandle = ksession.getEntryPoint( this.entryPoint ).insert( object ); } if ( outIdentifier != null ) { if ( this.returnObject ) { ((RegistryContext) context).lookup( ExecutionResultImpl.class ).setResult( this.outIdentifier, object ); } ((RegistryContext) context).lookup( ExecutionResultImpl.class ).getFactHandles().put( this.outIdentifier, factHandle ); } if ( disconnected ) { DefaultFactHandle disconnectedHandle = ((DefaultFactHandle)factHandle).clone(); disconnectedHandle.disconnect(); return disconnectedHandle; } return factHandle; }
Example #4
Source File: InsertElementsCommand.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public Collection<FactHandle> execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); List<FactHandle> handles = new ArrayList<FactHandle>(); EntryPoint wmep; if ( StringUtils.isEmpty( this.entryPoint ) ) { wmep = ksession; } else { wmep = ksession.getEntryPoint( this.entryPoint ); } for ( Object object : objects ) { handles.add( wmep.insert( object ) ); } if ( outIdentifier != null ) { if ( this.returnObject ) { ((RegistryContext) context).lookup( ExecutionResultImpl.class ).setResult( this.outIdentifier, objects ); } ((RegistryContext) context).lookup( ExecutionResultImpl.class ).getFactHandles().put( this.outIdentifier, handles ); } return handles; }
Example #5
Source File: JavaRuleBuilderHelper.java From kogito-runtimes with Apache License 2.0 | 6 votes |
private static void generateInvokerTemplate(final String invokerTemplate, final RuleBuildContext context, final String className, final Map vars, final Object invokerLookup, final BaseDescr descrLookup) { TemplateRegistry registry = getInvokerTemplateRegistry(context.getKnowledgeBuilder().getRootClassLoader()); final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + StringUtils.ucFirst( className ) + "Invoker"; context.addInvoker( invokerClassName, (String) TemplateRuntime.execute( registry.getNamedTemplate( invokerTemplate ), null, new MapVariableResolverFactory( vars ), registry ) ); context.addInvokerLookup( invokerClassName, invokerLookup ); context.addDescrLookups( invokerClassName, descrLookup ); }
Example #6
Source File: SessionConfiguration.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public final String getProperty(String name) { name = name.trim(); if ( StringUtils.isEmpty( name ) ) { return null; } if ( name.equals( KeepReferenceOption.PROPERTY_NAME ) ) { return Boolean.toString(isKeepReference()); } else if ( name.equals( ClockTypeOption.PROPERTY_NAME ) ) { return getClockType().toExternalForm(); } else if ( name.equals( TimerJobFactoryOption.PROPERTY_NAME ) ) { return getTimerJobFactoryType().toExternalForm(); } else if ( name.equals( QueryListenerOption.PROPERTY_NAME ) ) { return getQueryListenerOption().getAsString(); } else if ( name.equals( BeliefSystemTypeOption.PROPERTY_NAME ) ) { return getBeliefSystemType().getId(); } return null; }
Example #7
Source File: JavaDialectRuntimeData.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public void removeRule( KnowledgePackageImpl pkg, RuleImpl rule ) { if (!( rule instanceof QueryImpl)) { // Query's don't have a consequence, so skip those final String consequenceName = rule.getConsequence().getClass().getName(); // check for compiled code and remove if present. if (remove( consequenceName )) { removeClasses( rule.getLhs() ); // Now remove the rule class - the name is a subset of the consequence name String sufix = StringUtils.ucFirst( rule.getConsequence().getName() ) + "ConsequenceInvoker"; remove( consequenceName.substring( 0, consequenceName.indexOf( sufix ) ) ); } } }
Example #8
Source File: DefaultAgenda.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Override public RuleAgendaItem createRuleAgendaItem(final int salience, final PathMemory rs, final TerminalNode rtn ) { String agendaGroupName = rtn.getRule().getAgendaGroup(); String ruleFlowGroupName = rtn.getRule().getRuleFlowGroup(); RuleAgendaItem lazyAgendaItem; if ( !StringUtils.isEmpty(ruleFlowGroupName) ) { lazyAgendaItem = new RuleAgendaItem( activationCounter++, null, salience, null, rs, rtn, isDeclarativeAgenda(), (InternalAgendaGroup) getAgendaGroup( ruleFlowGroupName )); } else { lazyAgendaItem = new RuleAgendaItem( activationCounter++, null, salience, null, rs, rtn, isDeclarativeAgenda(), (InternalAgendaGroup) getRuleFlowGroup( agendaGroupName )); } return lazyAgendaItem; }
Example #9
Source File: ProcessToExecModelGenerator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public ProcessMetaData generate(WorkflowProcess process) { CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE)); parsedClazzFile.setPackageDeclaration(process.getPackageName()); Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst(ClassOrInterfaceDeclaration.class, sl -> true); String extractedProcessId = extractProcessId(process.getId()); if (!processClazzOptional.isPresent()) { throw new NoSuchElementException("Cannot find class declaration in the template"); } ClassOrInterfaceDeclaration processClazz = processClazzOptional.get(); processClazz.setName(StringUtils.capitalize(extractedProcessId + PROCESS_CLASS_SUFFIX)); String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null); ProcessMetaData metadata = new ProcessMetaData(process.getId(), extractedProcessId, process.getName(), process.getVersion(), packageName, processClazz.getNameAsString()); Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl.getName().asString().equals("process")); processVisitor.visitProcess(process, processMethod.get(), metadata); metadata.setGeneratedClassModel(parsedClazzFile); return metadata; }
Example #10
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Byte getDefaultValueAsByte( ) { try { return initExpr == null ? 0 : Byte.parseByte(initExpr); } catch (NumberFormatException nfe) { return StringUtils.isEmpty( initExpr ) ? 0 : MVELSafeHelper.getEvaluator().eval( initExpr, Byte.class ); } }
Example #11
Source File: ClassPathResource.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public boolean isDirectory() { try { URL url = getURL(); if ( !"file".equals( url.getProtocol() ) ) { return false; } File file = new File( StringUtils.toURI( url.toString() ).getSchemeSpecificPart() ); return file.isDirectory(); } catch ( Exception e ) { return false; } }
Example #12
Source File: OutputModelClassGenerator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public OutputModelClassGenerator(GeneratorContext context, WorkflowProcess workFlowProcess) { String pid = workFlowProcess.getId(); className = StringUtils.capitalize(ProcessToExecModelGenerator.extractProcessId(pid) + "ModelOutput"); this.modelClassName = workFlowProcess.getPackageName() + "." + className; this.context = context; this.workFlowProcess = workFlowProcess; }
Example #13
Source File: UrlResource.java From kogito-runtimes with Apache License 2.0 | 5 votes |
/** * Determine a cleaned URL for the given original URL. * @param originalUrl the original URL * @param originalPath the original URL path * @return the cleaned URL */ private URL getCleanedUrl(URL originalUrl, String originalPath) { try { return new URL(StringUtils.cleanPath(originalPath)); } catch (MalformedURLException ex) { // Cleaned URL path cannot be converted to URL // -> take original URL. return originalUrl; } }
Example #14
Source File: AssertEquals.java From kogito-runtimes with Apache License 2.0 | 5 votes |
static String format(String message, Object expected, Object actual) { StringBuilder builder = new StringBuilder(); if ( !StringUtils.isEmpty( message ) ) { builder.append( message ); builder.append( " " ); } String expectedString = String.valueOf( expected ); String actualString = String.valueOf( actual ); if ( expectedString.equals( actualString ) ) { builder.append( "expected: " ); builder.append( formatClassAndValue( expected, expectedString ) ); builder.append( " but was: " ); builder.append( formatClassAndValue( actual, actualString ) ); } else { builder.append( "expected:<" ); builder.append( expectedString ); builder.append( "> but was:<" ); builder.append( actualString ); } return builder.toString(); }
Example #15
Source File: DefaultFactHandle.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private static void populateFactHandleFromExternalForm( String[] elements, DefaultFactHandle handle ) { handle.id = Integer.parseInt( elements[1] ); handle.identityHashCode = Integer.parseInt( elements[2] ); handle.objectHashCode = Integer.parseInt( elements[3] ); handle.recency = Long.parseLong( elements[4] ); handle.setEntryPoint( ( StringUtils.isEmpty( elements[5] ) || "null".equals( elements[5].trim() ) ) ? null : new DisconnectedWorkingMemoryEntryPoint( elements[5].trim() ) ); handle.disconnected = true; handle.traitType = elements.length > 6 ? TraitTypeEnum.valueOf( elements[6] ) : TraitTypeEnum.NON_TRAIT; handle.objectClassName = elements.length > 7 ? elements[7] : null; }
Example #16
Source File: DefaultAgenda.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public void activateRuleFlowGroup(final InternalRuleFlowGroup group, String processInstanceId, String nodeInstanceId) { this.workingMemory.getAgendaEventSupport().fireBeforeRuleFlowGroupActivated( group, this.workingMemory ); group.setActive( true ); group.hasRuleFlowListener(true); if ( !StringUtils.isEmpty( nodeInstanceId ) ) { group.addNodeInstance( processInstanceId, nodeInstanceId ); group.setActive( true ); } group.setFocus(); this.workingMemory.getAgendaEventSupport().fireAfterRuleFlowGroupActivated( group, this.workingMemory ); propagationList.notifyWaitOnRest(); }
Example #17
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public short getDefaultValueAs_short() { try { return initExpr == null ? 0 : Short.parseShort(initExpr); } catch (NumberFormatException nfe) { return StringUtils.isEmpty( initExpr ) ? 0 : MVELSafeHelper.getEvaluator().eval( initExpr, Short.class ); } }
Example #18
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public byte getDefaultValueAs_byte() { try { return initExpr == null ? 0 : Byte.parseByte(initExpr); } catch (NumberFormatException nfe) { return StringUtils.isEmpty( initExpr ) ? 0 : MVELSafeHelper.getEvaluator().eval( initExpr, Byte.class ); } }
Example #19
Source File: MessageDataEventGenerator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public MessageDataEventGenerator( WorkflowProcess process, TriggerMetaData trigger) { this.process = process; this.trigger = trigger; this.packageName = process.getPackageName(); this.processId = process.getId(); this.processName = processId.substring(processId.lastIndexOf('.') + 1); String classPrefix = StringUtils.capitalize(processName); this.resourceClazzName = classPrefix + "MessageDataEvent_" + trigger.getOwnerId(); this.relativePath = packageName.replace(".", "/") + "/" + resourceClazzName + ".java"; }
Example #20
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Long getDefaultValueAsLong( ) { try { return initExpr == null ? 0L : Long.parseLong(initExpr); } catch (NumberFormatException nfe) { return StringUtils.isEmpty( initExpr ) ? 0L : MVELSafeHelper.getEvaluator().eval( initExpr, Long.class ); } }
Example #21
Source File: WidMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private static String getRevisedExpression(String expression) { if (StringUtils.isEmpty(expression)) { return expression; } return expression.replaceAll("import org\\.drools\\.core\\.process\\.core\\.datatype\\.impl\\.type\\.*([^;])*;", ""). replaceAll("import org\\.jbpm\\.process\\.core\\.datatype\\.impl\\.type\\.*([^;])*;", ""); }
Example #22
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Float getDefaultValueAsFloat( ) { try { return initExpr == null ? 0.0f : Float.parseFloat(initExpr); } catch (NumberFormatException nfe) { return StringUtils.isEmpty( initExpr ) ? 0.0f : MVELSafeHelper.getEvaluator().eval( initExpr, Float.class ); } }
Example #23
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Character getDefaultValueAsChar() { if ( StringUtils.isEmpty( initExpr ) ) { return '\u0000'; } else { if ( initExpr.length() == 1 ) { return initExpr.charAt(0); } else { return MVELSafeHelper.getEvaluator().eval( initExpr, Character.class ); } } }
Example #24
Source File: FieldDefinition.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public char getDefaultValueAs_char() { if ( StringUtils.isEmpty( initExpr ) ) { return '\u0000'; } else { if ( initExpr.length() == 1 ) { return initExpr.charAt(0); } else { return MVELSafeHelper.getEvaluator().eval( initExpr, Character.class ); } } }
Example #25
Source File: UserTaskModelMetaData.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public UserTaskModelMetaData(String packageName, VariableScope processVariableScope, VariableScope variableScope, HumanTaskNode humanTaskNode, String processId) { this.packageName = packageName; this.processVariableScope = processVariableScope; this.variableScope = variableScope; this.humanTaskNode = humanTaskNode; this.processId = processId; this.inputModelClassSimpleName = StringUtils.capitalize(ProcessToExecModelGenerator.extractProcessId(processId) + "_" + humanTaskNode.getId() + "_" + TASK_INTPUT_CLASS_SUFFIX); this.inputModelClassName = packageName + '.' + inputModelClassSimpleName; this.outputModelClassSimpleName = StringUtils.capitalize(ProcessToExecModelGenerator.extractProcessId(processId) + "_" + humanTaskNode.getId() + "_" + TASK_OUTTPUT_CLASS_SUFFIX); this.outputModelClassName = packageName + '.' + outputModelClassSimpleName; }
Example #26
Source File: ObjectMarshallingStrategyStoreImpl.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public ObjectMarshallingStrategy getStrategyObject(String strategyName) { if( StringUtils.isEmpty(strategyName) ) { return null; } if (strategyName.startsWith("org.drools.marshalling.impl")) { strategyName = strategyName.replaceFirst("org.drools.marshalling.impl", "org.drools.core.marshalling.impl"); } for( int i = 0; i < this.strategiesList.length; ++i ) { if( strategiesList[i].getName().equals(strategyName) ) { return strategiesList[i]; } } throw new RuntimeException( "Unable to find PlaceholderResolverStrategy for name : " + strategyName ); }
Example #27
Source File: SignalV6andV5Test.java From flowable-engine with Apache License 2.0 | 5 votes |
public void testBoundarySignalFromV6ToV5() throws Exception { // Deploy processes String deploymentId = repositoryService.createDeployment() .addClasspathResource("org/activiti/engine/test/regression/signalBoundaryCatch.bpmn") .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .deploy() .getId(); String deploymentId2 = repositoryService.createDeployment() .addClasspathResource("org/activiti/engine/test/regression/signalThrow.bpmn") .deploy() .getId(); runtimeService.startProcessInstanceByKey("signalBoundaryCatch"); runtimeService.startProcessInstanceByKey("signalThrow"); ProcessDefinition v5Definition = repositoryService.createProcessDefinitionQuery().processDefinitionEngineVersion("v5").singleResult(); assertNotNull(v5Definition); assertEquals("signalBoundaryCatch", v5Definition.getKey()); ProcessDefinition v6Definition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("signalThrow").singleResult(); assertNotNull(v6Definition); assertTrue(StringUtils.isEmpty(v6Definition.getEngineVersion())); org.flowable.task.api.Task signalTask = taskService.createTaskQuery().processDefinitionKey("signalBoundaryCatch").singleResult(); assertNotNull(signalTask); assertEquals("task", signalTask.getTaskDefinitionKey()); org.flowable.task.api.Task beforeTask = taskService.createTaskQuery().processDefinitionKey("signalThrow").singleResult(); taskService.complete(beforeTask.getId()); org.flowable.task.api.Task afterTask = taskService.createTaskQuery().processDefinitionKey("signalBoundaryCatch").singleResult(); assertNotNull(afterTask); assertEquals("afterTask", afterTask.getTaskDefinitionKey()); // Clean repositoryService.deleteDeployment(deploymentId, true); repositoryService.deleteDeployment(deploymentId2, true); }
Example #28
Source File: XmlPackageReaderTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testParseLhs() throws Exception { final XmlPackageReader xmlPackageReader = getXmReader(); xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseLhs.xml" ) ) ); final PackageDescr packageDescr = xmlPackageReader.getPackageDescr(); String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseLhs.drl" ) ) ); String expectedWithoutHeader = removeLicenseHeader( expected ); String actual = new DrlDumper().dump( packageDescr ); assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual); }
Example #29
Source File: XmlPackageReaderTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testParseCollect() throws Exception { final XmlPackageReader xmlPackageReader = getXmReader(); xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseCollect.xml" ) ) ); final PackageDescr packageDescr = xmlPackageReader.getPackageDescr(); String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseCollect.drl" ) ) ); String expectedWithoutHeader = removeLicenseHeader( expected ); String actual = new DrlDumper().dump( packageDescr ); assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual); }
Example #30
Source File: FileSystemResource.java From kogito-runtimes with Apache License 2.0 | 5 votes |
/** * Create a new FileSystemResource from a File handle. * <p>Note: When building relative resources via {@link #createRelative}, * the relative path will apply <i>at the same directory level</i>: * e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"! * If you prefer to have relative paths built underneath the given root * directory, use the {@link #FileSystemResource(String) constructor with a file path} * to append a trailing slash to the root path: "C:/dir1/", which * indicates this directory as root for all relative paths. * @param file a File handle */ public FileSystemResource(File file) { if ( file == null ) { throw new IllegalArgumentException( "File must not be null" ); } this.file = new File( StringUtils.cleanPath(file.getPath()) ); try { setSourcePath( file.getCanonicalPath() ); } catch (IOException e) { setSourcePath( file.getAbsolutePath() ); } setResourceType( ResourceType.determineResourceType( getSourcePath() ) ); }