/* * ============LICENSE_START====================================================================== * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. * =============================================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * 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. * ============LICENSE_END======================================================================== * */ package com.oransc.rappmanager.models.csar.validator; import com.oransc.rappmanager.models.exception.RappValidationException; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.web.multipart.MultipartFile; @Component public class NamingValidator implements RappValidator { private static final int VALIDATION_ORDER = 1; @Override public int getOrder() { return VALIDATION_ORDER; } @Override public void validate(Object target, Errors errors) { MultipartFile multipartFile = (MultipartFile) target; String originalFilename = multipartFile.getOriginalFilename(); if (originalFilename == null || !originalFilename.endsWith(".csar")) { throw new RappValidationException("rApp package name should end with .csar"); } } }