Skip to content
Snippets Groups Projects
Commit 30dc6217 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-6239 Remove ParameterValidatorService

parent f0ebfafc
Branches
Tags
No related merge requests found
/*
* @formatter:off
*
* Copyright 2021-2022 Koordinierungsstelle für IT-Standards (KoSIT)
*
* Licensed under the European Public License, Version 1.2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/EUPL-1.2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* @formatter:on
*/
package de.ozgcloud.xta.test.app.service;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
import genv3.de.xoev.transport.xta.x211.ContentType;
import genv3.de.xoev.transport.xta.x211.GenericContentContainer;
import genv3.de.xoev.transport.xta.x211.GenericContentContainer.ContentContainer;
import genv3.eu.osci.ws.x2008.x05.transport.MsgSelector;
import genv3.eu.osci.ws.x2014.x10.transport.DestinationsType;
import genv3.eu.osci.ws.x2014.x10.transport.MessageMetaData;
import genv3.eu.osci.ws.x2014.x10.transport.MsgIdentificationType;
import genv3.eu.osci.ws.x2014.x10.transport.OriginatorsType;
import genv3.eu.osci.ws.x2014.x10.transport.PartyIdentifierType;
import genv3.eu.osci.ws.x2014.x10.transport.PartyType;
import genv3.eu.osci.ws.x2014.x10.transport.QualifierType;
import lombok.extern.log4j.Log4j2;
@Log4j2
@Service
public class ParameterValidatorService {
public boolean isNotNull(final Object obj, final CharSequence parameter) {
if (obj == null) {
log.error("Parameter '{}' was null", parameter);
return false;
}
return true;
}
public boolean isNotBlank(final String str, final CharSequence parameter) {
boolean result = isNotNull(str, parameter);
if (result && str.trim().length() == 0) {
log.error("Parameter '{}' was blank", parameter);
return false;
}
return result;
}
public boolean isEquals(final String expectedStr, final String otherStr, final CharSequence parameter) {
if (isNotNull(otherStr, parameter)) {
if (!expectedStr.equals(otherStr)) {
log.error("Parameter '{}' was wrong. expected='{}' received='{}'", parameter, expectedStr, otherStr);
}
return false;
}
return true;
}
public boolean isListNotEmpty(final List<?> list, final CharSequence parameter) {
boolean result = isNotNull(list, parameter);
if (result && list.isEmpty()) {
log.error("Parameter list '{}' was empty", parameter);
return false;
}
return result;
}
public boolean isListSizeEquals(final List<?> list, final int expectedSize, final CharSequence parameter) {
boolean result = isNotNull(list, parameter);
if (result && list.size() != expectedSize) {
log.error("Parameter list '{}' has wrong size.", parameter);
return false;
}
return result;
}
public void checkMessageMetaData(final MessageMetaData messageMetaData, // NOSONAR
final Optional<String> expectedMessageId) {
XtaParameter param = XtaParameter.MESSAGE_META_DATA;
// TODO scenario is needed to check delivery attributes
if (isNotNull(messageMetaData, param)) {
// TODO use ScenarioRole to check the properties see Table 5.1 of the specification
// if (isNotNull(messageMetaData.getDeliveryAttributes(), param.join(XtaParameter.DELIVERY_ATTRIBUTES))) {
// XtaParameter subparam = param.join(XtaParameter.DELIVERY_ATTRIBUTES);
// DeliveryAttributesType deliveryAttributes = messageMetaData.getDeliveryAttributes();
// isNotNull(deliveryAttributes.getDelivery(), subparam.join(XtaParameter.DELIVERY));
// isNotNull(deliveryAttributes.getInitialFetch(), subparam.join(XtaParameter.INITIAL_FETCH));
// isNotNull(deliveryAttributes.getInitialSend(), subparam.join(XtaParameter.INITIAL_SEND));
// isNotNull(deliveryAttributes.getOrigin(), subparam.join(XtaParameter.ORIGIN));
// }
if (isNotNull(messageMetaData.getOriginators(), param.join(XtaParameter.ORIGINATORS))) {
XtaParameter subparam = param.join(XtaParameter.ORIGINATORS);
OriginatorsType originators = messageMetaData.getOriginators();
checkPartyType(originators.getAuthor(), subparam.join(XtaParameter.AUTHOR));
if (originators.getSender() != null) {
checkPartyType(originators.getSender(), subparam.join(XtaParameter.SENDER));
} else {
// TODO wir haben keine protokoll-warnung, daher nur eine log-message
log.warn("originator/sender is missing, but it's not required");
}
}
if (isNotNull(messageMetaData.getDestinations(), param.join(XtaParameter.DESTINATIONS))) {
DestinationsType destinations = messageMetaData.getDestinations();
checkPartyType(destinations.getReader(), param.join(XtaParameter.DESTINATIONS, XtaParameter.READER));
}
if (isNotNull(messageMetaData.getMsgIdentification(), param.join(XtaParameter.MSG_IDENTIFICATION))) {
MsgIdentificationType msgIdentification = messageMetaData.getMsgIdentification();
if (expectedMessageId.isPresent()) {
isEquals(expectedMessageId.get(), msgIdentification.getMessageID().getValue(),
param.join(XtaParameter.MSG_IDENTIFICATION, XtaParameter.MESSAGE_ID));
}
}
if (isNotNull(messageMetaData.getQualifier(), param.join(XtaParameter.QUALIFIER))) {
XtaParameter subparam = param.join(XtaParameter.QUALIFIER);
QualifierType qualifier = messageMetaData.getQualifier();
isNotNull(qualifier.getService(), subparam.join(XtaParameter.SERVICE));
isNotNull(qualifier.getBusinessScenario(), param.join(XtaParameter.BUSINESS_SCENARIO));
isNotNull(qualifier.getMessageType(), param.join(XtaParameter.MESSAGE_TYPE));
}
isNotNull(messageMetaData.getMsgSize(), param.join(XtaParameter.MSG_SIZE));
}
}
public void checkPartyType(final PartyType partyType, final XtaParameter parameter) {
if (isNotNull(partyType, parameter)) {
XtaParameter subparam = parameter.join(XtaParameter.IDENTIFIER);
if (isNotNull(partyType.getIdentifier(), subparam)) {
PartyIdentifierType identifier = partyType.getIdentifier();
isNotBlank(identifier.getCategory(), subparam.join(XtaParameter.CATEGORY));
isNotBlank(identifier.getType(), subparam.join(XtaParameter.TYPE));
}
}
}
public void checkMessage(final GenericContentContainer request) {
if (request.getContentContainer() == null && request.getEncryptedData() == null) {
log.error("No ContentContainer or EncryptedData element found");
} else if (request.getContentContainer() != null) {
ContentContainer contentContainer = request.getContentContainer();
if (isNotNull(contentContainer.getMessage(), XtaParameter.MESSAGE)) {
ContentType message = contentContainer.getMessage();
isNotNull(message.getValue(), XtaParameter.MESSAGE.join("value"));
isNotBlank(message.getContentType(), XtaParameter.MESSAGE.join("contentType"));
isNotBlank(message.getEncoding(), XtaParameter.MESSAGE.join("encoding"));
isNotBlank(message.getFilename(), XtaParameter.MESSAGE.join("filename"));
isNotBlank(message.getId(), XtaParameter.MESSAGE.join("id"));
isNotNull(message.getSize(), XtaParameter.MESSAGE.join("size"));
}
} else {
log.info("message is encryptd");
}
}
public void checkMsgSelector(final MsgSelector msgSelector, final Optional<String> expectedMessageId) {
if (isNotNull(msgSelector, XtaParameter.MSG_SELECTOR)) {
isNotNull(msgSelector.isNewEntry(), XtaParameter.MSG_SELECTOR.join("newEntry"));
isNotNull(msgSelector.getMsgBoxEntryTimeFrom(),
XtaParameter.MSG_SELECTOR.join("MsgBoxEntryTimeFrom"));
isNotNull(msgSelector.getMsgBoxEntryTimeTo(),
XtaParameter.MSG_SELECTOR.join("MsgBoxEntryTimeTo"));
if (expectedMessageId.isPresent() && isListNotEmpty(msgSelector.getMessageID(),
XtaParameter.MSG_SELECTOR.join(XtaParameter.MESSAGE_ID))) {
isEquals(expectedMessageId.get(), msgSelector.getMessageID().get(0).getValue(),
XtaParameter.MSG_SELECTOR.join(XtaParameter.MESSAGE_ID));
}
}
}
}
/*
* @formatter:off
*
* Copyright 2021-2022 Koordinierungsstelle für IT-Standards (KoSIT)
*
* Licensed under the European Public License, Version 1.2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/EUPL-1.2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* @formatter:on
*/
package de.ozgcloud.xta.test.app.service;
import java.util.StringJoiner;
import groovy.transform.EqualsAndHashCode;
@EqualsAndHashCode
public class XtaParameter implements CharSequence {
private static final String SEPARATOR = ".";
public static final XtaParameter AUTHOR = new XtaParameter("Author");
public static final XtaParameter BUSINESS_SCENARIO = new XtaParameter("BusinessScenario");
public static final XtaParameter CATEGORY = new XtaParameter("category");
public static final XtaParameter DELIVERY = new XtaParameter("Delivery");
public static final XtaParameter DELIVERY_ATTRIBUTES = new XtaParameter("DeliveryAttributes");
public static final XtaParameter DESTINATIONS = new XtaParameter("Destinations");
public static final XtaParameter IDENTIFIER = new XtaParameter("Identifier");
public static final XtaParameter INITIAL_FETCH = new XtaParameter("InitialFetch");
public static final XtaParameter INITIAL_SEND = new XtaParameter("InitialSend");
public static final XtaParameter MESSAGE = new XtaParameter("Message");
public static final XtaParameter MESSAGE_ID = new XtaParameter("MessageID");
public static final XtaParameter MESSAGE_META_DATA = new XtaParameter("MessageMetaData");
public static final XtaParameter MESSAGE_TYPE = new XtaParameter("MessageType");
public static final XtaParameter MSG_BOX_REQUEST_ID = new XtaParameter("MsgBoxRequestID");
public static final XtaParameter MSG_BOX_RESPONSE = new XtaParameter("MsgBoxResponse");
public static final XtaParameter MSG_IDENTIFICATION = new XtaParameter("MsgIdentification");
public static final XtaParameter MSG_SELECTOR = new XtaParameter("MsgSelector");
public static final XtaParameter MSG_SIZE = new XtaParameter("MsgSize");
public static final XtaParameter QUALIFIER = new XtaParameter("Qualifier");
public static final XtaParameter READER = new XtaParameter("Reader");
public static final XtaParameter SENDER = new XtaParameter("Sender");
public static final XtaParameter SERVICE = new XtaParameter("Service");
public static final XtaParameter ORIGIN = new XtaParameter("Origin");
public static final XtaParameter ORIGINATORS = new XtaParameter("Originators");
public static final XtaParameter TYPE = new XtaParameter("type");
private String parameter;
public XtaParameter(final String parameter) {
this.parameter = parameter;
}
public XtaParameter join(final CharSequence parameter) {
return new XtaParameter(this.parameter + SEPARATOR + parameter);
}
public XtaParameter join(final CharSequence parameter, final CharSequence parameter2) {
return new XtaParameter(this.parameter + SEPARATOR + parameter + SEPARATOR + parameter2);
}
public XtaParameter join(final CharSequence parameter, final CharSequence... charSequences) {
StringJoiner stringJoiner = new StringJoiner(SEPARATOR);
stringJoiner.add(this.parameter);
stringJoiner.add(parameter);
for (int i = 0; i < charSequences.length; i++) {
stringJoiner.add(charSequences[i]);
}
return new XtaParameter(stringJoiner.toString());
}
@Override
public int length() {
return parameter.length();
}
@Override
public char charAt(final int index) {
return parameter.charAt(index);
}
@Override
public CharSequence subSequence(final int start, final int end) {
return parameter.subSequence(start, end);
}
@Override
public String toString() {
return parameter;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment