Skip to content

Commit

Permalink
Add method ParameterList#hasParameter and apply where relevant. (fran…
Browse files Browse the repository at this point in the history
  • Loading branch information
tnleeuw authored Jul 16, 2024
1 parent c5c7aa6 commit accc67f
Show file tree
Hide file tree
Showing 25 changed files with 77 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public void configure() throws ConfigurationException {


ParameterList parameterList = getParameterList();
if(getAction() == Action.UPLOAD && parameterList.findParameter(FILE_PARAM_KEY) == null) {
if(getAction() == Action.UPLOAD && !parameterList.hasParameter(FILE_PARAM_KEY)) {
throw new ConfigurationException(getLogPrefix()+"the upload action requires a file parameter to be present");
}
if(getAction() == Action.RENAME && parameterList.findParameter(DESTINATION_PARAM_KEY) == null) {
if(getAction() == Action.RENAME && !parameterList.hasParameter(DESTINATION_PARAM_KEY)) {
throw new ConfigurationException(getLogPrefix()+"the rename action requires a destination parameter to be present");
}
if(getAction() == Action.MTIME && parameterList.findParameter(MTIME_PARAM_KEY) == null) {
if(getAction() == Action.MTIME && !parameterList.hasParameter(MTIME_PARAM_KEY)) {
throw new ConfigurationException(getLogPrefix()+"the mtime action requires a mtime parameter to be present");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void configure() throws ConfigurationException {

if (getParameterList() != null) {
// Legacy; check if the session should be created runtime (and thus for each call)
if(getParameterList().findParameter("authAlias") != null || getParameterList().findParameter("username") != null ) {
if(getParameterList().hasParameter("authAlias") || getParameterList().hasParameter("username")) {
runtimeSession = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.frankframework.collection.ICollector;
import org.frankframework.configuration.ConfigurationException;
import org.frankframework.core.PipeLineSession;
import org.frankframework.parameters.IParameter;
import org.frankframework.parameters.ParameterList;
import org.frankframework.parameters.ParameterValueList;
import org.frankframework.stream.FileMessage;
Expand All @@ -54,19 +53,17 @@ static void validateParametersForAction(Action action, ParameterList parameterLi
if(parameterList == null) {
throw new ConfigurationException("parameter '"+PARAMETER_FILENAME+"' or parameter '"+PARAMETER_CONTENTS+"' is required");
}
IParameter filenameParameter=parameterList.findParameter(PARAMETER_FILENAME);
IParameter contentsParameter=parameterList.findParameter(PARAMETER_CONTENTS);
if (filenameParameter==null && contentsParameter==null) {
if (!parameterList.hasParameter(PARAMETER_FILENAME) && !parameterList.hasParameter(PARAMETER_CONTENTS)) {
throw new ConfigurationException("parameter '"+PARAMETER_FILENAME+"' or parameter '"+PARAMETER_CONTENTS+"' is required");
}
break;
case CLOSE:
if (parameterList != null && parameterList.findParameter(PARAMETER_FILENAME)!=null) {
if (parameterList != null && parameterList.hasParameter(PARAMETER_FILENAME)) {
throw new ConfigurationException("parameter '"+PARAMETER_FILENAME+"' cannot not be configured on action [close]");
}
break;
case STREAM:
if(parameterList == null || parameterList.findParameter(PARAMETER_FILENAME)==null) {
if(parameterList == null || !parameterList.hasParameter(PARAMETER_FILENAME)) {
throw new ConfigurationException("parameter '"+PARAMETER_FILENAME+"' is required");
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Date;
import java.util.List;

import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.frankframework.configuration.ConfigurationException;
Expand All @@ -37,9 +39,6 @@
import org.frankframework.stream.Message;
import org.frankframework.util.StringUtil;

import lombok.Getter;
import lombok.SneakyThrows;

/**
* Send messages to the IBISSTORE database table to have them processed exactly-once by another
* adapter which will read the messages using a {@link MessageStoreListener}.
Expand Down Expand Up @@ -141,7 +140,7 @@ public SenderResult sendMessage(Message message, PipeLineSession session) throws
// the messageId to be inserted in the messageStore defaults to the messageId of the session
String messageId = session.getMessageId();
String correlationID = session.getCorrelationId();
if (paramList != null && paramList.findParameter(PARAM_MESSAGEID) != null) {
if (paramList != null && paramList.hasParameter(PARAM_MESSAGEID)) {
try {
// the messageId to be inserted can also be specified via the parameter messageId
messageId = paramList.getValues(message, session).get(PARAM_MESSAGEID).asStringValue();
Expand Down
15 changes: 7 additions & 8 deletions core/src/main/java/org/frankframework/jms/JmsSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import javax.naming.NamingException;
import javax.xml.transform.TransformerException;

import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.frankframework.configuration.ConfigurationException;
Expand All @@ -47,13 +53,6 @@
import org.frankframework.util.XmlException;
import org.xml.sax.SAXException;

import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;
import lombok.Getter;

/**
* This class sends messages with JMS.
*
Expand Down Expand Up @@ -98,7 +97,7 @@ public enum LinkMethod {
*/
@Override
public void configure() throws ConfigurationException {
if (StringUtils.isNotEmpty(getSoapAction()) && (paramList==null || paramList.findParameter("SoapAction")==null)) {
if (StringUtils.isNotEmpty(getSoapAction()) && (paramList==null || !paramList.hasParameter("SoapAction"))) {
Parameter p = SpringUtils.createBean(getApplicationContext(), Parameter.class);
p.setName("SoapAction");
p.setValue(getSoapAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import org.frankframework.configuration.ConfigurationException;
import org.frankframework.configuration.ConfigurationWarning;
import org.frankframework.core.IPipe;
Expand Down Expand Up @@ -65,16 +64,16 @@ public class LdapChallengePipe extends FixedForwardPipe {
public void configure() throws ConfigurationException {
super.configure();

if (StringUtils.isEmpty(ldapProviderURL) && getParameterList().findParameter("ldapProviderURL")==null) {
if (StringUtils.isEmpty(ldapProviderURL) && !getParameterList().hasParameter("ldapProviderURL")) {
throw new ConfigurationException("ldapProviderURL must be specified, either as attribute or as parameter");
}
if (StringUtils.isNotEmpty(ldapProviderURL) && getParameterList().findParameter("ldapProviderURL")!=null) {
if (StringUtils.isNotEmpty(ldapProviderURL) && getParameterList().hasParameter("ldapProviderURL")) {
throw new ConfigurationException("ldapProviderURL can only be specified once, either as attribute or as parameter");
}
if (getParameterList().findParameter("principal")==null) {
if (!getParameterList().hasParameter("principal")) {
throw new ConfigurationException("Parameter 'principal' must be specified");
}
if (getParameterList().findParameter("credentials")==null) {
if (!getParameterList().hasParameter("credentials")) {
throw new ConfigurationException("Parameter 'credentials' must be specified");
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/frankframework/ldap/LdapSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public LdapSender() {

@Override
public void configure() throws ConfigurationException {
if (paramList == null || (paramList.findParameter(ENTRYNAME) == null && getOperation() != Operation.CHALLENGE)) {
if (paramList == null || (!paramList.hasParameter(ENTRYNAME) && getOperation() != Operation.CHALLENGE)) {
throw new ConfigurationException("[" + getName()+ "] Required parameter with the name [entryName] not found!");
}
paramList.configure();
Expand All @@ -299,7 +299,7 @@ public void configure() throws ConfigurationException {
throw new ConfigurationException("["+ getClass().getName() + "] manipulationSubject invalid for update operation (must be ['"
+ Manipulation.ATTRIBUTE + "'], which is default - remove from <pipe>)");
}
if (getOperation() == Operation.CHALLENGE && paramList.findParameter("principal") == null) {
if (getOperation() == Operation.CHALLENGE && !paramList.hasParameter("principal")) {
throw new ConfigurationException("principal should be specified using a parameter when using operation challenge");
}
IParameter credentials = paramList.findParameter("credentials");
Expand All @@ -314,8 +314,8 @@ public void configure() throws ConfigurationException {
if (newPassword != null && !newPassword.isHidden()) {
ConfigurationWarnings.add(this, log, "It's advised to set attribute hidden to true for parameter newPassword.");
}
if (paramList.findParameter("principal") != null) {
if (paramList.findParameter("credentials") == null) {
if (paramList.hasParameter("principal")) {
if (!paramList.hasParameter("credentials")) {
throw new ConfigurationException("principal set as parameter, but no credentials parameter found");
}
principalParameterFound = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void configure() throws ConfigurationException {
if (getAction()==null) {
throw new ConfigurationException("attribute action not specified");
}
if ((getLimit()>0 || (getParameterList()!=null && getParameterList().findParameter(PARAM_LIMIT)!=null)) && getAction()!=MongoAction.FINDMANY) {
if ((getLimit()>0 || (getParameterList()!=null && getParameterList().hasParameter(PARAM_LIMIT))) && getAction()!=MongoAction.FINDMANY) {
throw new ConfigurationException("attribute limit or parameter "+PARAM_LIMIT+" can only be used for action "+MongoAction.FINDMANY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import java.util.concurrent.atomic.AtomicInteger;

import jakarta.annotation.Nonnull;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.frankframework.configuration.ConfigurationException;
import org.frankframework.core.ParameterException;
import org.frankframework.core.PipeLineSession;
import org.frankframework.stream.Message;

import lombok.Getter;
import lombok.Setter;


/**
* List of parameters.
Expand Down Expand Up @@ -92,6 +91,10 @@ public IParameter findParameter(String name) {
return null;
}

public boolean hasParameter(String name) {
return stream().anyMatch(p -> p.getName().equals(name));
}

private boolean parameterEvaluationRequiresInputValue() {
for (IParameter p:this) {
if (p.requiresInputValueForResolution()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void configure() throws ConfigurationException {
throw new ConfigurationException("forward [" + EQUALSFORWARD + "] is not defined");

ParameterList parameterList = getParameterList();
if (parameterList.findParameter(OPERAND1) == null && parameterList.findParameter(OPERAND2) == null) {
if (!parameterList.hasParameter(OPERAND1) && !parameterList.hasParameter(OPERAND2)) {
throw new ConfigurationException("has neither parameter [" + OPERAND1 + "] nor parameter [" + OPERAND2 + "] specified");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package org.frankframework.pipes;

import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import org.frankframework.configuration.ConfigurationException;
import org.frankframework.core.ParameterException;
import org.frankframework.core.PipeLineSession;
Expand All @@ -32,6 +29,8 @@
import org.frankframework.parameters.ParameterValueList;
import org.frankframework.stream.Message;
import org.frankframework.util.XmlUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
* Pipe that lexicographically compares two strings, that must NOT be empty.
Expand Down Expand Up @@ -84,7 +83,7 @@ public void configure() throws ConfigurationException {
throw new ConfigurationException("forward [" + EQUALSFORWARD + "] is not defined");

ParameterList parameterList = getParameterList();
if (parameterList.findParameter(OPERAND1) == null && parameterList.findParameter(OPERAND2) == null) {
if (!parameterList.hasParameter(OPERAND1) && !parameterList.hasParameter(OPERAND2)) {
throw new ConfigurationException("has neither parameter [" + OPERAND1 + "] nor parameter [" + OPERAND2 + "] specified");
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/frankframework/pipes/JwtPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void configure() throws ConfigurationException {
}
}

if (globalSigner == null && getParameterList().findParameter(SHARED_SECRET_PARAMETER_NAME) == null) {
if (globalSigner == null && !getParameterList().hasParameter(SHARED_SECRET_PARAMETER_NAME)) {
throw new ConfigurationException("must either provide a [sharedSecret] (alias) or parameter");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public void configure() throws ConfigurationException {

AuthSSLContextFactory.verifyKeystoreConfiguration(this, null);
if (getAction() == Action.VERIFY) {
if (getParameterList().findParameter(PARAMETER_SIGNATURE)==null) {
if (!getParameterList().hasParameter(PARAMETER_SIGNATURE)) {
throw new ConfigurationException("Parameter [" + PARAMETER_SIGNATURE + "] must be specfied for action [" + action + "]");
}
failureForward = findForward("failure");
if (failureForward==null) {
throw new ConfigurationException("Forward [failure] must be specfied for action [" + action + "]");
throw new ConfigurationException("Forward [failure] must be specified for action [" + action + "]");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void setLogLevel(String level) {

@Override
public String toString() {
String level = getParameterList() != null && getParameterList().findParameter(LOG_LEVEL_ATTRIBUTE_NAME)!=null ? "dynamic" : logLevel;
String level = getParameterList() != null && getParameterList().hasParameter(LOG_LEVEL_ATTRIBUTE_NAME) ? "dynamic" : logLevel;
return "LogSender ["+getName()+"] logLevel ["+level+"] logCategory ["+logCategory+"]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.frankframework.senders;

import jakarta.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.frankframework.configuration.ConfigurationException;
import org.frankframework.core.ISenderWithParameters;
Expand All @@ -26,8 +27,6 @@
import org.frankframework.parameters.ParameterValueList;
import org.frankframework.stream.Message;

import jakarta.annotation.Nullable;

/**
* Provides a base class for senders with parameters.
*
Expand Down Expand Up @@ -64,7 +63,7 @@ public ParameterList getParameterList() {
}

protected void checkStringAttributeOrParameter(String attributeName, String attributeValue, String parameterName) throws ConfigurationException {
if (StringUtils.isEmpty(attributeValue) && (getParameterList()==null || getParameterList().findParameter(parameterName)==null)) {
if (StringUtils.isEmpty(attributeValue) && (getParameterList()==null || !getParameterList().hasParameter(parameterName))) {
throw new ConfigurationException("either attribute "+attributeName+" or parameter "+parameterName+" must be specified");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.frankframework.parameters;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.frankframework.configuration.ConfigurationException;
import org.junit.jupiter.api.Test;

import org.frankframework.configuration.ConfigurationException;

public class ParameterListTest {

@Test
Expand All @@ -25,8 +28,11 @@ public void testParameterList() throws Exception {
list.configure();

assertNotNull(list.findParameter("key1"));
assertTrue(list.hasParameter("key1"), "Expected to find parameter [key1] in parameter list");
assertNotNull(list.findParameter("key2"));
assertTrue(list.hasParameter("key2"), "Expected to find parameter [key2] in parameter list");
assertNull(list.findParameter("doesnt-exist"));
assertFalse(list.hasParameter("doesnt-exist"), "Expected not to find parameter [doesnt-exist] in parameter list");
assertEquals(4, list.size());

List<String> sortedList2 = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void configure(S fileSystem, ParameterList parameterList, IConfigurable o
actions.addAll(Arrays.asList(ACTIONS_MAIL_FS));
}

if (parameterList!=null && parameterList.findParameter(PARAMETER_CONTENTS2) != null && parameterList.findParameter(PARAMETER_CONTENTS1) == null) {
if (parameterList!=null && parameterList.hasParameter(PARAMETER_CONTENTS2) && !parameterList.hasParameter(PARAMETER_CONTENTS1)) {
ConfigurationWarnings.add(owner, log, "parameter ["+PARAMETER_CONTENTS2+"] has been replaced with ["+PARAMETER_CONTENTS1+"]");
parameterList.findParameter(PARAMETER_CONTENTS2).setName(PARAMETER_CONTENTS1);
}
Expand All @@ -193,11 +193,11 @@ public void configure(S fileSystem, ParameterList parameterList, IConfigurable o
action=FileSystemAction.WRITE;
}
checkConfiguration(getAction());
} else if (parameterList == null || parameterList.findParameter(PARAMETER_ACTION) == null) {
} else if (parameterList == null || !parameterList.hasParameter(PARAMETER_ACTION)) {
throw new ConfigurationException(ClassUtils.nameOf(owner)+": either attribute [action] or parameter ["+PARAMETER_ACTION+"] must be specified");
}

if (StringUtils.isNotEmpty(getInputFolder()) && parameterList!=null && parameterList.findParameter(PARAMETER_INPUTFOLDER) != null) {
if (StringUtils.isNotEmpty(getInputFolder()) && parameterList!=null && parameterList.hasParameter(PARAMETER_INPUTFOLDER)) {
ConfigurationWarnings.add(owner, log, "inputFolder configured via attribute [inputFolder] as well as via parameter ["+PARAMETER_INPUTFOLDER+"], parameter will be ignored");
}

Expand Down Expand Up @@ -236,8 +236,8 @@ private void checkConfiguration(FileSystemAction action2) throws ConfigurationEx

protected void actionRequiresAtLeastOneOfTwoParametersOrAttribute(INamedObject owner, ParameterList parameterList, FileSystemAction configuredAction, FileSystemAction action, String parameter1, String parameter2, String attributeName, String attributeValue) throws ConfigurationException {
if (configuredAction == action) {
boolean parameter1Set = parameterList != null && parameterList.findParameter(parameter1) != null;
boolean parameter2Set = parameterList != null && parameterList.findParameter(parameter2) != null;
boolean parameter1Set = parameterList != null && parameterList.hasParameter(parameter1);
boolean parameter2Set = parameterList != null && parameterList.hasParameter(parameter2);
boolean attributeSet = StringUtils.isNotEmpty(attributeValue);
if (!parameter1Set && !parameter2Set && !attributeSet) {
throw new ConfigurationException(ClassUtils.nameOf(owner)+": the ["+action+"] action requires the parameter ["+parameter1+"] "+(parameter2!=null?"or parameter ["+parameter2+"] ":"")+(attributeName!=null?"or the attribute ["+attributeName+"] ": "")+"to be present");
Expand Down
Loading

0 comments on commit accc67f

Please sign in to comment.