001/*
002 * Copyright 2019 Leibniz-Institut für Analytische Wissenschaften – ISAS – e.V..
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.isas.mztab2.io.validators;
017
018import de.isas.mztab2.model.CV;
019import de.isas.mztab2.model.Metadata;
020import java.util.LinkedList;
021import java.util.List;
022import uk.ac.ebi.pride.jmztab2.utils.errors.LogicalErrorType;
023import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabError;
024import uk.ac.ebi.pride.jmztab2.utils.parser.MZTabParserContext;
025
026/**
027 * Validates that the controlled vocabulary section is present in metadata and
028 * that it is correctly populated.
029 *
030 * @author nilshoffmann
031 */
032public class CvValidator implements MetadataValidator<Metadata> {
033
034    @Override
035    public List<MZTabError> validateRefine(Metadata metadata, MZTabParserContext parserContext) {
036        List<MZTabError> errorList = new LinkedList<>();
037        if (metadata.getCv() == null || metadata.getCv().
038                isEmpty()) {
039            errorList.add(new MZTabError(
040                    LogicalErrorType.NotDefineInMetadata, -1,
041                    Metadata.Properties.cv + ""));
042        } else {
043            for (CV cv : metadata.getCv()) {
044                if (cv.getLabel() == null || cv.getLabel().isEmpty()) {
045                    errorList.add(new MZTabError(
046                            LogicalErrorType.NotDefineInMetadata, -1,
047                            Metadata.Properties.cv + "[" + cv.getId() + "]-" + CV.Properties.label));
048                }
049                if (cv.getFullName() == null || cv.getFullName().isEmpty()) {
050                    errorList.add(new MZTabError(
051                            LogicalErrorType.NotDefineInMetadata, -1,
052                            Metadata.Properties.cv + "[" + cv.getId() + "]-" + CV.Properties.fullName));
053                }
054                if (cv.getVersion() == null || cv.getVersion().isEmpty()) {
055                    errorList.add(new MZTabError(
056                            LogicalErrorType.NotDefineInMetadata, -1,
057                            Metadata.Properties.cv + "[" + cv.getId() + "]-" + CV.Properties.version));
058                }
059                if (cv.getUri() == null || cv.getUri().isEmpty()) {
060                    errorList.add(new MZTabError(
061                            LogicalErrorType.NotDefineInMetadata, -1,
062                            Metadata.Properties.cv + "[" + cv.getId() + "]-" + CV.Properties.uri));
063                }
064            }
065        }
066        return errorList;
067    }
068
069}