use of org.onap.so.serviceinstancebeans.RequestParameters in project so by onap.
the class ServiceInstancesTest method testUserParams.
@Test
public void testUserParams() throws IOException {
ObjectMapper mapper = new ObjectMapper();
ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
String userParamsTxt = inputStream("/userParams.txt");
List<Map<String, Object>> userParams = requestHandlerUtils.configureUserParams(requestParameters);
System.out.println(userParams);
assertTrue(userParams.size() > 0);
assertTrue(userParams.get(0).containsKey("name"));
assertTrue(userParams.get(0).containsKey("value"));
assertEquals(userParamsTxt.replaceAll("\\s+", ""), userParams.toString().replaceAll("\\s+", ""));
}
use of org.onap.so.serviceinstancebeans.RequestParameters in project so by onap.
the class RequestParametersValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
int reqVersion = info.getReqVersion();
String requestScope = info.getRequestScope();
Actions action = info.getAction();
RequestParameters requestParameters = info.getReqParameters();
if (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action == Action.createInstance || action == Action.assignInstance)) {
if (requestParameters == null) {
throw new ValidationException("requestParameters");
}
if (empty(requestParameters.getSubscriptionServiceType())) {
throw new ValidationException("subscriptionServiceType");
}
}
if (reqVersion >= 4) {
if (Action.addRelationships.equals(action) || Action.removeRelationships.equals(action)) {
if (requestParameters == null || requestParameters.getALaCarte() == null) {
throw new ValidationException("aLaCarte in requestParameters");
}
}
}
if (requestParameters == null && !requestScope.equalsIgnoreCase(ModelType.service.name())) {
info.setALaCarteFlag(true);
}
if (requestParameters != null) {
if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
if (action == Action.updateInstance) {
if (requestParameters.isUsePreload() == null) {
requestParameters.setUsePreload(true);
}
}
if (action == Action.replaceInstance) {
if (requestParameters.getRebuildVolumeGroups() == null) {
requestParameters.setRebuildVolumeGroups(false);
}
}
}
if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) {
if (action == Action.createInstance || action == Action.updateInstance) {
if (requestParameters.isUsePreload() == null) {
if (reqVersion >= 4) {
if (requestParameters.getALaCarte() == null || requestParameters.getALaCarte() == true) {
requestParameters.setUsePreload(true);
} else {
requestParameters.setUsePreload(false);
}
} else {
requestParameters.setUsePreload(true);
}
}
}
}
if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
if (action == Action.createInstance) {
if (requestParameters.isUsePreload() == null) {
if (reqVersion >= 4) {
if (requestParameters.getALaCarte() == null || requestParameters.getALaCarte() == false) {
requestParameters.setUsePreload(false);
} else {
requestParameters.setUsePreload(true);
}
} else {
requestParameters.setUsePreload(true);
}
}
}
}
if (reqVersion >= 4) {
if (requestParameters.getALaCarte() != null) {
info.setALaCarteFlag(requestParameters.getALaCarte());
} else if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
if (action == Action.createInstance || action == Action.deleteInstance || action == Action.activateInstance || action == Action.deactivateInstance) {
if (requestParameters.getALaCarte() == null) {
requestParameters.setaLaCarte(false);
info.setALaCarteFlag(requestParameters.getALaCarte());
}
}
} else {
info.setALaCarteFlag(true);
}
} else {
info.setALaCarteFlag(true);
}
}
return info;
}
use of org.onap.so.serviceinstancebeans.RequestParameters in project so by onap.
the class BpmnRequestBuilder method createRequestParameters.
public RequestParameters createRequestParameters() {
RequestParameters requestParams = new RequestParameters();
requestParams.setaLaCarte(true);
requestParams.setTestApi("GR_API");
return requestParams;
}
use of org.onap.so.serviceinstancebeans.RequestParameters in project so by onap.
the class ModelInfoValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
ModelInfo modelInfo = info.getSir().getRequestDetails().getModelInfo();
RequestParameters requestParameters = info.getReqParameters();
String requestScope = info.getRequestScope();
Actions action = info.getAction();
int reqVersion = info.getReqVersion();
Boolean aLaCarteFlag = info.getALaCarteFlag();
if (!requestScope.equals(ModelType.instanceGroup.toString())) {
if (!empty(modelInfo.getModelNameVersionId())) {
modelInfo.setModelVersionId(modelInfo.getModelNameVersionId());
}
// modelCustomizationId is required when usePreLoad is false for v4 and higher for VF Module Create
if (requestParameters != null && reqVersion >= 4 && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.createInstance && !requestParameters.isUsePreload()) {
if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
throw new ValidationException("modelCustomizationId");
}
}
// modelCustomizationId is required for v5 and higher for VF Module Replace
if (requestParameters != null && reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.replaceInstance) {
if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
throw new ValidationException("modelCustomizationId");
}
}
// modelCustomizationId or modelCustomizationName are required for VNF Replace
if (requestParameters != null && reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.replaceInstance || action == Action.recreateInstance) {
if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId()) && modelInfo.getModelCustomizationName() == null) {
throw new ValidationException("modelCustomizationId or modelCustomizationName");
}
}
// create and updates except for network (except v4)
if (empty(modelInfo.getModelInvariantId()) && ((reqVersion > 2 && (aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) || !(reqVersion < 4 && requestScope.equalsIgnoreCase(ModelType.network.name())) && (action == Action.createInstance || action == Action.updateInstance || action == Action.enablePort || action == Action.disablePort || action == Action.addRelationships || action == Action.removeRelationships || (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) {
throw new ValidationException("modelInvariantId");
}
if (empty(modelInfo.getModelInvariantId()) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)) {
throw new ValidationException("modelInvariantId");
}
if (empty(modelInfo.getModelInvariantId()) && (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.recreateInstance)) {
throw new ValidationException("modelInvariantId", true);
}
if (!empty(modelInfo.getModelInvariantId()) && !UUIDChecker.isValidUUID(modelInfo.getModelInvariantId())) {
throw new ValidationException("modelInvariantId format");
}
if (reqVersion >= 4 && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && empty(modelInfo.getModelName()) && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships || action == Action.recreateInstance || ((action == Action.deleteInstance || action == Action.scaleOut) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()))))) {
throw new ValidationException("modelName", true);
}
if (empty(modelInfo.getModelVersion()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (!(reqVersion < 4 && requestScope.equalsIgnoreCase(ModelType.network.name())) && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships || action == Action.scaleOut))) {
throw new ValidationException("modelVersion");
}
if (empty(modelInfo.getModelVersion()) && (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.recreateInstance)) {
throw new ValidationException("modelVersion", true);
}
// is required for serviceInstance delete macro when aLaCarte=false in v4
if (reqVersion >= 4 && empty(modelInfo.getModelVersionId()) && (((aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) || (action == Action.createInstance || action == Action.updateInstance || action == Action.enablePort || action == Action.disablePort || action == Action.addRelationships || action == Action.removeRelationships || (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) {
throw new ValidationException("modelVersionId");
}
if (empty(modelInfo.getModelVersionId()) && (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.recreateInstance)) {
throw new ValidationException("modelVersionId", true);
}
if (empty(modelInfo.getModelVersionId()) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)) {
throw new ValidationException("modelVersionId");
}
if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty(modelInfo.getModelCustomizationName())) {
if (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
throw new ValidationException("modelCustomizationId or modelCustomizationName");
}
}
if (reqVersion >= 4 && (!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) && (requestScope.equalsIgnoreCase(ModelType.network.name()) || requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.updateInstance || action == Action.createInstance)) {
throw new ValidationException("modelCustomizationId");
}
if (empty(modelInfo.getModelCustomizationId()) && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut && !(requestParameters.getTestApi() == TestApi.VNF_API.name() && requestParameters.isUsePreload() == true)) {
throw new ValidationException("modelCustomizationId");
}
} else {
if (empty(modelInfo.getModelVersionId()) && action == Action.createInstance) {
throw new ValidationException("modelVersionId", true);
}
}
return info;
}
use of org.onap.so.serviceinstancebeans.RequestParameters in project so by onap.
the class ApplyUpdatedConfigValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
RequestParameters requestParameters = info.getSir().getRequestDetails().getRequestParameters();
RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
if (requestInfo == null) {
throw new ValidationException("requestInfo");
} else if (empty(requestInfo.getRequestorId())) {
throw new ValidationException("requestorId");
} else if (empty(requestInfo.getSource())) {
throw new ValidationException("source");
}
if (requestParameters == null) {
throw new ValidationException("requestParameters");
}
return info;
}
Aggregations