001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 Echo Three, LLC 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// -------------------------------------------------------------------------------- 016 017package com.echothree.model.control.item.server.logic.checksum; 018 019import com.echothree.util.common.message.ExecutionErrors; 020import com.echothree.util.server.message.ExecutionErrorAccumulator; 021import javax.enterprise.context.ApplicationScoped; 022import javax.inject.Inject; 023 024@ApplicationScoped 025public class BooklandEanChecksumLogic 026 extends BaseChecksumLogic 027 implements ItemAliasChecksumInterface { 028 029 @Inject 030 Ean13ChecksumLogic ean13ChecksumLogic; 031 032 protected BooklandEanChecksumLogic() { 033 super(); 034 } 035 036 @Override 037 public void checkChecksum(final ExecutionErrorAccumulator eea, final String alias) { 038 if(alias.length() == 13) { 039 if(alias.matches("\\d{13}")) { 040 switch(Integer.parseInt(alias.substring(0, 3))) { 041 case 978, 979 -> ean13ChecksumLogic.checkChecksum(eea, alias); 042 default -> eea.addExecutionError(ExecutionErrors.IncorrectBooklandEanPrefix.name(), alias); 043 } 044 } else { 045 eea.addExecutionError(ExecutionErrors.IncorrectBooklandEanCharacter.name(), alias); 046 } 047 } else { 048 eea.addExecutionError(ExecutionErrors.IncorrectBooklandEanLength.name(), alias); 049 } 050 } 051 052}