Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.regnosys.rosetta.common.hashing;
/*-
* ==============
* Rune Common
* ==============
* Copyright (C) 2018 - 2024 REGnosys
* ==============
* 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.
* ==============
*/
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import com.regnosys.rosetta.common.translation.Path;
import com.regnosys.rosetta.common.util.PathUtils;
import com.regnosys.rosetta.common.util.SimpleBuilderProcessor;
import com.regnosys.rosetta.common.util.SimpleProcessor;
import com.rosetta.lib.postprocess.PostProcessorReport;
import com.rosetta.model.lib.GlobalKey;
import com.rosetta.model.lib.RosettaModelObject;
import com.rosetta.model.lib.RosettaModelObjectBuilder;
import com.rosetta.model.lib.meta.FieldWithMeta;
import com.rosetta.model.lib.meta.GlobalKeyFields;
import com.rosetta.model.lib.meta.ReferenceWithMeta.ReferenceWithMetaBuilder;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.process.AttributeMeta;
import com.rosetta.model.lib.process.PostProcessStep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
public class ReferenceResolverProcessStep implements PostProcessStep {
private final ReferenceConfig referenceConfig;
public ReferenceResolverProcessStep(ReferenceConfig referenceConfig) {
this.referenceConfig = referenceConfig;
}
@Override
public Integer getPriority() {
return 2;
}
@Override
public String getName() {
return "Reference Resolver";
}
@Override
public ReferenceResolverPostProcessorReport runProcessStep(
Class extends T> topClass,
T instance) {
RosettaPath path = RosettaPath.valueOf(topClass.getSimpleName());
ReferenceCollector collector = new ReferenceCollector(referenceConfig);
instance.process(path, collector);
ReferenceResolver resolver =
new ReferenceResolver(referenceConfig, collector.globalReferences, collector.helper);
RosettaModelObjectBuilder builder = instance.toBuilder();
builder.process(path, resolver);
return new ReferenceResolverPostProcessorReport((T) builder.build());
}
private static class ReferenceCollector extends SimpleProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(ReferenceCollector.class);
// Table:
// - Class>: referenced Class> (e.g. Quantity or QuantityBuilder)
// - String: reference key value (e.g. "quantity-1")
// - Object: referenced object (e.g. populated Quantity object to be set on ReferenceWithMetaQuantity.value)
private final Table, String, Object> globalReferences = HashBasedTable.create();
private final ScopeReferenceHelper