All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.regnosys.rosetta.translate.ParserResult.xtend Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.regnosys.rosetta.translate

import com.regnosys.rosetta.common.translation.MappingContext
import com.regnosys.rosetta.common.translation.MappingProcessor
import com.regnosys.rosetta.common.translation.Path.PathElement
import com.rosetta.model.lib.RosettaModelObjectBuilder
import com.rosetta.model.lib.path.RosettaPath
import java.util.Collections
import java.util.List
import java.util.Map
import java.util.Optional
import java.util.regex.Pattern
import org.eclipse.xtend.lib.annotations.Data

@Data
class ParserResult {
	RosettaModelObjectBuilder rosettaInstance
	Context context
	
	def getMappingForRosetta(String path) {
		val split = path.split("\\.").map[s|s.toPathElement].toList
		context.mappingContext.mappings.findFirst[m|m.rosettaPath?.elements==split]
		context.mappingContext.mappings.filter[rosettaPath!==null].findFirst[m|m.rosettaPath.elements==split]
	}
	
	static Pattern elementPattern = Pattern.compile("(\\w*)(?:\\[(\\d*)\\])?")
	
	def toPathElement(String string) {
		val matcher = elementPattern.matcher(string)
		matcher.matches
		new PathElement(matcher.group(1), Optional.ofNullable(matcher.group(2))
			.map[i|Integer.valueOf(i)], Collections.emptyMap)
	}

	@Data
	static class Context {
		MappingContext mappingContext
		Map mappingProcessors = newHashMap
		List xmlValidationErrors = newArrayList
		
		new(SynonymToEnumMapBuilder synonymToEnumMap) {
			mappingContext = new MappingContext(synonymToEnumMap.map)
		}
	}	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy