use of org.onap.so.apihandlerinfra.Actions 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.apihandlerinfra.Actions in project so by onap.
the class ConfigurationParametersValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
ServiceInstancesRequest sir = info.getSir();
List<Map<String, String>> configParams = sir.getRequestDetails().getConfigurationParameters();
String requestScope = info.getRequestScope();
Actions action = info.getAction();
if (configParams.isEmpty() && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut) {
throw new ValidationException("configuration parameters");
}
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class ProjectOwningEntityValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
int reqVersion = info.getReqVersion();
Project project;
OwningEntity owningEntity;
String requestScope = info.getRequestScope();
Actions action = info.getAction();
project = info.getSir().getRequestDetails().getProject();
owningEntity = info.getSir().getRequestDetails().getOwningEntity();
if (reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance || action == Action.assignInstance) {
if (reqVersion > 5 && owningEntity == null) {
throw new ValidationException("owningEntity");
}
if (owningEntity != null && empty(owningEntity.getOwningEntityId())) {
throw new ValidationException("owningEntityId");
}
if (project != null && empty(project.getProjectName())) {
throw new ValidationException("projectName");
}
}
info.setProject(project);
info.setOE(owningEntity);
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class RequestInfoValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
int reqVersion = info.getReqVersion();
String requestScope = info.getRequestScope();
Actions action = info.getAction();
Boolean aLaCarteFlag = info.getALaCarteFlag();
// required for all operations in V4
if (empty(requestInfo.getRequestorId()) && reqVersion >= 4) {
throw new ValidationException("requestorId");
}
if (empty(requestInfo.getSource())) {
throw new ValidationException("source");
}
if (!empty(requestInfo.getInstanceName())) {
if (!requestInfo.getInstanceName().matches(Constants.VALID_INSTANCE_NAME_FORMAT)) {
throw new ValidationException("instanceName format");
}
}
if (empty(requestInfo.getProductFamilyId())) {
// Mandatory for macro request create service instance
if ((requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.createInstance) || (requestScope.equalsIgnoreCase(ModelType.network.name()) && (action == Action.createInstance || action == Action.updateInstance)) || (reqVersion > 3 && (aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance)) {
throw new ValidationException("productFamilyId");
}
}
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class CloudConfigurationValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
CloudConfiguration cloudConfiguration = info.getSir().getRequestDetails().getCloudConfiguration();
String requestScope = info.getRequestScope();
int reqVersion = info.getReqVersion();
Actions action = info.getAction();
Boolean aLaCarteFlag = info.getALaCarteFlag();
if (!requestScope.equals(ModelType.instanceGroup.toString())) {
if (cloudConfiguration == null && reqVersion >= 5 && (aLaCarteFlag != null && aLaCarteFlag)) {
if ((!requestScope.equalsIgnoreCase(ModelType.service.name()) && !requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.createInstance || action == Action.deleteInstance || action == Action.updateInstance)) {
throw new ValidationException("cloudConfiguration");
}
if (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.enablePort || action == Action.disablePort || action == Action.activateInstance || action == Action.deactivateInstance)) {
throw new ValidationException("cloudConfiguration");
}
if (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && (action == Action.deactivateAndCloudDelete || action == Action.scaleOut)) {
throw new ValidationException("cloudConfiguration");
}
if (requestScope.equals(ModelType.vnf.name()) && action == Action.recreateInstance) {
throw new ValidationException("cloudConfiguration", true);
}
}
}
if (cloudConfiguration == null && ((aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && reqVersion < 5)) {
throw new ValidationException("cloudConfiguration");
}
if (cloudConfiguration != null) {
if (empty(cloudConfiguration.getLcpCloudRegionId())) {
throw new ValidationException("lcpCloudRegionId");
}
if (empty(cloudConfiguration.getTenantId()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name()))) {
throw new ValidationException("tenantId");
}
}
return info;
}
Aggregations