@Override
public ResponseEntity<Object> getMoi(final HttpServletRequest httpServletRequest, final Scope scope,
- final String filter, final List<String> attributes,
+ final String filter, List<String> attributes,
final List<String> fields,
final ClassNameIdGetDataNodeSelectorParameter dataNodeSelector) {
final RequestPathParameters requestPathParameters =
parameterMapper.extractRequestParameters(httpServletRequest);
+ attributes = isAttributesInRequest(httpServletRequest) ? attributes : null;
try {
final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(
alternateIdMatcher.getCmHandleIdByLongestMatchingAlternateId(
return alternateId + " not found";
}
+ private boolean isAttributesInRequest(final HttpServletRequest httpServletRequest) {
+ return httpServletRequest.getParameterMap().containsKey("attributes");
+ }
}
import com.fasterxml.jackson.databind.ObjectMapper
import jakarta.servlet.ServletException
-import org.onap.cps.ncmp.api.data.models.OperationType
-import org.onap.cps.ncmp.api.exceptions.ProvMnSException
import org.onap.cps.ncmp.api.inventory.models.CompositeState
import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException
import org.onap.cps.ncmp.impl.data.policyexecutor.PolicyExecutor
import org.onap.cps.ncmp.impl.inventory.InventoryPersistence
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
import org.onap.cps.ncmp.impl.provmns.model.PatchItem
-import org.onap.cps.ncmp.impl.provmns.model.PatchOperation
import org.onap.cps.ncmp.impl.provmns.model.ResourceOneOf
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
import org.onap.cps.ncmp.rest.provmns.ErrorResponseBuilder
.queryParameter("scopeType", scope.getScopeType() != null ? scope.getScopeType().getValue() : null)
.queryParameter("scopeLevel", scope.getScopeLevel() != null ? scope.getScopeLevel().toString() : null)
.queryParameter("filter", filter)
- .queryParameter("attributes", attributesString.isBlank() ? null : attributesString)
+ .queryParameterWithBlankValue("attributes", attributes == null ? null : attributesString)
.queryParameter("fields", fieldsString.isBlank() ? null : fieldsString)
.queryParameter("dataNodeSelector", dataNodeSelector.getDataNodeSelector())
.createUrlTemplateParameters(dmiServiceName, "ProvMnS");
/**
* Add a query parameter to the URL.
- * Do NOT encode as the builder wil take care of encoding
+ * Do NOT encode as the builder will take care of encoding
*
* @param queryParameterName the name of the variable
* @param queryParameterValue the value of the variable (only Strings are supported).
return this;
}
+ /**
+ * Add a query parameter to the URL. Query parameter could have a blank value.
+ * Do NOT encode as the builder will take care of encoding
+ *
+ * @param queryParameterName the name of the variable
+ * @param queryParameterValue the value of the variable (only Strings are supported).
+ *
+ * @return this builder instance
+ */
+ public RestServiceUrlTemplateBuilder queryParameterWithBlankValue(final String queryParameterName,
+ final String queryParameterValue) {
+ if (queryParameterValue != null) {
+ queryParameters.put(queryParameterName, queryParameterValue);
+ }
+ return this;
+ }
+
/**
* Constructs a URL template with variables based on the accumulated path segments and query parameters.
*
new ClassNameIdGetDataNodeSelectorParameter(dataNodeSelector: 'my dataNodeSelector'),
new YangModelCmHandle(dmiServiceName: 'myDmiService'),
new RequestPathParameters(uriLdnFirstPart:'myPathVariable=myPathValue', className: 'myClassName', id:'myId'))
- then: 'the template has the correct correct'
+ then: 'the template has the correct result'
assert result.urlTemplate.toString().startsWith('myDmiService/ProvMnS/v1/myPathVariable=myPathValue/myClassName=myId')
and: 'all url variable have been set correctly'
assert result.urlVariables.size() == 6
assert result.urlVariables.keySet()[0] == 'dataNodeSelector'
}
+ def 'Create url template parameters for GET with empty attributes'() {
+ when: 'Creating URL parameters for GET with empty attributes and fields'
+ def result = objectUnderTest.createUrlTemplateParametersForRead(new Scope(),
+ null,
+ [],
+ [],
+ new ClassNameIdGetDataNodeSelectorParameter(dataNodeSelector: 'my dataNodeSelector'),
+ new YangModelCmHandle(dmiServiceName: 'myDmiService'),
+ new RequestPathParameters(uriLdnFirstPart:'myPathVariable=myPathValue', className: 'myClassName', id:'myId'))
+ then: 'the template has the correct result'
+ assert result.urlTemplate.toString().startsWith('myDmiService/ProvMnS/v1/myPathVariable=myPathValue/myClassName=myId')
+ and: 'The url variables contains a data node selector and attributes parameters'
+ assert result.urlVariables.size() == 2
+ assert result.urlVariables.keySet()[0] == 'dataNodeSelector'
+ assert result.urlVariables.keySet()[1] == 'attributes'
+ and: 'the attributes value is blank'
+ assert result.urlVariables.attributes == ''
+ }
+
def 'Create url template parameters for PUT and PATCH.'() {
when: 'Creating URL parameters for PUT (or PATCH)'
def result = objectUnderTest.createUrlTemplateParametersForWrite(
where: 'the following parameter values are used'
value << [ null, '', ' ' ]
}
+
+ def 'Build URL template parameters with empty value query parameters.'() {
+ when: 'the query parameter with a blank value is given to the builder'
+ objectUnderTest.queryParameterWithBlankValue('myParam', '')
+ and: 'the URL template parameters are created'
+ def result = objectUnderTest.createUrlTemplateParameters('myServer', 'myBasePath')
+ then: 'parameter myParam is added with empty value'
+ assert result.urlVariables() == ['myParam': '']
+ }
+
+ def 'Build URL template parameters with null value query parameters.'() {
+ when: 'the query parameter with null value is given to the builder'
+ objectUnderTest.queryParameterWithBlankValue('myParam', null)
+ and: 'the URL template parameters are created'
+ def result = objectUnderTest.createUrlTemplateParameters('myServer', 'myBasePath')
+ then: 'parameter myParam is not added'
+ assert result.urlVariables().size() == 0
+ }
}