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.Database; 020import de.isas.mztab2.model.Metadata; 021import java.util.LinkedList; 022import java.util.List; 023import uk.ac.ebi.pride.jmztab2.utils.errors.LogicalErrorType; 024import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabError; 025import uk.ac.ebi.pride.jmztab2.utils.parser.MZTabParserContext; 026 027/** 028 * Validates that the database section is present and correctly populated in 029 * metadata. 030 * 031 * @author nilshoffmann 032 */ 033public class DatabaseValidator implements RefiningValidator<Metadata> { 034 035 @Override 036 public List<MZTabError> validateRefine(Metadata metadata, MZTabParserContext parserContext) { 037 List<MZTabError> errorList = new LinkedList<>(); 038 if (metadata.getDatabase() == null || metadata.getDatabase(). 039 isEmpty()) { 040 errorList.add(new MZTabError( 041 LogicalErrorType.NotDefineInMetadata, -1, 042 Metadata.Properties.database + "")); 043 } else { 044 for (Database db : metadata.getDatabase()) { 045 if (db.getParam(). 046 getName(). 047 equals("no database")) { 048 if (db.getPrefix() != null && !db.getPrefix(). 049 equals("null")) { 050 errorList.add(new MZTabError( 051 LogicalErrorType.NoDatabaseMustHaveNullPrefix, 052 -1, 053 db.getId() + "", db.getPrefix())); 054 } 055 if (db.getUri() != null && !db.getUri(). 056 equals("null")) { 057 errorList.add(new MZTabError( 058 LogicalErrorType.NotDefineInMetadata, -1, 059 Metadata.Properties.database + "[" + db.getId() + "]-" + Database.Properties.uri)); 060 } 061 } else { 062 if (db.getUri() == null) { 063 errorList.add(new MZTabError( 064 LogicalErrorType.NotDefineInMetadata, -1, 065 Metadata.Properties.database + "[" + db.getId() + "]-" + Database.Properties.uri)); 066 } 067 } 068 if (db.getVersion() == null) { 069 errorList.add(new MZTabError( 070 LogicalErrorType.NotDefineInMetadata, -1, 071 Metadata.Properties.database + "[" + db.getId() + "]-" + Database.Properties.version)); 072 } 073 } 074 } 075 return errorList; 076 } 077 078}