001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.oscal.lib.profile.resolver.support; 007 008import gov.nist.secauto.metaschema.core.metapath.item.node.IModelNodeItem; 009import gov.nist.secauto.oscal.lib.profile.resolver.support.IEntityItem.ItemType; 010 011import edu.umd.cs.findbugs.annotations.NonNull; 012 013public class ReassignmentIndexer 014 extends BasicIndexer { 015 @NonNull 016 private final IIdentifierMapper mapper; 017 018 public ReassignmentIndexer(@NonNull IIdentifierMapper mapper) { 019 this.mapper = mapper; 020 } 021 022 @NonNull 023 protected IIdentifierMapper getMapper() { 024 return mapper; 025 } 026 027 @Override 028 protected AbstractEntityItem.Builder newBuilder( 029 IModelNodeItem<?, ?> item, 030 ItemType itemType, 031 String identifier) { 032 AbstractEntityItem.Builder builder = super.newBuilder(item, itemType, identifier); 033 034 String reassignment = getMapper().mapByItemType(itemType, identifier); 035 if (!identifier.equals(reassignment)) { 036 builder.reassignedIdentifier(reassignment); 037 } 038 return builder; 039 } 040 041 @Override 042 public IEntityItem getEntity(ItemType itemType, String identifier, boolean normalize) { 043 // reassign the identifier 044 String reassignment = getMapper().mapByItemType(itemType, identifier); 045 // lookup using the reassigned identifier 046 return super.getEntity(itemType, reassignment, normalize); 047 } 048}